Search in sources :

Example 6 with RecordCursor

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

the class TestJdbcRecordSetProvider method testGetRecordSet.

@Test
public void testGetRecordSet() {
    ConnectorTransactionHandle transaction = new JdbcTransactionHandle();
    JdbcRecordSetProvider recordSetProvider = new JdbcRecordSetProvider(jdbcClient, executor);
    RecordSet recordSet = recordSetProvider.getRecordSet(transaction, SESSION, split, table, ImmutableList.of(textColumn, textShortColumn, valueColumn));
    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(2));
        assertEquals(cursor.getSlice(0), cursor.getSlice(1));
    }
    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) ConnectorTransactionHandle(io.trino.spi.connector.ConnectorTransactionHandle) OptionalLong(java.util.OptionalLong) RecordSet(io.trino.spi.connector.RecordSet) LinkedHashMap(java.util.LinkedHashMap) Test(org.testng.annotations.Test)

Example 7 with RecordCursor

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

the class TestFieldSetFilteringRecordSet method test.

@Test
public void test() {
    ArrayType arrayOfBigintType = new ArrayType(BIGINT);
    FieldSetFilteringRecordSet fieldSetFilteringRecordSet = new FieldSetFilteringRecordSet(new TypeOperators(), new InMemoryRecordSet(ImmutableList.of(BIGINT, BIGINT, TIMESTAMP_WITH_TIME_ZONE, TIMESTAMP_WITH_TIME_ZONE, arrayOfBigintType, arrayOfBigintType), ImmutableList.of(ImmutableList.of(100L, 100L, // test same time in different time zone to make sure equal check was done properly
    packDateTimeWithZone(100, getTimeZoneKeyForOffset(123)), packDateTimeWithZone(100, getTimeZoneKeyForOffset(234)), // test structural type
    arrayBlockOf(BIGINT, 12, 34, 56), arrayBlockOf(BIGINT, 12, 34, 56)))), ImmutableList.of(ImmutableSet.of(0, 1), ImmutableSet.of(2, 3), ImmutableSet.of(4, 5)));
    RecordCursor recordCursor = fieldSetFilteringRecordSet.cursor();
    assertTrue(recordCursor.advanceNextPosition());
}
Also used : ArrayType(io.trino.spi.type.ArrayType) RecordCursor(io.trino.spi.connector.RecordCursor) InMemoryRecordSet(io.trino.spi.connector.InMemoryRecordSet) TypeOperators(io.trino.spi.type.TypeOperators) Test(org.testng.annotations.Test)

Example 8 with RecordCursor

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

the class TestPrometheusRecordSet method testCursorSimple.

@Test
public void testCursorSimple() {
    RecordSet recordSet = new PrometheusRecordSet(new PrometheusClient(new PrometheusConnectorConfig(), METRIC_CODEC, TESTING_TYPE_MANAGER), new PrometheusSplit(dataUri), ImmutableList.of(new PrometheusColumnHandle("labels", varcharMapType, 0), new PrometheusColumnHandle("timestamp", TIMESTAMP_COLUMN_TYPE, 1), new PrometheusColumnHandle("value", DoubleType.DOUBLE, 2)));
    RecordCursor cursor = recordSet.cursor();
    assertEquals(cursor.getType(0), varcharMapType);
    assertEquals(cursor.getType(1), TIMESTAMP_COLUMN_TYPE);
    assertEquals(cursor.getType(2), DoubleType.DOUBLE);
    List<PrometheusStandardizedRow> actual = new ArrayList<>();
    while (cursor.advanceNextPosition()) {
        actual.add(new PrometheusStandardizedRow((Block) cursor.getObject(0), (Instant) cursor.getObject(1), cursor.getDouble(2)));
        assertFalse(cursor.isNull(0));
        assertFalse(cursor.isNull(1));
        assertFalse(cursor.isNull(2));
    }
    List<PrometheusStandardizedRow> expected = ImmutableList.<PrometheusStandardizedRow>builder().add(new PrometheusStandardizedRow(getBlockFromMap(varcharMapType, ImmutableMap.of("instance", "localhost:9090", "__name__", "up", "job", "prometheus")), ofEpochMilli(1565962969044L), 1.0)).add(new PrometheusStandardizedRow(getBlockFromMap(varcharMapType, ImmutableMap.of("instance", "localhost:9090", "__name__", "up", "job", "prometheus")), ofEpochMilli(1565962984045L), 1.0)).add(new PrometheusStandardizedRow(getBlockFromMap(varcharMapType, ImmutableMap.of("instance", "localhost:9090", "__name__", "up", "job", "prometheus")), ofEpochMilli(1565962999044L), 1.0)).add(new PrometheusStandardizedRow(getBlockFromMap(varcharMapType, ImmutableMap.of("instance", "localhost:9090", "__name__", "up", "job", "prometheus")), ofEpochMilli(1565963014044L), 1.0)).build();
    assertThat(actual).as("actual").hasSize(expected.size());
    for (int i = 0; i < actual.size(); i++) {
        PrometheusStandardizedRow actualRow = actual.get(i);
        PrometheusStandardizedRow expectedRow = expected.get(i);
        assertEquals(getMapFromBlock(varcharMapType, actualRow.getLabels()), getMapFromBlock(varcharMapType, expectedRow.getLabels()));
        assertEquals(actualRow.getTimestamp(), expectedRow.getTimestamp());
        assertEquals(actualRow.getValue(), expectedRow.getValue());
    }
}
Also used : RecordCursor(io.trino.spi.connector.RecordCursor) Instant(java.time.Instant) ArrayList(java.util.ArrayList) PrometheusRecordCursor.getMapFromBlock(io.trino.plugin.prometheus.PrometheusRecordCursor.getMapFromBlock) Block(io.trino.spi.block.Block) RecordSet(io.trino.spi.connector.RecordSet) Test(org.testng.annotations.Test)

Example 9 with RecordCursor

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

the class TestPrometheusRecordSetProvider method testGetRecordSet.

@Test
public void testGetRecordSet() {
    ConnectorTableHandle tableHandle = new PrometheusTableHandle("schema", "table");
    PrometheusRecordSetProvider recordSetProvider = new PrometheusRecordSetProvider(client);
    RecordSet recordSet = recordSetProvider.getRecordSet(PrometheusTransactionHandle.INSTANCE, SESSION, new PrometheusSplit(dataUri), tableHandle, ImmutableList.of(new PrometheusColumnHandle("labels", varcharMapType, 0), new PrometheusColumnHandle("timestamp", TIMESTAMP_COLUMN_TYPE, 1), new PrometheusColumnHandle("value", DoubleType.DOUBLE, 2)));
    assertNotNull(recordSet, "recordSet is null");
    RecordCursor cursor = recordSet.cursor();
    assertNotNull(cursor, "cursor is null");
    Map<Instant, Map<?, ?>> actual = new LinkedHashMap<>();
    while (cursor.advanceNextPosition()) {
        actual.put((Instant) cursor.getObject(1), getMapFromBlock(varcharMapType, (Block) cursor.getObject(0)));
    }
    Map<Instant, Map<String, String>> expected = ImmutableMap.<Instant, Map<String, String>>builder().put(ofEpochMilli(1565962969044L), ImmutableMap.of("instance", "localhost:9090", "__name__", "up", "job", "prometheus")).put(ofEpochMilli(1565962984045L), ImmutableMap.of("instance", "localhost:9090", "__name__", "up", "job", "prometheus")).put(ofEpochMilli(1565962999044L), ImmutableMap.of("instance", "localhost:9090", "__name__", "up", "job", "prometheus")).put(ofEpochMilli(1565963014044L), ImmutableMap.of("instance", "localhost:9090", "__name__", "up", "job", "prometheus")).buildOrThrow();
    assertEquals(actual, expected);
}
Also used : RecordCursor(io.trino.spi.connector.RecordCursor) Instant(java.time.Instant) ConnectorTableHandle(io.trino.spi.connector.ConnectorTableHandle) LinkedHashMap(java.util.LinkedHashMap) PrometheusRecordCursor.getMapFromBlock(io.trino.plugin.prometheus.PrometheusRecordCursor.getMapFromBlock) Block(io.trino.spi.block.Block) RecordSet(io.trino.spi.connector.RecordSet) ImmutableMap(com.google.common.collect.ImmutableMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) Test(org.testng.annotations.Test)

Example 10 with RecordCursor

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

the class TrinoThriftPageResult method totalRecords.

private static int totalRecords(RecordSet recordSet) {
    RecordCursor cursor = recordSet.cursor();
    int result = 0;
    while (cursor.advanceNextPosition()) {
        result++;
    }
    return result;
}
Also used : RecordCursor(io.trino.spi.connector.RecordCursor)

Aggregations

RecordCursor (io.trino.spi.connector.RecordCursor)32 Test (org.testng.annotations.Test)18 RecordSet (io.trino.spi.connector.RecordSet)12 LinkedHashMap (java.util.LinkedHashMap)8 List (java.util.List)8 Optional (java.util.Optional)6 ImmutableList (com.google.common.collect.ImmutableList)5 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)5 Block (io.trino.spi.block.Block)5 TupleDomain (io.trino.spi.predicate.TupleDomain)5 Type (io.trino.spi.type.Type)5 ArrayList (java.util.ArrayList)5 Map (java.util.Map)5 Preconditions.checkArgument (com.google.common.base.Preconditions.checkArgument)4 ColumnHandle (io.trino.spi.connector.ColumnHandle)4 ConnectorTableHandle (io.trino.spi.connector.ConnectorTableHandle)4 ConnectorTableMetadata (io.trino.spi.connector.ConnectorTableMetadata)4 ConnectorTransactionHandle (io.trino.spi.connector.ConnectorTransactionHandle)4 Objects.requireNonNull (java.util.Objects.requireNonNull)4 Slice (io.airlift.slice.Slice)3