Search in sources :

Example 6 with InPredicate

use of io.confluent.ksql.execution.expression.tree.InPredicate in project ksql by confluentinc.

the class ExpressionTypeManagerTest method shouldReturnBooleanForInPredicate.

@Test
public void shouldReturnBooleanForInPredicate() {
    // Given:
    final Expression expression = new InPredicate(TestExpressions.COL0, new InListExpression(ImmutableList.of(new IntegerLiteral(1), new IntegerLiteral(2))));
    // When:
    final SqlType result = expressionTypeManager.getExpressionSqlType(expression);
    // Then:
    assertThat(result, is(SqlTypes.BOOLEAN));
}
Also used : ArithmeticBinaryExpression(io.confluent.ksql.execution.expression.tree.ArithmeticBinaryExpression) Expression(io.confluent.ksql.execution.expression.tree.Expression) CreateMapExpression(io.confluent.ksql.execution.expression.tree.CreateMapExpression) DereferenceExpression(io.confluent.ksql.execution.expression.tree.DereferenceExpression) CreateArrayExpression(io.confluent.ksql.execution.expression.tree.CreateArrayExpression) CreateStructExpression(io.confluent.ksql.execution.expression.tree.CreateStructExpression) NotExpression(io.confluent.ksql.execution.expression.tree.NotExpression) SimpleCaseExpression(io.confluent.ksql.execution.expression.tree.SimpleCaseExpression) SubscriptExpression(io.confluent.ksql.execution.expression.tree.SubscriptExpression) InListExpression(io.confluent.ksql.execution.expression.tree.InListExpression) ComparisonExpression(io.confluent.ksql.execution.expression.tree.ComparisonExpression) SearchedCaseExpression(io.confluent.ksql.execution.expression.tree.SearchedCaseExpression) InListExpression(io.confluent.ksql.execution.expression.tree.InListExpression) SqlType(io.confluent.ksql.schema.ksql.types.SqlType) InPredicate(io.confluent.ksql.execution.expression.tree.InPredicate) IntegerLiteral(io.confluent.ksql.execution.expression.tree.IntegerLiteral) Test(org.junit.Test)

Example 7 with InPredicate

use of io.confluent.ksql.execution.expression.tree.InPredicate in project ksql by confluentinc.

the class ExpressionTreeRewriterTest method shouldRewriteInListExpression.

@Test
public void shouldRewriteInListExpression() {
    // Given:
    final InPredicate inPredicate = parseExpression("1 IN (1, 2, 3)");
    final InListExpression parsed = inPredicate.getValueList();
    when(processor.apply(parsed.getValues().get(0), context)).thenReturn(expr1);
    when(processor.apply(parsed.getValues().get(1), context)).thenReturn(expr2);
    when(processor.apply(parsed.getValues().get(2), context)).thenReturn(expr3);
    // When:
    final Expression rewritten = expressionRewriter.rewrite(parsed, context);
    // Then:
    assertThat(rewritten, equalTo(new InListExpression(parsed.getLocation(), ImmutableList.of(expr1, expr2, expr3))));
}
Also used : ArithmeticBinaryExpression(io.confluent.ksql.execution.expression.tree.ArithmeticBinaryExpression) LogicalBinaryExpression(io.confluent.ksql.execution.expression.tree.LogicalBinaryExpression) Expression(io.confluent.ksql.execution.expression.tree.Expression) CreateMapExpression(io.confluent.ksql.execution.expression.tree.CreateMapExpression) DereferenceExpression(io.confluent.ksql.execution.expression.tree.DereferenceExpression) ArithmeticUnaryExpression(io.confluent.ksql.execution.expression.tree.ArithmeticUnaryExpression) CreateArrayExpression(io.confluent.ksql.execution.expression.tree.CreateArrayExpression) CreateStructExpression(io.confluent.ksql.execution.expression.tree.CreateStructExpression) NotExpression(io.confluent.ksql.execution.expression.tree.NotExpression) SimpleCaseExpression(io.confluent.ksql.execution.expression.tree.SimpleCaseExpression) SubscriptExpression(io.confluent.ksql.execution.expression.tree.SubscriptExpression) InListExpression(io.confluent.ksql.execution.expression.tree.InListExpression) ComparisonExpression(io.confluent.ksql.execution.expression.tree.ComparisonExpression) SearchedCaseExpression(io.confluent.ksql.execution.expression.tree.SearchedCaseExpression) InListExpression(io.confluent.ksql.execution.expression.tree.InListExpression) InPredicate(io.confluent.ksql.execution.expression.tree.InPredicate) Test(org.junit.Test)

Example 8 with InPredicate

use of io.confluent.ksql.execution.expression.tree.InPredicate in project ksql by confluentinc.

the class ExpressionTreeRewriterTest method shouldRewriteInListUsingPlugin.

@Test
public void shouldRewriteInListUsingPlugin() {
    // Given:
    final InPredicate inPredicate = parseExpression("1 IN (1, 2, 3)");
    final InListExpression parsed = inPredicate.getValueList();
    // When/Then:
    shouldRewriteUsingPlugin(parsed);
}
Also used : InListExpression(io.confluent.ksql.execution.expression.tree.InListExpression) InPredicate(io.confluent.ksql.execution.expression.tree.InPredicate) Test(org.junit.Test)

Example 9 with InPredicate

use of io.confluent.ksql.execution.expression.tree.InPredicate in project ksql by confluentinc.

the class InterpretedExpressionTest method shouldEvaluateInPredicate.

@Test
public void shouldEvaluateInPredicate() {
    // Given:
    final Expression in1 = new InPredicate(COL7, new InListExpression(ImmutableList.of(new IntegerLiteral(4), new IntegerLiteral(6), new IntegerLiteral(8))));
    final Expression in2 = new InPredicate(COL1, new InListExpression(ImmutableList.of(new StringLiteral("a"), new StringLiteral("b"), new StringLiteral("c"))));
    // When:
    InterpretedExpression interpreter1 = interpreter(in1);
    InterpretedExpression interpreter2 = interpreter(in2);
    // Then:
    assertThat(interpreter1.evaluate(make(7, 1)), is(false));
    assertThat(interpreter1.evaluate(make(7, 6)), is(true));
    assertThat(interpreter1.evaluate(make(7, 8)), is(true));
    assertThat(interpreter1.evaluate(make(7, 10)), is(false));
    assertThat(interpreter2.evaluate(make(1, "z")), is(false));
    assertThat(interpreter2.evaluate(make(1, "a")), is(true));
    assertThat(interpreter2.evaluate(make(1, "c")), is(true));
}
Also used : StringLiteral(io.confluent.ksql.execution.expression.tree.StringLiteral) ArithmeticBinaryExpression(io.confluent.ksql.execution.expression.tree.ArithmeticBinaryExpression) LogicalBinaryExpression(io.confluent.ksql.execution.expression.tree.LogicalBinaryExpression) Expression(io.confluent.ksql.execution.expression.tree.Expression) CreateMapExpression(io.confluent.ksql.execution.expression.tree.CreateMapExpression) DereferenceExpression(io.confluent.ksql.execution.expression.tree.DereferenceExpression) ArithmeticUnaryExpression(io.confluent.ksql.execution.expression.tree.ArithmeticUnaryExpression) CreateArrayExpression(io.confluent.ksql.execution.expression.tree.CreateArrayExpression) CreateStructExpression(io.confluent.ksql.execution.expression.tree.CreateStructExpression) SubscriptExpression(io.confluent.ksql.execution.expression.tree.SubscriptExpression) InListExpression(io.confluent.ksql.execution.expression.tree.InListExpression) ComparisonExpression(io.confluent.ksql.execution.expression.tree.ComparisonExpression) SearchedCaseExpression(io.confluent.ksql.execution.expression.tree.SearchedCaseExpression) InListExpression(io.confluent.ksql.execution.expression.tree.InListExpression) InPredicate(io.confluent.ksql.execution.expression.tree.InPredicate) IntegerLiteral(io.confluent.ksql.execution.expression.tree.IntegerLiteral) Test(org.junit.Test)

Example 10 with InPredicate

use of io.confluent.ksql.execution.expression.tree.InPredicate in project ksql by confluentinc.

the class TermCompiler method visitInPredicate.

@Override
public Term visitInPredicate(final InPredicate inPredicate, final Context context) {
    final InPredicate preprocessed = InListEvaluator.preprocess(inPredicate, expressionTypeManager, context.getLambdaSqlTypeMapping());
    final Term value = process(preprocessed.getValue(), context);
    final List<Term> valueList = preprocessed.getValueList().getValues().stream().map(v -> process(v, context)).collect(ImmutableList.toImmutableList());
    return new InPredicateTerm(value, valueList);
}
Also used : TimestampLiteral(io.confluent.ksql.execution.expression.tree.TimestampLiteral) LogicalBinaryExpression(io.confluent.ksql.execution.expression.tree.LogicalBinaryExpression) GenericsUtil(io.confluent.ksql.function.GenericsUtil) Pair(io.confluent.ksql.util.Pair) Term(io.confluent.ksql.execution.interpreter.terms.Term) LambdaFunction3Term(io.confluent.ksql.execution.interpreter.terms.LambdaFunctionTerms.LambdaFunction3Term) LiteralTerms(io.confluent.ksql.execution.interpreter.terms.LiteralTerms) Map(java.util.Map) ColumnReferenceTerm(io.confluent.ksql.execution.interpreter.terms.ColumnReferenceTerm) ExpressionTypeManager(io.confluent.ksql.execution.util.ExpressionTypeManager) NullLiteral(io.confluent.ksql.execution.expression.tree.NullLiteral) SchemaConverters.sqlToFunctionConverter(io.confluent.ksql.schema.ksql.SchemaConverters.sqlToFunctionConverter) DecimalLiteral(io.confluent.ksql.execution.expression.tree.DecimalLiteral) BytesLiteral(io.confluent.ksql.execution.expression.tree.BytesLiteral) LambdaVariable(io.confluent.ksql.execution.expression.tree.LambdaVariable) Expression(io.confluent.ksql.execution.expression.tree.Expression) DereferenceExpression(io.confluent.ksql.execution.expression.tree.DereferenceExpression) LambdaFunction1Term(io.confluent.ksql.execution.interpreter.terms.LambdaFunctionTerms.LambdaFunction1Term) KsqlException(io.confluent.ksql.util.KsqlException) ArithmeticUnaryExpression(io.confluent.ksql.execution.expression.tree.ArithmeticUnaryExpression) Iterables(com.google.common.collect.Iterables) KsqlScalarFunction(io.confluent.ksql.function.KsqlScalarFunction) ExpressionVisitor(io.confluent.ksql.execution.expression.tree.ExpressionVisitor) UnqualifiedColumnReferenceExp(io.confluent.ksql.execution.expression.tree.UnqualifiedColumnReferenceExp) Field(io.confluent.ksql.execution.expression.tree.CreateStructExpression.Field) SqlMap(io.confluent.ksql.schema.ksql.types.SqlMap) SqlBaseType(io.confluent.ksql.schema.ksql.types.SqlBaseType) ArrayList(java.util.ArrayList) InListEvaluator(io.confluent.ksql.execution.codegen.helpers.InListEvaluator) BetweenPredicate(io.confluent.ksql.execution.expression.tree.BetweenPredicate) Cast(io.confluent.ksql.execution.expression.tree.Cast) LikeTerm(io.confluent.ksql.execution.interpreter.terms.LikeTerm) CoercionUtil(io.confluent.ksql.execution.util.CoercionUtil) FunctionCallTerm(io.confluent.ksql.execution.interpreter.terms.FunctionCallTerm) SqlType(io.confluent.ksql.schema.ksql.types.SqlType) Context(io.confluent.ksql.execution.interpreter.TermCompiler.Context) LogicalBinaryTerms(io.confluent.ksql.execution.interpreter.terms.LogicalBinaryTerms) FunctionTypeInfo(io.confluent.ksql.execution.util.FunctionArgumentsUtil.FunctionTypeInfo) Type(io.confluent.ksql.execution.expression.tree.Type) Kudf(io.confluent.ksql.function.udf.Kudf) ParamTypes(io.confluent.ksql.function.types.ParamTypes) InPredicate(io.confluent.ksql.execution.expression.tree.InPredicate) FunctionCall(io.confluent.ksql.execution.expression.tree.FunctionCall) SimpleCaseExpression(io.confluent.ksql.execution.expression.tree.SimpleCaseExpression) InListExpression(io.confluent.ksql.execution.expression.tree.InListExpression) ArrayType(io.confluent.ksql.function.types.ArrayType) SearchedCaseExpression(io.confluent.ksql.execution.expression.tree.SearchedCaseExpression) DecimalUtil(io.confluent.ksql.util.DecimalUtil) ArithmeticBinaryExpression(io.confluent.ksql.execution.expression.tree.ArithmeticBinaryExpression) UdfFactory(io.confluent.ksql.function.UdfFactory) ArgumentInfo(io.confluent.ksql.execution.util.FunctionArgumentsUtil.ArgumentInfo) SearchedCaseTerm(io.confluent.ksql.execution.interpreter.terms.SearchedCaseTerm) StructTerm(io.confluent.ksql.execution.interpreter.terms.StructTerm) StringLiteral(io.confluent.ksql.execution.expression.tree.StringLiteral) LambdaVariableTerm(io.confluent.ksql.execution.interpreter.terms.LambdaVariableTerm) DateLiteral(io.confluent.ksql.execution.expression.tree.DateLiteral) IntegerLiteral(io.confluent.ksql.execution.expression.tree.IntegerLiteral) LambdaFunctionCall(io.confluent.ksql.execution.expression.tree.LambdaFunctionCall) DoubleLiteral(io.confluent.ksql.execution.expression.tree.DoubleLiteral) Immutable(com.google.errorprone.annotations.Immutable) IntervalUnit(io.confluent.ksql.execution.expression.tree.IntervalUnit) CreateMapTerm(io.confluent.ksql.execution.interpreter.terms.CreateMapTerm) LambdaFunction2Term(io.confluent.ksql.execution.interpreter.terms.LambdaFunctionTerms.LambdaFunction2Term) SubscriptTerm(io.confluent.ksql.execution.interpreter.terms.SubscriptTerm) ImmutableMap(com.google.common.collect.ImmutableMap) NotTerm(io.confluent.ksql.execution.interpreter.terms.NotTerm) FunctionRegistry(io.confluent.ksql.function.FunctionRegistry) CreateMapExpression(io.confluent.ksql.execution.expression.tree.CreateMapExpression) WhenClause(io.confluent.ksql.execution.expression.tree.WhenClause) IsNullTerm(io.confluent.ksql.execution.interpreter.terms.IsNullTerm) IsNotNullPredicate(io.confluent.ksql.execution.expression.tree.IsNotNullPredicate) FunctionArgumentsUtil(io.confluent.ksql.execution.util.FunctionArgumentsUtil) KsqlConfig(io.confluent.ksql.util.KsqlConfig) Streams(com.google.common.collect.Streams) SqlArray(io.confluent.ksql.schema.ksql.types.SqlArray) LogicalSchema(io.confluent.ksql.schema.ksql.LogicalSchema) String.format(java.lang.String.format) CreateArrayTerm(io.confluent.ksql.execution.interpreter.terms.CreateArrayTerm) List(java.util.List) BooleanLiteral(io.confluent.ksql.execution.expression.tree.BooleanLiteral) Optional(java.util.Optional) Column(io.confluent.ksql.schema.ksql.Column) DereferenceTerm(io.confluent.ksql.execution.interpreter.terms.DereferenceTerm) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings) ArrayAccess(io.confluent.ksql.execution.codegen.helpers.ArrayAccess) IsNullPredicate(io.confluent.ksql.execution.expression.tree.IsNullPredicate) ParamType(io.confluent.ksql.function.types.ParamType) CreateArrayExpression(io.confluent.ksql.execution.expression.tree.CreateArrayExpression) HashMap(java.util.HashMap) LongLiteral(io.confluent.ksql.execution.expression.tree.LongLiteral) ImmutableList(com.google.common.collect.ImmutableList) QualifiedColumnReferenceExp(io.confluent.ksql.execution.expression.tree.QualifiedColumnReferenceExp) SchemaConverters(io.confluent.ksql.schema.ksql.SchemaConverters) TimeLiteral(io.confluent.ksql.execution.expression.tree.TimeLiteral) CreateStructExpression(io.confluent.ksql.execution.expression.tree.CreateStructExpression) IsNotNullTerm(io.confluent.ksql.execution.interpreter.terms.IsNotNullTerm) NotExpression(io.confluent.ksql.execution.expression.tree.NotExpression) InPredicateTerm(io.confluent.ksql.execution.interpreter.terms.InPredicateTerm) LikePredicate(io.confluent.ksql.execution.expression.tree.LikePredicate) SubscriptExpression(io.confluent.ksql.execution.expression.tree.SubscriptExpression) ComparisonExpression(io.confluent.ksql.execution.expression.tree.ComparisonExpression) Term(io.confluent.ksql.execution.interpreter.terms.Term) LambdaFunction3Term(io.confluent.ksql.execution.interpreter.terms.LambdaFunctionTerms.LambdaFunction3Term) ColumnReferenceTerm(io.confluent.ksql.execution.interpreter.terms.ColumnReferenceTerm) LambdaFunction1Term(io.confluent.ksql.execution.interpreter.terms.LambdaFunctionTerms.LambdaFunction1Term) LikeTerm(io.confluent.ksql.execution.interpreter.terms.LikeTerm) FunctionCallTerm(io.confluent.ksql.execution.interpreter.terms.FunctionCallTerm) SearchedCaseTerm(io.confluent.ksql.execution.interpreter.terms.SearchedCaseTerm) StructTerm(io.confluent.ksql.execution.interpreter.terms.StructTerm) LambdaVariableTerm(io.confluent.ksql.execution.interpreter.terms.LambdaVariableTerm) CreateMapTerm(io.confluent.ksql.execution.interpreter.terms.CreateMapTerm) LambdaFunction2Term(io.confluent.ksql.execution.interpreter.terms.LambdaFunctionTerms.LambdaFunction2Term) SubscriptTerm(io.confluent.ksql.execution.interpreter.terms.SubscriptTerm) NotTerm(io.confluent.ksql.execution.interpreter.terms.NotTerm) IsNullTerm(io.confluent.ksql.execution.interpreter.terms.IsNullTerm) CreateArrayTerm(io.confluent.ksql.execution.interpreter.terms.CreateArrayTerm) DereferenceTerm(io.confluent.ksql.execution.interpreter.terms.DereferenceTerm) IsNotNullTerm(io.confluent.ksql.execution.interpreter.terms.IsNotNullTerm) InPredicateTerm(io.confluent.ksql.execution.interpreter.terms.InPredicateTerm) InPredicate(io.confluent.ksql.execution.expression.tree.InPredicate) InPredicateTerm(io.confluent.ksql.execution.interpreter.terms.InPredicateTerm)

Aggregations

InListExpression (io.confluent.ksql.execution.expression.tree.InListExpression)12 InPredicate (io.confluent.ksql.execution.expression.tree.InPredicate)12 Expression (io.confluent.ksql.execution.expression.tree.Expression)10 Test (org.junit.Test)10 ComparisonExpression (io.confluent.ksql.execution.expression.tree.ComparisonExpression)9 ArithmeticBinaryExpression (io.confluent.ksql.execution.expression.tree.ArithmeticBinaryExpression)7 ArithmeticUnaryExpression (io.confluent.ksql.execution.expression.tree.ArithmeticUnaryExpression)7 CreateArrayExpression (io.confluent.ksql.execution.expression.tree.CreateArrayExpression)7 CreateMapExpression (io.confluent.ksql.execution.expression.tree.CreateMapExpression)7 CreateStructExpression (io.confluent.ksql.execution.expression.tree.CreateStructExpression)7 SearchedCaseExpression (io.confluent.ksql.execution.expression.tree.SearchedCaseExpression)7 SubscriptExpression (io.confluent.ksql.execution.expression.tree.SubscriptExpression)7 DereferenceExpression (io.confluent.ksql.execution.expression.tree.DereferenceExpression)6 IntegerLiteral (io.confluent.ksql.execution.expression.tree.IntegerLiteral)6 LogicalBinaryExpression (io.confluent.ksql.execution.expression.tree.LogicalBinaryExpression)6 SimpleCaseExpression (io.confluent.ksql.execution.expression.tree.SimpleCaseExpression)6 NotExpression (io.confluent.ksql.execution.expression.tree.NotExpression)5 StringLiteral (io.confluent.ksql.execution.expression.tree.StringLiteral)4 SqlType (io.confluent.ksql.schema.ksql.types.SqlType)4 UnqualifiedColumnReferenceExp (io.confluent.ksql.execution.expression.tree.UnqualifiedColumnReferenceExp)3