Java Code Examples for io.prestosql.spi.predicate.Domain#onlyNull()

The following examples show how to use io.prestosql.spi.predicate.Domain#onlyNull() . 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: HiveMetadata.java    From presto with Apache License 2.0 5 votes vote down vote up
private static Domain buildColumnDomain(ColumnHandle column, List<HivePartition> partitions)
{
    checkArgument(!partitions.isEmpty(), "partitions cannot be empty");

    boolean hasNull = false;
    List<Object> nonNullValues = new ArrayList<>();
    Type type = null;

    for (HivePartition partition : partitions) {
        NullableValue value = partition.getKeys().get(column);
        if (value == null) {
            throw new PrestoException(HIVE_UNKNOWN_ERROR, format("Partition %s does not have a value for partition column %s", partition, column));
        }

        if (value.isNull()) {
            hasNull = true;
        }
        else {
            nonNullValues.add(value.getValue());
        }

        if (type == null) {
            type = value.getType();
        }
    }

    if (!nonNullValues.isEmpty()) {
        Domain domain = Domain.multipleValues(type, nonNullValues);
        if (hasNull) {
            return domain.union(Domain.onlyNull(type));
        }

        return domain;
    }

    return Domain.onlyNull(type);
}
 
Example 2
Source File: TupleDomainOrcPredicate.java    From presto with Apache License 2.0 4 votes vote down vote up
@VisibleForTesting
public static Domain getDomain(Type type, long rowCount, ColumnStatistics columnStatistics)
{
    if (rowCount == 0) {
        return Domain.none(type);
    }

    if (columnStatistics == null) {
        return Domain.all(type);
    }

    if (columnStatistics.hasNumberOfValues() && columnStatistics.getNumberOfValues() == 0) {
        return Domain.onlyNull(type);
    }

    boolean hasNullValue = columnStatistics.getNumberOfValues() != rowCount;

    if (type.getJavaType() == boolean.class && columnStatistics.getBooleanStatistics() != null) {
        BooleanStatistics booleanStatistics = columnStatistics.getBooleanStatistics();

        boolean hasTrueValues = (booleanStatistics.getTrueValueCount() != 0);
        boolean hasFalseValues = (columnStatistics.getNumberOfValues() != booleanStatistics.getTrueValueCount());
        if (hasTrueValues && hasFalseValues) {
            return Domain.all(BOOLEAN);
        }
        if (hasTrueValues) {
            return Domain.create(ValueSet.of(BOOLEAN, true), hasNullValue);
        }
        if (hasFalseValues) {
            return Domain.create(ValueSet.of(BOOLEAN, false), hasNullValue);
        }
    }
    else if (isShortDecimal(type) && columnStatistics.getDecimalStatistics() != null) {
        return createDomain(type, hasNullValue, columnStatistics.getDecimalStatistics(), value -> rescale(value, (DecimalType) type).unscaledValue().longValue());
    }
    else if (isLongDecimal(type) && columnStatistics.getDecimalStatistics() != null) {
        return createDomain(type, hasNullValue, columnStatistics.getDecimalStatistics(), value -> encodeUnscaledValue(rescale(value, (DecimalType) type).unscaledValue()));
    }
    else if (isCharType(type) && columnStatistics.getStringStatistics() != null) {
        return createDomain(type, hasNullValue, columnStatistics.getStringStatistics(), value -> truncateToLengthAndTrimSpaces(value, type));
    }
    else if (isVarcharType(type) && columnStatistics.getStringStatistics() != null) {
        return createDomain(type, hasNullValue, columnStatistics.getStringStatistics());
    }
    else if (type instanceof DateType && columnStatistics.getDateStatistics() != null) {
        return createDomain(type, hasNullValue, columnStatistics.getDateStatistics(), value -> (long) value);
    }
    else if (type.getJavaType() == long.class && columnStatistics.getIntegerStatistics() != null) {
        return createDomain(type, hasNullValue, columnStatistics.getIntegerStatistics());
    }
    else if (type.getJavaType() == double.class && columnStatistics.getDoubleStatistics() != null) {
        return createDomain(type, hasNullValue, columnStatistics.getDoubleStatistics());
    }
    else if (REAL.equals(type) && columnStatistics.getDoubleStatistics() != null) {
        return createDomain(type, hasNullValue, columnStatistics.getDoubleStatistics(), value -> (long) floatToRawIntBits(value.floatValue()));
    }
    return Domain.create(ValueSet.all(type), hasNullValue);
}