Search in sources :

Example 11 with RecordCursor

use of io.prestosql.spi.connector.RecordCursor in project hetu-core by openlookeng.

the class TestExampleRecordSet method testCursorSimple.

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

Example 12 with RecordCursor

use of io.prestosql.spi.connector.RecordCursor in project hetu-core by openlookeng.

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).build());
}
Also used : RecordCursor(io.prestosql.spi.connector.RecordCursor) RecordSet(io.prestosql.spi.connector.RecordSet) LinkedHashMap(java.util.LinkedHashMap) Test(org.testng.annotations.Test)

Example 13 with RecordCursor

use of io.prestosql.spi.connector.RecordCursor in project hetu-core by openlookeng.

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).build());
}
Also used : RecordCursor(io.prestosql.spi.connector.RecordCursor) RecordSet(io.prestosql.spi.connector.RecordSet) ConnectorTableHandle(io.prestosql.spi.connector.ConnectorTableHandle) LinkedHashMap(java.util.LinkedHashMap) Test(org.testng.annotations.Test)

Example 14 with RecordCursor

use of io.prestosql.spi.connector.RecordCursor in project hetu-core by openlookeng.

the class TestJdbcRecordSet method testCursorMixedOrder.

@Test
public void testCursorMixedOrder() {
    RecordSet recordSet = new JdbcRecordSet(jdbcClient, SESSION, split, table, 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).build());
    }
}
Also used : RecordCursor(io.prestosql.spi.connector.RecordCursor) RecordSet(io.prestosql.spi.connector.RecordSet) LinkedHashMap(java.util.LinkedHashMap) Test(org.testng.annotations.Test)

Example 15 with RecordCursor

use of io.prestosql.spi.connector.RecordCursor in project hetu-core by openlookeng.

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, 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).build());
}
Also used : RecordCursor(io.prestosql.spi.connector.RecordCursor) ConnectorTransactionHandle(io.prestosql.spi.connector.ConnectorTransactionHandle) OptionalLong(java.util.OptionalLong) RecordSet(io.prestosql.spi.connector.RecordSet) LinkedHashMap(java.util.LinkedHashMap) Test(org.testng.annotations.Test)

Aggregations

RecordCursor (io.prestosql.spi.connector.RecordCursor)27 Test (org.testng.annotations.Test)16 RecordSet (io.prestosql.spi.connector.RecordSet)10 List (java.util.List)8 ImmutableList (com.google.common.collect.ImmutableList)7 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)7 Optional (java.util.Optional)7 Objects.requireNonNull (java.util.Objects.requireNonNull)6 Joiner (com.google.common.base.Joiner)5 ImmutableMap (com.google.common.collect.ImmutableMap)5 ConnectorPageSource (io.prestosql.spi.connector.ConnectorPageSource)5 ConnectorSession (io.prestosql.spi.connector.ConnectorSession)5 ArrayType (io.prestosql.spi.type.ArrayType)5 LinkedHashMap (java.util.LinkedHashMap)5 Slice (io.airlift.slice.Slice)4 RecordPageSource (io.prestosql.spi.connector.RecordPageSource)4 Assert.assertEquals (org.testng.Assert.assertEquals)4 Assert.assertTrue (org.testng.Assert.assertTrue)4 Preconditions.checkArgument (com.google.common.base.Preconditions.checkArgument)3 Predicates.not (com.google.common.base.Predicates.not)3