use of io.confluent.ksql.execution.streams.materialization.PullProcessingContext in project ksql by confluentinc.
the class ProjectOperator method next.
@Override
public Object next() {
final QueryRow row = (QueryRow) child.next();
if (row == null) {
return null;
}
if (row.getOffsetRange().isPresent()) {
return row;
}
final GenericRow intermediate = PhysicalOperatorUtil.getIntermediateRow(row, logicalNode.getAddAdditionalColumnsToIntermediateSchema());
if (logicalNode.getIsSelectStar()) {
return QueryRowImpl.of(logicalNode.getSchema(), GenericKey.genericKey(), Optional.empty(), GenericRow.fromList(createRowForSelectStar(intermediate)), row.rowTime());
}
final GenericRow mapped = transformer.transform(row.key(), intermediate, new PullProcessingContext(row.rowTime()));
validateProjection(mapped, logicalNode.getSchema());
return QueryRowImpl.of(logicalNode.getSchema(), GenericKey.genericKey(), Optional.empty(), GenericRow.fromList(mapped.values()), row.rowTime());
}
use of io.confluent.ksql.execution.streams.materialization.PullProcessingContext in project ksql by confluentinc.
the class ProjectOperatorTest method shouldProjectOnlyWindowStartWindowed.
@Test
public void shouldProjectOnlyWindowStartWindowed() {
// Given:
final LogicalSchema schema = LogicalSchema.builder().valueColumn(SystemColumns.WINDOWSTART_NAME, SqlTypes.BIGINT).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(A_WINDOW.start().toEpochMilli()));
projectOperator.open();
// When:
QueryRow result = (QueryRow) projectOperator.next();
// Then:
assertThat(result.value().values(), is(ImmutableList.of(A_WINDOW.start().toEpochMilli())));
}
use of io.confluent.ksql.execution.streams.materialization.PullProcessingContext in project ksql by confluentinc.
the class ProjectOperatorTest method shouldCallTransformWithCorrectArgumentsWindowed.
@Test
public void shouldCallTransformWithCorrectArgumentsWindowed() {
// 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 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(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", A_WINDOW.start().toEpochMilli(), A_WINDOW.end().toEpochMilli(), 12335L, "k", A_WINDOW.start().toEpochMilli(), A_WINDOW.end().toEpochMilli()), new PullProcessingContext(12335L));
}
use of io.confluent.ksql.execution.streams.materialization.PullProcessingContext in project ksql by confluentinc.
the class ProjectOperatorTest method shouldProjectKeyAndValueNonWindowed.
@Test
public void shouldProjectKeyAndValueNonWindowed() {
// 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 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", "b"));
projectOperator.open();
// When:
QueryRow result = (QueryRow) projectOperator.next();
// Then:
final List<Object> expected = new ArrayList<>(row.key().values());
expected.add(row.value().values().get(1));
assertThat(result.value().values(), is(expected));
}
use of io.confluent.ksql.execution.streams.materialization.PullProcessingContext in project ksql by confluentinc.
the class SelectOperatorTest method shouldSelectKeyNonWindowed.
@Test
public void shouldSelectKeyNonWindowed() {
// Given:
when(logicalNode.getAddAdditionalColumnsToIntermediateSchema()).thenReturn(true);
when(logicalNode.getIntermediateSchema()).thenReturn(INTERMEDIATE_SCHEMA_WITH_PSEUDO);
when(predicateFactory.create(any(), any())).thenReturn(sqlPredicate);
final SelectOperator selectOperator = new SelectOperator(logicalNode, logger, predicateFactory);
selectOperator.addChild(child);
final QueryRowImpl row = QueryRowImpl.of(OUTPUT_SCHEMA, A_KEY, Optional.empty(), GenericRow.genericRow("a", "b"), A_ROWTIME);
when(child.next()).thenReturn(row);
when(sqlPredicate.getTransformer(logger)).thenReturn(transformer);
final QueryRowImpl intermediateRow = QueryRowImpl.of(INTERMEDIATE_SCHEMA_WITH_PSEUDO, A_KEY, Optional.empty(), GenericRow.genericRow("a", "b", A_ROWTIME, "k"), A_ROWTIME);
when(transformer.transform(A_KEY, intermediateRow.value(), new PullProcessingContext(12335L))).thenReturn(Optional.of(GenericRow.genericRow("a", "b", A_ROWTIME, "k")));
selectOperator.open();
// When:
Object result = selectOperator.next();
// Then:
assertThat(result, is(intermediateRow));
}
Aggregations