use of io.confluent.ksql.execution.expression.tree.StringLiteral 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.StringLiteral 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.StringLiteral 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.StringLiteral in project ksql by confluentinc.
the class SqlToJavaVisitorTest method shouldProcessCreateArrayExpressionCorrectly.
@Test
public void shouldProcessCreateArrayExpressionCorrectly() {
// Given:
Expression expression = new CreateArrayExpression(ImmutableList.of(new SubscriptExpression(MAPCOL, new StringLiteral("key1")), new DoubleLiteral(1.0d)));
// When:
String java = sqlToJavaVisitor.process(expression);
// Then:
assertThat(java, equalTo("((List)new ArrayBuilder(2)" + ".add( (new Supplier<Object>() {@Override public Object get() { try { return ((Double) ((java.util.Map)COL5).get(\"key1\")); } catch (Exception e) { " + onException("array item") + " }}}).get())" + ".add( (new Supplier<Object>() {@Override public Object get() { try { return 1E0; } catch (Exception e) { " + onException("array item") + " }}}).get()).build())"));
}
use of io.confluent.ksql.execution.expression.tree.StringLiteral 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