Search in sources :

Example 6 with QueryRow

use of io.confluent.ksql.physical.common.QueryRow 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())));
}
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 7 with QueryRow

use of io.confluent.ksql.physical.common.QueryRow 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));
}
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 QueryRow

use of io.confluent.ksql.physical.common.QueryRow in project ksql by confluentinc.

the class ScalablePushConsumer method handleProgressToken.

private void handleProgressToken(final PushOffsetVector startOffsetVector, final PushOffsetVector endOffsetVector) {
    final PushOffsetRange range = new PushOffsetRange(Optional.of(startOffsetVector), endOffsetVector);
    for (ProcessingQueue queue : processingQueues.values()) {
        final QueryRow row = OffsetsRow.of(clock.millis(), range);
        queue.offer(row);
    }
}
Also used : QueryRow(io.confluent.ksql.physical.common.QueryRow) ProcessingQueue(io.confluent.ksql.physical.scalablepush.ProcessingQueue) PushOffsetRange(io.confluent.ksql.util.PushOffsetRange)

Example 9 with QueryRow

use of io.confluent.ksql.physical.common.QueryRow in project ksql by confluentinc.

the class PullPhysicalPlan method execute.

public void execute(final List<KsqlPartitionLocation> locations, final PullQueryQueue pullQueryQueue, final BiFunction<List<?>, LogicalSchema, PullQueryRow> rowFactory) {
    // We only know at runtime which partitions to get from which node.
    // That's why we need to set this explicitly for the dataSource operators
    dataSourceOperator.setPartitionLocations(locations);
    open();
    QueryRow row;
    while ((row = (QueryRow) next()) != null) {
        if (pullQueryQueue.isClosed()) {
            // If the queue has been closed, we stop adding rows and cleanup. This should be triggered
            // because the client has closed their connection with the server before the results have
            // completed.
            LOGGER.info("Queue closed before results completed. Stopping execution.");
            break;
        }
        if (!pullQueryQueue.acceptRow(rowFactory.apply(row.value().values(), schema))) {
            LOGGER.info("Failed to queue row");
        }
    }
    close();
}
Also used : QueryRow(io.confluent.ksql.physical.common.QueryRow)

Example 10 with QueryRow

use of io.confluent.ksql.physical.common.QueryRow 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)

Aggregations

QueryRow (io.confluent.ksql.physical.common.QueryRow)14 PullProcessingContext (io.confluent.ksql.execution.streams.materialization.PullProcessingContext)8 Test (org.junit.Test)8 QueryRowImpl (io.confluent.ksql.physical.common.QueryRowImpl)7 LogicalSchema (io.confluent.ksql.schema.ksql.LogicalSchema)5 ArrayList (java.util.ArrayList)4 GenericRow (io.confluent.ksql.GenericRow)2 ProcessingQueue (io.confluent.ksql.physical.scalablepush.ProcessingQueue)2 List (java.util.List)2 ImmutableList (com.google.common.collect.ImmutableList)1 GenericKey (io.confluent.ksql.GenericKey)1 PushConnectionsHandle (io.confluent.ksql.physical.scalablepush.PushRouting.PushConnectionsHandle)1 TransientQueryQueue (io.confluent.ksql.query.TransientQueryQueue)1 BufferedPublisher (io.confluent.ksql.reactive.BufferedPublisher)1 PushOffsetRange (io.confluent.ksql.util.PushOffsetRange)1