Java Code Examples for io.prestosql.spi.connector.RecordSet#getColumnTypes()

The following examples show how to use io.prestosql.spi.connector.RecordSet#getColumnTypes() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TpchIndexedData.java    From presto with Apache License 2.0 6 votes vote down vote up
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());
}
 
Example 2
Source File: FieldSetFilteringRecordSet.java    From presto with Apache License 2.0 6 votes vote down vote up
public FieldSetFilteringRecordSet(Metadata metadata, RecordSet delegate, List<Set<Integer>> fieldSets)
{
    requireNonNull(metadata, "metadata is null");
    this.delegate = requireNonNull(delegate, "delegate is null");

    ImmutableList.Builder<Set<Field>> fieldSetsBuilder = ImmutableList.builder();
    List<Type> columnTypes = delegate.getColumnTypes();
    for (Set<Integer> fieldSet : requireNonNull(fieldSets, "fieldSets is null")) {
        ImmutableSet.Builder<Field> fieldSetBuilder = ImmutableSet.builder();
        for (int field : fieldSet) {
            ResolvedFunction resolvedFunction = metadata.resolveOperator(EQUAL, ImmutableList.of(columnTypes.get(field), columnTypes.get(field)));
            MethodHandle methodHandle = metadata.getScalarFunctionInvoker(resolvedFunction, Optional.empty()).getMethodHandle();
            fieldSetBuilder.add(new Field(field, methodHandle));
        }
        fieldSetsBuilder.add(fieldSetBuilder.build());
    }
    this.fieldSets = fieldSetsBuilder.build();
}
 
Example 3
Source File: PrestoThriftPageResult.java    From presto with Apache License 2.0 5 votes vote down vote up
public static PrestoThriftPageResult fromRecordSet(RecordSet recordSet)
{
    List<Type> types = recordSet.getColumnTypes();
    int numberOfColumns = types.size();
    int positions = totalRecords(recordSet);
    if (numberOfColumns == 0) {
        return new PrestoThriftPageResult(ImmutableList.of(), positions, null);
    }
    List<PrestoThriftBlock> thriftBlocks = new ArrayList<>(numberOfColumns);
    for (int columnIndex = 0; columnIndex < numberOfColumns; columnIndex++) {
        thriftBlocks.add(fromRecordSetColumn(recordSet, columnIndex, positions));
    }
    return new PrestoThriftPageResult(thriftBlocks, positions, null);
}
 
Example 4
Source File: MappedRecordSet.java    From presto with Apache License 2.0 5 votes vote down vote up
public MappedRecordSet(RecordSet delegate, List<Integer> delegateFieldIndex)
{
    this.delegate = requireNonNull(delegate, "delegate is null");
    this.delegateFieldIndex = Ints.toArray(requireNonNull(delegateFieldIndex, "delegateFieldIndex is null"));

    List<Type> types = delegate.getColumnTypes();
    this.columnTypes = delegateFieldIndex.stream().map(types::get).collect(toImmutableList());
}