use of io.confluent.ksql.execution.expression.tree.ComparisonExpression in project ksql by confluentinc.
the class SqlToJavaVisitorTest method shouldGenerateCorrectCodeForDateStringEQ.
@Test
public void shouldGenerateCorrectCodeForDateStringEQ() {
// Given:
final ComparisonExpression compExp = new ComparisonExpression(Type.EQUAL, DATECOL, new StringLiteral("2021-06-23"));
// When:
final String java = sqlToJavaVisitor.process(compExp);
// Then:
assertThat(java, containsString("(COL13.compareTo(SqlTimeTypes.parseDate(\"2021-06-23\")) == 0)"));
}
use of io.confluent.ksql.execution.expression.tree.ComparisonExpression in project ksql by confluentinc.
the class SqlToJavaVisitorTest method shouldGenerateCorrectCodeForCaseStatement.
@Test
public void shouldGenerateCorrectCodeForCaseStatement() {
// Given:
final Expression expression = new SearchedCaseExpression(ImmutableList.of(new WhenClause(new ComparisonExpression(ComparisonExpression.Type.LESS_THAN, COL7, new IntegerLiteral(10)), new StringLiteral("small")), new WhenClause(new ComparisonExpression(ComparisonExpression.Type.LESS_THAN, COL7, new IntegerLiteral(100)), new StringLiteral("medium"))), Optional.of(new StringLiteral("large")));
// 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)(10)) == null) ? false : (COL7 < 10)); }}, new Supplier<java.lang.String>() { @Override public java.lang.String get() { return \"small\"; }}), SearchedCaseFunction.whenClause( new Supplier<Boolean>() { @Override public Boolean get() { return ((((Object)(COL7)) == null || ((Object)(100)) == null) ? false : (COL7 < 100)); }}, new Supplier<java.lang.String>() { @Override public java.lang.String get() { return \"medium\"; }}))), new Supplier<java.lang.String>() { @Override public java.lang.String get() { return \"large\"; }}))"));
}
use of io.confluent.ksql.execution.expression.tree.ComparisonExpression in project ksql by confluentinc.
the class SqlToJavaVisitorTest method shouldGenerateCorrectCodeForTimeStringEQ.
@Test
public void shouldGenerateCorrectCodeForTimeStringEQ() {
// Given:
final ComparisonExpression compExp = new ComparisonExpression(Type.EQUAL, TIMECOL, new StringLiteral("01:23:45"));
// When:
final String java = sqlToJavaVisitor.process(compExp);
// Then:
assertThat(java, containsString("(COL12.compareTo(SqlTimeTypes.parseTime(\"01:23:45\")) == 0)"));
}
use of io.confluent.ksql.execution.expression.tree.ComparisonExpression in project ksql by confluentinc.
the class SqlToJavaVisitorTest method shouldThrowOnTimestampTimeLEQ.
@Test
public void shouldThrowOnTimestampTimeLEQ() {
// Given:
final ComparisonExpression compExp = new ComparisonExpression(Type.LESS_THAN_OR_EQUAL, TIMESTAMPCOL, TIMECOL);
// Then:
final Exception e = assertThrows(KsqlException.class, () -> sqlToJavaVisitor.process(compExp));
assertThat(e.getMessage(), is("Unexpected comparison to TIME: TIMESTAMP"));
}
use of io.confluent.ksql.execution.expression.tree.ComparisonExpression in project ksql by confluentinc.
the class SqlToJavaVisitorTest method shouldGenerateCorrectCodeForTimestampStringGEQ.
@Test
public void shouldGenerateCorrectCodeForTimestampStringGEQ() {
// Given:
final ComparisonExpression compExp = new ComparisonExpression(Type.GREATER_THAN_OR_EQUAL, new StringLiteral("2020-01-01T00:00:00"), TIMESTAMPCOL);
// When:
final String java = sqlToJavaVisitor.process(compExp);
// Then:
assertThat(java, containsString("(SqlTimeTypes.parseTimestamp(\"2020-01-01T00:00:00\").compareTo(COL10) >= 0)"));
}
Aggregations