use of io.confluent.ksql.execution.expression.tree.IntegerLiteral 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.IntegerLiteral in project ksql by confluentinc.
the class CreateSourceProperties method withPartitions.
public CreateSourceProperties withPartitions(final int partitions) {
final Map<String, Literal> originals = props.copyOfOriginalLiterals();
originals.put(CommonCreateConfigs.SOURCE_NUMBER_OF_PARTITIONS, new IntegerLiteral(partitions));
return new CreateSourceProperties(originals, durationParser);
}
use of io.confluent.ksql.execution.expression.tree.IntegerLiteral in project ksql by confluentinc.
the class GenericExpressionResolverTest method shouldThrowIfCannotCoerce.
@Test
public void shouldThrowIfCannotCoerce() {
// Given:
final SqlType type = SqlTypes.array(SqlTypes.INTEGER);
final Expression exp = new IntegerLiteral(1);
// When:
final KsqlException e = assertThrows(KsqlException.class, () -> new GenericExpressionResolver(type, FIELD_NAME, registry, config, "insert value", false).resolve(exp));
// Then:
assertThat(e.getMessage(), containsString("Expected type ARRAY<INTEGER> for field `FOO` but got INTEGER(1)"));
}
use of io.confluent.ksql.execution.expression.tree.IntegerLiteral in project ksql by confluentinc.
the class AstSanitizerTest method shouldAllowDuplicateLambdaArgumentInSeparateExpression.
@Test
public void shouldAllowDuplicateLambdaArgumentInSeparateExpression() {
// Given:
final Statement stmt = givenQuery("SELECT TRANSFORM_ARRAY(Col4, X => X + 5, (X,Y) => Y + 5) FROM TEST1;");
// When:
final Query result = (Query) AstSanitizer.sanitize(stmt, META_STORE, true);
// Then:
assertThat(result.getSelect(), is(new Select(ImmutableList.of(new SingleColumn(new FunctionCall(FunctionName.of("TRANSFORM_ARRAY"), ImmutableList.of(column(TEST1_NAME, "COL4"), new LambdaFunctionCall(ImmutableList.of("X"), new ArithmeticBinaryExpression(Operator.ADD, new LambdaVariable("X"), new IntegerLiteral(5))), new LambdaFunctionCall(ImmutableList.of("X", "Y"), new ArithmeticBinaryExpression(Operator.ADD, new LambdaVariable("Y"), new IntegerLiteral(5))))), Optional.of(ColumnName.of("KSQL_COL_0")))))));
}
use of io.confluent.ksql.execution.expression.tree.IntegerLiteral in project ksql by confluentinc.
the class DefaultSchemaInjectorTest method shouldThrowIfCtasKeyTableElementsNotCompatibleExtraKey.
@Test
public void shouldThrowIfCtasKeyTableElementsNotCompatibleExtraKey() {
// Given:
givenFormatsAndProps("protobuf", null, ImmutableMap.of("KEY_SCHEMA_ID", new IntegerLiteral(42)));
givenDDLSchemaAndFormats(LOGICAL_SCHEMA_EXTRA_KEY, "protobuf", "avro", SerdeFeature.WRAP_SINGLES, SerdeFeature.UNWRAP_SINGLES);
// When:
final Exception e = assertThrows(KsqlException.class, () -> injector.inject(ctasStatement));
// Then:
// Then:
assertThat(e.getMessage(), containsString("The following key columns are changed, missing or reordered: " + "[`key1` STRING KEY]. Schema from schema registry is [`key` STRING KEY]"));
}
Aggregations