use of com.facebook.presto.common.predicate.TupleDomainFilter in project presto by prestodb.
the class TestListFilter method buildListFilter.
private static ListFilter buildListFilter(Map<RowAndColumn, TupleDomainFilter> filters, Integer[][][] data) {
Map<Subfield, TupleDomainFilter> subfieldFilters = filters.entrySet().stream().collect(toImmutableMap(entry -> toSubfield(entry.getKey()), Map.Entry::getValue));
ListFilter filter = new ListFilter(makeStreamDescriptor(2), subfieldFilters);
int[] lengths = Arrays.stream(data).mapToInt(v -> v.length).toArray();
filter.populateElementFilters(data.length, null, lengths, Arrays.stream(lengths).sum());
int[] nestedLenghts = Arrays.stream(data).flatMap(Arrays::stream).mapToInt(v -> v.length).toArray();
((ListFilter) filter.getChild()).populateElementFilters(Arrays.stream(lengths).sum(), null, nestedLenghts, Arrays.stream(nestedLenghts).sum());
return filter;
}
use of com.facebook.presto.common.predicate.TupleDomainFilter in project presto by prestodb.
the class TestCoercingFilters method testIntegerToVarchar.
@Test
public void testIntegerToVarchar() {
TupleDomainFilter filter = BytesRange.of("10".getBytes(), false, "10".getBytes(), false, false);
HiveCoercer coercer = new IntegerNumberToVarcharCoercer(INTEGER, VARCHAR);
TupleDomainFilter coercingFilter = coercer.toCoercingFilter(filter, new Subfield("c"));
assertTrue(coercingFilter.testLong(10));
assertFalse(coercingFilter.testLong(25));
assertFalse(coercingFilter.testNull());
}
use of com.facebook.presto.common.predicate.TupleDomainFilter in project presto by prestodb.
the class TestCoercingFilters method testVarcharToInteger.
@Test
public void testVarcharToInteger() {
TupleDomainFilter filter = BigintRange.of(100, Integer.MAX_VALUE, false);
HiveCoercer coercer = new VarcharToIntegerNumberCoercer(VARCHAR, INTEGER);
TupleDomainFilter coercingFilter = coercer.toCoercingFilter(filter, new Subfield("c"));
assertTrue(coercingFilter.testLength(1));
assertTrue(coercingFilter.testLength(2));
assertTrue(coercingFilter.testLength(3));
assertTrue(coercingFilter.testBytes("100".getBytes(), 0, 3));
assertTrue(coercingFilter.testBytes("145".getBytes(), 0, 3));
assertTrue(coercingFilter.testBytes("2147483647".getBytes(), 0, 10));
assertFalse(coercingFilter.testBytes("50".getBytes(), 0, 2));
assertFalse(coercingFilter.testBytes("-50".getBytes(), 0, 3));
// parsing error
assertFalse(coercingFilter.testBytes("abc".getBytes(), 0, 3));
// out of range
assertFalse(coercingFilter.testBytes("2147483648".getBytes(), 0, 10));
assertFalse(coercingFilter.testNull());
}
use of com.facebook.presto.common.predicate.TupleDomainFilter in project presto by prestodb.
the class SelectiveStreamReaders method createStreamReader.
public static SelectiveStreamReader createStreamReader(StreamDescriptor streamDescriptor, Map<Subfield, TupleDomainFilter> filters, Optional<Type> outputType, List<Subfield> requiredSubfields, DateTimeZone hiveStorageTimeZone, OrcRecordReaderOptions options, boolean legacyMapSubscript, OrcAggregatedMemoryContext systemMemoryContext) {
OrcTypeKind type = streamDescriptor.getOrcTypeKind();
switch(type) {
case BOOLEAN:
{
checkArgument(requiredSubfields.isEmpty(), "Boolean stream reader doesn't support subfields");
verifyStreamType(streamDescriptor, outputType, BooleanType.class::isInstance);
return new BooleanSelectiveStreamReader(streamDescriptor, getOptionalOnlyFilter(type, filters), outputType.isPresent(), systemMemoryContext.newOrcLocalMemoryContext(SelectiveStreamReaders.class.getSimpleName()));
}
case BYTE:
{
checkArgument(requiredSubfields.isEmpty(), "Byte stream reader doesn't support subfields");
verifyStreamType(streamDescriptor, outputType, TinyintType.class::isInstance);
return new ByteSelectiveStreamReader(streamDescriptor, getOptionalOnlyFilter(type, filters), outputType.isPresent(), systemMemoryContext.newOrcLocalMemoryContext(SelectiveStreamReaders.class.getSimpleName()));
}
case SHORT:
case INT:
case LONG:
case DATE:
{
checkArgument(requiredSubfields.isEmpty(), "Primitive type stream reader doesn't support subfields");
verifyStreamType(streamDescriptor, outputType, t -> t instanceof BigintType || t instanceof IntegerType || t instanceof SmallintType || t instanceof DateType);
return new LongSelectiveStreamReader(streamDescriptor, getOptionalOnlyFilter(type, filters), outputType, systemMemoryContext);
}
case FLOAT:
{
checkArgument(requiredSubfields.isEmpty(), "Float type stream reader doesn't support subfields");
verifyStreamType(streamDescriptor, outputType, RealType.class::isInstance);
return new FloatSelectiveStreamReader(streamDescriptor, getOptionalOnlyFilter(type, filters), outputType.isPresent(), systemMemoryContext.newOrcLocalMemoryContext(SelectiveStreamReaders.class.getSimpleName()));
}
case DOUBLE:
checkArgument(requiredSubfields.isEmpty(), "Double stream reader doesn't support subfields");
verifyStreamType(streamDescriptor, outputType, DoubleType.class::isInstance);
return new DoubleSelectiveStreamReader(streamDescriptor, getOptionalOnlyFilter(type, filters), outputType.isPresent(), systemMemoryContext.newOrcLocalMemoryContext(SelectiveStreamReaders.class.getSimpleName()));
case BINARY:
case STRING:
case VARCHAR:
case CHAR:
checkArgument(requiredSubfields.isEmpty(), "Primitive stream reader doesn't support subfields");
verifyStreamType(streamDescriptor, outputType, t -> t instanceof VarcharType || t instanceof CharType || t instanceof VarbinaryType);
return new SliceSelectiveStreamReader(streamDescriptor, getOptionalOnlyFilter(type, filters), outputType, systemMemoryContext);
case TIMESTAMP:
{
checkArgument(requiredSubfields.isEmpty(), "Timestamp stream reader doesn't support subfields");
verifyStreamType(streamDescriptor, outputType, TimestampType.class::isInstance);
return new TimestampSelectiveStreamReader(streamDescriptor, getOptionalOnlyFilter(type, filters), hiveStorageTimeZone, outputType.isPresent(), systemMemoryContext.newOrcLocalMemoryContext(SelectiveStreamReaders.class.getSimpleName()), options);
}
case LIST:
verifyStreamType(streamDescriptor, outputType, ArrayType.class::isInstance);
return new ListSelectiveStreamReader(streamDescriptor, filters, requiredSubfields, null, 0, outputType, hiveStorageTimeZone, options, legacyMapSubscript, systemMemoryContext);
case STRUCT:
verifyStreamType(streamDescriptor, outputType, RowType.class::isInstance);
return new StructSelectiveStreamReader(streamDescriptor, filters, requiredSubfields, outputType, hiveStorageTimeZone, options, legacyMapSubscript, systemMemoryContext);
case MAP:
verifyStreamType(streamDescriptor, outputType, MapType.class::isInstance);
return new MapSelectiveStreamReader(streamDescriptor, filters, requiredSubfields, outputType, hiveStorageTimeZone, options, legacyMapSubscript, systemMemoryContext);
case DECIMAL:
{
verifyStreamType(streamDescriptor, outputType, DecimalType.class::isInstance);
if (streamDescriptor.getOrcType().getPrecision().get() <= MAX_SHORT_PRECISION) {
return new ShortDecimalSelectiveStreamReader(streamDescriptor, getOptionalOnlyFilter(type, filters), outputType, systemMemoryContext.newOrcLocalMemoryContext(SelectiveStreamReaders.class.getSimpleName()));
} else {
return new LongDecimalSelectiveStreamReader(streamDescriptor, getOptionalOnlyFilter(type, filters), outputType, systemMemoryContext.newOrcLocalMemoryContext(SelectiveStreamReaders.class.getSimpleName()));
}
}
case UNION:
default:
throw new IllegalArgumentException("Unsupported type: " + type);
}
}
use of com.facebook.presto.common.predicate.TupleDomainFilter in project presto by prestodb.
the class ListSelectiveStreamReader method getTopLevelFilter.
private static Optional<TupleDomainFilter> getTopLevelFilter(Map<Subfield, TupleDomainFilter> filters) {
Map<Subfield, TupleDomainFilter> topLevelFilters = Maps.filterEntries(filters, entry -> entry.getKey().getPath().isEmpty());
if (topLevelFilters.isEmpty()) {
return Optional.empty();
}
checkArgument(topLevelFilters.size() == 1, "ARRAY column may have at most one top-level range filter");
TupleDomainFilter filter = Iterables.getOnlyElement(topLevelFilters.values());
checkArgument(filter == IS_NULL || filter == IS_NOT_NULL, "Top-level range filter on ARRAY column must be IS NULL or IS NOT NULL");
return Optional.of(filter);
}
Aggregations