Search in sources :

Example 21 with NullableValue

use of io.prestosql.spi.predicate.NullableValue in project hetu-core by openlookeng.

the class HivePartitionManager method parsePartition.

public static HivePartition parsePartition(SchemaTableName tableName, String partitionName, List<HiveColumnHandle> partitionColumns, List<Type> partitionColumnTypes) {
    List<String> partitionValues = extractPartitionValues(partitionName);
    ImmutableMap.Builder<ColumnHandle, NullableValue> builder = ImmutableMap.builder();
    for (int i = 0; i < partitionColumns.size(); i++) {
        HiveColumnHandle column = partitionColumns.get(i);
        NullableValue parsedValue = parsePartitionValue(partitionName, partitionValues.get(i), partitionColumnTypes.get(i));
        builder.put(column, parsedValue);
    }
    Map<ColumnHandle, NullableValue> values = builder.build();
    return new HivePartition(tableName, partitionName, values);
}
Also used : ColumnHandle(io.prestosql.spi.connector.ColumnHandle) NullableValue(io.prestosql.spi.predicate.NullableValue) ImmutableMap(com.google.common.collect.ImmutableMap) Constraint(io.prestosql.spi.connector.Constraint)

Example 22 with NullableValue

use of io.prestosql.spi.predicate.NullableValue in project hetu-core by openlookeng.

the class HiveBucketing method getHiveBucket.

private static OptionalInt getHiveBucket(Table table, Map<ColumnHandle, NullableValue> bindings) {
    if (bindings.isEmpty()) {
        return OptionalInt.empty();
    }
    List<String> bucketColumns = table.getStorage().getBucketProperty().get().getBucketedBy();
    Map<String, HiveType> hiveTypes = new HashMap<>();
    for (Column column : table.getDataColumns()) {
        hiveTypes.put(column.getName(), column.getType());
    }
    // Verify the bucket column types are supported
    for (String column : bucketColumns) {
        if (!SUPPORTED_TYPES_FOR_BUCKET_FILTER.contains(hiveTypes.get(column))) {
            return OptionalInt.empty();
        }
    }
    // Get bindings for bucket columns
    Map<String, Object> bucketBindings = new HashMap<>();
    for (Entry<ColumnHandle, NullableValue> entry : bindings.entrySet()) {
        HiveColumnHandle colHandle = (HiveColumnHandle) entry.getKey();
        if (!entry.getValue().isNull() && bucketColumns.contains(colHandle.getName())) {
            bucketBindings.put(colHandle.getName(), entry.getValue().getValue());
        }
    }
    // Check that we have bindings for all bucket columns
    if (bucketBindings.size() != bucketColumns.size()) {
        return OptionalInt.empty();
    }
    // Get bindings of bucket columns
    ImmutableList.Builder<TypeInfo> typeInfos = ImmutableList.builder();
    Object[] values = new Object[bucketColumns.size()];
    for (int i = 0; i < bucketColumns.size(); i++) {
        String column = bucketColumns.get(i);
        typeInfos.add(hiveTypes.get(column).getTypeInfo());
        values[i] = bucketBindings.get(column);
    }
    BucketingVersion bucketingVersion = getBucketingVersion(table);
    return OptionalInt.of(getHiveBucket(bucketingVersion, table.getStorage().getBucketProperty().get().getBucketCount(), typeInfos.build(), values));
}
Also used : ColumnHandle(io.prestosql.spi.connector.ColumnHandle) HashMap(java.util.HashMap) ImmutableList(com.google.common.collect.ImmutableList) NullableValue(io.prestosql.spi.predicate.NullableValue) MapTypeInfo(org.apache.hadoop.hive.serde2.typeinfo.MapTypeInfo) ListTypeInfo(org.apache.hadoop.hive.serde2.typeinfo.ListTypeInfo) PrimitiveTypeInfo(org.apache.hadoop.hive.serde2.typeinfo.PrimitiveTypeInfo) TypeInfo(org.apache.hadoop.hive.serde2.typeinfo.TypeInfo) Column(io.prestosql.plugin.hive.metastore.Column)

Example 23 with NullableValue

use of io.prestosql.spi.predicate.NullableValue in project hetu-core by openlookeng.

the class JmxSplitManager method getSplits.

@Override
public ConnectorSplitSource getSplits(ConnectorTransactionHandle transaction, ConnectorSession session, ConnectorTableHandle table, SplitSchedulingStrategy splitSchedulingStrategy) {
    JmxTableHandle tableHandle = (JmxTableHandle) table;
    // TODO is there a better way to get the node column?
    Optional<JmxColumnHandle> nodeColumnHandle = tableHandle.getColumnHandles().stream().filter(jmxColumnHandle -> jmxColumnHandle.getColumnName().equals(NODE_COLUMN_NAME)).findFirst();
    checkState(nodeColumnHandle.isPresent(), "Failed to find %s column", NODE_COLUMN_NAME);
    TupleDomain<ColumnHandle> nodeFilter = tableHandle.getNodeFilter();
    List<ConnectorSplit> splits = nodeManager.getAllNodes().stream().filter(node -> {
        NullableValue value = NullableValue.of(createUnboundedVarcharType(), utf8Slice(node.getNodeIdentifier()));
        return nodeFilter.overlaps(fromFixedValues(ImmutableMap.of(nodeColumnHandle.get(), value)));
    }).map(node -> new JmxSplit(ImmutableList.of(node.getHostAndPort()))).collect(toList());
    return new FixedSplitSource(splits);
}
Also used : NODE_COLUMN_NAME(io.prestosql.plugin.jmx.JmxMetadata.NODE_COLUMN_NAME) ImmutableMap(com.google.common.collect.ImmutableMap) ConnectorSplit(io.prestosql.spi.connector.ConnectorSplit) ConnectorSplitManager(io.prestosql.spi.connector.ConnectorSplitManager) ConnectorTableHandle(io.prestosql.spi.connector.ConnectorTableHandle) TupleDomain(io.prestosql.spi.predicate.TupleDomain) ConnectorSplitSource(io.prestosql.spi.connector.ConnectorSplitSource) NullableValue(io.prestosql.spi.predicate.NullableValue) TupleDomain.fromFixedValues(io.prestosql.spi.predicate.TupleDomain.fromFixedValues) Preconditions.checkState(com.google.common.base.Preconditions.checkState) Inject(javax.inject.Inject) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList) ImmutableList(com.google.common.collect.ImmutableList) ConnectorSession(io.prestosql.spi.connector.ConnectorSession) ColumnHandle(io.prestosql.spi.connector.ColumnHandle) VarcharType.createUnboundedVarcharType(io.prestosql.spi.type.VarcharType.createUnboundedVarcharType) Objects.requireNonNull(java.util.Objects.requireNonNull) FixedSplitSource(io.prestosql.spi.connector.FixedSplitSource) ConnectorTransactionHandle(io.prestosql.spi.connector.ConnectorTransactionHandle) Optional(java.util.Optional) NodeManager(io.prestosql.spi.NodeManager) Slices.utf8Slice(io.airlift.slice.Slices.utf8Slice) ColumnHandle(io.prestosql.spi.connector.ColumnHandle) FixedSplitSource(io.prestosql.spi.connector.FixedSplitSource) NullableValue(io.prestosql.spi.predicate.NullableValue) ConnectorSplit(io.prestosql.spi.connector.ConnectorSplit)

Example 24 with NullableValue

use of io.prestosql.spi.predicate.NullableValue in project hetu-core by openlookeng.

the class TestJmxMetadata method testApplyFilterWithConstraint.

@Test
public void testApplyFilterWithConstraint() {
    JmxTableHandle handle = metadata.getTableHandle(SESSION, new SchemaTableName(JMX_SCHEMA_NAME, "java.lang:*"));
    JmxColumnHandle nodeColumnHandle = new JmxColumnHandle("node", createUnboundedVarcharType());
    NullableValue nodeColumnValue = NullableValue.of(createUnboundedVarcharType(), utf8Slice(localNode.getNodeIdentifier()));
    JmxColumnHandle objectNameColumnHandle = new JmxColumnHandle("object_name", createUnboundedVarcharType());
    NullableValue objectNameColumnValue = NullableValue.of(createUnboundedVarcharType(), utf8Slice("presto.memory:type=MemoryPool,name=reserved"));
    TupleDomain<ColumnHandle> tupleDomain = TupleDomain.fromFixedValues(ImmutableMap.of(nodeColumnHandle, nodeColumnValue, objectNameColumnHandle, objectNameColumnValue));
    Optional<ConstraintApplicationResult<ConnectorTableHandle>> result = metadata.applyFilter(SESSION, handle, new Constraint(tupleDomain));
    assertTrue(result.isPresent());
    assertEquals(result.get().getRemainingFilter(), TupleDomain.fromFixedValues(ImmutableMap.of(objectNameColumnHandle, objectNameColumnValue)));
    assertEquals(((JmxTableHandle) result.get().getHandle()).getNodeFilter(), TupleDomain.fromFixedValues(ImmutableMap.of(nodeColumnHandle, nodeColumnValue)));
}
Also used : ColumnHandle(io.prestosql.spi.connector.ColumnHandle) Constraint(io.prestosql.spi.connector.Constraint) NullableValue(io.prestosql.spi.predicate.NullableValue) ConstraintApplicationResult(io.prestosql.spi.connector.ConstraintApplicationResult) SchemaTableName(io.prestosql.spi.connector.SchemaTableName) Test(org.testng.annotations.Test)

Example 25 with NullableValue

use of io.prestosql.spi.predicate.NullableValue in project hetu-core by openlookeng.

the class HiveSplitSource method matchesUserDefinedCachedPredicates.

/**
 * Validate the partitions key against all the user defined predicates
 * to determine whether or not that split should be cached.
 *
 * @return true if partition key matches the user defined cache predicates
 * false otherwise
 */
private boolean matchesUserDefinedCachedPredicates(List<HivePartitionKey> partitionKeys) {
    if (userDefinedCachePredicates == null || userDefinedCachePredicates.isEmpty() || partitionKeys == null || partitionKeys.isEmpty()) {
        return false;
    }
    try {
        Map<String, HivePartitionKey> hivePartitionKeyMap = partitionKeys.stream().collect(Collectors.toMap(HivePartitionKey::getName, Function.identity()));
        for (TupleDomain<ColumnMetadata> tupleDomain : userDefinedCachePredicates) {
            if (!tupleDomain.getDomains().isPresent()) {
                continue;
            }
            Map<ColumnMetadata, Domain> domainMap = tupleDomain.getDomains().get();
            Collection<String> columnsDefinedInPredicate = domainMap.keySet().stream().map(ColumnMetadata::getName).collect(Collectors.toList());
            if (!hivePartitionKeyMap.keySet().containsAll(columnsDefinedInPredicate)) {
                continue;
            }
            boolean allMatches = domainMap.entrySet().stream().allMatch(entry -> {
                ColumnMetadata columnMetadata = entry.getKey();
                Domain domain = entry.getValue();
                String partitionStringValue = hivePartitionKeyMap.get(columnMetadata.getName()).getValue();
                NullableValue nullableValue;
                if (partitionStringValue.equals("\\N")) {
                    nullableValue = NullableValue.asNull(columnMetadata.getType());
                } else {
                    nullableValue = HiveUtil.parsePartitionValue(columnMetadata.getName(), partitionStringValue, columnMetadata.getType());
                }
                return domain.includesNullableValue(nullableValue.getValue());
            });
            if (allMatches) {
                return true;
            }
        }
    } catch (Exception ex) {
        log.warn(ex, "Unable to match partition keys %s with cached predicates. Ignoring this partition key. Error = %s", partitionKeys, ex.getMessage());
    }
    return false;
}
Also used : ColumnMetadata(io.prestosql.spi.connector.ColumnMetadata) NullableValue(io.prestosql.spi.predicate.NullableValue) Domain(io.prestosql.spi.predicate.Domain) TupleDomain(io.prestosql.spi.predicate.TupleDomain) PrestoException(io.prestosql.spi.PrestoException) FileNotFoundException(java.io.FileNotFoundException)

Aggregations

NullableValue (io.prestosql.spi.predicate.NullableValue)35 ColumnHandle (io.prestosql.spi.connector.ColumnHandle)27 ConnectorSession (io.prestosql.spi.connector.ConnectorSession)18 TupleDomain (io.prestosql.spi.predicate.TupleDomain)16 Optional (java.util.Optional)15 ConnectorTableHandle (io.prestosql.spi.connector.ConnectorTableHandle)14 ImmutableList (com.google.common.collect.ImmutableList)13 ImmutableMap (com.google.common.collect.ImmutableMap)13 Domain (io.prestosql.spi.predicate.Domain)13 Objects.requireNonNull (java.util.Objects.requireNonNull)13 SchemaTableName (io.prestosql.spi.connector.SchemaTableName)12 Type (io.prestosql.spi.type.Type)12 List (java.util.List)12 Map (java.util.Map)12 Preconditions.checkArgument (com.google.common.base.Preconditions.checkArgument)11 ConnectorMetadata (io.prestosql.spi.connector.ConnectorMetadata)11 PrestoException (io.prestosql.spi.PrestoException)10 Constraint (io.prestosql.spi.connector.Constraint)10 ArrayList (java.util.ArrayList)10 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)9