Search in sources :

Example 6 with PullProcessingContext

use of io.confluent.ksql.execution.streams.materialization.PullProcessingContext in project ksql by confluentinc.

the class ProjectOperatorTest method shouldCallTransformWithCorrectArguments.

@Test
public void shouldCallTransformWithCorrectArguments() {
    // Given:
    when(logicalNode.getAddAdditionalColumnsToIntermediateSchema()).thenReturn(true);
    when(logicalNode.getSchema()).thenReturn(OUTPUT_SCHEMA);
    when(logicalNode.getCompiledSelectExpressions()).thenReturn(Collections.emptyList());
    final ProjectOperator projectOperator = new ProjectOperator(logger, logicalNode, selectValueMapperFactorySupplier);
    projectOperator.addChild(child);
    final QueryRowImpl row = QueryRowImpl.of(INTERMEDIATE_SCHEMA_WITH_PSEUDO, A_KEY, Optional.empty(), GenericRow.genericRow("a", "b", A_ROWTIME, "k"), A_ROWTIME);
    when(child.next()).thenReturn(row);
    when(selectValueMapperFactorySupplier.create(any(), any())).thenReturn(selectValueMapper);
    when(selectValueMapper.getTransformer(logger)).thenReturn(transformer);
    when(transformer.transform(any(), any(), any())).thenReturn(GenericRow.genericRow("k", "a", "b"));
    projectOperator.open();
    // When:
    projectOperator.next();
    // Then:
    verify(transformer).transform(A_KEY, GenericRow.genericRow("a", "b", 12335L, "k", 12335L, "k"), new PullProcessingContext(12335L));
}
Also used : QueryRowImpl(io.confluent.ksql.physical.common.QueryRowImpl) PullProcessingContext(io.confluent.ksql.execution.streams.materialization.PullProcessingContext) Test(org.junit.Test)

Example 7 with PullProcessingContext

use of io.confluent.ksql.execution.streams.materialization.PullProcessingContext in project ksql by confluentinc.

the class ProjectOperatorTest method shouldProjectKeyAndValueWindowed.

@Test
public void shouldProjectKeyAndValueWindowed() {
    // Given:
    final LogicalSchema schema = LogicalSchema.builder().keyColumn(ColumnName.of("k0"), SqlTypes.STRING).valueColumn(ColumnName.of("v1"), SqlTypes.STRING).build();
    when(logicalNode.getAddAdditionalColumnsToIntermediateSchema()).thenReturn(true);
    when(logicalNode.getSchema()).thenReturn(schema);
    when(logicalNode.getCompiledSelectExpressions()).thenReturn(Collections.emptyList());
    final ProjectOperator projectOperator = new ProjectOperator(logger, logicalNode, selectValueMapperFactorySupplier);
    projectOperator.addChild(child);
    final QueryRowImpl windowedRow = QueryRowImpl.of(WINDOWED_INTERMEDIATE_SCHEMA_WITH_PSEUDO, A_KEY, Optional.of(A_WINDOW), GenericRow.genericRow("a", "b", A_ROWTIME, "k", A_WINDOW.start().toEpochMilli(), A_WINDOW.end().toEpochMilli()), A_ROWTIME);
    when(child.next()).thenReturn(windowedRow);
    when(selectValueMapperFactorySupplier.create(any(), any())).thenReturn(selectValueMapper);
    when(selectValueMapper.getTransformer(logger)).thenReturn(transformer);
    when(transformer.transform(A_KEY, windowedRow.value(), new PullProcessingContext(12335L))).thenReturn(GenericRow.genericRow("k", "b"));
    projectOperator.open();
    // When:
    QueryRow result = (QueryRow) projectOperator.next();
    // Then:
    final List<Object> expected = new ArrayList<>(windowedRow.key().values());
    expected.add(windowedRow.value().values().get(1));
    assertThat(result.value().values(), is(expected));
}
Also used : QueryRow(io.confluent.ksql.physical.common.QueryRow) QueryRowImpl(io.confluent.ksql.physical.common.QueryRowImpl) ArrayList(java.util.ArrayList) LogicalSchema(io.confluent.ksql.schema.ksql.LogicalSchema) PullProcessingContext(io.confluent.ksql.execution.streams.materialization.PullProcessingContext) Test(org.junit.Test)

Example 8 with PullProcessingContext

use of io.confluent.ksql.execution.streams.materialization.PullProcessingContext in project ksql by confluentinc.

the class ProjectOperatorTest method shouldProjectAllColumnsWhenSelectStarNonWindowed.

@Test
public void shouldProjectAllColumnsWhenSelectStarNonWindowed() {
    // Given:
    when(logicalNode.getSchema()).thenReturn(OUTPUT_SCHEMA);
    final ProjectOperator projectOperator = new ProjectOperator(logger, logicalNode, selectValueMapperFactorySupplier);
    projectOperator.addChild(child);
    final QueryRowImpl row = QueryRowImpl.of(INTERMEDIATE_SCHEMA_WITH_PSEUDO, A_KEY, Optional.empty(), GenericRow.genericRow("a", "b", A_ROWTIME, "k"), A_ROWTIME);
    when(child.next()).thenReturn(row);
    when(selectValueMapperFactorySupplier.create(any(), any())).thenReturn(selectValueMapper);
    when(selectValueMapper.getTransformer(logger)).thenReturn(transformer);
    when(transformer.transform(A_KEY, row.value(), new PullProcessingContext(12335L))).thenReturn(GenericRow.genericRow("k", "a", "b"));
    projectOperator.open();
    // When:
    QueryRow result = (QueryRow) projectOperator.next();
    // Then:
    final List<Object> expected = new ArrayList<>(row.key().values());
    expected.add("a");
    expected.add("b");
    assertThat(result.value().values(), is(expected));
}
Also used : QueryRow(io.confluent.ksql.physical.common.QueryRow) QueryRowImpl(io.confluent.ksql.physical.common.QueryRowImpl) ArrayList(java.util.ArrayList) PullProcessingContext(io.confluent.ksql.execution.streams.materialization.PullProcessingContext) Test(org.junit.Test)

Example 9 with PullProcessingContext

use of io.confluent.ksql.execution.streams.materialization.PullProcessingContext in project ksql by confluentinc.

the class ProjectOperatorTest method shouldProjectOnlyKeyNonWindowed.

@Test
public void shouldProjectOnlyKeyNonWindowed() {
    // Given:
    final LogicalSchema schema = LogicalSchema.builder().keyColumn(ColumnName.of("k0"), SqlTypes.STRING).build();
    when(logicalNode.getAddAdditionalColumnsToIntermediateSchema()).thenReturn(true);
    when(logicalNode.getSchema()).thenReturn(schema);
    when(logicalNode.getCompiledSelectExpressions()).thenReturn(Collections.emptyList());
    final ProjectOperator projectOperator = new ProjectOperator(logger, logicalNode, selectValueMapperFactorySupplier);
    projectOperator.addChild(child);
    final QueryRowImpl row = QueryRowImpl.of(INTERMEDIATE_SCHEMA_WITH_PSEUDO, A_KEY, Optional.empty(), GenericRow.genericRow("a", "b", A_ROWTIME, "k"), A_ROWTIME);
    when(child.next()).thenReturn(row);
    when(selectValueMapperFactorySupplier.create(any(), any())).thenReturn(selectValueMapper);
    when(selectValueMapper.getTransformer(logger)).thenReturn(transformer);
    when(transformer.transform(A_KEY, row.value(), new PullProcessingContext(12335L))).thenReturn(GenericRow.genericRow("k"));
    projectOperator.open();
    // When:
    QueryRow result = (QueryRow) projectOperator.next();
    // Then:
    assertThat(result.value().values(), is(row.key().values()));
}
Also used : QueryRow(io.confluent.ksql.physical.common.QueryRow) QueryRowImpl(io.confluent.ksql.physical.common.QueryRowImpl) LogicalSchema(io.confluent.ksql.schema.ksql.LogicalSchema) PullProcessingContext(io.confluent.ksql.execution.streams.materialization.PullProcessingContext) Test(org.junit.Test)

Example 10 with PullProcessingContext

use of io.confluent.ksql.execution.streams.materialization.PullProcessingContext in project ksql by confluentinc.

the class ProjectOperatorTest method shouldProjectAllColumnsWhenSelectStarWindowed.

@Test
public void shouldProjectAllColumnsWhenSelectStarWindowed() {
    // Given:
    when(logicalNode.getSchema()).thenReturn(WINDOWED_OUTPUT_SCHEMA);
    final ProjectOperator projectOperator = new ProjectOperator(logger, logicalNode, selectValueMapperFactorySupplier);
    projectOperator.addChild(child);
    final QueryRowImpl windowedRow = QueryRowImpl.of(WINDOWED_INTERMEDIATE_SCHEMA_WITH_PSEUDO, A_KEY, Optional.of(A_WINDOW), GenericRow.genericRow("a", "b", A_ROWTIME, "k", A_WINDOW.start().toEpochMilli(), A_WINDOW.end().toEpochMilli()), A_ROWTIME);
    when(child.next()).thenReturn(windowedRow);
    when(selectValueMapperFactorySupplier.create(any(), any())).thenReturn(selectValueMapper);
    when(selectValueMapper.getTransformer(logger)).thenReturn(transformer);
    when(transformer.transform(A_KEY, windowedRow.value(), new PullProcessingContext(A_ROWTIME))).thenReturn(GenericRow.genericRow("k", A_WINDOW.start().toEpochMilli(), A_WINDOW.end().toEpochMilli(), "a", "b"));
    projectOperator.open();
    // When:
    QueryRow result = (QueryRow) projectOperator.next();
    // Then:
    final List<Object> expected = new ArrayList<>(windowedRow.key().values());
    expected.add(windowedRow.window().get().start().toEpochMilli());
    expected.add(windowedRow.window().get().end().toEpochMilli());
    expected.add("a");
    expected.add("b");
    assertThat(result.value().values(), is(expected));
}
Also used : QueryRow(io.confluent.ksql.physical.common.QueryRow) QueryRowImpl(io.confluent.ksql.physical.common.QueryRowImpl) ArrayList(java.util.ArrayList) PullProcessingContext(io.confluent.ksql.execution.streams.materialization.PullProcessingContext) Test(org.junit.Test)

Aggregations

PullProcessingContext (io.confluent.ksql.execution.streams.materialization.PullProcessingContext)12 QueryRowImpl (io.confluent.ksql.physical.common.QueryRowImpl)11 Test (org.junit.Test)11 QueryRow (io.confluent.ksql.physical.common.QueryRow)8 LogicalSchema (io.confluent.ksql.schema.ksql.LogicalSchema)5 ArrayList (java.util.ArrayList)4 GenericRow (io.confluent.ksql.GenericRow)1