Search in sources :

Example 11 with NullableValue

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

the class JmxSplitManager method getSplits.

@Override
public ConnectorSplitSource getSplits(ConnectorTransactionHandle transaction, ConnectorSession session, ConnectorTableLayoutHandle layout, SplitSchedulingContext splitSchedulingContext) {
    JmxTableLayoutHandle jmxLayout = (JmxTableLayoutHandle) layout;
    JmxTableHandle tableHandle = jmxLayout.getTable();
    TupleDomain<ColumnHandle> predicate = jmxLayout.getConstraint();
    // 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);
    List<ConnectorSplit> splits = nodeManager.getAllNodes().stream().filter(node -> {
        NullableValue value = NullableValue.of(createUnboundedVarcharType(), utf8Slice(node.getNodeIdentifier()));
        return predicate.overlaps(fromFixedValues(ImmutableMap.of(nodeColumnHandle.get(), value)));
    }).map(node -> new JmxSplit(tableHandle, ImmutableList.of(node.getHostAndPort()))).collect(toList());
    return new FixedSplitSource(splits);
}
Also used : ConnectorSplitManager(com.facebook.presto.spi.connector.ConnectorSplitManager) ConnectorSplitSource(com.facebook.presto.spi.ConnectorSplitSource) NullableValue(com.facebook.presto.common.predicate.NullableValue) NodeManager(com.facebook.presto.spi.NodeManager) ImmutableMap(com.google.common.collect.ImmutableMap) VarcharType.createUnboundedVarcharType(com.facebook.presto.common.type.VarcharType.createUnboundedVarcharType) ConnectorTableLayoutHandle(com.facebook.presto.spi.ConnectorTableLayoutHandle) FixedSplitSource(com.facebook.presto.spi.FixedSplitSource) TupleDomain(com.facebook.presto.common.predicate.TupleDomain) ConnectorTransactionHandle(com.facebook.presto.spi.connector.ConnectorTransactionHandle) Preconditions.checkState(com.google.common.base.Preconditions.checkState) ConnectorSession(com.facebook.presto.spi.ConnectorSession) Inject(javax.inject.Inject) ConnectorSplit(com.facebook.presto.spi.ConnectorSplit) List(java.util.List) NODE_COLUMN_NAME(com.facebook.presto.connector.jmx.JmxMetadata.NODE_COLUMN_NAME) Collectors.toList(java.util.stream.Collectors.toList) TupleDomain.fromFixedValues(com.facebook.presto.common.predicate.TupleDomain.fromFixedValues) ImmutableList(com.google.common.collect.ImmutableList) ColumnHandle(com.facebook.presto.spi.ColumnHandle) Objects.requireNonNull(java.util.Objects.requireNonNull) Optional(java.util.Optional) Slices.utf8Slice(io.airlift.slice.Slices.utf8Slice) ColumnHandle(com.facebook.presto.spi.ColumnHandle) FixedSplitSource(com.facebook.presto.spi.FixedSplitSource) NullableValue(com.facebook.presto.common.predicate.NullableValue) ConnectorSplit(com.facebook.presto.spi.ConnectorSplit)

Example 12 with NullableValue

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

the class HivePartitionManager method parsePartition.

public static HivePartition parsePartition(SchemaTableName tableName, String partitionName, List<HiveColumnHandle> partitionColumns, List<Type> partitionColumnTypes, DateTimeZone timeZone) {
    List<String> partitionColumnNames = partitionColumns.stream().map(HiveColumnHandle::getName).collect(Collectors.toList());
    List<String> partitionValues = extractPartitionValues(partitionName, Optional.of(partitionColumnNames));
    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), timeZone);
        builder.put(column, parsedValue);
    }
    Map<ColumnHandle, NullableValue> values = builder.build();
    return new HivePartition(tableName, partitionName, values);
}
Also used : ColumnHandle(com.facebook.presto.spi.ColumnHandle) NullableValue(com.facebook.presto.common.predicate.NullableValue) ImmutableMap(com.google.common.collect.ImmutableMap) Constraint(com.facebook.presto.spi.Constraint)

Example 13 with NullableValue

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

the class HiveMaterializedViewUtils method getMaterializedDataPredicates.

public static MaterializedDataPredicates getMaterializedDataPredicates(SemiTransactionalHiveMetastore metastore, MetastoreContext metastoreContext, TypeManager typeManager, Table table, DateTimeZone timeZone) {
    List<Column> partitionColumns = table.getPartitionColumns();
    for (Column partitionColumn : partitionColumns) {
        HiveType hiveType = partitionColumn.getType();
        if (!hiveType.isSupportedType()) {
            throw new PrestoException(NOT_SUPPORTED, String.format("Unsupported Hive type %s found in partition keys of table %s.%s", hiveType, table.getDatabaseName(), table.getTableName()));
        }
    }
    List<HiveColumnHandle> partitionKeyColumnHandles = getPartitionKeyColumnHandles(table);
    Map<String, Type> partitionTypes = partitionKeyColumnHandles.stream().collect(toImmutableMap(HiveColumnHandle::getName, column -> typeManager.getType(column.getTypeSignature())));
    List<String> partitionNames = metastore.getPartitionNames(metastoreContext, table.getDatabaseName(), table.getTableName()).orElseThrow(() -> new TableNotFoundException(new SchemaTableName(table.getDatabaseName(), table.getTableName())));
    ImmutableList.Builder<TupleDomain<String>> partitionNamesAndValues = ImmutableList.builder();
    for (String partitionName : partitionNames) {
        ImmutableMap.Builder<String, NullableValue> partitionNameAndValuesMap = ImmutableMap.builder();
        Map<String, String> partitions = toPartitionNamesAndValues(partitionName);
        if (partitionColumns.size() != partitions.size()) {
            throw new PrestoException(HIVE_INVALID_METADATA, String.format("Expected %d partition key values, but got %d", partitionColumns.size(), partitions.size()));
        }
        partitionTypes.forEach((name, type) -> {
            String value = partitions.get(name);
            if (value == null) {
                throw new PrestoException(HIVE_INVALID_PARTITION_VALUE, String.format("partition key value cannot be null for field: %s", name));
            }
            partitionNameAndValuesMap.put(name, parsePartitionValue(name, value, type, timeZone));
        });
        TupleDomain<String> tupleDomain = TupleDomain.fromFixedValues(partitionNameAndValuesMap.build());
        partitionNamesAndValues.add(tupleDomain);
    }
    return new MaterializedDataPredicates(partitionNamesAndValues.build(), partitionColumns.stream().map(Column::getName).collect(toImmutableList()));
}
Also used : DateTimeZone(org.joda.time.DateTimeZone) Table(com.facebook.presto.hive.metastore.Table) Column(com.facebook.presto.hive.metastore.Column) HiveUtil.getPartitionKeyColumnHandles(com.facebook.presto.hive.HiveUtil.getPartitionKeyColumnHandles) MetastoreContext(com.facebook.presto.hive.metastore.MetastoreContext) HIVE_INVALID_PARTITION_VALUE(com.facebook.presto.hive.HiveErrorCode.HIVE_INVALID_PARTITION_VALUE) HashMap(java.util.HashMap) PrestoException(com.facebook.presto.spi.PrestoException) MetastoreUtil.toPartitionNamesAndValues(com.facebook.presto.hive.metastore.MetastoreUtil.toPartitionNamesAndValues) HashSet(java.util.HashSet) LinkedHashMap(java.util.LinkedHashMap) SchemaTableName(com.facebook.presto.spi.SchemaTableName) ImmutableList(com.google.common.collect.ImmutableList) TupleDomain.extractFixedValues(com.facebook.presto.common.predicate.TupleDomain.extractFixedValues) TypeManager(com.facebook.presto.common.type.TypeManager) Map(java.util.Map) ConnectorMaterializedViewDefinition(com.facebook.presto.spi.ConnectorMaterializedViewDefinition) MaterializedDataPredicates(com.facebook.presto.spi.MaterializedViewStatus.MaterializedDataPredicates) Type(com.facebook.presto.common.type.Type) Collections.emptyMap(java.util.Collections.emptyMap) NullableValue(com.facebook.presto.common.predicate.NullableValue) ImmutableMap(com.google.common.collect.ImmutableMap) HIVE_INVALID_METADATA(com.facebook.presto.hive.HiveErrorCode.HIVE_INVALID_METADATA) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) Set(java.util.Set) SemiTransactionalHiveMetastore(com.facebook.presto.hive.metastore.SemiTransactionalHiveMetastore) Collectors(java.util.stream.Collectors) TupleDomain(com.facebook.presto.common.predicate.TupleDomain) String.format(java.lang.String.format) List(java.util.List) ImmutableMap.toImmutableMap(com.google.common.collect.ImmutableMap.toImmutableMap) TableNotFoundException(com.facebook.presto.spi.TableNotFoundException) NOT_SUPPORTED(com.facebook.presto.spi.StandardErrorCode.NOT_SUPPORTED) Optional(java.util.Optional) HiveUtil.parsePartitionValue(com.facebook.presto.hive.HiveUtil.parsePartitionValue) TupleDomain.toLinkedMap(com.facebook.presto.common.predicate.TupleDomain.toLinkedMap) ImmutableList(com.google.common.collect.ImmutableList) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) NullableValue(com.facebook.presto.common.predicate.NullableValue) PrestoException(com.facebook.presto.spi.PrestoException) SchemaTableName(com.facebook.presto.spi.SchemaTableName) MaterializedDataPredicates(com.facebook.presto.spi.MaterializedViewStatus.MaterializedDataPredicates) ImmutableMap(com.google.common.collect.ImmutableMap) ImmutableMap.toImmutableMap(com.google.common.collect.ImmutableMap.toImmutableMap) TableNotFoundException(com.facebook.presto.spi.TableNotFoundException) Type(com.facebook.presto.common.type.Type) TupleDomain(com.facebook.presto.common.predicate.TupleDomain) Column(com.facebook.presto.hive.metastore.Column)

Example 14 with NullableValue

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

the class InformationSchemaMetadata method calculatePrefixesWithSchemaName.

private Set<QualifiedTablePrefix> calculatePrefixesWithSchemaName(ConnectorSession connectorSession, TupleDomain<ColumnHandle> constraint, Optional<Predicate<Map<ColumnHandle, NullableValue>>> predicate) {
    Optional<Set<String>> schemas = filterString(constraint, SCHEMA_COLUMN_HANDLE);
    if (schemas.isPresent()) {
        return schemas.get().stream().filter(this::isLowerCase).map(schema -> new QualifiedTablePrefix(catalogName, schema)).collect(toImmutableSet());
    }
    Session session = ((FullConnectorSession) connectorSession).getSession();
    return metadata.listSchemaNames(session, catalogName).stream().filter(schema -> !predicate.isPresent() || predicate.get().test(schemaAsFixedValues(schema))).map(schema -> new QualifiedTablePrefix(catalogName, schema)).collect(toImmutableSet());
}
Also used : ConnectorMetadata(com.facebook.presto.spi.connector.ConnectorMetadata) EquatableValueSet(com.facebook.presto.common.predicate.EquatableValueSet) Slice(io.airlift.slice.Slice) VarcharType.createUnboundedVarcharType(com.facebook.presto.common.type.VarcharType.createUnboundedVarcharType) ConnectorTableLayoutHandle(com.facebook.presto.spi.ConnectorTableLayoutHandle) ConnectorTableHandle(com.facebook.presto.spi.ConnectorTableHandle) Preconditions.checkArgument(com.google.common.base.Preconditions.checkArgument) SchemaTableName(com.facebook.presto.spi.SchemaTableName) ImmutableList(com.google.common.collect.ImmutableList) Collectors.toMap(java.util.stream.Collectors.toMap) Map(java.util.Map) Objects.requireNonNull(java.util.Objects.requireNonNull) QualifiedObjectName(com.facebook.presto.common.QualifiedObjectName) ImmutableSet.toImmutableSet(com.google.common.collect.ImmutableSet.toImmutableSet) Slices.utf8Slice(io.airlift.slice.Slices.utf8Slice) FullConnectorSession(com.facebook.presto.FullConnectorSession) ENGLISH(java.util.Locale.ENGLISH) ConnectorTableMetadata(com.facebook.presto.spi.ConnectorTableMetadata) BIGINT(com.facebook.presto.common.type.BigintType.BIGINT) ImmutableSet(com.google.common.collect.ImmutableSet) NullableValue(com.facebook.presto.common.predicate.NullableValue) QualifiedTablePrefix(com.facebook.presto.metadata.QualifiedTablePrefix) ImmutableMap(com.google.common.collect.ImmutableMap) Predicate(java.util.function.Predicate) Session(com.facebook.presto.Session) ConnectorTableLayout(com.facebook.presto.spi.ConnectorTableLayout) Collection(java.util.Collection) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) Set(java.util.Set) Constraint(com.facebook.presto.spi.Constraint) TableMetadataBuilder.tableMetadataBuilder(com.facebook.presto.metadata.MetadataUtil.TableMetadataBuilder.tableMetadataBuilder) Predicates.compose(com.google.common.base.Predicates.compose) Domain(com.facebook.presto.common.predicate.Domain) TupleDomain(com.facebook.presto.common.predicate.TupleDomain) MetadataUtil.findColumnMetadata(com.facebook.presto.metadata.MetadataUtil.findColumnMetadata) ConnectorSession(com.facebook.presto.spi.ConnectorSession) ConnectorTableLayoutResult(com.facebook.presto.spi.ConnectorTableLayoutResult) List(java.util.List) ColumnMetadata(com.facebook.presto.spi.ColumnMetadata) Stream(java.util.stream.Stream) SchemaTablePrefix(com.facebook.presto.spi.SchemaTablePrefix) ColumnHandle(com.facebook.presto.spi.ColumnHandle) SchemaMetadataBuilder.schemaMetadataBuilder(com.facebook.presto.metadata.MetadataUtil.SchemaMetadataBuilder.schemaMetadataBuilder) Entry(java.util.Map.Entry) Function.identity(java.util.function.Function.identity) Optional(java.util.Optional) Metadata(com.facebook.presto.metadata.Metadata) EquatableValueSet(com.facebook.presto.common.predicate.EquatableValueSet) ImmutableSet.toImmutableSet(com.google.common.collect.ImmutableSet.toImmutableSet) ImmutableSet(com.google.common.collect.ImmutableSet) Set(java.util.Set) QualifiedTablePrefix(com.facebook.presto.metadata.QualifiedTablePrefix) FullConnectorSession(com.facebook.presto.FullConnectorSession) Session(com.facebook.presto.Session) ConnectorSession(com.facebook.presto.spi.ConnectorSession) FullConnectorSession(com.facebook.presto.FullConnectorSession)

Example 15 with NullableValue

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

the class InformationSchemaMetadata method calculatePrefixesWithTableName.

public Set<QualifiedTablePrefix> calculatePrefixesWithTableName(ConnectorSession connectorSession, Set<QualifiedTablePrefix> prefixes, TupleDomain<ColumnHandle> constraint, Optional<Predicate<Map<ColumnHandle, NullableValue>>> predicate) {
    Session session = ((FullConnectorSession) connectorSession).getSession();
    Optional<Set<String>> tables = filterString(constraint, TABLE_NAME_COLUMN_HANDLE);
    if (tables.isPresent()) {
        return prefixes.stream().flatMap(prefix -> tables.get().stream().filter(this::isLowerCase).map(table -> table.toLowerCase(ENGLISH)).map(table -> new QualifiedObjectName(catalogName, prefix.getSchemaName().get(), table))).filter(objectName -> metadata.getTableHandle(session, objectName).isPresent() || metadata.getView(session, objectName).isPresent()).map(QualifiedTablePrefix::toQualifiedTablePrefix).collect(toImmutableSet());
    }
    return prefixes.stream().flatMap(prefix -> Stream.concat(metadata.listTables(session, prefix).stream(), metadata.listViews(session, prefix).stream())).filter(objectName -> !predicate.isPresent() || predicate.get().test(asFixedValues(objectName))).map(QualifiedTablePrefix::toQualifiedTablePrefix).collect(toImmutableSet());
}
Also used : ConnectorMetadata(com.facebook.presto.spi.connector.ConnectorMetadata) EquatableValueSet(com.facebook.presto.common.predicate.EquatableValueSet) Slice(io.airlift.slice.Slice) VarcharType.createUnboundedVarcharType(com.facebook.presto.common.type.VarcharType.createUnboundedVarcharType) ConnectorTableLayoutHandle(com.facebook.presto.spi.ConnectorTableLayoutHandle) ConnectorTableHandle(com.facebook.presto.spi.ConnectorTableHandle) Preconditions.checkArgument(com.google.common.base.Preconditions.checkArgument) SchemaTableName(com.facebook.presto.spi.SchemaTableName) ImmutableList(com.google.common.collect.ImmutableList) Collectors.toMap(java.util.stream.Collectors.toMap) Map(java.util.Map) Objects.requireNonNull(java.util.Objects.requireNonNull) QualifiedObjectName(com.facebook.presto.common.QualifiedObjectName) ImmutableSet.toImmutableSet(com.google.common.collect.ImmutableSet.toImmutableSet) Slices.utf8Slice(io.airlift.slice.Slices.utf8Slice) FullConnectorSession(com.facebook.presto.FullConnectorSession) ENGLISH(java.util.Locale.ENGLISH) ConnectorTableMetadata(com.facebook.presto.spi.ConnectorTableMetadata) BIGINT(com.facebook.presto.common.type.BigintType.BIGINT) ImmutableSet(com.google.common.collect.ImmutableSet) NullableValue(com.facebook.presto.common.predicate.NullableValue) QualifiedTablePrefix(com.facebook.presto.metadata.QualifiedTablePrefix) ImmutableMap(com.google.common.collect.ImmutableMap) Predicate(java.util.function.Predicate) Session(com.facebook.presto.Session) ConnectorTableLayout(com.facebook.presto.spi.ConnectorTableLayout) Collection(java.util.Collection) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) Set(java.util.Set) Constraint(com.facebook.presto.spi.Constraint) TableMetadataBuilder.tableMetadataBuilder(com.facebook.presto.metadata.MetadataUtil.TableMetadataBuilder.tableMetadataBuilder) Predicates.compose(com.google.common.base.Predicates.compose) Domain(com.facebook.presto.common.predicate.Domain) TupleDomain(com.facebook.presto.common.predicate.TupleDomain) MetadataUtil.findColumnMetadata(com.facebook.presto.metadata.MetadataUtil.findColumnMetadata) ConnectorSession(com.facebook.presto.spi.ConnectorSession) ConnectorTableLayoutResult(com.facebook.presto.spi.ConnectorTableLayoutResult) List(java.util.List) ColumnMetadata(com.facebook.presto.spi.ColumnMetadata) Stream(java.util.stream.Stream) SchemaTablePrefix(com.facebook.presto.spi.SchemaTablePrefix) ColumnHandle(com.facebook.presto.spi.ColumnHandle) SchemaMetadataBuilder.schemaMetadataBuilder(com.facebook.presto.metadata.MetadataUtil.SchemaMetadataBuilder.schemaMetadataBuilder) Entry(java.util.Map.Entry) Function.identity(java.util.function.Function.identity) Optional(java.util.Optional) Metadata(com.facebook.presto.metadata.Metadata) EquatableValueSet(com.facebook.presto.common.predicate.EquatableValueSet) ImmutableSet.toImmutableSet(com.google.common.collect.ImmutableSet.toImmutableSet) ImmutableSet(com.google.common.collect.ImmutableSet) Set(java.util.Set) QualifiedObjectName(com.facebook.presto.common.QualifiedObjectName) FullConnectorSession(com.facebook.presto.FullConnectorSession) Session(com.facebook.presto.Session) ConnectorSession(com.facebook.presto.spi.ConnectorSession) FullConnectorSession(com.facebook.presto.FullConnectorSession)

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