use of io.confluent.ksql.execution.expression.tree.Expression in project ksql by confluentinc.
the class GenericExpressionResolverTest method shouldParseTimestamp.
@Test
public void shouldParseTimestamp() {
// Given:
final SqlType type = SqlTypes.TIMESTAMP;
final Expression exp = new StringLiteral("2021-01-09T04:40:02");
// When:
Object o = new GenericExpressionResolver(type, FIELD_NAME, registry, config, "insert value", false).resolve(exp);
// Then:
assertTrue(o instanceof Timestamp);
assertThat(((Timestamp) o).getTime(), is(1610167202000L));
}
use of io.confluent.ksql.execution.expression.tree.Expression in project ksql by confluentinc.
the class GenericExpressionResolverTest method shouldParseTime.
@Test
public void shouldParseTime() {
// Given:
final SqlType type = SqlTypes.TIME;
final Expression exp = new StringLiteral("04:40:02");
// When:
Object o = new GenericExpressionResolver(type, FIELD_NAME, registry, config, "insert value", false).resolve(exp);
// Then:
assertTrue(o instanceof Time);
assertThat(((Time) o).getTime(), is(16802000L));
}
use of io.confluent.ksql.execution.expression.tree.Expression in project ksql by confluentinc.
the class UserRepartitionNodeTest method shouldResolveSelectToPartitionByColumn.
@Test
public void shouldResolveSelectToPartitionByColumn() {
// When:
final Expression result = repartitionNode.resolveSelect(0, rewrittenPartitionBy);
// Then:
assertThat(result, is(new UnqualifiedColumnReferenceExp(K0)));
}
use of io.confluent.ksql.execution.expression.tree.Expression in project ksql by confluentinc.
the class SqlToJavaVisitorTest method shouldThrowOnQualifiedColumnReference.
@Test
public void shouldThrowOnQualifiedColumnReference() {
// Given:
final Expression expression = new QualifiedColumnReferenceExp(of("foo"), ColumnName.of("bar"));
// When:
assertThrows(UnsupportedOperationException.class, () -> sqlToJavaVisitor.process(expression));
}
use of io.confluent.ksql.execution.expression.tree.Expression in project ksql by confluentinc.
the class SqlToJavaVisitorTest method shouldGenerateCorrectCodeForCaseStatementWith13Conditions.
@Test
public void shouldGenerateCorrectCodeForCaseStatementWith13Conditions() {
// Given:
final ImmutableList<Integer> numbers = ImmutableList.of(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12);
final ImmutableList<String> numberNames = ImmutableList.of("zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten", "eleven", "twelve");
final ImmutableList<WhenClause> arg = numbers.stream().map(n -> new WhenClause(new ComparisonExpression(ComparisonExpression.Type.EQUAL, COL7, new IntegerLiteral(n)), new StringLiteral(numberNames.get(n)))).collect(ImmutableList.toImmutableList());
final Expression expression = new SearchedCaseExpression(arg, Optional.empty());
// 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)(0)) == null) ? false : ((COL7 <= 0) && (COL7 >= 0))); }}, new Supplier<java.lang.String>() { @Override public java.lang.String get() { return \"zero\"; }}), SearchedCaseFunction.whenClause( new Supplier<Boolean>() { @Override public Boolean get() { return ((((Object)(COL7)) == null || ((Object)(1)) == null) ? false : ((COL7 <= 1) && (COL7 >= 1))); }}, new Supplier<java.lang.String>() { @Override public java.lang.String get() { return \"one\"; }}), SearchedCaseFunction.whenClause( new Supplier<Boolean>() { @Override public Boolean get() { return ((((Object)(COL7)) == null || ((Object)(2)) == null) ? false : ((COL7 <= 2) && (COL7 >= 2))); }}, new Supplier<java.lang.String>() { @Override public java.lang.String get() { return \"two\"; }}), SearchedCaseFunction.whenClause( new Supplier<Boolean>() { @Override public Boolean get() { return ((((Object)(COL7)) == null || ((Object)(3)) == null) ? false : ((COL7 <= 3) && (COL7 >= 3))); }}, new Supplier<java.lang.String>() { @Override public java.lang.String get() { return \"three\"; }}), SearchedCaseFunction.whenClause( new Supplier<Boolean>() { @Override public Boolean get() { return ((((Object)(COL7)) == null || ((Object)(4)) == null) ? false : ((COL7 <= 4) && (COL7 >= 4))); }}, new Supplier<java.lang.String>() { @Override public java.lang.String get() { return \"four\"; }}), SearchedCaseFunction.whenClause( new Supplier<Boolean>() { @Override public Boolean get() { return ((((Object)(COL7)) == null || ((Object)(5)) == null) ? false : ((COL7 <= 5) && (COL7 >= 5))); }}, new Supplier<java.lang.String>() { @Override public java.lang.String get() { return \"five\"; }}), SearchedCaseFunction.whenClause( new Supplier<Boolean>() { @Override public Boolean get() { return ((((Object)(COL7)) == null || ((Object)(6)) == null) ? false : ((COL7 <= 6) && (COL7 >= 6))); }}, new Supplier<java.lang.String>() { @Override public java.lang.String get() { return \"six\"; }}), SearchedCaseFunction.whenClause( new Supplier<Boolean>() { @Override public Boolean get() { return ((((Object)(COL7)) == null || ((Object)(7)) == null) ? false : ((COL7 <= 7) && (COL7 >= 7))); }}, new Supplier<java.lang.String>() { @Override public java.lang.String get() { return \"seven\"; }}), SearchedCaseFunction.whenClause( new Supplier<Boolean>() { @Override public Boolean get() { return ((((Object)(COL7)) == null || ((Object)(8)) == null) ? false : ((COL7 <= 8) && (COL7 >= 8))); }}, new Supplier<java.lang.String>() { @Override public java.lang.String get() { return \"eight\"; }}), SearchedCaseFunction.whenClause( new Supplier<Boolean>() { @Override public Boolean get() { return ((((Object)(COL7)) == null || ((Object)(9)) == null) ? false : ((COL7 <= 9) && (COL7 >= 9))); }}, new Supplier<java.lang.String>() { @Override public java.lang.String get() { return \"nine\"; }}), SearchedCaseFunction.whenClause( new Supplier<Boolean>() { @Override public Boolean get() { return ((((Object)(COL7)) == null || ((Object)(10)) == null) ? false : ((COL7 <= 10) && (COL7 >= 10))); }}, new Supplier<java.lang.String>() { @Override public java.lang.String get() { return \"ten\"; }}), SearchedCaseFunction.whenClause( new Supplier<Boolean>() { @Override public Boolean get() { return ((((Object)(COL7)) == null || ((Object)(11)) == null) ? false : ((COL7 <= 11) && (COL7 >= 11))); }}, new Supplier<java.lang.String>() { @Override public java.lang.String get() { return \"eleven\"; }}), SearchedCaseFunction.whenClause( new Supplier<Boolean>() { @Override public Boolean get() { return ((((Object)(COL7)) == null || ((Object)(12)) == null) ? false : ((COL7 <= 12) && (COL7 >= 12))); }}, new Supplier<java.lang.String>() { @Override public java.lang.String get() { return \"twelve\"; }}))), new Supplier<java.lang.String>() { @Override public java.lang.String get() { return null; }}))"));
}
Aggregations