Search in sources :

Example 1 with SortingColumn

use of io.prestosql.plugin.memory.SortingColumn in project hetu-core by openlookeng.

the class Table method add.

/**
 * Add page to splits in a robin-robin way.
 *
 * @param page page to add
 */
public void add(Page page) {
    // if there is no partition statement, just create one LP with the empty partition key
    if (partitionedBy.isEmpty()) {
        if (logicalParts.isEmpty() || !logicalParts.get(logicalParts.size() - 1).canAdd()) {
            this.logicalParts.add(new LogicalPart(columns, sortedBy, indexColumns, tableDataRoot, pageSorter, maxLogicalPartBytes, maxPageSizeBytes, typeManager, pagesSerde, logicalParts.size() + 1, compressionEnabled));
        }
        logicalParts.get(logicalParts.size() - 1).add(page);
    } else // if there is partitioned_by string,
    // 1. get the partition values from the partitioned column;
    // 2. partition the page to multiple subpages according to the values and add their indices to the logicalPartPartitionedMap accordingly
    {
        Map<String, Page> partitions = LogicalPart.partitionPage(page, partitionedBy, columns, typeManager);
        for (Map.Entry<String, Page> entry : partitions.entrySet()) {
            String curPartitionKey = entry.getKey();
            Page curSubPage = entry.getValue();
            logicalPartPartitionedMap.putIfAbsent(curPartitionKey, new ArrayList<>());
            List<Integer> logicalPartIndices = logicalPartPartitionedMap.get(curPartitionKey);
            LogicalPart lastLogicalPart = logicalPartIndices.isEmpty() ? null : this.logicalParts.get(logicalPartIndices.get(logicalPartIndices.size() - 1) - 1);
            if (lastLogicalPart == null || !lastLogicalPart.canAdd()) {
                int logicalPartNum = logicalParts.size() + 1;
                if (sortedBy.isEmpty()) {
                    // 1. partitioned only -> force sorting on partition column
                    // 2. partitioned and sorted_by on different columns -> sort on the specified column.
                    // The purpose is to prevent generating many small pages.
                    List<SortingColumn> convertedSortingCol = Arrays.asList(new SortingColumn(partitionedBy.get(0), SortOrder.ASC_NULLS_LAST));
                    lastLogicalPart = new LogicalPart(columns, convertedSortingCol, indexColumns, tableDataRoot, pageSorter, maxLogicalPartBytes, maxPageSizeBytes, typeManager, pagesSerde, logicalPartNum, compressionEnabled);
                } else {
                    lastLogicalPart = new LogicalPart(columns, sortedBy, indexColumns, tableDataRoot, pageSorter, maxLogicalPartBytes, maxPageSizeBytes, typeManager, pagesSerde, logicalPartNum, compressionEnabled);
                }
                logicalParts.add(lastLogicalPart);
                logicalPartIndices.add(logicalPartNum);
            }
            lastLogicalPart.add(curSubPage);
        }
    }
    byteSize += page.getSizeInBytes();
    tableState = TableState.MODIFIED;
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) SortingColumn(io.prestosql.plugin.memory.SortingColumn) Page(io.prestosql.spi.Page) HashMap(java.util.HashMap) Map(java.util.Map) AbstractMap(java.util.AbstractMap) TreeMap(java.util.TreeMap)

Aggregations

SortingColumn (io.prestosql.plugin.memory.SortingColumn)1 Page (io.prestosql.spi.Page)1 AbstractMap (java.util.AbstractMap)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 TreeMap (java.util.TreeMap)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1