Skip to content

Commit

Permalink
fix: Allows results from CAST to compared. (#9186)
Browse files Browse the repository at this point in the history
* fix: Allows results from CAST to compared.

Address #9185
  • Loading branch information
jnh5y authored Jun 8, 2022
1 parent e12cb2d commit 3defb6b
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,8 @@ public static String generateApply(
final String mapperCode,
final Class<?> returnType
) {
return "(" + returnType.getSimpleName() + ")" + NullSafe.class.getSimpleName()
+ ".apply(" + inputCode + "," + mapperCode + ")";
return "((" + returnType.getSimpleName() + ")" + NullSafe.class.getSimpleName()
+ ".apply(" + inputCode + "," + mapperCode + "))";
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@

import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import io.confluent.ksql.execution.codegen.CodeGenTestUtil.Evaluator;
import io.confluent.ksql.execution.codegen.helpers.CastEvaluator;
import io.confluent.ksql.execution.expression.tree.ArithmeticBinaryExpression;
import io.confluent.ksql.execution.expression.tree.ArithmeticUnaryExpression;
Expand All @@ -64,6 +65,7 @@
import io.confluent.ksql.execution.expression.tree.LambdaFunctionCall;
import io.confluent.ksql.execution.expression.tree.LambdaVariable;
import io.confluent.ksql.execution.expression.tree.LikePredicate;
import io.confluent.ksql.execution.expression.tree.LongLiteral;
import io.confluent.ksql.execution.expression.tree.QualifiedColumnReferenceExp;
import io.confluent.ksql.execution.expression.tree.SearchedCaseExpression;
import io.confluent.ksql.execution.expression.tree.SimpleCaseExpression;
Expand Down Expand Up @@ -628,6 +630,20 @@ public void shouldGenerateCastDecimalToDoubleInBinaryExpression() {
assertThat(java, containsString(doubleCast));
}

@Test
public void shouldGenerateCastExpressionsWhichAreComparable() {
// Given:
final Expression cast = new Cast(new StringLiteral("2020-01-01"), new io.confluent.ksql.execution.expression.tree.Type(SqlTypes.DATE));
final ComparisonExpression exp = new ComparisonExpression(Type.GREATER_THAN_OR_EQUAL, cast, cast);

// When:
final String java = sqlToJavaVisitor.process(exp);

// Then:
final Evaluator evaluator = CodeGenTestUtil.cookCode(java, Boolean.class);
evaluator.evaluate(Collections.emptyList());
}

@Test
public void shouldGenerateCorrectCodeForDecimalSubtract() {
// Given:
Expand Down Expand Up @@ -1298,24 +1314,24 @@ public void shouldGenerateCorrectCodeForNestedLambdas() {
// Then
assertThat(
javaExpression, equalTo(
"(((Double) nested_0.evaluate(COL4, (Double)NullSafe.apply(0,new Function() {\n"
"(((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"
+ "})), 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"
+ " 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"
+ "})), new BiFunction() {\n"
+ " @Override\n"
+ " public Object apply(Object arg1, Object arg2) {\n"
+ " final Double Q = (Double) arg1;\n"
Expand Down

0 comments on commit 3defb6b

Please sign in to comment.