Search in sources :

Example 1 with RecordCursor

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

the class TestListBasedRecordSet method testEmptyCursor.

@Test
public void testEmptyCursor() {
    ListBasedRecordSet recordSet = new ListBasedRecordSet(ImmutableList.of(), ImmutableList.of(BIGINT, INTEGER));
    assertEquals(recordSet.getColumnTypes(), ImmutableList.of(BIGINT, INTEGER));
    RecordCursor cursor = recordSet.cursor();
    assertFalse(cursor.advanceNextPosition());
}
Also used : RecordCursor(io.prestosql.spi.connector.RecordCursor) Test(org.testng.annotations.Test)

Example 2 with RecordCursor

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

the class TestListBasedRecordSet method testCursor.

@Test
public void testCursor() {
    ListBasedRecordSet recordSet = new ListBasedRecordSet(ImmutableList.of(Arrays.asList("1", null, "3"), Arrays.asList("ab", "c", null)), ImmutableList.of(BIGINT, VARCHAR));
    assertEquals(recordSet.getColumnTypes(), ImmutableList.of(BIGINT, VARCHAR));
    RecordCursor cursor = recordSet.cursor();
    assertTrue(cursor.advanceNextPosition());
    assertEquals(cursor.getType(0), BIGINT);
    assertEquals(cursor.getType(1), VARCHAR);
    assertThrows(IndexOutOfBoundsException.class, () -> cursor.getLong(2));
    assertEquals(cursor.getLong(0), 1L);
    assertEquals(cursor.getSlice(1), Slices.utf8Slice("ab"));
    assertTrue(cursor.advanceNextPosition());
    assertTrue(cursor.isNull(0));
    assertEquals(cursor.getSlice(1), Slices.utf8Slice("c"));
    assertTrue(cursor.advanceNextPosition());
    assertEquals(cursor.getLong(0), 3L);
    assertTrue(cursor.isNull(1));
    assertFalse(cursor.advanceNextPosition());
    assertThrows(IndexOutOfBoundsException.class, () -> cursor.getLong(0));
}
Also used : RecordCursor(io.prestosql.spi.connector.RecordCursor) Test(org.testng.annotations.Test)

Example 3 with RecordCursor

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

the class PrestoThriftTypeUtils method fromLongBasedColumn.

public static PrestoThriftBlock fromLongBasedColumn(RecordSet recordSet, int columnIndex, int positions, BiFunction<boolean[], long[], PrestoThriftBlock> result) {
    if (positions == 0) {
        return result.apply(null, null);
    }
    boolean[] nulls = null;
    long[] longs = null;
    RecordCursor cursor = recordSet.cursor();
    for (int position = 0; position < positions; position++) {
        checkState(cursor.advanceNextPosition(), "cursor has less values than expected");
        if (cursor.isNull(columnIndex)) {
            if (nulls == null) {
                nulls = new boolean[positions];
            }
            nulls[position] = true;
        } else {
            if (longs == null) {
                longs = new long[positions];
            }
            longs[position] = cursor.getLong(columnIndex);
        }
    }
    checkState(!cursor.advanceNextPosition(), "cursor has more values than expected");
    return result.apply(nulls, longs);
}
Also used : RecordCursor(io.prestosql.spi.connector.RecordCursor)

Example 4 with RecordCursor

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

the class PrestoThriftTypeUtils method fromIntBasedColumn.

public static PrestoThriftBlock fromIntBasedColumn(RecordSet recordSet, int columnIndex, int positions, BiFunction<boolean[], int[], PrestoThriftBlock> result) {
    if (positions == 0) {
        return result.apply(null, null);
    }
    boolean[] nulls = null;
    int[] ints = null;
    RecordCursor cursor = recordSet.cursor();
    for (int position = 0; position < positions; position++) {
        checkState(cursor.advanceNextPosition(), "cursor has less values than expected");
        if (cursor.isNull(columnIndex)) {
            if (nulls == null) {
                nulls = new boolean[positions];
            }
            nulls[position] = true;
        } else {
            if (ints == null) {
                ints = new int[positions];
            }
            ints[position] = (int) cursor.getLong(columnIndex);
        }
    }
    checkState(!cursor.advanceNextPosition(), "cursor has more values than expected");
    return result.apply(nulls, ints);
}
Also used : RecordCursor(io.prestosql.spi.connector.RecordCursor)

Example 5 with RecordCursor

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

the class TpchIndexedData method indexTable.

private static IndexedTable indexTable(RecordSet recordSet, final List<String> outputColumns, List<String> keyColumns) {
    List<Integer> keyPositions = keyColumns.stream().map(columnName -> {
        int position = outputColumns.indexOf(columnName);
        checkState(position != -1);
        return position;
    }).collect(toImmutableList());
    ImmutableListMultimap.Builder<MaterializedTuple, MaterializedTuple> indexedValuesBuilder = ImmutableListMultimap.builder();
    List<Type> outputTypes = recordSet.getColumnTypes();
    List<Type> keyTypes = extractPositionValues(outputTypes, keyPositions);
    RecordCursor cursor = recordSet.cursor();
    while (cursor.advanceNextPosition()) {
        List<Object> values = extractValues(cursor, outputTypes);
        List<Object> keyValues = extractPositionValues(values, keyPositions);
        indexedValuesBuilder.put(new MaterializedTuple(keyValues), new MaterializedTuple(values));
    }
    return new IndexedTable(keyColumns, keyTypes, outputColumns, outputTypes, indexedValuesBuilder.build());
}
Also used : Iterables(com.google.common.collect.Iterables) TpchTableHandle(io.prestosql.plugin.tpch.TpchTableHandle) Slice(io.airlift.slice.Slice) ListMultimap(com.google.common.collect.ListMultimap) RecordSet(io.prestosql.spi.connector.RecordSet) ArrayList(java.util.ArrayList) LinkedHashMap(java.util.LinkedHashMap) SchemaTableName(io.prestosql.spi.connector.SchemaTableName) Preconditions.checkArgument(com.google.common.base.Preconditions.checkArgument) Lists(com.google.common.collect.Lists) ImmutableList(com.google.common.collect.ImmutableList) Map(java.util.Map) Objects.requireNonNull(java.util.Objects.requireNonNull) TpchRecordSetProvider(io.prestosql.plugin.tpch.TpchRecordSetProvider) ImmutableSet.toImmutableSet(com.google.common.collect.ImmutableSet.toImmutableSet) RecordCursor(io.prestosql.spi.connector.RecordCursor) Preconditions.checkPositionIndex(com.google.common.base.Preconditions.checkPositionIndex) Type(io.prestosql.spi.type.Type) ImmutableMap(com.google.common.collect.ImmutableMap) TupleDomain(io.prestosql.spi.predicate.TupleDomain) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) AbstractIterator(com.google.common.collect.AbstractIterator) Set(java.util.Set) Preconditions.checkState(com.google.common.base.Preconditions.checkState) TpchTable(io.airlift.tpch.TpchTable) Objects(java.util.Objects) List(java.util.List) TpchMetadata(io.prestosql.plugin.tpch.TpchMetadata) ColumnHandle(io.prestosql.spi.connector.ColumnHandle) ImmutableListMultimap(com.google.common.collect.ImmutableListMultimap) Optional(java.util.Optional) Type(io.prestosql.spi.type.Type) RecordCursor(io.prestosql.spi.connector.RecordCursor) ImmutableListMultimap(com.google.common.collect.ImmutableListMultimap)

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