Search in sources :

Example 36 with GenericKey

use of io.confluent.ksql.GenericKey in project ksql by confluentinc.

the class PartitionByParamsFactoryTest method shouldPropagateNullValueWhenPartitioningByKeyExpression.

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

Example 37 with GenericKey

use of io.confluent.ksql.GenericKey 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 38 with GenericKey

use of io.confluent.ksql.GenericKey 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 39 with GenericKey

use of io.confluent.ksql.GenericKey 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 40 with GenericKey

use of io.confluent.ksql.GenericKey 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

GenericKey (io.confluent.ksql.GenericKey)147 GenericRow (io.confluent.ksql.GenericRow)100 Test (org.junit.Test)93 LogicalSchema (io.confluent.ksql.schema.ksql.LogicalSchema)24 Windowed (org.apache.kafka.streams.kstream.Windowed)20 WindowedRow (io.confluent.ksql.execution.streams.materialization.WindowedRow)14 PhysicalSchema (io.confluent.ksql.schema.ksql.PhysicalSchema)14 Materialized (org.apache.kafka.streams.kstream.Materialized)13 ValueAndTimestamp (org.apache.kafka.streams.state.ValueAndTimestamp)13 UnqualifiedColumnReferenceExp (io.confluent.ksql.execution.expression.tree.UnqualifiedColumnReferenceExp)12 MaterializationException (io.confluent.ksql.execution.streams.materialization.MaterializationException)9 IntegrationTest (io.confluent.common.utils.IntegrationTest)8 Materialization (io.confluent.ksql.execution.streams.materialization.Materialization)8 Row (io.confluent.ksql.execution.streams.materialization.Row)8 PersistentQueryMetadata (io.confluent.ksql.util.PersistentQueryMetadata)8 TimeWindow (org.apache.kafka.streams.kstream.internals.TimeWindow)8 IntegrationTest (org.apache.kafka.test.IntegrationTest)8 InOrder (org.mockito.InOrder)8 MaterializedTable (io.confluent.ksql.execution.streams.materialization.MaterializedTable)7 Objects (java.util.Objects)7