use of com.facebook.presto.spi.RecordSet in project presto by prestodb.
the class TestPrometheusRetrieveUpValueIntegrationTests method testGetColumnTypes.
@Test(dependsOnMethods = "testRetrieveUpValue")
public void testGetColumnTypes() {
URI dataUri = server.getUri();
RecordSet recordSet = new PrometheusRecordSet(client, new PrometheusSplit(dataUri), ImmutableList.of(new PrometheusColumnHandle("labels", createUnboundedVarcharType(), 0), new PrometheusColumnHandle("value", DoubleType.DOUBLE, 1), new PrometheusColumnHandle("timestamp", TIMESTAMP_WITH_TIME_ZONE, 2)));
assertEquals(recordSet.getColumnTypes(), ImmutableList.of(createUnboundedVarcharType(), DoubleType.DOUBLE, TIMESTAMP_WITH_TIME_ZONE));
recordSet = new PrometheusRecordSet(client, new PrometheusSplit(dataUri), ImmutableList.of(new PrometheusColumnHandle("value", BIGINT, 1), new PrometheusColumnHandle("text", createUnboundedVarcharType(), 0)));
assertEquals(recordSet.getColumnTypes(), ImmutableList.of(BIGINT, createUnboundedVarcharType()));
recordSet = new PrometheusRecordSet(client, new PrometheusSplit(dataUri), ImmutableList.of(new PrometheusColumnHandle("value", BIGINT, 1), new PrometheusColumnHandle("value", BIGINT, 1), new PrometheusColumnHandle("text", createUnboundedVarcharType(), 0)));
assertEquals(recordSet.getColumnTypes(), ImmutableList.of(BIGINT, BIGINT, createUnboundedVarcharType()));
recordSet = new PrometheusRecordSet(client, new PrometheusSplit(dataUri), ImmutableList.of());
assertEquals(recordSet.getColumnTypes(), ImmutableList.of());
}
use of com.facebook.presto.spi.RecordSet in project presto by prestodb.
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), ImmutableList.of(new PrometheusColumnHandle("labels", varcharMapType, 0), new PrometheusColumnHandle("timestamp", TIMESTAMP_WITH_TIME_ZONE, 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")).build();
assertEquals(actual, expected);
}
use of com.facebook.presto.spi.RecordSet in project presto by prestodb.
the class TestPrometheusRecordSet method testCursorSimple.
@Test
public void testCursorSimple() {
RecordSet recordSet = new PrometheusRecordSet(new PrometheusClient(new PrometheusConnectorConfig(), METRIC_CODEC, TYPE_MANAGER), new PrometheusSplit(dataUri), ImmutableList.of(new PrometheusColumnHandle("labels", varcharMapType, 0), new PrometheusColumnHandle("timestamp", TIMESTAMP_WITH_TIME_ZONE, 1), new PrometheusColumnHandle("value", DoubleType.DOUBLE, 2)));
RecordCursor cursor = recordSet.cursor();
assertEquals(cursor.getType(0), varcharMapType);
assertEquals(cursor.getType(1), TIMESTAMP_WITH_TIME_ZONE);
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();
List<PairLike<PrometheusStandardizedRow, PrometheusStandardizedRow>> pairs = Streams.zip(actual.stream(), expected.stream(), PairLike::new).collect(Collectors.toList());
pairs.forEach(pair -> {
assertEquals(getMapFromBlock(varcharMapType, pair.getFirst().getLabels()), getMapFromBlock(varcharMapType, pair.getSecond().getLabels()));
assertEquals(pair.getFirst().getTimestamp(), pair.getSecond().getTimestamp());
assertEquals(pair.getFirst().getValue(), pair.getSecond().getValue());
});
}
use of com.facebook.presto.spi.RecordSet in project presto by prestodb.
the class TestJdbcRecordSetProvider method testGetRecordSet.
@Test
public void testGetRecordSet() {
ConnectorTransactionHandle transaction = new JdbcTransactionHandle();
JdbcRecordSetProvider recordSetProvider = new JdbcRecordSetProvider(jdbcClient);
RecordSet recordSet = recordSetProvider.getRecordSet(transaction, SESSION, split, 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).build());
}
use of com.facebook.presto.spi.RecordSet in project presto by prestodb.
the class TestJdbcRecordSet method testIdempotentClose.
@Test
public void testIdempotentClose() {
RecordSet recordSet = new JdbcRecordSet(jdbcClient, session, split, ImmutableList.of(columnHandles.get("value"), columnHandles.get("value"), columnHandles.get("text")));
RecordCursor cursor = recordSet.cursor();
cursor.close();
cursor.close();
}
Aggregations