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());
}
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());
}
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());
}
}
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);
}
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;
}
Aggregations