Search in sources :

Example 26 with RecordCursor

use of com.facebook.presto.spi.RecordCursor in project presto by prestodb.

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(com.facebook.presto.spi.RecordCursor) Test(org.testng.annotations.Test)

Example 27 with RecordCursor

use of com.facebook.presto.spi.RecordCursor in project presto by prestodb.

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(com.facebook.presto.spi.RecordCursor) Test(org.testng.annotations.Test)

Example 28 with RecordCursor

use of com.facebook.presto.spi.RecordCursor in project presto by prestodb.

the class TableStatisticsRecorder method recordStatistics.

public TableStatisticsData recordStatistics(Table table, double scaleFactor) {
    Session session = Session.getDefaultSession().withScale(scaleFactor).withParallelism(1).withNoSexism(false);
    List<Column> columns = ImmutableList.copyOf(table.getColumns());
    RecordCursor recordCursor = new TpcdsRecordSet(Results.constructResults(table, session), columns).cursor();
    List<ColumnStatisticsRecorder> statisticsRecorders = createStatisticsRecorders(columns);
    long rowCount = 0;
    while (recordCursor.advanceNextPosition()) {
        rowCount++;
        for (int columnId = 0; columnId < columns.size(); columnId++) {
            Comparable<?> value = getPrestoValue(recordCursor, columns, columnId);
            statisticsRecorders.get(columnId).record(value);
        }
    }
    Map<String, ColumnStatisticsData> columnSampleStatistics = IntStream.range(0, columns.size()).boxed().collect(toImmutableMap(i -> columns.get(i).getName(), i -> statisticsRecorders.get(i).getRecording()));
    return new TableStatisticsData(rowCount, columnSampleStatistics);
}
Also used : IntStream(java.util.stream.IntStream) Session(com.teradata.tpcds.Session) TpcdsRecordSet(com.facebook.presto.tpcds.TpcdsRecordSet) Results(com.teradata.tpcds.Results) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) String.format(java.lang.String.format) RecordCursor(com.facebook.presto.spi.RecordCursor) List(java.util.List) ImmutableMap.toImmutableMap(com.google.common.collect.ImmutableMap.toImmutableMap) ImmutableList(com.google.common.collect.ImmutableList) Column(com.teradata.tpcds.column.Column) Map(java.util.Map) ColumnType(com.teradata.tpcds.column.ColumnType) Table(com.teradata.tpcds.Table) RecordCursor(com.facebook.presto.spi.RecordCursor) TpcdsRecordSet(com.facebook.presto.tpcds.TpcdsRecordSet) Column(com.teradata.tpcds.column.Column) Session(com.teradata.tpcds.Session)

Example 29 with RecordCursor

use of com.facebook.presto.spi.RecordCursor in project presto by prestodb.

the class PrestoThriftPageResult method totalRecords.

private static int totalRecords(RecordSet recordSet) {
    RecordCursor cursor = recordSet.cursor();
    int result = 0;
    while (cursor.advanceNextPosition()) {
        result++;
    }
    return result;
}
Also used : RecordCursor(com.facebook.presto.spi.RecordCursor)

Aggregations

RecordCursor (com.facebook.presto.spi.RecordCursor)29 Test (org.testng.annotations.Test)17 RecordSet (com.facebook.presto.spi.RecordSet)11 List (java.util.List)9 ImmutableList (com.google.common.collect.ImmutableList)8 Optional (java.util.Optional)7 TupleDomain (com.facebook.presto.common.predicate.TupleDomain)6 LinkedHashMap (java.util.LinkedHashMap)6 Map (java.util.Map)6 Objects.requireNonNull (java.util.Objects.requireNonNull)6 OptionalInt (java.util.OptionalInt)6 SchemaTableName (com.facebook.presto.spi.SchemaTableName)5 ConnectorTransactionHandle (com.facebook.presto.spi.connector.ConnectorTransactionHandle)5 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)5 Type (com.facebook.presto.common.type.Type)4 ColumnHandle (com.facebook.presto.spi.ColumnHandle)4 ConnectorSession (com.facebook.presto.spi.ConnectorSession)4 RecordPageSource (com.facebook.presto.spi.RecordPageSource)4 DateTimeZone (org.joda.time.DateTimeZone)4 ArrayType (com.facebook.presto.common.type.ArrayType)3