Search in sources :

Example 21 with RecordSet

use of io.trino.spi.connector.RecordSet in project trino by trinodb.

the class TpchConnectorIndex method lookup.

@Override
public ConnectorPageSource lookup(RecordSet rawInputRecordSet) {
    // convert the input record set from the column ordering in the query to
    // match the column ordering of the index
    RecordSet inputRecordSet = keyFormatter.apply(rawInputRecordSet);
    // lookup the values in the index
    RecordSet rawOutputRecordSet = indexedTable.lookupKeys(inputRecordSet);
    // expect by the query
    return new RecordPageSource(outputFormatter.apply(rawOutputRecordSet));
}
Also used : RecordSet(io.trino.spi.connector.RecordSet) RecordPageSource(io.trino.spi.connector.RecordPageSource)

Example 22 with RecordSet

use of io.trino.spi.connector.RecordSet in project trino by trinodb.

the class TestLocalFileRecordSet method assertData.

private static void assertData(LocalFileTables localFileTables, LocalFileMetadata metadata) {
    LocalFileTableHandle tableHandle = new LocalFileTableHandle(getSchemaTableName(), OptionalInt.of(0), OptionalInt.of(-1));
    List<LocalFileColumnHandle> columnHandles = metadata.getColumnHandles(SESSION, tableHandle).values().stream().map(column -> (LocalFileColumnHandle) column).collect(Collectors.toList());
    LocalFileSplit split = new LocalFileSplit(address);
    RecordSet recordSet = new LocalFileRecordSet(localFileTables, split, tableHandle, columnHandles);
    RecordCursor cursor = recordSet.cursor();
    for (int i = 0; i < columnHandles.size(); i++) {
        assertEquals(cursor.getType(i), columnHandles.get(i).getColumnType());
    }
    // test one row
    assertTrue(cursor.advanceNextPosition());
    assertEquals(cursor.getSlice(0).toStringUtf8(), address.toString());
    assertEquals(cursor.getSlice(2).toStringUtf8(), "127.0.0.1");
    assertEquals(cursor.getSlice(3).toStringUtf8(), "POST");
    assertEquals(cursor.getSlice(4).toStringUtf8(), "/v1/memory");
    assertTrue(cursor.isNull(5));
    assertTrue(cursor.isNull(6));
    assertEquals(cursor.getLong(7), 200);
    assertEquals(cursor.getLong(8), 0);
    assertEquals(cursor.getLong(9), 1000);
    assertEquals(cursor.getLong(10), 10);
    assertTrue(cursor.isNull(11));
    assertTrue(cursor.advanceNextPosition());
    assertEquals(cursor.getSlice(0).toStringUtf8(), address.toString());
    assertEquals(cursor.getSlice(2).toStringUtf8(), "127.0.0.1");
    assertEquals(cursor.getSlice(3).toStringUtf8(), "GET");
    assertEquals(cursor.getSlice(4).toStringUtf8(), "/v1/service/presto/general");
    assertEquals(cursor.getSlice(5).toStringUtf8(), "foo");
    assertEquals(cursor.getSlice(6).toStringUtf8(), "ffffffff-ffff-ffff-ffff-ffffffffffff");
    assertEquals(cursor.getLong(7), 200);
    assertEquals(cursor.getLong(8), 0);
    assertEquals(cursor.getLong(9), 37);
    assertEquals(cursor.getLong(10), 1094);
    assertEquals(cursor.getSlice(11).toStringUtf8(), "a7229d56-5cbd-4e23-81ff-312ba6be0f12");
}
Also used : List(java.util.List) RecordCursor(io.trino.spi.connector.RecordCursor) HttpRequestLogTable.getSchemaTableName(io.trino.plugin.localfile.LocalFileTables.HttpRequestLogTable.getSchemaTableName) SESSION(io.trino.testing.TestingConnectorSession.SESSION) RecordSet(io.trino.spi.connector.RecordSet) Assert.assertEquals(org.testng.Assert.assertEquals) Assert.assertTrue(org.testng.Assert.assertTrue) Test(org.testng.annotations.Test) OptionalInt(java.util.OptionalInt) Collectors(java.util.stream.Collectors) HostAddress(io.trino.spi.HostAddress) RecordCursor(io.trino.spi.connector.RecordCursor) RecordSet(io.trino.spi.connector.RecordSet)

Example 23 with RecordSet

use of io.trino.spi.connector.RecordSet in project trino by trinodb.

the class TestJmxSplitManager method testHistoryRecordSetProvider.

@Test
public void testHistoryRecordSetProvider() throws Exception {
    for (SchemaTableName schemaTableName : metadata.listTables(SESSION, Optional.of(HISTORY_SCHEMA_NAME))) {
        // wait for at least two samples
        List<Long> timeStamps = ImmutableList.of();
        for (int waited = 0; waited < TIMEOUT_TIME; waited += SLEEP_TIME) {
            RecordSet recordSet = getRecordSet(schemaTableName);
            timeStamps = readTimeStampsFrom(recordSet);
            if (timeStamps.size() >= 2) {
                break;
            }
            Thread.sleep(SLEEP_TIME);
        }
        assertTrue(timeStamps.size() >= 2);
        // we don't have equality check here because JmxHistoryDumper scheduling can lag
        assertTrue(timeStamps.get(1) - timeStamps.get(0) >= JMX_STATS_DUMP.toMillis());
    }
}
Also used : RecordSet(io.trino.spi.connector.RecordSet) SchemaTableName(io.trino.spi.connector.SchemaTableName) Test(org.testng.annotations.Test)

Example 24 with RecordSet

use of io.trino.spi.connector.RecordSet in project trino by trinodb.

the class KinesisRecordSetProvider method getRecordSet.

@Override
public RecordSet getRecordSet(ConnectorTransactionHandle transactionHandle, ConnectorSession session, ConnectorSplit split, List<? extends ColumnHandle> columns) {
    KinesisSplit kinesisSplit = (KinesisSplit) split;
    List<KinesisColumnHandle> kinesisColumns = columns.stream().map(x -> (KinesisColumnHandle) x).collect(toImmutableList());
    ImmutableList.Builder<KinesisColumnHandle> handleBuilder = ImmutableList.builder();
    RowDecoder messageDecoder = decoderFactory.create(kinesisSplit.getMessageDataFormat(), new HashMap<>(), kinesisColumns.stream().filter(column -> !column.isInternal()).collect(toImmutableSet()));
    for (ColumnHandle handle : columns) {
        KinesisColumnHandle columnHandle = (KinesisColumnHandle) handle;
        handleBuilder.add(columnHandle);
    }
    return new KinesisRecordSet(kinesisSplit, session, clientManager, handleBuilder.build(), messageDecoder, kinesisConfig);
}
Also used : ConnectorRecordSetProvider(io.trino.spi.connector.ConnectorRecordSetProvider) Inject(com.google.inject.Inject) ConnectorSplit(io.trino.spi.connector.ConnectorSplit) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) HashMap(java.util.HashMap) ConnectorSession(io.trino.spi.connector.ConnectorSession) List(java.util.List) ImmutableList(com.google.common.collect.ImmutableList) RowDecoder(io.trino.decoder.RowDecoder) DispatchingRowDecoderFactory(io.trino.decoder.DispatchingRowDecoderFactory) Objects.requireNonNull(java.util.Objects.requireNonNull) ColumnHandle(io.trino.spi.connector.ColumnHandle) RecordSet(io.trino.spi.connector.RecordSet) ImmutableSet.toImmutableSet(com.google.common.collect.ImmutableSet.toImmutableSet) ConnectorTransactionHandle(io.trino.spi.connector.ConnectorTransactionHandle) ColumnHandle(io.trino.spi.connector.ColumnHandle) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) ImmutableList(com.google.common.collect.ImmutableList) RowDecoder(io.trino.decoder.RowDecoder)

Example 25 with RecordSet

use of io.trino.spi.connector.RecordSet in project trino by trinodb.

the class KafkaRecordSetProvider method getRecordSet.

@Override
public RecordSet getRecordSet(ConnectorTransactionHandle transaction, ConnectorSession session, ConnectorSplit split, ConnectorTableHandle table, List<? extends ColumnHandle> columns) {
    KafkaSplit kafkaSplit = (KafkaSplit) split;
    List<KafkaColumnHandle> kafkaColumns = columns.stream().map(KafkaColumnHandle.class::cast).collect(toImmutableList());
    RowDecoder keyDecoder = decoderFactory.create(kafkaSplit.getKeyDataFormat(), getDecoderParameters(kafkaSplit.getKeyDataSchemaContents()), kafkaColumns.stream().filter(col -> !col.isInternal()).filter(KafkaColumnHandle::isKeyCodec).collect(toImmutableSet()));
    RowDecoder messageDecoder = decoderFactory.create(kafkaSplit.getMessageDataFormat(), getDecoderParameters(kafkaSplit.getMessageDataSchemaContents()), kafkaColumns.stream().filter(col -> !col.isInternal()).filter(col -> !col.isKeyCodec()).collect(toImmutableSet()));
    return new KafkaRecordSet(kafkaSplit, consumerFactory, session, kafkaColumns, keyDecoder, messageDecoder);
}
Also used : ConnectorRecordSetProvider(io.trino.spi.connector.ConnectorRecordSetProvider) ImmutableMap(com.google.common.collect.ImmutableMap) ConnectorSplit(io.trino.spi.connector.ConnectorSplit) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) ConnectorSession(io.trino.spi.connector.ConnectorSession) Inject(javax.inject.Inject) List(java.util.List) RowDecoder(io.trino.decoder.RowDecoder) DispatchingRowDecoderFactory(io.trino.decoder.DispatchingRowDecoderFactory) ConnectorTableHandle(io.trino.spi.connector.ConnectorTableHandle) Map(java.util.Map) Objects.requireNonNull(java.util.Objects.requireNonNull) ColumnHandle(io.trino.spi.connector.ColumnHandle) RecordSet(io.trino.spi.connector.RecordSet) Optional(java.util.Optional) ImmutableSet.toImmutableSet(com.google.common.collect.ImmutableSet.toImmutableSet) ConnectorTransactionHandle(io.trino.spi.connector.ConnectorTransactionHandle) RowDecoder(io.trino.decoder.RowDecoder)

Aggregations

RecordSet (io.trino.spi.connector.RecordSet)25 Test (org.testng.annotations.Test)14 RecordCursor (io.trino.spi.connector.RecordCursor)12 LinkedHashMap (java.util.LinkedHashMap)8 ConnectorTransactionHandle (io.trino.spi.connector.ConnectorTransactionHandle)6 List (java.util.List)6 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)5 ColumnHandle (io.trino.spi.connector.ColumnHandle)5 Objects.requireNonNull (java.util.Objects.requireNonNull)5 ImmutableSet.toImmutableSet (com.google.common.collect.ImmutableSet.toImmutableSet)4 ConnectorSession (io.trino.spi.connector.ConnectorSession)4 ConnectorTableHandle (io.trino.spi.connector.ConnectorTableHandle)4 ArrayList (java.util.ArrayList)4 Preconditions.checkArgument (com.google.common.base.Preconditions.checkArgument)3 Preconditions.checkState (com.google.common.base.Preconditions.checkState)3 ImmutableList (com.google.common.collect.ImmutableList)3 ImmutableMap (com.google.common.collect.ImmutableMap)3 DispatchingRowDecoderFactory (io.trino.decoder.DispatchingRowDecoderFactory)3 RowDecoder (io.trino.decoder.RowDecoder)3 ConnectorRecordSetProvider (io.trino.spi.connector.ConnectorRecordSetProvider)3