use of io.confluent.ksql.execution.expression.tree.Expression in project ksql by confluentinc.
the class InterpretedExpressionTest method shouldEvaluateCastToMap.
@Test
public void shouldEvaluateCastToMap() {
// Given:
final Expression cast1 = new Cast(new CreateMapExpression(ImmutableMap.of(new StringLiteral("1"), new StringLiteral("2"), new StringLiteral("3"), new StringLiteral("4"))), new Type(SqlTypes.map(SqlTypes.INTEGER, SqlTypes.INTEGER)));
final Expression cast2 = new Cast(new CreateMapExpression(ImmutableMap.of(new DoubleLiteral(2.5), new StringLiteral("2"), new DoubleLiteral(3.5), new StringLiteral("4"))), new Type(SqlTypes.map(SqlTypes.STRING, SqlTypes.BIGINT)));
// When:
InterpretedExpression interpreter1 = interpreter(cast1);
InterpretedExpression interpreter2 = interpreter(cast2);
// Then:
assertThat(interpreter1.evaluate(ROW), is(ImmutableMap.of(1, 2, 3, 4)));
assertThat(interpreter2.evaluate(ROW), is(ImmutableMap.of("2.5", 2L, "3.5", 4L)));
}
use of io.confluent.ksql.execution.expression.tree.Expression in project ksql by confluentinc.
the class SqlToJavaVisitorTest method shouldGenerateCorrectCodeForLikePatternWithEscape.
@Test
public void shouldGenerateCorrectCodeForLikePatternWithEscape() {
// Given:
final Expression expression = new LikePredicate(COL1, new StringLiteral("%foo"), Optional.of('!'));
// When:
final String javaExpression = sqlToJavaVisitor.process(expression);
// Then:
assertThat(javaExpression, equalTo("LikeEvaluator.matches(COL1, \"%foo\", '!')"));
}
use of io.confluent.ksql.execution.expression.tree.Expression in project ksql by confluentinc.
the class GenericRecordFactory method resolveValues.
private static Map<ColumnName, Object> resolveValues(final List<ColumnName> columns, final List<Expression> expressions, final LogicalSchema schema, final FunctionRegistry functionRegistry, final KsqlConfig config) {
final Map<ColumnName, Object> values = new HashMap<>();
for (int i = 0; i < columns.size(); i++) {
final ColumnName column = columns.get(i);
final SqlType columnType = columnType(column, schema);
final Expression valueExp = expressions.get(i);
final Object value = new GenericExpressionResolver(columnType, column, functionRegistry, config, "insert value", false).resolve(valueExp);
values.put(column, value);
}
return values;
}
use of io.confluent.ksql.execution.expression.tree.Expression in project ksql by confluentinc.
the class ExpressionTreeRewriterTest method shouldRewriteInPredicate.
@Test
public void shouldRewriteInPredicate() {
// Given:
final InPredicate parsed = parseExpression("1 IN (1, 2, 3)");
when(processor.apply(parsed.getValue(), context)).thenReturn(expr1);
when(processor.apply(parsed.getValueList(), context)).thenReturn(inList);
// When:
final Expression rewritten = expressionRewriter.rewrite(parsed, context);
// Then:
assertThat(rewritten, equalTo(new InPredicate(parsed.getLocation(), expr1, inList)));
}
use of io.confluent.ksql.execution.expression.tree.Expression in project ksql by confluentinc.
the class ExpressionTreeRewriterTest method shouldRewriteDereferenceExpression.
@Test
public void shouldRewriteDereferenceExpression() {
// Given:
final DereferenceExpression parsed = parseExpression("col0->foo");
when(processor.apply(parsed.getBase(), context)).thenReturn(expr1);
// When:
final Expression rewritten = expressionRewriter.rewrite(parsed, context);
// Then:
assertThat(rewritten, equalTo(new DereferenceExpression(parsed.getLocation(), expr1, parsed.getFieldName())));
}
Aggregations