use of io.confluent.ksql.execution.expression.tree.ArithmeticBinaryExpression 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" + "}))"));
}
use of io.confluent.ksql.execution.expression.tree.ArithmeticBinaryExpression in project ksql by confluentinc.
the class SqlToJavaVisitorTest method shouldProcessBasicJavaMath.
@Test
public void shouldProcessBasicJavaMath() {
// Given:
final Expression expression = new ArithmeticBinaryExpression(Operator.ADD, COL0, COL3);
// When:
final String javaExpression = sqlToJavaVisitor.process(expression);
// Then:
assertThat(javaExpression, equalTo("(COL0 + COL3)"));
}
use of io.confluent.ksql.execution.expression.tree.ArithmeticBinaryExpression in project ksql by confluentinc.
the class PartitionByParamsFactoryTest method shouldAppendNewKeyColumnsToValueIfPartitioningByMixOfColumnsAndExpressions.
@Test
public void shouldAppendNewKeyColumnsToValueIfPartitioningByMixOfColumnsAndExpressions() {
// Given:
final Mapper<GenericKey> mapper = partitionBy(ImmutableList.of(new ArithmeticBinaryExpression(Operator.ADD, new UnqualifiedColumnReferenceExp(COL0), new StringLiteral("-foo")), new UnqualifiedColumnReferenceExp(COL1), new FunctionCall(CONSTANT_UDF_NAME, ImmutableList.of(new UnqualifiedColumnReferenceExp(COL1))))).getMapper();
final ImmutableList<Object> originals = ImmutableList.copyOf(value.values());
// When:
final KeyValue<GenericKey, GenericRow> result = mapper.apply(key, value);
// Then:
assertThat(result.value, is(GenericRow.fromList(originals).append(OLD_KEY + "-foo").append(ConstantUdf.VALUE)));
}
use of io.confluent.ksql.execution.expression.tree.ArithmeticBinaryExpression in project ksql by confluentinc.
the class PartitionByParamsFactoryTest method shouldPropagateNullValueWhenPartitioningByMixOfKeyAndNonKeyExpressions.
@Test
public void shouldPropagateNullValueWhenPartitioningByMixOfKeyAndNonKeyExpressions() {
// Given:
final Mapper<GenericKey> mapper = partitionBy(ImmutableList.of(new ArithmeticBinaryExpression(Operator.ADD, new UnqualifiedColumnReferenceExp(COL0), new StringLiteral("-foo")), new UnqualifiedColumnReferenceExp(COL1))).getMapper();
// When:
final KeyValue<GenericKey, GenericRow> result = mapper.apply(key, null);
// Then:
assertThat(result.key, is(genericKey(OLD_KEY + "-foo", null)));
assertThat(result.value, is(nullValue()));
}
use of io.confluent.ksql.execution.expression.tree.ArithmeticBinaryExpression in project ksql by confluentinc.
the class PartitionByParamsFactoryTest method shouldPropagateNullValueWhenPartitioningByKeyExpression.
@Test
public void shouldPropagateNullValueWhenPartitioningByKeyExpression() {
// Given:
final Mapper<GenericKey> mapper = partitionBy(ImmutableList.of(new ArithmeticBinaryExpression(Operator.ADD, new UnqualifiedColumnReferenceExp(COL0), new StringLiteral("-foo")))).getMapper();
// When:
final KeyValue<GenericKey, GenericRow> result = mapper.apply(key, null);
// Then:
assertThat(result.key, is(genericKey((OLD_KEY + "-foo"))));
assertThat(result.value, is(nullValue()));
}
Aggregations