Search in sources :

Example 11 with UnqualifiedColumnReferenceExp

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

the class QueryProjectNodeTest method shouldBuildPullQueryOutputSchemaSelectKeyAndWindowBounds.

@Test
public void shouldBuildPullQueryOutputSchemaSelectKeyAndWindowBounds() {
    // Given:
    when(keyFormat.isWindowed()).thenReturn(true);
    when(source.getSchema()).thenReturn(INPUT_SCHEMA.withPseudoAndKeyColsInValue(true));
    final UnqualifiedColumnReferenceExp windowstartRef = new UnqualifiedColumnReferenceExp(SystemColumns.WINDOWSTART_NAME);
    final UnqualifiedColumnReferenceExp windowendRef = new UnqualifiedColumnReferenceExp(SystemColumns.WINDOWEND_NAME);
    selects = ImmutableList.<SelectItem>builder().add(new SingleColumn(windowstartRef, Optional.of(SystemColumns.WINDOWSTART_NAME))).add((new SingleColumn(windowendRef, Optional.of(SystemColumns.WINDOWEND_NAME)))).add((new SingleColumn(K_REF, Optional.of(K)))).build();
    when(analysis.getSelectColumnNames()).thenReturn(ImmutableSet.of(SystemColumns.WINDOWSTART_NAME, SystemColumns.WINDOWEND_NAME, K));
    // When:
    final QueryProjectNode projectNode = new QueryProjectNode(NODE_ID, source, selects, metaStore, ksqlConfig, analysis, true, plannerOptions, false);
    // Then:
    final LogicalSchema expected = LogicalSchema.builder().keyColumn(SystemColumns.WINDOWSTART_NAME, SqlTypes.BIGINT).keyColumn(SystemColumns.WINDOWEND_NAME, SqlTypes.BIGINT).keyColumn(K, SqlTypes.STRING).build();
    assertThat(expected, is(projectNode.getSchema()));
}
Also used : LogicalSchema(io.confluent.ksql.schema.ksql.LogicalSchema) SingleColumn(io.confluent.ksql.parser.tree.SingleColumn) UnqualifiedColumnReferenceExp(io.confluent.ksql.execution.expression.tree.UnqualifiedColumnReferenceExp) Test(org.junit.Test)

Example 12 with UnqualifiedColumnReferenceExp

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

the class QueryProjectNodeTest method shouldBuildPullQueryOutputSchemaSelectValueAndWindowBounds.

@Test
public void shouldBuildPullQueryOutputSchemaSelectValueAndWindowBounds() {
    // Given:
    when(keyFormat.isWindowed()).thenReturn(true);
    when(source.getSchema()).thenReturn(INPUT_SCHEMA.withPseudoAndKeyColsInValue(true));
    final UnqualifiedColumnReferenceExp windowstartRef = new UnqualifiedColumnReferenceExp(SystemColumns.WINDOWSTART_NAME);
    final UnqualifiedColumnReferenceExp windowendRef = new UnqualifiedColumnReferenceExp(SystemColumns.WINDOWEND_NAME);
    selects = ImmutableList.<SelectItem>builder().add(new SingleColumn(windowstartRef, Optional.of(SystemColumns.WINDOWSTART_NAME))).add((new SingleColumn(windowendRef, Optional.of(SystemColumns.WINDOWEND_NAME)))).add((new SingleColumn(COL0_REF, Optional.of(COL0)))).build();
    when(analysis.getSelectColumnNames()).thenReturn(ImmutableSet.of(SystemColumns.WINDOWSTART_NAME, SystemColumns.WINDOWEND_NAME, COL0));
    // When:
    final QueryProjectNode projectNode = new QueryProjectNode(NODE_ID, source, selects, metaStore, ksqlConfig, analysis, true, plannerOptions, false);
    // Then:
    final LogicalSchema expected = LogicalSchema.builder().keyColumn(SystemColumns.WINDOWSTART_NAME, SqlTypes.BIGINT).keyColumn(SystemColumns.WINDOWEND_NAME, SqlTypes.BIGINT).valueColumn(COL0, SqlTypes.STRING).build();
    assertThat(expected, is(projectNode.getSchema()));
}
Also used : LogicalSchema(io.confluent.ksql.schema.ksql.LogicalSchema) SingleColumn(io.confluent.ksql.parser.tree.SingleColumn) UnqualifiedColumnReferenceExp(io.confluent.ksql.execution.expression.tree.UnqualifiedColumnReferenceExp) Test(org.junit.Test)

Example 13 with UnqualifiedColumnReferenceExp

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

the class QueryFilterNodeTest method shouldExtractKeyValueAndWindowBoundsFromExpressionWithEQWindowEnd.

@Test
public void shouldExtractKeyValueAndWindowBoundsFromExpressionWithEQWindowEnd() {
    // 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);
    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(), new WindowRange(Range.singleton(Instant.ofEpochMilli(2)), null, null)))));
}
Also used : LogicalBinaryExpression(io.confluent.ksql.execution.expression.tree.LogicalBinaryExpression) ComparisonExpression(io.confluent.ksql.execution.expression.tree.ComparisonExpression) 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 14 with UnqualifiedColumnReferenceExp

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

the class QueryFilterNodeTest method shouldThrowIfNonConvertibleType.

@Test
public void shouldThrowIfNonConvertibleType() {
    // Given:
    final Expression expression = new ComparisonExpression(Type.EQUAL, new UnqualifiedColumnReferenceExp(ColumnName.of("K")), new StringLiteral("foo"));
    // When:
    final KsqlException e = assertThrows(KsqlException.class, () -> new QueryFilterNode(NODE_ID, source, expression, metaStore, ksqlConfig, false, plannerOptions));
    // Then:
    assertThat(e.getMessage(), containsString("'foo' can not be converted to the type of the key column: K INTEGER KEY"));
}
Also used : 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) KsqlException(io.confluent.ksql.util.KsqlException) UnqualifiedColumnReferenceExp(io.confluent.ksql.execution.expression.tree.UnqualifiedColumnReferenceExp) Test(org.junit.Test)

Example 15 with UnqualifiedColumnReferenceExp

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

the class QueryFilterNodeTest method shouldExtractKeyValueFromExpressionEquals_multipleDisjuncts.

@Test
public void shouldExtractKeyValueFromExpressionEquals_multipleDisjuncts() {
    // Given:
    final Expression keyExp1 = new ComparisonExpression(Type.EQUAL, new UnqualifiedColumnReferenceExp(ColumnName.of("K")), new IntegerLiteral(1));
    final Expression keyExp2 = new ComparisonExpression(Type.EQUAL, new UnqualifiedColumnReferenceExp(ColumnName.of("K")), new IntegerLiteral(2));
    final Expression expression = new LogicalBinaryExpression(LogicalBinaryExpression.Type.OR, keyExp1, keyExp2);
    QueryFilterNode filterNode = new QueryFilterNode(NODE_ID, source, expression, metaStore, ksqlConfig, false, plannerOptions);
    // When:
    final List<LookupConstraint> keys = filterNode.getLookupConstraints();
    // Then:
    assertThat(filterNode.isWindowed(), is(false));
    assertThat(keys.size(), is(2));
    final KeyConstraint keyConstraint1 = (KeyConstraint) keys.get(0);
    assertThat(keyConstraint1.getKey(), is(GenericKey.genericKey(1)));
    assertThat(keyConstraint1.getWindowBounds(), is(Optional.empty()));
    final KeyConstraint keyConstraint2 = (KeyConstraint) keys.get(1);
    assertThat(keyConstraint2.getKey(), is(GenericKey.genericKey(2)));
    assertThat(keyConstraint2.getWindowBounds(), is(Optional.empty()));
}
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

UnqualifiedColumnReferenceExp (io.confluent.ksql.execution.expression.tree.UnqualifiedColumnReferenceExp)152 Test (org.junit.Test)138 Expression (io.confluent.ksql.execution.expression.tree.Expression)85 ComparisonExpression (io.confluent.ksql.execution.expression.tree.ComparisonExpression)79 InListExpression (io.confluent.ksql.execution.expression.tree.InListExpression)59 ArithmeticUnaryExpression (io.confluent.ksql.execution.expression.tree.ArithmeticUnaryExpression)57 LogicalBinaryExpression (io.confluent.ksql.execution.expression.tree.LogicalBinaryExpression)55 IntegerLiteral (io.confluent.ksql.execution.expression.tree.IntegerLiteral)45 KsqlException (io.confluent.ksql.util.KsqlException)32 LogicalSchema (io.confluent.ksql.schema.ksql.LogicalSchema)29 ArithmeticBinaryExpression (io.confluent.ksql.execution.expression.tree.ArithmeticBinaryExpression)26 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)22 StringLiteral (io.confluent.ksql.execution.expression.tree.StringLiteral)18 DereferenceExpression (io.confluent.ksql.execution.expression.tree.DereferenceExpression)17 GenericKey (io.confluent.ksql.GenericKey)12 WindowBounds (io.confluent.ksql.planner.plan.QueryFilterNode.WindowBounds)12 GenericRow (io.confluent.ksql.GenericRow)11 PlanNode (io.confluent.ksql.planner.plan.PlanNode)11 WindowRange (io.confluent.ksql.planner.plan.QueryFilterNode.WindowBounds.WindowRange)11 CreateArrayExpression (io.confluent.ksql.execution.expression.tree.CreateArrayExpression)10