Search in sources :

Example 1 with Row

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

the class TableScanOperator method next.

@Override
public Object next() {
    if (shouldCancelOperations.isDone()) {
        return null;
    }
    while (!resultIterator.hasNext()) {
        // Exhausted resultIterator
        if (partitionLocationIterator.hasNext()) {
            nextLocation = partitionLocationIterator.next();
        } else {
            // Exhausted all iterators
            return null;
        }
        if (nextLocation.getKeys().isPresent()) {
            throw new IllegalStateException("Table scans should not be done with keys");
        }
        updateIterator();
    }
    returnedRows++;
    final Row row = resultIterator.next();
    return QueryRowImpl.of(row.schema(), row.key(), row.window(), row.value(), row.rowTime());
}
Also used : Row(io.confluent.ksql.execution.streams.materialization.Row)

Example 2 with Row

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

the class KsMaterializedTableIQv2Test method shouldReturnValueIfKeyPresent.

@Test
public void shouldReturnValueIfKeyPresent() {
    // Given:
    final GenericRow value = GenericRow.genericRow("col0");
    final long rowTime = -1L;
    when(kafkaStreams.query(any())).thenReturn(getRowResult(ROW1));
    // When:
    final Iterator<Row> rowIterator = table.get(A_KEY, PARTITION).rowIterator;
    // Then:
    assertThat(rowIterator.hasNext(), is(true));
    assertThat(rowIterator.next(), is(Row.of(SCHEMA, A_KEY, value, rowTime)));
}
Also used : GenericRow(io.confluent.ksql.GenericRow) Row(io.confluent.ksql.execution.streams.materialization.Row) GenericRow(io.confluent.ksql.GenericRow) Test(org.junit.Test)

Example 3 with Row

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

the class KsMaterializedTableTest method shouldReturnValueIfKeyPresent.

@Test
public void shouldReturnValueIfKeyPresent() {
    // Given:
    final GenericRow value = GenericRow.genericRow("col0");
    final long rowTime = 2343553L;
    when(tableStore.get(any())).thenReturn(ValueAndTimestamp.make(value, rowTime));
    // When:
    final Iterator<Row> rowIterator = table.get(A_KEY, PARTITION).rowIterator;
    // Then:
    assertThat(rowIterator.hasNext(), is(true));
    assertThat(rowIterator.next(), is(Row.of(SCHEMA, A_KEY, value, rowTime)));
}
Also used : GenericRow(io.confluent.ksql.GenericRow) Row(io.confluent.ksql.execution.streams.materialization.Row) GenericRow(io.confluent.ksql.GenericRow) Test(org.junit.Test)

Example 4 with Row

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

the class KeyedTableLookupOperator method next.

@Override
public Object next() {
    while (!resultIterator.hasNext()) {
        // Exhausted resultIterator
        if (!keyIterator.hasNext()) {
            if (partitionLocationIterator.hasNext()) {
                nextLocation = partitionLocationIterator.next();
            } else {
                // Exhausted all iterators
                return null;
            }
            if (!nextLocation.getKeys().isPresent()) {
                throw new IllegalStateException("Table lookup queries should be done with keys");
            }
            keyIterator = nextLocation.getKeys().get().stream().iterator();
        }
        nextKey = keyIterator.next();
        resultIterator = getMatIterator(nextKey);
    }
    returnedRows++;
    final Row row = resultIterator.next();
    return QueryRowImpl.of(row.schema(), row.key(), row.window(), row.value(), row.rowTime());
}
Also used : Row(io.confluent.ksql.execution.streams.materialization.Row)

Example 5 with Row

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

the class KsMaterializationFunctionalTest method shouldQueryMaterializedTableWithKeyFieldsInProjection.

@Test
public void shouldQueryMaterializedTableWithKeyFieldsInProjection() {
    // Given:
    final PersistentQueryMetadata query = executeQuery("CREATE TABLE " + output + " AS" + " SELECT USERID, COUNT(*), AS_VALUE(USERID) AS USERID_2 FROM " + USER_TABLE + " GROUP BY USERID;");
    final LogicalSchema schema = schema("KSQL_COL_0", SqlTypes.BIGINT, "USERID_2", SqlTypes.STRING);
    final Map<String, GenericRow> rows = waitForUniqueUserRows(STRING_DESERIALIZER, schema);
    // When:
    final Materialization materialization = query.getMaterialization(queryId, contextStacker).get();
    // Then:
    assertThat(materialization.windowType(), is(Optional.empty()));
    final MaterializedTable table = materialization.nonWindowed();
    rows.forEach((rowKey, value) -> {
        final GenericKey key = genericKey(rowKey);
        final List<Row> rowList = withRetry(() -> Lists.newArrayList(table.get(key, PARTITION)));
        assertThat(rowList.size(), is(1));
        assertThat(rowList.get(0).schema(), is(schema));
        assertThat(rowList.get(0).key(), is(key));
        assertThat(rowList.get(0).value(), is(value));
    });
}
Also used : GenericRow(io.confluent.ksql.GenericRow) Materialization(io.confluent.ksql.execution.streams.materialization.Materialization) LogicalSchema(io.confluent.ksql.schema.ksql.LogicalSchema) GenericKey(io.confluent.ksql.GenericKey) Row(io.confluent.ksql.execution.streams.materialization.Row) WindowedRow(io.confluent.ksql.execution.streams.materialization.WindowedRow) GenericRow(io.confluent.ksql.GenericRow) MaterializedTable(io.confluent.ksql.execution.streams.materialization.MaterializedTable) PersistentQueryMetadata(io.confluent.ksql.util.PersistentQueryMetadata) IntegrationTest(org.apache.kafka.test.IntegrationTest) Test(org.junit.Test)

Aggregations

Row (io.confluent.ksql.execution.streams.materialization.Row)12 GenericRow (io.confluent.ksql.GenericRow)9 GenericKey (io.confluent.ksql.GenericKey)8 MaterializedTable (io.confluent.ksql.execution.streams.materialization.MaterializedTable)7 Test (org.junit.Test)7 Materialization (io.confluent.ksql.execution.streams.materialization.Materialization)5 WindowedRow (io.confluent.ksql.execution.streams.materialization.WindowedRow)5 LogicalSchema (io.confluent.ksql.schema.ksql.LogicalSchema)5 PersistentQueryMetadata (io.confluent.ksql.util.PersistentQueryMetadata)5 IntegrationTest (org.apache.kafka.test.IntegrationTest)5 ImmutableList (com.google.common.collect.ImmutableList)2 ImmutableSet (com.google.common.collect.ImmutableSet)2 Streams (com.google.common.collect.Streams)2 MaterializationException (io.confluent.ksql.execution.streams.materialization.MaterializationException)2 StreamsMaterializedTable (io.confluent.ksql.execution.streams.materialization.StreamsMaterializedTable)2 IteratorUtil (io.confluent.ksql.util.IteratorUtil)2 Collections (java.util.Collections)2 Objects (java.util.Objects)2 Optional (java.util.Optional)2 FailureReason (org.apache.kafka.streams.query.FailureReason)2