Java Code Examples for io.prestosql.spi.predicate.TupleDomain#none()

The following examples show how to use io.prestosql.spi.predicate.TupleDomain#none() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: IcebergPageSourceProvider.java    From presto with Apache License 2.0 6 votes vote down vote up
private static TupleDomain<ColumnDescriptor> getParquetTupleDomain(Map<List<String>, RichColumnDescriptor> descriptorsByPath, TupleDomain<IcebergColumnHandle> effectivePredicate)
{
    if (effectivePredicate.isNone()) {
        return TupleDomain.none();
    }

    ImmutableMap.Builder<ColumnDescriptor, Domain> predicate = ImmutableMap.builder();
    effectivePredicate.getDomains().get().forEach((columnHandle, domain) -> {
        String baseType = columnHandle.getType().getTypeSignature().getBase();
        // skip looking up predicates for complex types as Parquet only stores stats for primitives
        if (!baseType.equals(StandardTypes.MAP) && !baseType.equals(StandardTypes.ARRAY) && !baseType.equals(StandardTypes.ROW)) {
            RichColumnDescriptor descriptor = descriptorsByPath.get(ImmutableList.of(columnHandle.getName()));
            if (descriptor != null) {
                predicate.put(descriptor, domain);
            }
        }
    });
    return TupleDomain.withColumnDomains(predicate.build());
}
 
Example 2
Source File: InformationSchemaMetadata.java    From presto with Apache License 2.0 5 votes vote down vote up
@Override
public ConnectorTableProperties getTableProperties(ConnectorSession session, ConnectorTableHandle table)
{
    InformationSchemaTableHandle tableHandle = (InformationSchemaTableHandle) table;
    return new ConnectorTableProperties(
            tableHandle.getPrefixes().isEmpty() ? TupleDomain.none() : TupleDomain.all(),
            Optional.empty(),
            Optional.empty(),
            Optional.empty(),
            emptyList());
}
 
Example 3
Source File: TestDomainTranslator.java    From presto with Apache License 2.0 5 votes vote down vote up
@Test
public void testNoneRoundTrip()
{
    TupleDomain<Symbol> tupleDomain = TupleDomain.none();
    ExtractionResult result = fromPredicate(toPredicate(tupleDomain));
    assertEquals(result.getRemainingExpression(), TRUE_LITERAL);
    assertEquals(result.getTupleDomain(), tupleDomain);
}
 
Example 4
Source File: HiveMetadata.java    From presto with Apache License 2.0 5 votes vote down vote up
@VisibleForTesting
static TupleDomain<ColumnHandle> createPredicate(List<ColumnHandle> partitionColumns, List<HivePartition> partitions)
{
    if (partitions.isEmpty()) {
        return TupleDomain.none();
    }

    return withColumnDomains(
            partitionColumns.stream()
                    .collect(toMap(identity(), column -> buildColumnDomain(column, partitions))));
}
 
Example 5
Source File: ParquetPageSourceFactory.java    From presto with Apache License 2.0 5 votes vote down vote up
public static TupleDomain<ColumnDescriptor> getParquetTupleDomain(
        Map<List<String>, RichColumnDescriptor> descriptorsByPath,
        TupleDomain<HiveColumnHandle> effectivePredicate,
        MessageType fileSchema,
        boolean useColumnNames)
{
    if (effectivePredicate.isNone()) {
        return TupleDomain.none();
    }

    ImmutableMap.Builder<ColumnDescriptor, Domain> predicate = ImmutableMap.builder();
    for (Entry<HiveColumnHandle, Domain> entry : effectivePredicate.getDomains().get().entrySet()) {
        HiveColumnHandle columnHandle = entry.getKey();
        // skip looking up predicates for complex types as Parquet only stores stats for primitives
        if (columnHandle.getHiveType().getCategory() != PRIMITIVE || columnHandle.getColumnType() != REGULAR) {
            continue;
        }

        RichColumnDescriptor descriptor;
        if (useColumnNames) {
            descriptor = descriptorsByPath.get(ImmutableList.of(columnHandle.getName()));
        }
        else {
            org.apache.parquet.schema.Type parquetField = getParquetType(columnHandle, fileSchema, false);
            if (parquetField == null || !parquetField.isPrimitive()) {
                // Parquet file has fewer column than partition
                // Or the field is a complex type
                continue;
            }
            descriptor = descriptorsByPath.get(ImmutableList.of(parquetField.getName()));
        }
        if (descriptor != null) {
            predicate.put(descriptor, entry.getValue());
        }
    }
    return TupleDomain.withColumnDomains(predicate.build());
}
 
Example 6
Source File: TestBackgroundHiveSplitLoader.java    From presto with Apache License 2.0 5 votes vote down vote up
private static BackgroundHiveSplitLoader backgroundHiveSplitLoader(List<LocatedFileStatus> files, DirectoryLister directoryLister)
{
    List<HivePartitionMetadata> hivePartitionMetadatas = ImmutableList.of(
            new HivePartitionMetadata(
                    new HivePartition(new SchemaTableName("testSchema", "table_name")),
                    Optional.empty(),
                    TableToPartitionMapping.empty()));

    ConnectorSession connectorSession = getHiveSession(new HiveConfig()
            .setMaxSplitSize(DataSize.of(1, GIGABYTE)));

    return new BackgroundHiveSplitLoader(
            SIMPLE_TABLE,
            hivePartitionMetadatas,
            TupleDomain.none(),
            TupleDomain::all,
            TYPE_MANAGER,
            Optional.empty(),
            connectorSession,
            new TestingHdfsEnvironment(files),
            new NamenodeStats(),
            directoryLister,
            EXECUTOR,
            2,
            false,
            false,
            Optional.empty());
}
 
Example 7
Source File: TableLayoutResult.java    From presto with Apache License 2.0 4 votes vote down vote up
public static TupleDomain<ColumnHandle> computeEnforced(TupleDomain<ColumnHandle> predicate, TupleDomain<ColumnHandle> unenforced)
{
    if (predicate.isNone()) {
        // If the engine requests that the connector provides a layout with a domain of "none". The connector can have two possible reactions, either:
        // 1. The connector can provide an empty table layout.
        //   * There would be no unenforced predicate, i.e., unenforced predicate is TupleDomain.all().
        //   * The predicate was successfully enforced. Enforced predicate would be same as predicate: TupleDomain.none().
        // 2. The connector can't/won't.
        //   * The connector would tell the engine to put a filter on top of the scan, i.e., unenforced predicate is TupleDomain.none().
        //   * The connector didn't successfully enforce anything. Therefore, enforced predicate would be TupleDomain.all().
        if (unenforced.isNone()) {
            return TupleDomain.all();
        }
        if (unenforced.isAll()) {
            return TupleDomain.none();
        }
        throw new IllegalArgumentException();
    }

    // The engine requested the connector provides a layout with a non-none TupleDomain.
    // A TupleDomain is effectively a list of column-Domain pairs.
    // The connector is expected enforce the respective domain entirely on none, some, or all of the columns.
    // 1. When the connector could enforce none of the domains, the unenforced would be equal to predicate;
    // 2. When the connector could enforce some of the domains, the unenforced would contain a subset of the column-Domain pairs;
    // 3. When the connector could enforce all of the domains, the unenforced would be TupleDomain.all().

    // In all 3 cases shown above, the unenforced is not TupleDomain.none().
    checkArgument(!unenforced.isNone());

    Map<ColumnHandle, Domain> predicateDomains = predicate.getDomains().get();
    Map<ColumnHandle, Domain> unenforcedDomains = unenforced.getDomains().get();
    ImmutableMap.Builder<ColumnHandle, Domain> enforcedDomainsBuilder = ImmutableMap.builder();
    for (Map.Entry<ColumnHandle, Domain> entry : predicateDomains.entrySet()) {
        ColumnHandle predicateColumnHandle = entry.getKey();
        if (unenforcedDomains.containsKey(predicateColumnHandle)) {
            checkArgument(
                    entry.getValue().equals(unenforcedDomains.get(predicateColumnHandle)),
                    "Enforced tuple domain cannot be determined. The connector is expected to enforce the respective domain entirely on none, some, or all of the column.");
        }
        else {
            enforcedDomainsBuilder.put(predicateColumnHandle, entry.getValue());
        }
    }
    Map<ColumnHandle, Domain> enforcedDomains = enforcedDomainsBuilder.build();
    checkArgument(
            enforcedDomains.size() + unenforcedDomains.size() == predicateDomains.size(),
            "Enforced tuple domain cannot be determined. Connector returned an unenforced TupleDomain that contains columns not in predicate.");
    return TupleDomain.withColumnDomains(enforcedDomains);
}
 
Example 8
Source File: DomainTranslator.java    From presto with Apache License 2.0 4 votes vote down vote up
@Override
protected ExtractionResult visitBooleanLiteral(BooleanLiteral node, Boolean complement)
{
    boolean value = complement ? !node.getValue() : node.getValue();
    return new ExtractionResult(value ? TupleDomain.all() : TupleDomain.none(), TRUE_LITERAL);
}
 
Example 9
Source File: DomainTranslator.java    From presto with Apache License 2.0 4 votes vote down vote up
@Override
protected ExtractionResult visitNullLiteral(NullLiteral node, Boolean complement)
{
    return new ExtractionResult(TupleDomain.none(), TRUE_LITERAL);
}
 
Example 10
Source File: TestEffectivePredicateExtractor.java    From presto with Apache License 2.0 4 votes vote down vote up
@Test
public void testTableScan()
{
    // Effective predicate is True if there is no effective predicate
    Map<Symbol, ColumnHandle> assignments = Maps.filterKeys(scanAssignments, Predicates.in(ImmutableList.of(A, B, C, D)));
    PlanNode node = TableScanNode.newInstance(
            newId(),
            makeTableHandle(TupleDomain.all()),
            ImmutableList.copyOf(assignments.keySet()),
            assignments);
    Expression effectivePredicate = effectivePredicateExtractor.extract(SESSION, node, TypeProvider.empty(), typeAnalyzer);
    assertEquals(effectivePredicate, BooleanLiteral.TRUE_LITERAL);

    node = new TableScanNode(
            newId(),
            makeTableHandle(TupleDomain.none()),
            ImmutableList.copyOf(assignments.keySet()),
            assignments,
            TupleDomain.none());
    effectivePredicate = effectivePredicateExtractor.extract(SESSION, node, TypeProvider.empty(), typeAnalyzer);
    assertEquals(effectivePredicate, FALSE_LITERAL);

    TupleDomain<ColumnHandle> predicate = TupleDomain.withColumnDomains(ImmutableMap.of(scanAssignments.get(A), Domain.singleValue(BIGINT, 1L)));
    node = new TableScanNode(
            newId(),
            makeTableHandle(predicate),
            ImmutableList.copyOf(assignments.keySet()),
            assignments,
            predicate);
    effectivePredicate = effectivePredicateExtractor.extract(SESSION, node, TypeProvider.empty(), typeAnalyzer);
    assertEquals(normalizeConjuncts(effectivePredicate), normalizeConjuncts(equals(bigintLiteral(1L), AE)));

    predicate = TupleDomain.withColumnDomains(ImmutableMap.of(
            scanAssignments.get(A), Domain.singleValue(BIGINT, 1L),
            scanAssignments.get(B), Domain.singleValue(BIGINT, 2L)));
    node = new TableScanNode(
            newId(),
            makeTableHandle(TupleDomain.withColumnDomains(ImmutableMap.of(scanAssignments.get(A), Domain.singleValue(BIGINT, 1L)))),
            ImmutableList.copyOf(assignments.keySet()),
            assignments,
            predicate);
    effectivePredicate = effectivePredicateExtractorWithoutTableProperties.extract(SESSION, node, TypeProvider.empty(), typeAnalyzer);
    assertEquals(normalizeConjuncts(effectivePredicate), normalizeConjuncts(equals(bigintLiteral(2L), BE), equals(bigintLiteral(1L), AE)));

    node = new TableScanNode(
            newId(),
            makeTableHandle(predicate),
            ImmutableList.copyOf(assignments.keySet()),
            assignments,
            TupleDomain.all());
    effectivePredicate = effectivePredicateExtractor.extract(SESSION, node, TypeProvider.empty(), typeAnalyzer);
    assertEquals(effectivePredicate, and(equals(AE, bigintLiteral(1)), equals(BE, bigintLiteral(2))));

    node = new TableScanNode(
            newId(),
            makeTableHandle(predicate),
            ImmutableList.copyOf(assignments.keySet()),
            assignments,
            TupleDomain.withColumnDomains(ImmutableMap.of(
                    scanAssignments.get(A), Domain.multipleValues(BIGINT, ImmutableList.of(1L, 2L, 3L)),
                    scanAssignments.get(B), Domain.multipleValues(BIGINT, ImmutableList.of(1L, 2L, 3L)))));
    effectivePredicate = effectivePredicateExtractor.extract(SESSION, node, TypeProvider.empty(), typeAnalyzer);
    assertEquals(normalizeConjuncts(effectivePredicate), normalizeConjuncts(equals(bigintLiteral(2L), BE), equals(bigintLiteral(1L), AE)));

    node = new TableScanNode(
            newId(),
            makeTableHandle(TupleDomain.all()),
            ImmutableList.copyOf(assignments.keySet()),
            assignments,
            TupleDomain.all());
    effectivePredicate = effectivePredicateExtractor.extract(SESSION, node, TypeProvider.empty(), typeAnalyzer);
    assertEquals(effectivePredicate, BooleanLiteral.TRUE_LITERAL);
}
 
Example 11
Source File: Constraint.java    From presto with Apache License 2.0 4 votes vote down vote up
public static Constraint alwaysFalse()
{
    return new Constraint(TupleDomain.none(), Optional.of(bindings -> false), Optional.empty());
}