Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Allows results from CAST to compared. #9186

Merged
merged 3 commits into from Jun 8, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
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