Search in sources :

Example 36 with Pair

use of io.prestosql.spi.heuristicindex.Pair in project hetu-core by openlookeng.

the class TestPartitionIndexWriter method testAddValue.

@Test
public void testAddValue() throws IOException {
    List<Pair<String, Type>> columns = new ArrayList<>();
    List<String> partitions = Collections.singletonList("partition1");
    Properties properties = new Properties();
    CreateIndexMetadata createIndexMetadata = new CreateIndexMetadata("hetu_partition_idx", "testTable", "BTREE", 0L, columns, partitions, properties, "testuser", CreateIndexMetadata.Level.PARTITION);
    HetuFileSystemClient fileSystemClient = Mockito.mock(HetuFileSystemClient.class);
    Properties connectorMetadata = new Properties();
    connectorMetadata.setProperty(HetuConstant.DATASOURCE_FILE_MODIFICATION, String.valueOf(System.currentTimeMillis()));
    connectorMetadata.setProperty(HetuConstant.DATASOURCE_FILE_PATH, "hdfs://testable/testcolumn/cp=123121/file1");
    connectorMetadata.setProperty(HetuConstant.DATASOURCE_STRIPE_OFFSET, "3");
    connectorMetadata.setProperty(HetuConstant.DATASOURCE_STRIPE_LENGTH, "100");
    PartitionIndexWriter indexWriter = new PartitionIndexWriter(createIndexMetadata, fileSystemClient, Paths.get("/tmp"));
    Map<String, List<Object>> valuesMap = new HashMap<>();
    List<Object> values = new ArrayList<>();
    for (int i = 0; i < 10; i++) {
        values.add("key" + i);
    }
    valuesMap.put("testcolumne", values);
    indexWriter.addData(valuesMap, connectorMetadata);
    Map<Comparable<? extends Comparable<?>>, String> result = indexWriter.getDataMap();
    assertEquals(10, result.size());
    assertEquals(1, indexWriter.getSymbolTable().size());
}
Also used : CreateIndexMetadata(io.prestosql.spi.connector.CreateIndexMetadata) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Properties(java.util.Properties) HetuFileSystemClient(io.prestosql.spi.filesystem.HetuFileSystemClient) ArrayList(java.util.ArrayList) List(java.util.List) Pair(io.prestosql.spi.heuristicindex.Pair) Test(org.testng.annotations.Test)

Example 37 with Pair

use of io.prestosql.spi.heuristicindex.Pair in project hetu-core by openlookeng.

the class CreateIndexOperator method addInput.

@Override
public void addInput(Page page) {
    checkState(needsInput(), "Operator is already finishing");
    requireNonNull(page, "page is null");
    // TODO-cp-I38S9O: Operator currently not supported for Snapshot
    if (page instanceof MarkerPage) {
        throw new UnsupportedOperationException("Operator doesn't support snapshotting.");
    }
    // if operator is still receiving input, it's not finished
    finished.putIfAbsent(this, false);
    if (page.getPositionCount() == 0) {
        return;
    }
    if (createIndexMetadata.getCreateLevel() == CreateIndexMetadata.Level.UNDEFINED) {
        boolean tableIsPartitioned = getPartitionName(page.getPageMetadata().getProperty(HetuConstant.DATASOURCE_FILE_PATH), createIndexMetadata.getTableName()) != null;
        createIndexMetadata.decideIndexLevel(tableIsPartitioned);
    }
    Map<String, List<Object>> values = new HashMap<>();
    for (int blockId = 0; blockId < page.getChannelCount(); blockId++) {
        Block block = page.getBlock(blockId);
        Pair<String, Type> entry = createIndexMetadata.getIndexColumns().get(blockId);
        String indexColumn = entry.getFirst();
        Type type = entry.getSecond();
        for (int position = 0; position < block.getPositionCount(); ++position) {
            Object value = getNativeValue(type, block, position);
            value = getActualValue(type, value);
            values.computeIfAbsent(indexColumn, k -> new ArrayList<>()).add(value);
        }
    }
    Properties connectorMetadata = new Properties();
    connectorMetadata.put(HetuConstant.DATASOURCE_CATALOG, createIndexMetadata.getTableName().split("\\.")[0]);
    connectorMetadata.putAll(page.getPageMetadata());
    try {
        switch(createIndexMetadata.getCreateLevel()) {
            case STRIPE:
                {
                    String filePath = page.getPageMetadata().getProperty(HetuConstant.DATASOURCE_FILE_PATH);
                    levelWriter.computeIfAbsent(filePath, k -> heuristicIndexerManager.getIndexWriter(createIndexMetadata, connectorMetadata));
                    persistBy.putIfAbsent(levelWriter.get(filePath), this);
                    levelWriter.get(filePath).addData(values, connectorMetadata);
                    break;
                }
            case PARTITION:
                {
                    String partition = getPartitionName(page.getPageMetadata().getProperty(HetuConstant.DATASOURCE_FILE_PATH), createIndexMetadata.getTableName());
                    if (partition == null) {
                        throw new IllegalStateException("Partition level is not supported for non partitioned table.");
                    }
                    if (!createIndexMetadata.getPartitions().isEmpty()) {
                        for (String userPart : createIndexMetadata.getPartitions()) {
                            String userPartCol = userPart.split("=")[0];
                            String actualPartCol = partition.split("=")[0];
                            if (!userPartCol.equals(actualPartCol)) {
                                throw new IllegalArgumentException(String.format("Creating index on %s is not supported as it's not first-level partition", userPartCol));
                            }
                        }
                    }
                    levelWriter.putIfAbsent(partition, heuristicIndexerManager.getIndexWriter(createIndexMetadata, connectorMetadata));
                    persistBy.putIfAbsent(levelWriter.get(partition), this);
                    levelWriter.get(partition).addData(values, connectorMetadata);
                    break;
                }
            case TABLE:
                {
                    levelWriter.putIfAbsent(createIndexMetadata.getTableName(), heuristicIndexerManager.getIndexWriter(createIndexMetadata, connectorMetadata));
                    persistBy.putIfAbsent(levelWriter.get(createIndexMetadata.getTableName()), this);
                    levelWriter.get(createIndexMetadata.getTableName()).addData(values, connectorMetadata);
                    break;
                }
            default:
                throw new IllegalArgumentException("Create level not supported");
        }
    } catch (IOException e) {
        throw new UncheckedIOException(e);
    }
}
Also used : Slice(io.airlift.slice.Slice) Logger(io.airlift.log.Logger) HashMap(java.util.HashMap) RestorableConfig(io.prestosql.spi.snapshot.RestorableConfig) ArrayList(java.util.ArrayList) HetuConstant(io.prestosql.spi.HetuConstant) IndexClient(io.prestosql.spi.heuristicindex.IndexClient) Map(java.util.Map) Objects.requireNonNull(java.util.Objects.requireNonNull) Type(io.prestosql.spi.type.Type) Path(java.nio.file.Path) TypeUtils.getActualValue(io.prestosql.spi.heuristicindex.TypeUtils.getActualValue) Block(io.prestosql.spi.block.Block) HeuristicIndexerManager(io.prestosql.heuristicindex.HeuristicIndexerManager) PlanNodeId(io.prestosql.spi.plan.PlanNodeId) Properties(java.util.Properties) MarkerPage(io.prestosql.spi.snapshot.MarkerPage) Iterator(java.util.Iterator) IndexWriter(io.prestosql.spi.heuristicindex.IndexWriter) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Page(io.prestosql.spi.Page) IOException(java.io.IOException) Pair(io.prestosql.spi.heuristicindex.Pair) Preconditions.checkState(com.google.common.base.Preconditions.checkState) UncheckedIOException(java.io.UncheckedIOException) TimeUnit(java.util.concurrent.TimeUnit) TypeUtils(io.prestosql.spi.type.TypeUtils) List(java.util.List) Paths(java.nio.file.Paths) CreateIndexMetadata(io.prestosql.spi.connector.CreateIndexMetadata) Collections(java.util.Collections) MarkerPage(io.prestosql.spi.snapshot.MarkerPage) HashMap(java.util.HashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) ArrayList(java.util.ArrayList) UncheckedIOException(java.io.UncheckedIOException) IOException(java.io.IOException) UncheckedIOException(java.io.UncheckedIOException) Properties(java.util.Properties) Type(io.prestosql.spi.type.Type) Block(io.prestosql.spi.block.Block) ArrayList(java.util.ArrayList) List(java.util.List)

Example 38 with Pair

use of io.prestosql.spi.heuristicindex.Pair in project hetu-core by openlookeng.

the class TestMemorySelection method getSplitAndMaterializedResult.

Pair<Integer, MaterializedResult> getSplitAndMaterializedResult(String testerQuery) {
    // Select the entry with specifics
    MaterializedResult queryResult = computeActual(testerQuery);
    String doublyQuotedQuery = testerQuery.replaceAll("'", "''");
    // Get queries executed and query ID to find the task with sum of splits
    String splits = "select sum(splits) from system.runtime.tasks where query_id in " + "(select query_id from system.runtime.queries " + "where query='" + doublyQuotedQuery + "' order by created desc limit 1)";
    MaterializedResult rows = computeActual(splits);
    assertEquals(rows.getRowCount(), 1);
    MaterializedRow materializedRow = rows.getMaterializedRows().get(0);
    int fieldCount = materializedRow.getFieldCount();
    assertEquals(fieldCount, 1, "Expected only one column, but got '%d', fiedlCount: " + fieldCount);
    Object value = materializedRow.getField(0);
    return new Pair<>((int) (long) value, queryResult);
}
Also used : MaterializedResult(io.prestosql.testing.MaterializedResult) MaterializedRow(io.prestosql.testing.MaterializedRow) Pair(io.prestosql.spi.heuristicindex.Pair)

Aggregations

Pair (io.prestosql.spi.heuristicindex.Pair)38 Test (org.testng.annotations.Test)25 File (java.io.File)24 FileOutputStream (java.io.FileOutputStream)24 FileInputStream (java.io.FileInputStream)23 ArrayList (java.util.ArrayList)22 RowExpression (io.prestosql.spi.relation.RowExpression)14 TempFolder (io.hetu.core.common.filesystem.TempFolder)12 List (java.util.List)10 IOException (java.io.IOException)9 CreateIndexMetadata (io.prestosql.spi.connector.CreateIndexMetadata)8 Map (java.util.Map)8 Properties (java.util.Properties)8 HashMap (java.util.HashMap)7 Iterator (java.util.Iterator)7 Collections (java.util.Collections)6 Index (io.prestosql.spi.heuristicindex.Index)5 Objects.requireNonNull (java.util.Objects.requireNonNull)5 Preconditions.checkState (com.google.common.base.Preconditions.checkState)4 HeuristicIndexerManager (io.prestosql.heuristicindex.HeuristicIndexerManager)4