Search in sources :

Example 11 with RecordSet

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

the class TestJdbcRecordSet method testCursorSimple.

@Test
public void testCursorSimple() {
    RecordSet recordSet = createRecordSet(ImmutableList.of(columnHandles.get("text"), columnHandles.get("text_short"), columnHandles.get("value")));
    try (RecordCursor cursor = recordSet.cursor()) {
        assertEquals(cursor.getType(0), VARCHAR);
        assertEquals(cursor.getType(1), createVarcharType(32));
        assertEquals(cursor.getType(2), BIGINT);
        Map<String, Long> data = new LinkedHashMap<>();
        while (cursor.advanceNextPosition()) {
            data.put(cursor.getSlice(0).toStringUtf8(), cursor.getLong(2));
            assertEquals(cursor.getSlice(0), cursor.getSlice(1));
            assertFalse(cursor.isNull(0));
            assertFalse(cursor.isNull(1));
            assertFalse(cursor.isNull(2));
        }
        assertEquals(data, ImmutableMap.<String, Long>builder().put("one", 1L).put("two", 2L).put("three", 3L).put("ten", 10L).put("eleven", 11L).put("twelve", 12L).buildOrThrow());
    }
}
Also used : RecordCursor(io.trino.spi.connector.RecordCursor) RecordSet(io.trino.spi.connector.RecordSet) LinkedHashMap(java.util.LinkedHashMap) Test(org.testng.annotations.Test)

Example 12 with RecordSet

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

the class TestJdbcRecordSet method testCursorMixedOrder.

@Test
public void testCursorMixedOrder() {
    RecordSet recordSet = createRecordSet(ImmutableList.of(columnHandles.get("value"), columnHandles.get("value"), columnHandles.get("text")));
    try (RecordCursor cursor = recordSet.cursor()) {
        assertEquals(cursor.getType(0), BIGINT);
        assertEquals(cursor.getType(1), BIGINT);
        assertEquals(cursor.getType(2), VARCHAR);
        Map<String, Long> data = new LinkedHashMap<>();
        while (cursor.advanceNextPosition()) {
            assertEquals(cursor.getLong(0), cursor.getLong(1));
            data.put(cursor.getSlice(2).toStringUtf8(), cursor.getLong(0));
        }
        assertEquals(data, ImmutableMap.<String, Long>builder().put("one", 1L).put("two", 2L).put("three", 3L).put("ten", 10L).put("eleven", 11L).put("twelve", 12L).buildOrThrow());
    }
}
Also used : RecordCursor(io.trino.spi.connector.RecordCursor) RecordSet(io.trino.spi.connector.RecordSet) LinkedHashMap(java.util.LinkedHashMap) Test(org.testng.annotations.Test)

Example 13 with RecordSet

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

the class TestJdbcRecordSetProvider method getCursor.

private RecordCursor getCursor(JdbcTableHandle jdbcTableHandle, List<JdbcColumnHandle> columns, TupleDomain<ColumnHandle> domain) {
    jdbcTableHandle = new JdbcTableHandle(jdbcTableHandle.getRelationHandle(), domain, ImmutableList.of(), Optional.empty(), OptionalLong.empty(), Optional.empty(), jdbcTableHandle.getOtherReferencedTables(), jdbcTableHandle.getNextSyntheticColumnId());
    ConnectorSplitSource splits = jdbcClient.getSplits(SESSION, jdbcTableHandle);
    JdbcSplit split = (JdbcSplit) getOnlyElement(getFutureValue(splits.getNextBatch(NOT_PARTITIONED, 1000)).getSplits());
    ConnectorTransactionHandle transaction = new JdbcTransactionHandle();
    JdbcRecordSetProvider recordSetProvider = new JdbcRecordSetProvider(jdbcClient, executor);
    RecordSet recordSet = recordSetProvider.getRecordSet(transaction, SESSION, split, jdbcTableHandle, columns);
    return recordSet.cursor();
}
Also used : ConnectorTransactionHandle(io.trino.spi.connector.ConnectorTransactionHandle) ConnectorSplitSource(io.trino.spi.connector.ConnectorSplitSource) RecordSet(io.trino.spi.connector.RecordSet)

Example 14 with RecordSet

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

the class TestExampleRecordSetProvider method testGetRecordSet.

@Test
public void testGetRecordSet() {
    ConnectorTableHandle tableHandle = new ExampleTableHandle("schema", "table");
    ExampleRecordSetProvider recordSetProvider = new ExampleRecordSetProvider();
    RecordSet recordSet = recordSetProvider.getRecordSet(ExampleTransactionHandle.INSTANCE, SESSION, new ExampleSplit(dataUri), tableHandle, ImmutableList.of(new ExampleColumnHandle("text", createUnboundedVarcharType(), 0), new ExampleColumnHandle("value", BIGINT, 1)));
    assertNotNull(recordSet, "recordSet is null");
    RecordCursor cursor = recordSet.cursor();
    assertNotNull(cursor, "cursor is null");
    Map<String, Long> data = new LinkedHashMap<>();
    while (cursor.advanceNextPosition()) {
        data.put(cursor.getSlice(0).toStringUtf8(), cursor.getLong(1));
    }
    assertEquals(data, ImmutableMap.<String, Long>builder().put("ten", 10L).put("eleven", 11L).put("twelve", 12L).buildOrThrow());
}
Also used : RecordCursor(io.trino.spi.connector.RecordCursor) RecordSet(io.trino.spi.connector.RecordSet) ConnectorTableHandle(io.trino.spi.connector.ConnectorTableHandle) LinkedHashMap(java.util.LinkedHashMap) Test(org.testng.annotations.Test)

Example 15 with RecordSet

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

the class TestExampleRecordSet method testCursorMixedOrder.

@Test
public void testCursorMixedOrder() {
    RecordSet recordSet = new ExampleRecordSet(new ExampleSplit(dataUri), ImmutableList.of(new ExampleColumnHandle("value", BIGINT, 1), new ExampleColumnHandle("value", BIGINT, 1), new ExampleColumnHandle("text", createUnboundedVarcharType(), 0)));
    RecordCursor cursor = recordSet.cursor();
    Map<String, Long> data = new LinkedHashMap<>();
    while (cursor.advanceNextPosition()) {
        assertEquals(cursor.getLong(0), cursor.getLong(1));
        data.put(cursor.getSlice(2).toStringUtf8(), cursor.getLong(0));
    }
    assertEquals(data, ImmutableMap.<String, Long>builder().put("ten", 10L).put("eleven", 11L).put("twelve", 12L).buildOrThrow());
}
Also used : RecordCursor(io.trino.spi.connector.RecordCursor) RecordSet(io.trino.spi.connector.RecordSet) LinkedHashMap(java.util.LinkedHashMap) Test(org.testng.annotations.Test)

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