Search in sources :

Example 1 with NullableValue

use of com.facebook.presto.common.predicate.NullableValue in project presto by prestodb.

the class TestOrcStorageManager method testReader.

@Test
public void testReader() throws Exception {
    OrcStorageManager manager = createOrcStorageManager();
    List<Long> columnIds = ImmutableList.of(2L, 4L, 6L, 7L, 8L, 9L);
    List<Type> columnTypes = ImmutableList.of(BIGINT, createVarcharType(10), VARBINARY, DATE, BOOLEAN, DOUBLE);
    byte[] bytes1 = octets(0x00, 0xFE, 0xFF);
    byte[] bytes3 = octets(0x01, 0x02, 0x19, 0x80);
    StoragePageSink sink = createStoragePageSink(manager, columnIds, columnTypes);
    Object[][] doubles = { { 881L, "-inf", null, null, null, Double.NEGATIVE_INFINITY }, { 882L, "+inf", null, null, null, Double.POSITIVE_INFINITY }, { 883L, "nan", null, null, null, Double.NaN }, { 884L, "min", null, null, null, Double.MIN_VALUE }, { 885L, "max", null, null, null, Double.MAX_VALUE }, { 886L, "pzero", null, null, null, 0.0 }, { 887L, "nzero", null, null, null, -0.0 } };
    List<Page> pages = rowPagesBuilder(columnTypes).row(123L, "hello", wrappedBuffer(bytes1), sqlDate(2001, 8, 22).getDays(), true, 123.45).row(null, null, null, null, null, null).row(456L, "bye", wrappedBuffer(bytes3), sqlDate(2005, 4, 22).getDays(), false, 987.65).rows(doubles).build();
    sink.appendPages(pages);
    List<ShardInfo> shards = getFutureValue(sink.commit());
    assertEquals(shards.size(), 1);
    UUID uuid = Iterables.getOnlyElement(shards).getShardUuid();
    MaterializedResult expected = resultBuilder(SESSION, columnTypes).row(123L, "hello", sqlBinary(bytes1), sqlDate(2001, 8, 22), true, 123.45).row(null, null, null, null, null, null).row(456L, "bye", sqlBinary(bytes3), sqlDate(2005, 4, 22), false, 987.65).rows(doubles).build();
    // no tuple domain (all)
    TupleDomain<RaptorColumnHandle> tupleDomain = TupleDomain.all();
    try (ConnectorPageSource pageSource = getPageSource(manager, columnIds, columnTypes, uuid, tupleDomain)) {
        MaterializedResult result = materializeSourceDataStream(SESSION, pageSource, columnTypes);
        assertEquals(result.getRowCount(), expected.getRowCount());
        assertEquals(result, expected);
    }
    // tuple domain within the column range
    tupleDomain = TupleDomain.fromFixedValues(ImmutableMap.<RaptorColumnHandle, NullableValue>builder().put(new RaptorColumnHandle("test", "c1", 2, BIGINT), NullableValue.of(BIGINT, 124L)).build());
    try (ConnectorPageSource pageSource = getPageSource(manager, columnIds, columnTypes, uuid, tupleDomain)) {
        MaterializedResult result = materializeSourceDataStream(SESSION, pageSource, columnTypes);
        assertEquals(result.getRowCount(), expected.getRowCount());
    }
    // tuple domain outside the column range
    tupleDomain = TupleDomain.fromFixedValues(ImmutableMap.<RaptorColumnHandle, NullableValue>builder().put(new RaptorColumnHandle("test", "c1", 2, BIGINT), NullableValue.of(BIGINT, 122L)).build());
    try (ConnectorPageSource pageSource = getPageSource(manager, columnIds, columnTypes, uuid, tupleDomain)) {
        MaterializedResult result = materializeSourceDataStream(SESSION, pageSource, columnTypes);
        assertEquals(result.getRowCount(), 0);
    }
}
Also used : RaptorColumnHandle(com.facebook.presto.raptor.RaptorColumnHandle) NullableValue(com.facebook.presto.common.predicate.NullableValue) Page(com.facebook.presto.common.Page) ConnectorPageSource(com.facebook.presto.spi.ConnectorPageSource) VarcharType.createVarcharType(com.facebook.presto.common.type.VarcharType.createVarcharType) Type(com.facebook.presto.common.type.Type) OptionalLong(java.util.OptionalLong) UUID(java.util.UUID) MaterializedResult(com.facebook.presto.testing.MaterializedResult) ShardInfo(com.facebook.presto.raptor.metadata.ShardInfo) Test(org.testng.annotations.Test)

Example 2 with NullableValue

use of com.facebook.presto.common.predicate.NullableValue in project presto by prestodb.

the class TableStatsSystemTable method buildPages.

private static List<Page> buildPages(MetadataDao dao, TupleDomain<Integer> tupleDomain) {
    Map<Integer, NullableValue> domainValues = extractFixedValues(tupleDomain).orElse(ImmutableMap.of());
    String schemaName = getStringValue(domainValues.get(getColumnIndex(METADATA, SCHEMA_NAME)));
    String tableName = getStringValue(domainValues.get(getColumnIndex(METADATA, TABLE_NAME)));
    PageListBuilder pageBuilder = new PageListBuilder(METADATA.getColumns().stream().map(ColumnMetadata::getType).collect(toList()));
    for (TableStatsRow row : dao.getTableStatsRows(schemaName, tableName)) {
        pageBuilder.beginRow();
        VARCHAR.writeSlice(pageBuilder.nextBlockBuilder(), utf8Slice(row.getSchemaName()));
        VARCHAR.writeSlice(pageBuilder.nextBlockBuilder(), utf8Slice(row.getTableName()));
        TIMESTAMP.writeLong(pageBuilder.nextBlockBuilder(), row.getCreateTime());
        TIMESTAMP.writeLong(pageBuilder.nextBlockBuilder(), row.getUpdateTime());
        BIGINT.writeLong(pageBuilder.nextBlockBuilder(), row.getTableVersion());
        BIGINT.writeLong(pageBuilder.nextBlockBuilder(), row.getShardCount());
        BIGINT.writeLong(pageBuilder.nextBlockBuilder(), row.getDeltaCount());
        BIGINT.writeLong(pageBuilder.nextBlockBuilder(), row.getRowCount());
        BIGINT.writeLong(pageBuilder.nextBlockBuilder(), row.getCompressedSize());
        BIGINT.writeLong(pageBuilder.nextBlockBuilder(), row.getUncompressedSize());
    }
    return pageBuilder.build();
}
Also used : TableStatsRow(com.facebook.presto.raptor.metadata.TableStatsRow) ColumnMetadata(com.facebook.presto.spi.ColumnMetadata) NullableValue(com.facebook.presto.common.predicate.NullableValue)

Example 3 with NullableValue

use of com.facebook.presto.common.predicate.NullableValue in project presto by prestodb.

the class TpchIndexProvider method getIndex.

@Override
public ConnectorIndex getIndex(ConnectorTransactionHandle transaction, ConnectorSession session, ConnectorIndexHandle indexHandle, List<ColumnHandle> lookupSchema, List<ColumnHandle> outputSchema) {
    TpchIndexHandle tpchIndexHandle = (TpchIndexHandle) indexHandle;
    Map<ColumnHandle, NullableValue> fixedValues = TupleDomain.extractFixedValues(tpchIndexHandle.getFixedValues()).get();
    checkArgument(lookupSchema.stream().noneMatch(handle -> fixedValues.keySet().contains(handle)), "Lookup columnHandles are not expected to overlap with the fixed value predicates");
    // Establish an order for the fixedValues
    List<ColumnHandle> fixedValueColumns = ImmutableList.copyOf(fixedValues.keySet());
    // Extract the fixedValues as their raw values and types
    List<Object> rawFixedValues = new ArrayList<>(fixedValueColumns.size());
    List<Type> rawFixedTypes = new ArrayList<>(fixedValueColumns.size());
    for (ColumnHandle fixedValueColumn : fixedValueColumns) {
        rawFixedValues.add(fixedValues.get(fixedValueColumn).getValue());
        rawFixedTypes.add(((TpchColumnHandle) fixedValueColumn).getType());
    }
    // Establish the schema after we append the fixed values to the lookup keys.
    List<ColumnHandle> finalLookupSchema = ImmutableList.<ColumnHandle>builder().addAll(lookupSchema).addAll(fixedValueColumns).build();
    Optional<TpchIndexedData.IndexedTable> indexedTable = indexedData.getIndexedTable(tpchIndexHandle.getTableName(), tpchIndexHandle.getScaleFactor(), tpchIndexHandle.getIndexColumnNames());
    checkState(indexedTable.isPresent());
    TpchIndexedData.IndexedTable table = indexedTable.get();
    // Compute how to map from the final lookup schema to the table index key order
    List<Integer> keyRemap = computeRemap(handleToNames(finalLookupSchema), table.getKeyColumns());
    Function<RecordSet, RecordSet> keyFormatter = key -> new MappedRecordSet(new AppendingRecordSet(key, rawFixedValues, rawFixedTypes), keyRemap);
    // Compute how to map from the output of the indexed data to the expected output schema
    List<Integer> outputRemap = computeRemap(table.getOutputColumns(), handleToNames(outputSchema));
    Function<RecordSet, RecordSet> outputFormatter = output -> new MappedRecordSet(output, outputRemap);
    return new TpchConnectorIndex(keyFormatter, outputFormatter, table);
}
Also used : ConnectorIndexHandle(com.facebook.presto.spi.ConnectorIndexHandle) Function(com.google.common.base.Function) NullableValue(com.facebook.presto.common.predicate.NullableValue) ConnectorIndexProvider(com.facebook.presto.spi.connector.ConnectorIndexProvider) TupleDomain(com.facebook.presto.common.predicate.TupleDomain) ConnectorTransactionHandle(com.facebook.presto.spi.connector.ConnectorTransactionHandle) RecordSet(com.facebook.presto.spi.RecordSet) ArrayList(java.util.ArrayList) Preconditions.checkState(com.google.common.base.Preconditions.checkState) ConnectorSession(com.facebook.presto.spi.ConnectorSession) List(java.util.List) Preconditions.checkArgument(com.google.common.base.Preconditions.checkArgument) Collectors.toList(java.util.stream.Collectors.toList) ImmutableList(com.google.common.collect.ImmutableList) ColumnHandle(com.facebook.presto.spi.ColumnHandle) TpchColumnHandle(com.facebook.presto.tpch.TpchColumnHandle) Map(java.util.Map) Objects.requireNonNull(java.util.Objects.requireNonNull) ConnectorIndex(com.facebook.presto.spi.ConnectorIndex) Optional(java.util.Optional) MappedRecordSet(com.facebook.presto.split.MappedRecordSet) Type(com.facebook.presto.common.type.Type) ColumnHandle(com.facebook.presto.spi.ColumnHandle) TpchColumnHandle(com.facebook.presto.tpch.TpchColumnHandle) ArrayList(java.util.ArrayList) NullableValue(com.facebook.presto.common.predicate.NullableValue) Type(com.facebook.presto.common.type.Type) MappedRecordSet(com.facebook.presto.split.MappedRecordSet) RecordSet(com.facebook.presto.spi.RecordSet) MappedRecordSet(com.facebook.presto.split.MappedRecordSet)

Example 4 with NullableValue

use of com.facebook.presto.common.predicate.NullableValue in project presto by prestodb.

the class TpchIndexMetadata method resolveIndex.

@Override
public Optional<ConnectorResolvedIndex> resolveIndex(ConnectorSession session, ConnectorTableHandle tableHandle, Set<ColumnHandle> indexableColumns, Set<ColumnHandle> outputColumns, TupleDomain<ColumnHandle> tupleDomain) {
    TpchTableHandle tpchTableHandle = (TpchTableHandle) tableHandle;
    // Keep the fixed values that don't overlap with the indexableColumns
    // Note: technically we could more efficiently utilize the overlapped columns, but this way is simpler for now
    Map<ColumnHandle, NullableValue> fixedValues = TupleDomain.extractFixedValues(tupleDomain).orElse(ImmutableMap.of()).entrySet().stream().filter(entry -> !indexableColumns.contains(entry.getKey())).filter(// strip nulls since meaningless in index join lookups
    entry -> !entry.getValue().isNull()).collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));
    // determine all columns available for index lookup
    Set<String> lookupColumnNames = ImmutableSet.<String>builder().addAll(handleToNames(ImmutableList.copyOf(indexableColumns))).addAll(handleToNames(ImmutableList.copyOf(fixedValues.keySet()))).build();
    // do we have an index?
    if (!indexedData.getIndexedTable(tpchTableHandle.getTableName(), tpchTableHandle.getScaleFactor(), lookupColumnNames).isPresent()) {
        return Optional.empty();
    }
    TupleDomain<ColumnHandle> filteredTupleDomain = tupleDomain;
    if (!tupleDomain.isNone()) {
        filteredTupleDomain = TupleDomain.withColumnDomains(Maps.filterKeys(tupleDomain.getDomains().get(), not(in(fixedValues.keySet()))));
    }
    TpchIndexHandle indexHandle = new TpchIndexHandle(tpchTableHandle.getTableName(), tpchTableHandle.getScaleFactor(), lookupColumnNames, TupleDomain.fromFixedValues(fixedValues));
    return Optional.of(new ConnectorResolvedIndex(indexHandle, filteredTupleDomain));
}
Also used : ImmutableSet(com.google.common.collect.ImmutableSet) NullableValue(com.facebook.presto.common.predicate.NullableValue) ImmutableMap(com.google.common.collect.ImmutableMap) TpchIndexProvider.handleToNames(com.facebook.presto.tests.tpch.TpchIndexProvider.handleToNames) Set(java.util.Set) ConnectorTableHandle(com.facebook.presto.spi.ConnectorTableHandle) ConnectorResolvedIndex(com.facebook.presto.spi.ConnectorResolvedIndex) TpchMetadata(com.facebook.presto.tpch.TpchMetadata) Maps(com.google.common.collect.Maps) Collectors(java.util.stream.Collectors) TupleDomain(com.facebook.presto.common.predicate.TupleDomain) ConnectorSession(com.facebook.presto.spi.ConnectorSession) TpchTableHandle(com.facebook.presto.tpch.TpchTableHandle) Predicates.in(com.google.common.base.Predicates.in) ImmutableList(com.google.common.collect.ImmutableList) Predicates.not(com.google.common.base.Predicates.not) ColumnHandle(com.facebook.presto.spi.ColumnHandle) Map(java.util.Map) Objects.requireNonNull(java.util.Objects.requireNonNull) Optional(java.util.Optional) ColumnHandle(com.facebook.presto.spi.ColumnHandle) ConnectorResolvedIndex(com.facebook.presto.spi.ConnectorResolvedIndex) NullableValue(com.facebook.presto.common.predicate.NullableValue) ImmutableMap(com.google.common.collect.ImmutableMap) Map(java.util.Map) TpchTableHandle(com.facebook.presto.tpch.TpchTableHandle)

Example 5 with NullableValue

use of com.facebook.presto.common.predicate.NullableValue in project presto by prestodb.

the class AbstractTestHiveClient method testBucketedTableStringInt.

@Test
public void testBucketedTableStringInt() throws Exception {
    try (Transaction transaction = newTransaction()) {
        ConnectorMetadata metadata = transaction.getMetadata();
        ConnectorSession session = newSession();
        ConnectorTableHandle tableHandle = getTableHandle(metadata, tableBucketedStringInt);
        List<ColumnHandle> columnHandles = ImmutableList.copyOf(metadata.getColumnHandles(session, tableHandle).values());
        Map<String, Integer> columnIndex = indexColumns(columnHandles);
        assertTableIsBucketed(transaction, tableHandle);
        String testString = "test";
        Integer testInt = 13;
        Short testSmallint = 12;
        // Reverse the order of bindings as compared to bucketing order
        ImmutableMap<ColumnHandle, NullableValue> bindings = ImmutableMap.<ColumnHandle, NullableValue>builder().put(columnHandles.get(columnIndex.get("t_int")), NullableValue.of(INTEGER, (long) testInt)).put(columnHandles.get(columnIndex.get("t_string")), NullableValue.of(createUnboundedVarcharType(), utf8Slice(testString))).put(columnHandles.get(columnIndex.get("t_smallint")), NullableValue.of(SMALLINT, (long) testSmallint)).build();
        MaterializedResult result = readTable(transaction, tableHandle, columnHandles, session, TupleDomain.fromFixedValues(bindings), OptionalInt.of(1), Optional.empty());
        boolean rowFound = false;
        for (MaterializedRow row : result) {
            if (testString.equals(row.getField(columnIndex.get("t_string"))) && testInt.equals(row.getField(columnIndex.get("t_int"))) && testSmallint.equals(row.getField(columnIndex.get("t_smallint")))) {
                rowFound = true;
            }
        }
        assertTrue(rowFound);
    }
}
Also used : HiveColumnHandle.bucketColumnHandle(com.facebook.presto.hive.HiveColumnHandle.bucketColumnHandle) ColumnHandle(com.facebook.presto.spi.ColumnHandle) NullableValue(com.facebook.presto.common.predicate.NullableValue) ConnectorTableHandle(com.facebook.presto.spi.ConnectorTableHandle) TestingConnectorSession(com.facebook.presto.testing.TestingConnectorSession) ConnectorSession(com.facebook.presto.spi.ConnectorSession) ConnectorMetadata(com.facebook.presto.spi.connector.ConnectorMetadata) MaterializedResult(com.facebook.presto.testing.MaterializedResult) MaterializedRow(com.facebook.presto.testing.MaterializedRow) Test(org.testng.annotations.Test)

Aggregations

NullableValue (com.facebook.presto.common.predicate.NullableValue)26 ColumnHandle (com.facebook.presto.spi.ColumnHandle)17 TupleDomain (com.facebook.presto.common.predicate.TupleDomain)12 ConnectorSession (com.facebook.presto.spi.ConnectorSession)12 ImmutableList (com.google.common.collect.ImmutableList)9 Map (java.util.Map)9 SchemaTableName (com.facebook.presto.spi.SchemaTableName)8 ImmutableMap (com.google.common.collect.ImmutableMap)8 Optional (java.util.Optional)8 Set (java.util.Set)8 Domain (com.facebook.presto.common.predicate.Domain)7 Type (com.facebook.presto.common.type.Type)7 ConnectorTableHandle (com.facebook.presto.spi.ConnectorTableHandle)7 ConnectorTableLayoutHandle (com.facebook.presto.spi.ConnectorTableLayoutHandle)7 Constraint (com.facebook.presto.spi.Constraint)7 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)7 List (java.util.List)7 Objects.requireNonNull (java.util.Objects.requireNonNull)7 PrestoException (com.facebook.presto.spi.PrestoException)6 ImmutableSet (com.google.common.collect.ImmutableSet)6