use of io.confluent.ksql.execution.expression.tree.IntegerLiteral in project ksql by confluentinc.
the class DefaultSchemaInjectorTest method shouldThrowIfCsasKeyTableElementsNotCompatibleWrongKeyType.
@Test
public void shouldThrowIfCsasKeyTableElementsNotCompatibleWrongKeyType() {
// Given:
givenFormatsAndProps("protobuf", null, ImmutableMap.of("KEY_SCHEMA_ID", new IntegerLiteral(42)));
givenDDLSchemaAndFormats(LOGICAL_SCHEMA_INT_KEY, "protobuf", "avro", SerdeFeature.WRAP_SINGLES, SerdeFeature.UNWRAP_SINGLES);
// When:
final Exception e = assertThrows(KsqlException.class, () -> injector.inject(csasStatement));
// Then:
assertThat(e.getMessage(), containsString("The following key columns are changed, missing or reordered: " + "[`key` INTEGER KEY]. Schema from schema registry is [`key` STRING KEY]"));
}
use of io.confluent.ksql.execution.expression.tree.IntegerLiteral in project ksql by confluentinc.
the class DefaultSchemaInjectorTest method shouldThrowWhenTableElementsAndValueSchemaIdPresent.
@Test
public void shouldThrowWhenTableElementsAndValueSchemaIdPresent() {
// Given:
givenFormatsAndProps("protobuf", "avro", ImmutableMap.of("VALUE_SCHEMA_ID", new IntegerLiteral(42)));
when(ct.getElements()).thenReturn(SOME_VALUE_ELEMENTS);
// When:
final Exception e = assertThrows(KsqlException.class, () -> injector.inject(ctStatement));
// Then:
assertThat(e.getMessage(), containsString("Table elements and VALUE_SCHEMA_ID cannot both exist for create statement."));
}
use of io.confluent.ksql.execution.expression.tree.IntegerLiteral in project ksql by confluentinc.
the class SqlToJavaVisitorTest method shouldHandleFunctionCallsWithGenerics.
@Test
public void shouldHandleFunctionCallsWithGenerics() {
// Given:
final UdfFactory udfFactory = mock(UdfFactory.class);
final KsqlScalarFunction udf = mock(KsqlScalarFunction.class);
givenUdf("FOO", udfFactory, udf, SqlTypes.STRING);
when(udf.parameters()).thenReturn(ImmutableList.of(GenericType.of("T"), GenericType.of("T")));
// When:
final String javaExpression = sqlToJavaVisitor.process(new FunctionCall(FunctionName.of("FOO"), ImmutableList.of(new IntegerLiteral(1), new IntegerLiteral(1))));
// Then:
assertThat(javaExpression, is("((String) FOO_0.evaluate(1, 1))"));
}
use of io.confluent.ksql.execution.expression.tree.IntegerLiteral in project ksql by confluentinc.
the class SqlToJavaVisitorTest method shouldGenerateCorrectCodeForCaseStatementWith13Conditions.
@Test
public void shouldGenerateCorrectCodeForCaseStatementWith13Conditions() {
// Given:
final ImmutableList<Integer> numbers = ImmutableList.of(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12);
final ImmutableList<String> numberNames = ImmutableList.of("zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten", "eleven", "twelve");
final ImmutableList<WhenClause> arg = numbers.stream().map(n -> new WhenClause(new ComparisonExpression(ComparisonExpression.Type.EQUAL, COL7, new IntegerLiteral(n)), new StringLiteral(numberNames.get(n)))).collect(ImmutableList.toImmutableList());
final Expression expression = new SearchedCaseExpression(arg, Optional.empty());
// When:
final String javaExpression = sqlToJavaVisitor.process(expression);
// ThenL
assertThat(javaExpression, equalTo("((java.lang.String)SearchedCaseFunction.searchedCaseFunction(ImmutableList.copyOf(Arrays.asList( SearchedCaseFunction.whenClause( new Supplier<Boolean>() { @Override public Boolean get() { return ((((Object)(COL7)) == null || ((Object)(0)) == null) ? false : ((COL7 <= 0) && (COL7 >= 0))); }}, new Supplier<java.lang.String>() { @Override public java.lang.String get() { return \"zero\"; }}), SearchedCaseFunction.whenClause( new Supplier<Boolean>() { @Override public Boolean get() { return ((((Object)(COL7)) == null || ((Object)(1)) == null) ? false : ((COL7 <= 1) && (COL7 >= 1))); }}, new Supplier<java.lang.String>() { @Override public java.lang.String get() { return \"one\"; }}), SearchedCaseFunction.whenClause( new Supplier<Boolean>() { @Override public Boolean get() { return ((((Object)(COL7)) == null || ((Object)(2)) == null) ? false : ((COL7 <= 2) && (COL7 >= 2))); }}, new Supplier<java.lang.String>() { @Override public java.lang.String get() { return \"two\"; }}), SearchedCaseFunction.whenClause( new Supplier<Boolean>() { @Override public Boolean get() { return ((((Object)(COL7)) == null || ((Object)(3)) == null) ? false : ((COL7 <= 3) && (COL7 >= 3))); }}, new Supplier<java.lang.String>() { @Override public java.lang.String get() { return \"three\"; }}), SearchedCaseFunction.whenClause( new Supplier<Boolean>() { @Override public Boolean get() { return ((((Object)(COL7)) == null || ((Object)(4)) == null) ? false : ((COL7 <= 4) && (COL7 >= 4))); }}, new Supplier<java.lang.String>() { @Override public java.lang.String get() { return \"four\"; }}), SearchedCaseFunction.whenClause( new Supplier<Boolean>() { @Override public Boolean get() { return ((((Object)(COL7)) == null || ((Object)(5)) == null) ? false : ((COL7 <= 5) && (COL7 >= 5))); }}, new Supplier<java.lang.String>() { @Override public java.lang.String get() { return \"five\"; }}), SearchedCaseFunction.whenClause( new Supplier<Boolean>() { @Override public Boolean get() { return ((((Object)(COL7)) == null || ((Object)(6)) == null) ? false : ((COL7 <= 6) && (COL7 >= 6))); }}, new Supplier<java.lang.String>() { @Override public java.lang.String get() { return \"six\"; }}), SearchedCaseFunction.whenClause( new Supplier<Boolean>() { @Override public Boolean get() { return ((((Object)(COL7)) == null || ((Object)(7)) == null) ? false : ((COL7 <= 7) && (COL7 >= 7))); }}, new Supplier<java.lang.String>() { @Override public java.lang.String get() { return \"seven\"; }}), SearchedCaseFunction.whenClause( new Supplier<Boolean>() { @Override public Boolean get() { return ((((Object)(COL7)) == null || ((Object)(8)) == null) ? false : ((COL7 <= 8) && (COL7 >= 8))); }}, new Supplier<java.lang.String>() { @Override public java.lang.String get() { return \"eight\"; }}), SearchedCaseFunction.whenClause( new Supplier<Boolean>() { @Override public Boolean get() { return ((((Object)(COL7)) == null || ((Object)(9)) == null) ? false : ((COL7 <= 9) && (COL7 >= 9))); }}, new Supplier<java.lang.String>() { @Override public java.lang.String get() { return \"nine\"; }}), SearchedCaseFunction.whenClause( new Supplier<Boolean>() { @Override public Boolean get() { return ((((Object)(COL7)) == null || ((Object)(10)) == null) ? false : ((COL7 <= 10) && (COL7 >= 10))); }}, new Supplier<java.lang.String>() { @Override public java.lang.String get() { return \"ten\"; }}), SearchedCaseFunction.whenClause( new Supplier<Boolean>() { @Override public Boolean get() { return ((((Object)(COL7)) == null || ((Object)(11)) == null) ? false : ((COL7 <= 11) && (COL7 >= 11))); }}, new Supplier<java.lang.String>() { @Override public java.lang.String get() { return \"eleven\"; }}), SearchedCaseFunction.whenClause( new Supplier<Boolean>() { @Override public Boolean get() { return ((((Object)(COL7)) == null || ((Object)(12)) == null) ? false : ((COL7 <= 12) && (COL7 >= 12))); }}, new Supplier<java.lang.String>() { @Override public java.lang.String get() { return \"twelve\"; }}))), new Supplier<java.lang.String>() { @Override public java.lang.String get() { return null; }}))"));
}
use of io.confluent.ksql.execution.expression.tree.IntegerLiteral in project ksql by confluentinc.
the class SqlToJavaVisitorTest method shouldGenerateCorrectCodeForFunctionWithMultipleLambdas.
@Test
public void shouldGenerateCorrectCodeForFunctionWithMultipleLambdas() {
// Given:
final UdfFactory udfFactory = mock(UdfFactory.class);
final KsqlScalarFunction udf = mock(KsqlScalarFunction.class);
givenUdf("function", udfFactory, udf, SqlTypes.STRING);
when(udf.parameters()).thenReturn(ImmutableList.of(ArrayType.of(ParamTypes.DOUBLE), ParamTypes.STRING, LambdaType.of(ImmutableList.of(ParamTypes.DOUBLE, ParamTypes.STRING), ParamTypes.DOUBLE), LambdaType.of(ImmutableList.of(ParamTypes.DOUBLE, ParamTypes.STRING), ParamTypes.STRING)));
final Expression expression = new FunctionCall(FunctionName.of("function"), ImmutableList.of(ARRAYCOL, COL1, new LambdaFunctionCall(ImmutableList.of("X", "S"), new ArithmeticBinaryExpression(Operator.ADD, new LambdaVariable("X"), new LambdaVariable("X"))), new LambdaFunctionCall(ImmutableList.of("X", "S"), new SearchedCaseExpression(ImmutableList.of(new WhenClause(new ComparisonExpression(ComparisonExpression.Type.LESS_THAN, new LambdaVariable("X"), new IntegerLiteral(10)), new StringLiteral("test")), new WhenClause(new ComparisonExpression(ComparisonExpression.Type.LESS_THAN, new LambdaVariable("X"), new IntegerLiteral(100)), new StringLiteral("test2"))), Optional.of(new LambdaVariable("S"))))));
// When:
final String javaExpression = sqlToJavaVisitor.process(expression);
// Then
assertThat(javaExpression, equalTo("((String) function_0.evaluate(COL4, COL1, new BiFunction() {\n" + " @Override\n" + " public Object apply(Object arg1, Object arg2) {\n" + " final Double X = (Double) arg1;\n" + " final String S = (String) arg2;\n" + " return (X + X);\n" + " }\n" + "}, new BiFunction() {\n" + " @Override\n" + " public Object apply(Object arg1, Object arg2) {\n" + " final Double X = (Double) arg1;\n" + " final String S = (String) arg2;\n" + " return ((java.lang.String)SearchedCaseFunction.searchedCaseFunction(ImmutableList.copyOf(Arrays.asList( SearchedCaseFunction.whenClause( new Supplier<Boolean>() { @Override public Boolean get() { return ((((Object)(X)) == null || ((Object)(10)) == null) ? false : (X < 10)); }}, new Supplier<java.lang.String>() { @Override public java.lang.String get() { return \"test\"; }}), SearchedCaseFunction.whenClause( new Supplier<Boolean>() { @Override public Boolean get() { return ((((Object)(X)) == null || ((Object)(100)) == null) ? false : (X < 100)); }}, new Supplier<java.lang.String>() { @Override public java.lang.String get() { return \"test2\"; }}))), new Supplier<java.lang.String>() { @Override public java.lang.String get() { return S; }}));\n" + " }\n" + "}))"));
}
Aggregations