Search in sources :

Example 1 with Type

use of io.prestosql.spi.type.Type in project hetu-core by openlookeng.

the class LogicalPart method writeObject.

private void writeObject(ObjectOutputStream out) throws IOException {
    out.defaultWriteObject();
    out.writeInt(types.size());
    for (Type type : types) {
        out.writeUTF(TYPE_SIGNATURE_JSON_CODEC.toJson(type.getTypeSignature()));
    }
}
Also used : Type(io.prestosql.spi.type.Type)

Example 2 with Type

use of io.prestosql.spi.type.Type in project hetu-core by openlookeng.

the class LogicalPart method partitionPage.

static Map<String, Page> partitionPage(Page page, List<String> partitionedBy, List<MemoryColumnHandle> columns, TypeManager typeManager) {
    // derive the channel numbers that corresponds to the partitionedBy list
    List<MemoryColumnHandle> partitionChannels = new ArrayList<>(partitionedBy.size());
    for (String name : partitionedBy) {
        for (MemoryColumnHandle handle : columns) {
            if (handle.getColumnName().equals(name)) {
                partitionChannels.add(handle);
            }
        }
    }
    // build the partitions
    Map<String, Page> partitions = new HashMap<>();
    MemoryColumnHandle partitionColumnHandle = partitionChannels.get(0);
    Block block = page.getBlock(partitionColumnHandle.getColumnIndex());
    Type type = partitionColumnHandle.getType(typeManager);
    Map<Object, ArrayList<Integer>> uniqueValues = new HashMap<>();
    for (int i = 0; i < page.getPositionCount(); i++) {
        Object value = getNativeValue(type, block, i);
        uniqueValues.putIfAbsent(value, new ArrayList<>());
        uniqueValues.get(value).add(i);
    }
    for (Map.Entry<Object, ArrayList<Integer>> valueAndPosition : uniqueValues.entrySet()) {
        int[] retainedPositions = valueAndPosition.getValue().stream().mapToInt(i -> i).toArray();
        Object valueKey = valueAndPosition.getKey();
        Page subPage = page.getPositions(retainedPositions, 0, retainedPositions.length);
        // NOTE: null partition key is allowed here in the map
        // but when this partition map is sent to coordinator via MemoryDataFragment
        // the JSON parser fails and can't handle null keys in the map
        // the JSON parser will ignore null keys
        // therefore during scheduling if the query predicate is for null
        // we MUST NOT do any partition filtering because the partition map
        // the coordinator has is missing null partitions
        // the coordinator must schedule all splits if the query predicate is null
        // see: MemorySplitManager#getSplits
        // 
        // note: the other option is to use an empty string as the null key
        // then the JSON parser could send the key to the coordinator
        // but then this would cause conflicts with actual empty string values
        partitions.put(valueKey == null ? null : valueKey.toString(), subPage);
    }
    return partitions;
}
Also used : GZIPInputStream(java.util.zip.GZIPInputStream) ObjectInputStream(java.io.ObjectInputStream) SliceInput(io.airlift.slice.SliceInput) SortOrder(io.prestosql.spi.block.SortOrder) InputStreamSliceInput(io.airlift.slice.InputStreamSliceInput) Locale(java.util.Locale) Slices(io.airlift.slice.Slices) Map(java.util.Map) Type(io.prestosql.spi.type.Type) Path(java.nio.file.Path) Set(java.util.Set) NavigableMap(java.util.NavigableMap) SortedRangeSet(io.prestosql.spi.predicate.SortedRangeSet) Serializable(java.io.Serializable) DataSize(io.airlift.units.DataSize) List(java.util.List) Domain(io.prestosql.spi.predicate.Domain) GZIPOutputStream(java.util.zip.GZIPOutputStream) TypeSignature(io.prestosql.spi.type.TypeSignature) JsonCodec(io.airlift.json.JsonCodec) Slice(io.airlift.slice.Slice) Logger(io.airlift.log.Logger) SliceOutput(io.airlift.slice.SliceOutput) Marker(io.prestosql.spi.predicate.Marker) HashMap(java.util.HashMap) AtomicReference(java.util.concurrent.atomic.AtomicReference) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) OutputStreamSliceOutput(io.airlift.slice.OutputStreamSliceOutput) BloomFilter(io.prestosql.spi.util.BloomFilter) PagesSerde(io.hetu.core.transport.execution.buffer.PagesSerde) Range(io.prestosql.spi.predicate.Range) Objects.requireNonNull(java.util.Objects.requireNonNull) ObjectOutputStream(java.io.ObjectOutputStream) Block(io.prestosql.spi.block.Block) OutputStream(java.io.OutputStream) BaseEncoding(com.google.common.io.BaseEncoding) Files(java.nio.file.Files) TupleDomain(io.prestosql.spi.predicate.TupleDomain) TypeManager(io.prestosql.spi.type.TypeManager) Page(io.prestosql.spi.Page) IOException(java.io.IOException) PageSorter(io.prestosql.spi.PageSorter) TypeUtils(io.prestosql.spi.type.TypeUtils) AbstractMap(java.util.AbstractMap) TreeMap(java.util.TreeMap) ColumnHandle(io.prestosql.spi.connector.ColumnHandle) MemoryColumnHandle(io.prestosql.plugin.memory.MemoryColumnHandle) PagesSerdeUtil(io.hetu.core.transport.execution.buffer.PagesSerdeUtil) VisibleForTesting(com.google.common.annotations.VisibleForTesting) SortingColumn(io.prestosql.plugin.memory.SortingColumn) Collections(java.util.Collections) InputStream(java.io.InputStream) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) MemoryColumnHandle(io.prestosql.plugin.memory.MemoryColumnHandle) Page(io.prestosql.spi.Page) Type(io.prestosql.spi.type.Type) Block(io.prestosql.spi.block.Block) Map(java.util.Map) NavigableMap(java.util.NavigableMap) HashMap(java.util.HashMap) AbstractMap(java.util.AbstractMap) TreeMap(java.util.TreeMap)

Example 3 with Type

use of io.prestosql.spi.type.Type in project hetu-core by openlookeng.

the class SortBuffer method appendPositionTo.

public static void appendPositionTo(Page page, int position, PageBuilder pageBuilder) {
    pageBuilder.declarePosition();
    for (int i = 0; i < page.getChannelCount(); i++) {
        Type type = pageBuilder.getType(i);
        Block block = page.getBlock(i);
        BlockBuilder blockBuilder = pageBuilder.getBlockBuilder(i);
        type.appendTo(block, position, blockBuilder);
    }
}
Also used : Type(io.prestosql.spi.type.Type) Block(io.prestosql.spi.block.Block) BlockBuilder(io.prestosql.spi.block.BlockBuilder)

Example 4 with Type

use of io.prestosql.spi.type.Type in project hetu-core by openlookeng.

the class OrcRecordReader method createColumnReaders.

private ColumnReader[] createColumnReaders(List<OrcColumn> columns, List<Type> readTypes, AggregatedMemoryContext systemMemoryContext, OrcBlockFactory blockFactory, OrcCacheStore orcCacheStore, OrcCacheProperties orcCacheProperties) throws OrcCorruptionException {
    ColumnReader[] columnReaders = new ColumnReader[columns.size()];
    for (int i = 0; i < columns.size(); i++) {
        int columnIndex = i;
        Type readType = readTypes.get(columnIndex);
        OrcColumn column = columns.get(columnIndex);
        ColumnReader columnReader = createColumnReader(readType, column, systemMemoryContext, blockFactory.createNestedBlockFactory(block -> blockLoaded(columnIndex, block)));
        if (orcCacheProperties.isRowDataCacheEnabled()) {
            columnReader = ColumnReaders.wrapWithCachingStreamReader(columnReader, column, orcCacheStore.getRowDataCache());
        }
        columnReaders[columnIndex] = columnReader;
    }
    return columnReaders;
}
Also used : IntStream(java.util.stream.IntStream) StripeStatistics(io.prestosql.orc.metadata.statistics.StripeStatistics) DateTimeZone(org.joda.time.DateTimeZone) Arrays(java.util.Arrays) ColumnReaders.createColumnReader(io.prestosql.orc.reader.ColumnReaders.createColumnReader) DATASOURCE_TOTAL_PAGES(io.prestosql.spi.HetuConstant.DATASOURCE_TOTAL_PAGES) Slice(io.airlift.slice.Slice) Logger(io.airlift.log.Logger) DATASOURCE_FILE_PATH(io.prestosql.spi.HetuConstant.DATASOURCE_FILE_PATH) PeekingIterator(com.google.common.collect.PeekingIterator) Function(java.util.function.Function) ArrayList(java.util.ArrayList) DATASOURCE_STRIPE_NUMBER(io.prestosql.spi.HetuConstant.DATASOURCE_STRIPE_NUMBER) DATASOURCE_STRIPE_OFFSET(io.prestosql.spi.HetuConstant.DATASOURCE_STRIPE_OFFSET) Slices(io.airlift.slice.Slices) Map(java.util.Map) AggregatedMemoryContext(io.prestosql.memory.context.AggregatedMemoryContext) Type(io.prestosql.spi.type.Type) Math.toIntExact(java.lang.Math.toIntExact) Block(io.prestosql.spi.block.Block) ColumnReaders(io.prestosql.orc.reader.ColumnReaders) Properties(java.util.Properties) ImmutableMap(com.google.common.collect.ImmutableMap) DATASOURCE_FILE_MODIFICATION(io.prestosql.spi.HetuConstant.DATASOURCE_FILE_MODIFICATION) OrcType(io.prestosql.orc.metadata.OrcType) HiveWriterVersion(io.prestosql.orc.metadata.PostScript.HiveWriterVersion) Page(io.prestosql.spi.Page) IOException(java.io.IOException) Maps(com.google.common.collect.Maps) ColumnMetadata(io.prestosql.orc.metadata.ColumnMetadata) DATASOURCE_INDEX_LEVEL(io.prestosql.spi.HetuConstant.DATASOURCE_INDEX_LEVEL) ColumnReader(io.prestosql.orc.reader.ColumnReader) DATASOURCE_PAGE_NUMBER(io.prestosql.spi.HetuConstant.DATASOURCE_PAGE_NUMBER) MetadataReader(io.prestosql.orc.metadata.MetadataReader) StripeInformation(io.prestosql.orc.metadata.StripeInformation) DataSize(io.airlift.units.DataSize) List(java.util.List) ClassLayout(org.openjdk.jol.info.ClassLayout) Domain(io.prestosql.spi.predicate.Domain) DATASOURCE_STRIPE_LENGTH(io.prestosql.spi.HetuConstant.DATASOURCE_STRIPE_LENGTH) ColumnStatistics(io.prestosql.orc.metadata.statistics.ColumnStatistics) Optional(java.util.Optional) VisibleForTesting(com.google.common.annotations.VisibleForTesting) IndexMetadata(io.prestosql.spi.heuristicindex.IndexMetadata) SplitMetadata(io.prestosql.spi.heuristicindex.SplitMetadata) Type(io.prestosql.spi.type.Type) OrcType(io.prestosql.orc.metadata.OrcType) ColumnReaders.createColumnReader(io.prestosql.orc.reader.ColumnReaders.createColumnReader) ColumnReader(io.prestosql.orc.reader.ColumnReader)

Example 5 with Type

use of io.prestosql.spi.type.Type in project hetu-core by openlookeng.

the class ParquetReader method readMap.

private ColumnChunk readMap(GroupField field) throws IOException {
    List<Type> parameters = field.getType().getTypeParameters();
    checkArgument(parameters.size() == 2, "Maps must have two type parameters, found %s", parameters.size());
    Block[] localBlocks = new Block[parameters.size()];
    ColumnChunk columnChunk = readColumnChunk(field.getChildren().get(0).get());
    localBlocks[0] = columnChunk.getBlock();
    localBlocks[1] = readColumnChunk(field.getChildren().get(1).get()).getBlock();
    IntList offsets = new IntArrayList();
    BooleanList valueIsNull = new BooleanArrayList();
    calculateCollectionOffsets(field, offsets, valueIsNull, columnChunk.getDefinitionLevels(), columnChunk.getRepetitionLevels());
    Block mapBlock = ((MapType) field.getType()).createBlockFromKeyValue(Optional.of(valueIsNull.toBooleanArray()), offsets.toIntArray(), localBlocks[0], localBlocks[1]);
    return new ColumnChunk(mapBlock, columnChunk.getDefinitionLevels(), columnChunk.getRepetitionLevels());
}
Also used : BooleanList(it.unimi.dsi.fastutil.booleans.BooleanList) MapType(io.prestosql.spi.type.MapType) Type(io.prestosql.spi.type.Type) BooleanArrayList(it.unimi.dsi.fastutil.booleans.BooleanArrayList) RunLengthEncodedBlock(io.prestosql.spi.block.RunLengthEncodedBlock) Block(io.prestosql.spi.block.Block) ArrayBlock(io.prestosql.spi.block.ArrayBlock) RowBlock(io.prestosql.spi.block.RowBlock) IntArrayList(it.unimi.dsi.fastutil.ints.IntArrayList) MapType(io.prestosql.spi.type.MapType) IntList(it.unimi.dsi.fastutil.ints.IntList)

Aggregations

Type (io.prestosql.spi.type.Type)615 Test (org.testng.annotations.Test)206 ImmutableList (com.google.common.collect.ImmutableList)163 List (java.util.List)149 ArrayList (java.util.ArrayList)138 ArrayType (io.prestosql.spi.type.ArrayType)132 VarcharType (io.prestosql.spi.type.VarcharType)116 RowType (io.prestosql.spi.type.RowType)114 Page (io.prestosql.spi.Page)110 Map (java.util.Map)107 Block (io.prestosql.spi.block.Block)104 ImmutableMap (com.google.common.collect.ImmutableMap)100 PrestoException (io.prestosql.spi.PrestoException)92 VarcharType.createUnboundedVarcharType (io.prestosql.spi.type.VarcharType.createUnboundedVarcharType)90 DecimalType (io.prestosql.spi.type.DecimalType)84 Optional (java.util.Optional)81 HashMap (java.util.HashMap)80 DecimalType.createDecimalType (io.prestosql.spi.type.DecimalType.createDecimalType)68 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)67 Slice (io.airlift.slice.Slice)67