use of io.confluent.ksql.execution.expression.tree.IntegerLiteral in project ksql by confluentinc.
the class CreateSourcePropertiesTest method shouldGetKeyAndValueSchemaIdFromFormat.
@Test
public void shouldGetKeyAndValueSchemaIdFromFormat() {
// Given:
final CreateSourceProperties props = CreateSourceProperties.from(ImmutableMap.<String, Literal>builder().putAll(MINIMUM_VALID_PROPS).put(FORMAT_PROPERTY, new StringLiteral("AVRO")).put(KEY_SCHEMA_ID, new IntegerLiteral(123)).put(VALUE_SCHEMA_ID, new IntegerLiteral(456)).build());
// When / Then:
assertThat(props.getKeyFormat(SourceName.of("foo")).get().getProperties(), hasEntry(ConnectProperties.SCHEMA_ID, "123"));
assertThat(props.getValueFormat().get().getProperties(), hasEntry(ConnectProperties.SCHEMA_ID, "456"));
}
use of io.confluent.ksql.execution.expression.tree.IntegerLiteral in project ksql by confluentinc.
the class KsqlParserTest method shouldParseIntegerLiterals.
@Test
public void shouldParseIntegerLiterals() {
shouldParseNumericLiteral(0, new IntegerLiteral(0));
shouldParseNumericLiteral(10, new IntegerLiteral(10));
shouldParseNumericLiteral(Integer.MAX_VALUE, new IntegerLiteral(Integer.MAX_VALUE));
}
use of io.confluent.ksql.execution.expression.tree.IntegerLiteral in project ksql by confluentinc.
the class CreateSourceAsPropertiesTest method shouldGetKeyAndValueSchemaIdFromFormat.
@Test
public void shouldGetKeyAndValueSchemaIdFromFormat() {
// Given:
final CreateSourceAsProperties props = CreateSourceAsProperties.from(ImmutableMap.<String, Literal>builder().put(FORMAT_PROPERTY, new StringLiteral("AVRO")).put(KEY_SCHEMA_ID, new IntegerLiteral(123)).put(VALUE_SCHEMA_ID, new IntegerLiteral(456)).build());
// When / Then:
assertThat(props.getKeyFormatProperties("foo", "Avro"), hasEntry(ConnectProperties.SCHEMA_ID, "123"));
assertThat(props.getValueFormatProperties(), hasEntry(ConnectProperties.SCHEMA_ID, "456"));
}
use of io.confluent.ksql.execution.expression.tree.IntegerLiteral in project ksql by confluentinc.
the class SqlToJavaVisitorTest method shouldThrowOnSimpleCase.
@Test
public void shouldThrowOnSimpleCase() {
// Given:
final Expression expression = new SimpleCaseExpression(COL0, ImmutableList.of(new WhenClause(new IntegerLiteral(10), new StringLiteral("ten"))), empty());
// When:
assertThrows(UnsupportedOperationException.class, () -> sqlToJavaVisitor.process(expression));
}
use of io.confluent.ksql.execution.expression.tree.IntegerLiteral in project ksql by confluentinc.
the class SqlToJavaVisitorTest method shouldGenerateCorrectCodeForNestedLambdas.
@Test
public void shouldGenerateCorrectCodeForNestedLambdas() {
// Given:
final UdfFactory udfFactory = mock(UdfFactory.class);
final KsqlScalarFunction udf = mock(KsqlScalarFunction.class);
givenUdf("nested", udfFactory, udf, SqlTypes.DOUBLE);
when(udf.parameters()).thenReturn(ImmutableList.of(ArrayType.of(ParamTypes.DOUBLE), ParamTypes.DOUBLE, LambdaType.of(ImmutableList.of(ParamTypes.DOUBLE, ParamTypes.INTEGER), ParamTypes.INTEGER)));
final Expression expression = new ArithmeticBinaryExpression(Operator.ADD, new FunctionCall(FunctionName.of("nested"), ImmutableList.of(ARRAYCOL, new IntegerLiteral(0), new LambdaFunctionCall(ImmutableList.of("A", "B"), new ArithmeticBinaryExpression(Operator.ADD, new FunctionCall(FunctionName.of("nested"), ImmutableList.of(ARRAYCOL, new IntegerLiteral(0), new LambdaFunctionCall(ImmutableList.of("Q", "V"), new ArithmeticBinaryExpression(Operator.ADD, new LambdaVariable("Q"), new LambdaVariable("V"))))), new LambdaVariable("B"))))), new IntegerLiteral(5));
// When:
final String javaExpression = sqlToJavaVisitor.process(expression);
// Then
assertThat(javaExpression, equalTo("(((Double) nested_0.evaluate(COL4, (Double)NullSafe.apply(0,new Function() {\n" + " @Override\n" + " public Object apply(Object arg1) {\n" + " final Integer val = (Integer) arg1;\n" + " return val.doubleValue();\n" + " }\n" + "}), new BiFunction() {\n" + " @Override\n" + " public Object apply(Object arg1, Object arg2) {\n" + " final Double A = (Double) arg1;\n" + " final Integer B = (Integer) arg2;\n" + " return (((Double) nested_1.evaluate(COL4, (Double)NullSafe.apply(0,new Function() {\n" + " @Override\n" + " public Object apply(Object arg1) {\n" + " final Integer val = (Integer) arg1;\n" + " return val.doubleValue();\n" + " }\n" + "}), new BiFunction() {\n" + " @Override\n" + " public Object apply(Object arg1, Object arg2) {\n" + " final Double Q = (Double) arg1;\n" + " final Integer V = (Integer) arg2;\n" + " return (Q + V);\n" + " }\n" + "})) + B);\n" + " }\n" + "})) + 5)"));
}
Aggregations