use of io.confluent.ksql.execution.expression.tree.LongLiteral in project ksql by confluentinc.
the class ExpressionFormatterTest method shouldFormatSimpleCaseExpression.
@Test
public void shouldFormatSimpleCaseExpression() {
final SimpleCaseExpression expression = new SimpleCaseExpression(new StringLiteral("operand"), Collections.singletonList(new WhenClause(new StringLiteral("foo"), new LongLiteral(1))), Optional.empty());
assertThat(ExpressionFormatter.formatExpression(expression), equalTo("(CASE 'operand' WHEN 'foo' THEN 1 END)"));
}
use of io.confluent.ksql.execution.expression.tree.LongLiteral in project ksql by confluentinc.
the class ExpressionFormatterTest method shouldFormatBetweenPredicate.
@Test
public void shouldFormatBetweenPredicate() {
final BetweenPredicate predicate = new BetweenPredicate(new StringLiteral("blah"), new LongLiteral(5), new LongLiteral(10));
assertThat(ExpressionFormatter.formatExpression(predicate), equalTo("('blah' BETWEEN 5 AND 10)"));
}
use of io.confluent.ksql.execution.expression.tree.LongLiteral in project ksql by confluentinc.
the class ParserUtil method visitIntegerLiteral.
public static Literal visitIntegerLiteral(final IntegerLiteralContext context) {
final Optional<NodeLocation> location = getLocation(context);
final long valueAsLong;
try {
valueAsLong = Long.parseLong(context.getText());
} catch (final NumberFormatException e) {
throw new ParsingException("Invalid numeric literal: " + context.getText(), location);
}
if (valueAsLong <= Integer.MAX_VALUE && valueAsLong >= Integer.MIN_VALUE) {
return new IntegerLiteral(location, (int) valueAsLong);
} else {
return new LongLiteral(location, valueAsLong);
}
}
use of io.confluent.ksql.execution.expression.tree.LongLiteral in project ksql by confluentinc.
the class GenericRecordFactoryTest method shouldThrowOnInsertRowoffset.
@Test
public void shouldThrowOnInsertRowoffset() {
// Given:
final LogicalSchema schema = LogicalSchema.builder().keyColumn(KEY, SqlTypes.STRING).valueColumn(COL0, SqlTypes.STRING).build();
final Expression exp = new StringLiteral("a");
when(ksqlConfig.getBoolean(KsqlConfig.KSQL_ROWPARTITION_ROWOFFSET_ENABLED)).thenReturn(true);
// When:
final KsqlException e = assertThrows(KsqlException.class, () -> recordFactory.build(ImmutableList.of(SystemColumns.ROWTIME_NAME, KEY, SystemColumns.ROWOFFSET_NAME), ImmutableList.of(new LongLiteral(1L), exp, exp), schema, DataSourceType.KSTREAM));
// Then:
assertThat(e.getMessage(), containsString("Inserting into column `ROWOFFSET` is not allowed."));
}
use of io.confluent.ksql.execution.expression.tree.LongLiteral in project ksql by confluentinc.
the class SqlPredicateTest method shouldCompileEvaluator.
@Test
public void shouldCompileEvaluator() {
// Given:
predicate = new SqlPredicate(new ComparisonExpression(Type.LESS_THAN, COL0, new LongLiteral(100)), SCHEMA, KSQL_CONFIG, functionRegistry);
transformer = predicate.getTransformer(processingLogger);
// When:
final Optional<GenericRow> result1 = transformer.transform("key", genericRow(99L), ctx);
final Optional<GenericRow> result2 = transformer.transform("key", genericRow(100L), ctx);
// Then:
assertThat(result1, is(not(Optional.empty())));
assertThat(result2, is(Optional.empty()));
}
Aggregations