Search in sources :

Example 11 with LogicalBinaryExpression

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

the class QueryFilterNodeTest method shouldReturnKeyConstraintString.

@Test
public void shouldReturnKeyConstraintString() {
    // Given:
    when(plannerOptions.getTableScansEnabled()).thenReturn(true);
    final LogicalSchema schema = LogicalSchema.builder().keyColumn(ColumnName.of("K1"), SqlTypes.STRING).valueColumn(ColumnName.of("C1"), SqlTypes.INTEGER).build();
    when(source.getSchema()).thenReturn(schema);
    final Expression keyExp1 = new ComparisonExpression(Type.GREATER_THAN, new UnqualifiedColumnReferenceExp(ColumnName.of("K1")), new StringLiteral("v1"));
    final Expression keyExp2 = new ComparisonExpression(Type.EQUAL, new UnqualifiedColumnReferenceExp(ColumnName.of("K1")), new StringLiteral("v2"));
    final Expression expression = new LogicalBinaryExpression(LogicalBinaryExpression.Type.AND, keyExp1, keyExp2);
    QueryFilterNode filterNode = new QueryFilterNode(NODE_ID, source, expression, metaStore, ksqlConfig, false, plannerOptions);
    // When:
    final List<LookupConstraint> keys = filterNode.getLookupConstraints();
    // Then:
    assertThat(keys.size(), is(1));
    assertThat(keys.get(0), instanceOf(KeyConstraint.class));
    final KeyConstraint keyConstraint = (KeyConstraint) keys.get(0);
    assertThat(keyConstraint.getKey(), is(GenericKey.genericKey("v2")));
    assertThat(keyConstraint.getOperator(), is(KeyConstraint.ConstraintOperator.EQUAL));
}
Also used : LogicalBinaryExpression(io.confluent.ksql.execution.expression.tree.LogicalBinaryExpression) ComparisonExpression(io.confluent.ksql.execution.expression.tree.ComparisonExpression) StringLiteral(io.confluent.ksql.execution.expression.tree.StringLiteral) LogicalBinaryExpression(io.confluent.ksql.execution.expression.tree.LogicalBinaryExpression) Expression(io.confluent.ksql.execution.expression.tree.Expression) InListExpression(io.confluent.ksql.execution.expression.tree.InListExpression) ComparisonExpression(io.confluent.ksql.execution.expression.tree.ComparisonExpression) ArithmeticUnaryExpression(io.confluent.ksql.execution.expression.tree.ArithmeticUnaryExpression) LogicalSchema(io.confluent.ksql.schema.ksql.LogicalSchema) UnqualifiedColumnReferenceExp(io.confluent.ksql.execution.expression.tree.UnqualifiedColumnReferenceExp) Test(org.junit.Test)

Example 12 with LogicalBinaryExpression

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

the class QueryFilterNodeTest method shouldExtractKeyValueAndWindowBoundsFromExpressionWithGTWindowStartText.

@Test
public void shouldExtractKeyValueAndWindowBoundsFromExpressionWithGTWindowStartText() {
    // Given:
    final Expression keyExp = new ComparisonExpression(Type.EQUAL, new UnqualifiedColumnReferenceExp(ColumnName.of("K")), new IntegerLiteral(1));
    final Expression windowStart = new ComparisonExpression(Type.GREATER_THAN, new UnqualifiedColumnReferenceExp(ColumnName.of("WINDOWSTART")), new StringLiteral("2020-01-01"));
    final Expression expression = new LogicalBinaryExpression(LogicalBinaryExpression.Type.AND, keyExp, windowStart);
    QueryFilterNode filterNode = new QueryFilterNode(NODE_ID, source, expression, metaStore, ksqlConfig, true, plannerOptions);
    // When:
    final List<LookupConstraint> keys = filterNode.getLookupConstraints();
    // Then:
    assertThat(filterNode.isWindowed(), is(true));
    assertThat(keys.size(), is(1));
    final KeyConstraint keyConstraint = (KeyConstraint) keys.get(0);
    assertThat(keyConstraint.getKey(), is(GenericKey.genericKey(1)));
    assertThat(keyConstraint.getWindowBounds(), is(Optional.of(new WindowBounds(new WindowRange(null, null, Range.downTo(Instant.ofEpochMilli(1577836800_000L), BoundType.OPEN)), new WindowRange()))));
}
Also used : LogicalBinaryExpression(io.confluent.ksql.execution.expression.tree.LogicalBinaryExpression) ComparisonExpression(io.confluent.ksql.execution.expression.tree.ComparisonExpression) StringLiteral(io.confluent.ksql.execution.expression.tree.StringLiteral) WindowBounds(io.confluent.ksql.planner.plan.QueryFilterNode.WindowBounds) LogicalBinaryExpression(io.confluent.ksql.execution.expression.tree.LogicalBinaryExpression) Expression(io.confluent.ksql.execution.expression.tree.Expression) InListExpression(io.confluent.ksql.execution.expression.tree.InListExpression) ComparisonExpression(io.confluent.ksql.execution.expression.tree.ComparisonExpression) ArithmeticUnaryExpression(io.confluent.ksql.execution.expression.tree.ArithmeticUnaryExpression) WindowRange(io.confluent.ksql.planner.plan.QueryFilterNode.WindowBounds.WindowRange) UnqualifiedColumnReferenceExp(io.confluent.ksql.execution.expression.tree.UnqualifiedColumnReferenceExp) IntegerLiteral(io.confluent.ksql.execution.expression.tree.IntegerLiteral) Test(org.junit.Test)

Example 13 with LogicalBinaryExpression

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

the class QueryFilterNodeTest method shouldThrowOnGTAndGTEComparisonsForSameBound.

@Test
public void shouldThrowOnGTAndGTEComparisonsForSameBound() {
    // Given:
    final Expression keyExp = new ComparisonExpression(Type.EQUAL, new UnqualifiedColumnReferenceExp(ColumnName.of("K")), new IntegerLiteral(1));
    final Expression windowStart = new ComparisonExpression(Type.GREATER_THAN, new UnqualifiedColumnReferenceExp(ColumnName.of("WINDOWSTART")), new IntegerLiteral(2));
    final Expression windowEnd = new ComparisonExpression(Type.GREATER_THAN_OR_EQUAL, new UnqualifiedColumnReferenceExp(ColumnName.of("WINDOWSTART")), new IntegerLiteral(3));
    final Expression expressionA = new LogicalBinaryExpression(LogicalBinaryExpression.Type.AND, keyExp, windowStart);
    final Expression expression = new LogicalBinaryExpression(LogicalBinaryExpression.Type.AND, expressionA, windowEnd);
    // When:
    final KsqlException e = assertThrows(KsqlException.class, () -> new QueryFilterNode(NODE_ID, source, expression, metaStore, ksqlConfig, true, plannerOptions));
    // Then:
    assertThat(e.getMessage(), containsString("Duplicate `WINDOWSTART` bounds on: GREATER_THAN"));
}
Also used : LogicalBinaryExpression(io.confluent.ksql.execution.expression.tree.LogicalBinaryExpression) ComparisonExpression(io.confluent.ksql.execution.expression.tree.ComparisonExpression) LogicalBinaryExpression(io.confluent.ksql.execution.expression.tree.LogicalBinaryExpression) Expression(io.confluent.ksql.execution.expression.tree.Expression) InListExpression(io.confluent.ksql.execution.expression.tree.InListExpression) ComparisonExpression(io.confluent.ksql.execution.expression.tree.ComparisonExpression) ArithmeticUnaryExpression(io.confluent.ksql.execution.expression.tree.ArithmeticUnaryExpression) KsqlException(io.confluent.ksql.util.KsqlException) UnqualifiedColumnReferenceExp(io.confluent.ksql.execution.expression.tree.UnqualifiedColumnReferenceExp) IntegerLiteral(io.confluent.ksql.execution.expression.tree.IntegerLiteral) Test(org.junit.Test)

Example 14 with LogicalBinaryExpression

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

the class QueryFilterNodeTest method shouldThrowOnUsageOfWindowBoundOnNonwindowedTable.

@Test
public void shouldThrowOnUsageOfWindowBoundOnNonwindowedTable() {
    // Given:
    final Expression keyExp = new ComparisonExpression(Type.EQUAL, new UnqualifiedColumnReferenceExp(ColumnName.of("K")), new IntegerLiteral(1));
    final Expression windowStart = new ComparisonExpression(Type.EQUAL, new UnqualifiedColumnReferenceExp(ColumnName.of("WINDOWEND")), new IntegerLiteral(2));
    final Expression expression = new LogicalBinaryExpression(LogicalBinaryExpression.Type.AND, keyExp, windowStart);
    // When:
    final KsqlException e = assertThrows(KsqlException.class, () -> new QueryFilterNode(NODE_ID, source, expression, metaStore, ksqlConfig, false, plannerOptions));
    // Then:
    assertThat(e.getMessage(), containsString("Cannot use WINDOWSTART/WINDOWEND on non-windowed source."));
}
Also used : LogicalBinaryExpression(io.confluent.ksql.execution.expression.tree.LogicalBinaryExpression) ComparisonExpression(io.confluent.ksql.execution.expression.tree.ComparisonExpression) LogicalBinaryExpression(io.confluent.ksql.execution.expression.tree.LogicalBinaryExpression) Expression(io.confluent.ksql.execution.expression.tree.Expression) InListExpression(io.confluent.ksql.execution.expression.tree.InListExpression) ComparisonExpression(io.confluent.ksql.execution.expression.tree.ComparisonExpression) ArithmeticUnaryExpression(io.confluent.ksql.execution.expression.tree.ArithmeticUnaryExpression) KsqlException(io.confluent.ksql.util.KsqlException) UnqualifiedColumnReferenceExp(io.confluent.ksql.execution.expression.tree.UnqualifiedColumnReferenceExp) IntegerLiteral(io.confluent.ksql.execution.expression.tree.IntegerLiteral) Test(org.junit.Test)

Example 15 with LogicalBinaryExpression

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

the class QueryFilterNodeTest method shouldSupportMultiRangeExpressionsUsingTableScan.

@Test
public void shouldSupportMultiRangeExpressionsUsingTableScan() {
    // Given:
    when(source.getSchema()).thenReturn(MULTI_KEY_SCHEMA);
    final Expression expression1 = new ComparisonExpression(Type.GREATER_THAN, new UnqualifiedColumnReferenceExp(ColumnName.of("K1")), new IntegerLiteral(1));
    final Expression expression2 = new ComparisonExpression(Type.GREATER_THAN, new UnqualifiedColumnReferenceExp(ColumnName.of("K2")), new IntegerLiteral(2));
    final Expression expression = new LogicalBinaryExpression(LogicalBinaryExpression.Type.AND, expression1, expression2);
    expectTableScan(expression, false);
}
Also used : LogicalBinaryExpression(io.confluent.ksql.execution.expression.tree.LogicalBinaryExpression) ComparisonExpression(io.confluent.ksql.execution.expression.tree.ComparisonExpression) LogicalBinaryExpression(io.confluent.ksql.execution.expression.tree.LogicalBinaryExpression) Expression(io.confluent.ksql.execution.expression.tree.Expression) InListExpression(io.confluent.ksql.execution.expression.tree.InListExpression) ComparisonExpression(io.confluent.ksql.execution.expression.tree.ComparisonExpression) ArithmeticUnaryExpression(io.confluent.ksql.execution.expression.tree.ArithmeticUnaryExpression) UnqualifiedColumnReferenceExp(io.confluent.ksql.execution.expression.tree.UnqualifiedColumnReferenceExp) IntegerLiteral(io.confluent.ksql.execution.expression.tree.IntegerLiteral) Test(org.junit.Test)

Aggregations

LogicalBinaryExpression (io.confluent.ksql.execution.expression.tree.LogicalBinaryExpression)37 Test (org.junit.Test)37 ComparisonExpression (io.confluent.ksql.execution.expression.tree.ComparisonExpression)35 Expression (io.confluent.ksql.execution.expression.tree.Expression)35 ArithmeticUnaryExpression (io.confluent.ksql.execution.expression.tree.ArithmeticUnaryExpression)33 InListExpression (io.confluent.ksql.execution.expression.tree.InListExpression)33 UnqualifiedColumnReferenceExp (io.confluent.ksql.execution.expression.tree.UnqualifiedColumnReferenceExp)32 IntegerLiteral (io.confluent.ksql.execution.expression.tree.IntegerLiteral)29 WindowBounds (io.confluent.ksql.planner.plan.QueryFilterNode.WindowBounds)11 WindowRange (io.confluent.ksql.planner.plan.QueryFilterNode.WindowBounds.WindowRange)11 KsqlException (io.confluent.ksql.util.KsqlException)10 StringLiteral (io.confluent.ksql.execution.expression.tree.StringLiteral)6 LogicalSchema (io.confluent.ksql.schema.ksql.LogicalSchema)4 ArithmeticBinaryExpression (io.confluent.ksql.execution.expression.tree.ArithmeticBinaryExpression)3 BooleanLiteral (io.confluent.ksql.execution.expression.tree.BooleanLiteral)3 CreateArrayExpression (io.confluent.ksql.execution.expression.tree.CreateArrayExpression)3 CreateMapExpression (io.confluent.ksql.execution.expression.tree.CreateMapExpression)3 CreateStructExpression (io.confluent.ksql.execution.expression.tree.CreateStructExpression)3 DereferenceExpression (io.confluent.ksql.execution.expression.tree.DereferenceExpression)3 SearchedCaseExpression (io.confluent.ksql.execution.expression.tree.SearchedCaseExpression)3