Search in sources :

Example 56 with UnqualifiedColumnReferenceExp

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

the class PartitionByParamsFactoryTest method shouldPropagateNullValueWhenPartitioningByKey.

@Test
public void shouldPropagateNullValueWhenPartitioningByKey() {
    // Given:
    final Mapper<GenericKey> mapper = partitionBy(ImmutableList.of(new UnqualifiedColumnReferenceExp(COL0))).getMapper();
    // When:
    final KeyValue<GenericKey, GenericRow> result = mapper.apply(key, null);
    // Then:
    assertThat(result.key, is(genericKey((OLD_KEY))));
    assertThat(result.value, is(nullValue()));
}
Also used : GenericRow(io.confluent.ksql.GenericRow) GenericKey(io.confluent.ksql.GenericKey) UnqualifiedColumnReferenceExp(io.confluent.ksql.execution.expression.tree.UnqualifiedColumnReferenceExp) Test(org.junit.Test)

Example 57 with UnqualifiedColumnReferenceExp

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

the class PartitionByParamsFactoryTest method shouldNotChangeValueIfPartitioningByKeyColumnReference.

@Test
public void shouldNotChangeValueIfPartitioningByKeyColumnReference() {
    // Given:
    final Mapper<GenericKey> mapper = partitionBy(ImmutableList.of(new UnqualifiedColumnReferenceExp(COL0))).getMapper();
    final ImmutableList<Object> originals = ImmutableList.copyOf(value.values());
    // When:
    final KeyValue<GenericKey, GenericRow> result = mapper.apply(key, value);
    // Then:
    assertThat(result.value, is(GenericRow.fromList(originals)));
}
Also used : GenericRow(io.confluent.ksql.GenericRow) GenericKey(io.confluent.ksql.GenericKey) UnqualifiedColumnReferenceExp(io.confluent.ksql.execution.expression.tree.UnqualifiedColumnReferenceExp) Test(org.junit.Test)

Example 58 with UnqualifiedColumnReferenceExp

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

the class PartitionByParamsFactoryTest method shouldBuildResultSchemaWhenPartitioningByStructField.

@Test
public void shouldBuildResultSchemaWhenPartitioningByStructField() {
    // Given:
    final List<Expression> partitionBy = ImmutableList.of(new DereferenceExpression(Optional.empty(), new UnqualifiedColumnReferenceExp(COL3), "someField"));
    // When:
    final LogicalSchema resultSchema = PartitionByParamsFactory.buildSchema(SCHEMA, partitionBy, functionRegistry);
    // Then:
    assertThat(resultSchema, is(LogicalSchema.builder().keyColumn(ColumnName.of("someField"), SqlTypes.BIGINT).valueColumn(COL1, SqlTypes.INTEGER).valueColumn(COL2, SqlTypes.INTEGER).valueColumn(COL3, COL3_TYPE).valueColumn(SystemColumns.ROWTIME_NAME, SqlTypes.BIGINT).valueColumn(COL0, SqlTypes.STRING).valueColumn(ColumnName.of("someField"), SqlTypes.BIGINT).build()));
}
Also used : DereferenceExpression(io.confluent.ksql.execution.expression.tree.DereferenceExpression) ArithmeticBinaryExpression(io.confluent.ksql.execution.expression.tree.ArithmeticBinaryExpression) Expression(io.confluent.ksql.execution.expression.tree.Expression) DereferenceExpression(io.confluent.ksql.execution.expression.tree.DereferenceExpression) 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 59 with UnqualifiedColumnReferenceExp

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

the class PartitionByParamsFactoryTest method shouldPartitionByNullAnyRowsWhereFailedToExtractKey.

@Test
public void shouldPartitionByNullAnyRowsWhereFailedToExtractKey() {
    // Given:
    final Mapper<GenericKey> mapper = partitionBy(ImmutableList.of(FAILING_UDF, new UnqualifiedColumnReferenceExp(COL1))).getMapper();
    // When:
    final KeyValue<GenericKey, GenericRow> result = mapper.apply(key, value);
    // Then:
    assertThat(result.key, is(genericKey(null, COL1_VALUE)));
}
Also used : GenericRow(io.confluent.ksql.GenericRow) GenericKey(io.confluent.ksql.GenericKey) UnqualifiedColumnReferenceExp(io.confluent.ksql.execution.expression.tree.UnqualifiedColumnReferenceExp) Test(org.junit.Test)

Example 60 with UnqualifiedColumnReferenceExp

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

the class PartitionByParamsFactoryTest method shouldAppendNewKeyColumnToValueIfNotPartitioningByColumnReference.

@Test
public void shouldAppendNewKeyColumnToValueIfNotPartitioningByColumnReference() {
    // Given:
    final Mapper<GenericKey> mapper = partitionBy(ImmutableList.of(new FunctionCall(CONSTANT_UDF_NAME, ImmutableList.of(new UnqualifiedColumnReferenceExp(COL1))))).getMapper();
    final ImmutableList<Object> originals = ImmutableList.copyOf(value.values());
    // When:
    final KeyValue<GenericKey, GenericRow> result = mapper.apply(key, value);
    // Then:
    assertThat(result.value, is(GenericRow.fromList(originals).append(ConstantUdf.VALUE)));
}
Also used : GenericRow(io.confluent.ksql.GenericRow) GenericKey(io.confluent.ksql.GenericKey) FunctionCall(io.confluent.ksql.execution.expression.tree.FunctionCall) UnqualifiedColumnReferenceExp(io.confluent.ksql.execution.expression.tree.UnqualifiedColumnReferenceExp) 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