Search in sources :

Example 1 with RecordSet

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());
}
Also used : RecordSet(com.facebook.presto.spi.RecordSet) URI(java.net.URI) Test(org.testng.annotations.Test)

Example 2 with RecordSet

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);
}
Also used : RecordCursor(com.facebook.presto.spi.RecordCursor) Instant(java.time.Instant) ConnectorTableHandle(com.facebook.presto.spi.ConnectorTableHandle) LinkedHashMap(java.util.LinkedHashMap) PrometheusRecordCursor.getMapFromBlock(com.facebook.presto.plugin.prometheus.PrometheusRecordCursor.getMapFromBlock) Block(com.facebook.presto.common.block.Block) RecordSet(com.facebook.presto.spi.RecordSet) ImmutableMap(com.google.common.collect.ImmutableMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) Test(org.testng.annotations.Test)

Example 3 with RecordSet

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());
    });
}
Also used : RecordCursor(com.facebook.presto.spi.RecordCursor) ArrayList(java.util.ArrayList) PrometheusRecordCursor.getMapFromBlock(com.facebook.presto.plugin.prometheus.PrometheusRecordCursor.getMapFromBlock) Block(com.facebook.presto.common.block.Block) RecordSet(com.facebook.presto.spi.RecordSet) Test(org.testng.annotations.Test)

Example 4 with RecordSet

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());
}
Also used : RecordCursor(com.facebook.presto.spi.RecordCursor) ConnectorTransactionHandle(com.facebook.presto.spi.connector.ConnectorTransactionHandle) RecordSet(com.facebook.presto.spi.RecordSet) LinkedHashMap(java.util.LinkedHashMap) Test(org.testng.annotations.Test)

Example 5 with RecordSet

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();
}
Also used : RecordCursor(com.facebook.presto.spi.RecordCursor) RecordSet(com.facebook.presto.spi.RecordSet) Test(org.testng.annotations.Test)

Aggregations

RecordSet (com.facebook.presto.spi.RecordSet)25 Test (org.testng.annotations.Test)14 RecordCursor (com.facebook.presto.spi.RecordCursor)11 LinkedHashMap (java.util.LinkedHashMap)8 Type (com.facebook.presto.common.type.Type)6 ConnectorTransactionHandle (com.facebook.presto.spi.connector.ConnectorTransactionHandle)5 ColumnHandle (com.facebook.presto.spi.ColumnHandle)4 ImmutableList (com.google.common.collect.ImmutableList)4 List (java.util.List)4 Map (java.util.Map)4 Objects.requireNonNull (java.util.Objects.requireNonNull)4 ConnectorSession (com.facebook.presto.spi.ConnectorSession)3 SchemaTableName (com.facebook.presto.spi.SchemaTableName)3 MappedRecordSet (com.facebook.presto.split.MappedRecordSet)3 ImmutableMap (com.google.common.collect.ImmutableMap)3 ImmutableSet.toImmutableSet (com.google.common.collect.ImmutableSet.toImmutableSet)3 ArrayList (java.util.ArrayList)3 Optional (java.util.Optional)3 PageBuilder (com.facebook.presto.common.PageBuilder)2 Block (com.facebook.presto.common.block.Block)2