本文整理汇总了Java中com.facebook.presto.spi.predicate.Domain类的典型用法代码示例。如果您正苦于以下问题:Java Domain类的具体用法?Java Domain怎么用?Java Domain使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Domain类属于com.facebook.presto.spi.predicate包,在下文中一共展示了Domain类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testNoSchemaFilter
import com.facebook.presto.spi.predicate.Domain; //导入依赖的package包/类
@Test
public void testNoSchemaFilter()
throws Exception
{
// Create "orders" table in a different schema
metadata.createTable(SESSION, tableMetadataBuilder(new SchemaTableName("other", "orders"))
.column("orderkey", BIGINT)
.build());
// Create another table that should not be selected
metadata.createTable(SESSION, tableMetadataBuilder(new SchemaTableName("schema1", "foo"))
.column("orderkey", BIGINT)
.build());
TupleDomain<Integer> tupleDomain = TupleDomain.withColumnDomains(
ImmutableMap.<Integer, Domain>builder()
.put(1, Domain.singleValue(VARCHAR, utf8Slice("orders")))
.build());
MetadataDao metadataDao = dummyHandle.attach(MetadataDao.class);
Set<Long> actual = ImmutableSet.copyOf(ShardMetadataRecordCursor.getTableIds(dbi, tupleDomain));
Set<Long> expected = ImmutableSet.of(
metadataDao.getTableInformation("other", "orders").getTableId(),
metadataDao.getTableInformation("test", "orders").getTableId());
assertEquals(actual, expected);
}
示例2: testNoTableFilter
import com.facebook.presto.spi.predicate.Domain; //导入依赖的package包/类
@Test
public void testNoTableFilter()
throws Exception
{
// Create "orders" table in a different schema
metadata.createTable(SESSION, tableMetadataBuilder(new SchemaTableName("test", "orders2"))
.column("orderkey", BIGINT)
.build());
// Create another table that should not be selected
metadata.createTable(SESSION, tableMetadataBuilder(new SchemaTableName("schema1", "foo"))
.column("orderkey", BIGINT)
.build());
TupleDomain<Integer> tupleDomain = TupleDomain.withColumnDomains(
ImmutableMap.<Integer, Domain>builder()
.put(0, Domain.singleValue(VARCHAR, utf8Slice("test")))
.build());
MetadataDao metadataDao = dummyHandle.attach(MetadataDao.class);
Set<Long> actual = ImmutableSet.copyOf(ShardMetadataRecordCursor.getTableIds(dbi, tupleDomain));
Set<Long> expected = ImmutableSet.of(
metadataDao.getTableInformation("test", "orders").getTableId(),
metadataDao.getTableInformation("test", "orders2").getTableId());
assertEquals(actual, expected);
}
示例3: matches
import com.facebook.presto.spi.predicate.Domain; //导入依赖的package包/类
@Override
public boolean matches(long numberOfRows, Map<Integer, ColumnStatistics> statisticsByColumnIndex)
{
ImmutableMap.Builder<C, Domain> domains = ImmutableMap.builder();
for (ColumnReference<C> columnReference : columnReferences) {
ColumnStatistics columnStatistics = statisticsByColumnIndex.get(columnReference.getOrdinal());
Domain domain;
if (columnStatistics == null) {
// no stats for column
domain = Domain.all(columnReference.getType());
}
else {
domain = getDomain(columnReference.getType(), numberOfRows, columnStatistics);
}
domains.put(columnReference.getColumn(), domain);
}
TupleDomain<C> stripeDomain = TupleDomain.withColumnDomains(domains.build());
return effectivePredicate.overlaps(stripeDomain);
}
示例4: createDomain
import com.facebook.presto.spi.predicate.Domain; //导入依赖的package包/类
private static <F, T extends Comparable<T>> Domain createDomain(Type type, boolean hasNullValue, RangeStatistics<F> rangeStatistics, Function<F, T> function)
{
F min = rangeStatistics.getMin();
F max = rangeStatistics.getMax();
if (min != null && max != null) {
return Domain.create(ValueSet.ofRanges(Range.range(type, function.apply(min), true, function.apply(max), true)), hasNullValue);
}
if (max != null) {
return Domain.create(ValueSet.ofRanges(Range.lessThanOrEqual(type, function.apply(max))), hasNullValue);
}
if (min != null) {
return Domain.create(ValueSet.ofRanges(Range.greaterThanOrEqual(type, function.apply(min))), hasNullValue);
}
return Domain.create(ValueSet.all(type), hasNullValue);
}
示例5: stringFilter
import com.facebook.presto.spi.predicate.Domain; //导入依赖的package包/类
public static Optional<String> stringFilter(TupleDomain<Integer> constraint, int index)
{
if (constraint.isNone()) {
return Optional.empty();
}
Domain domain = constraint.getDomains().get().get(index);
if ((domain == null) || !domain.isSingleValue()) {
return Optional.empty();
}
Object value = domain.getSingleValue();
if (value instanceof Slice) {
return Optional.of(((Slice) value).toStringUtf8());
}
return Optional.empty();
}
示例6: rewriteFilterSource
import com.facebook.presto.spi.predicate.Domain; //导入依赖的package包/类
private PlanNode rewriteFilterSource(FilterNode filterNode, PlanNode source, Symbol rowNumberSymbol, int upperBound)
{
ExtractionResult extractionResult = fromPredicate(metadata, session, filterNode.getPredicate(), types);
TupleDomain<Symbol> tupleDomain = extractionResult.getTupleDomain();
if (!isEqualRange(tupleDomain, rowNumberSymbol, upperBound)) {
return new FilterNode(filterNode.getId(), source, filterNode.getPredicate());
}
// Remove the row number domain because it is absorbed into the node
Map<Symbol, Domain> newDomains = tupleDomain.getDomains().get().entrySet().stream()
.filter(entry -> !entry.getKey().equals(rowNumberSymbol))
.collect(toMap(Map.Entry::getKey, Map.Entry::getValue));
// Construct a new predicate
TupleDomain<Symbol> newTupleDomain = TupleDomain.withColumnDomains(newDomains);
Expression newPredicate = ExpressionUtils.combineConjuncts(
extractionResult.getRemainingExpression(),
toPredicate(newTupleDomain));
if (newPredicate.equals(BooleanLiteral.TRUE_LITERAL)) {
return source;
}
return new FilterNode(filterNode.getId(), source, newPredicate);
}
示例7: simplifyDomain
import com.facebook.presto.spi.predicate.Domain; //导入依赖的package包/类
/**
* Reduces the number of discrete components in the Domain if there are too many.
*/
public static Domain simplifyDomain(Domain domain)
{
ValueSet values = domain.getValues();
ValueSet simplifiedValueSet = values.getValuesProcessor().<Optional<ValueSet>>transform(
ranges -> {
if (ranges.getOrderedRanges().size() <= 32) {
return Optional.empty();
}
return Optional.of(ValueSet.ofRanges(ranges.getSpan()));
},
discreteValues -> {
if (discreteValues.getValues().size() <= 32) {
return Optional.empty();
}
return Optional.of(ValueSet.all(domain.getType()));
},
allOrNone -> Optional.empty())
.orElse(values);
return Domain.create(simplifiedValueSet, domain.isNullAllowed());
}
示例8: toPredicate
import com.facebook.presto.spi.predicate.Domain; //导入依赖的package包/类
private static Expression toPredicate(Domain domain, QualifiedNameReference reference)
{
if (domain.getValues().isNone()) {
return domain.isNullAllowed() ? new IsNullPredicate(reference) : FALSE_LITERAL;
}
if (domain.getValues().isAll()) {
return domain.isNullAllowed() ? TRUE_LITERAL : new NotExpression(new IsNullPredicate(reference));
}
List<Expression> disjuncts = new ArrayList<>();
disjuncts.addAll(domain.getValues().getValuesProcessor().transform(
ranges -> extractDisjuncts(domain.getType(), ranges, reference),
discreteValues -> extractDisjuncts(domain.getType(), discreteValues, reference),
allOrNone -> {
throw new IllegalStateException("Case should not be reachable");
}));
// Add nullability disjuncts
if (domain.isNullAllowed()) {
disjuncts.add(new IsNullPredicate(reference));
}
return combineDisjunctsWithDefault(disjuncts, TRUE_LITERAL);
}
示例9: extractOrderableDomain
import com.facebook.presto.spi.predicate.Domain; //导入依赖的package包/类
private static Domain extractOrderableDomain(ComparisonExpression.Type comparisonType, Type type, Object value, boolean complement)
{
checkArgument(value != null);
switch (comparisonType) {
case EQUAL:
return Domain.create(complementIfNecessary(ValueSet.ofRanges(Range.equal(type, value)), complement), false);
case GREATER_THAN:
return Domain.create(complementIfNecessary(ValueSet.ofRanges(Range.greaterThan(type, value)), complement), false);
case GREATER_THAN_OR_EQUAL:
return Domain.create(complementIfNecessary(ValueSet.ofRanges(Range.greaterThanOrEqual(type, value)), complement), false);
case LESS_THAN:
return Domain.create(complementIfNecessary(ValueSet.ofRanges(Range.lessThan(type, value)), complement), false);
case LESS_THAN_OR_EQUAL:
return Domain.create(complementIfNecessary(ValueSet.ofRanges(Range.lessThanOrEqual(type, value)), complement), false);
case NOT_EQUAL:
return Domain.create(complementIfNecessary(ValueSet.ofRanges(Range.lessThan(type, value), Range.greaterThan(type, value)), complement), false);
case IS_DISTINCT_FROM:
// Need to potential complement the whole domain for IS_DISTINCT_FROM since it is null-aware
return complementIfNecessary(Domain.create(ValueSet.ofRanges(Range.lessThan(type, value), Range.greaterThan(type, value)), true), complement);
default:
throw new AssertionError("Unhandled type: " + comparisonType);
}
}
示例10: testRoundTrip
import com.facebook.presto.spi.predicate.Domain; //导入依赖的package包/类
@Test
public void testRoundTrip()
throws Exception
{
TupleDomain<Symbol> tupleDomain = withColumnDomains(ImmutableMap.<Symbol, Domain>builder()
.put(A, Domain.singleValue(BIGINT, 1L))
.put(B, Domain.onlyNull(DOUBLE))
.put(C, Domain.notNull(VARCHAR))
.put(D, Domain.singleValue(BOOLEAN, true))
.put(E, Domain.singleValue(BIGINT, 2L))
.put(F, Domain.create(ValueSet.ofRanges(Range.lessThanOrEqual(DOUBLE, 1.1), Range.equal(DOUBLE, 2.0), Range.range(DOUBLE, 3.0, false, 3.5, true)), true))
.put(G, Domain.create(ValueSet.ofRanges(Range.lessThanOrEqual(VARCHAR, utf8Slice("2013-01-01")), Range.greaterThan(VARCHAR, utf8Slice("2013-10-01"))), false))
.put(H, Domain.singleValue(TIMESTAMP, TIMESTAMP_VALUE))
.put(I, Domain.singleValue(DATE, DATE_VALUE))
.put(J, Domain.singleValue(COLOR, COLOR_VALUE_1))
.put(K, Domain.notNull(HYPER_LOG_LOG))
.build());
ExtractionResult result = fromPredicate(toPredicate(tupleDomain));
assertEquals(result.getRemainingExpression(), TRUE_LITERAL);
assertEquals(result.getTupleDomain(), tupleDomain);
}
示例11: testToPredicateAllIgnored
import com.facebook.presto.spi.predicate.Domain; //导入依赖的package包/类
@Test
public void testToPredicateAllIgnored()
throws Exception
{
TupleDomain<Symbol> tupleDomain = withColumnDomains(ImmutableMap.<Symbol, Domain>builder()
.put(A, Domain.singleValue(BIGINT, 1L))
.put(B, Domain.onlyNull(DOUBLE))
.put(C, Domain.notNull(VARCHAR))
.put(D, Domain.all(BOOLEAN))
.build());
ExtractionResult result = fromPredicate(toPredicate(tupleDomain));
assertEquals(result.getRemainingExpression(), TRUE_LITERAL);
assertEquals(result.getTupleDomain(), withColumnDomains(ImmutableMap.<Symbol, Domain>builder()
.put(A, Domain.singleValue(BIGINT, 1L))
.put(B, Domain.onlyNull(DOUBLE))
.put(C, Domain.notNull(VARCHAR))
.build()));
}
示例12: testFromAndPredicate
import com.facebook.presto.spi.predicate.Domain; //导入依赖的package包/类
@Test
public void testFromAndPredicate()
throws Exception
{
Expression originalPredicate = and(
and(greaterThan(A, longLiteral(1L)), unprocessableExpression1(A)),
and(lessThan(A, longLiteral(5L)), unprocessableExpression2(A)));
ExtractionResult result = fromPredicate(originalPredicate);
assertEquals(result.getRemainingExpression(), and(unprocessableExpression1(A), unprocessableExpression2(A)));
assertEquals(result.getTupleDomain(), withColumnDomains(ImmutableMap.of(A, Domain.create(ValueSet.ofRanges(Range.range(BIGINT, 1L, false, 5L, false)), false))));
// Test complements
originalPredicate = not(and(
and(greaterThan(A, longLiteral(1L)), unprocessableExpression1(A)),
and(lessThan(A, longLiteral(5L)), unprocessableExpression2(A))));
result = fromPredicate(originalPredicate);
assertEquals(result.getRemainingExpression(), originalPredicate);
assertTrue(result.getTupleDomain().isAll());
originalPredicate = not(and(
not(and(greaterThan(A, longLiteral(1L)), unprocessableExpression1(A))),
not(and(lessThan(A, longLiteral(5L)), unprocessableExpression2(A)))));
result = fromPredicate(originalPredicate);
assertEquals(result.getRemainingExpression(), originalPredicate);
assertEquals(result.getTupleDomain(), withColumnDomains(ImmutableMap.of(A, Domain.notNull(BIGINT))));
}
示例13: testFromNotPredicate
import com.facebook.presto.spi.predicate.Domain; //导入依赖的package包/类
@Test
public void testFromNotPredicate()
throws Exception
{
Expression originalPredicate = not(and(equal(A, longLiteral(1L)), unprocessableExpression1(A)));
ExtractionResult result = fromPredicate(originalPredicate);
assertEquals(result.getRemainingExpression(), originalPredicate);
assertTrue(result.getTupleDomain().isAll());
originalPredicate = not(unprocessableExpression1(A));
result = fromPredicate(originalPredicate);
assertEquals(result.getRemainingExpression(), originalPredicate);
assertTrue(result.getTupleDomain().isAll());
originalPredicate = not(TRUE_LITERAL);
result = fromPredicate(originalPredicate);
assertEquals(result.getRemainingExpression(), TRUE_LITERAL);
assertTrue(result.getTupleDomain().isNone());
originalPredicate = not(equal(A, longLiteral(1L)));
result = fromPredicate(originalPredicate);
assertEquals(result.getRemainingExpression(), TRUE_LITERAL);
assertEquals(result.getTupleDomain(), withColumnDomains(ImmutableMap.of(A, Domain.create(ValueSet.ofRanges(Range.lessThan(BIGINT, 1L), Range.greaterThan(BIGINT, 1L)), false))));
}
示例14: testFromIsNullPredicate
import com.facebook.presto.spi.predicate.Domain; //导入依赖的package包/类
@Test
public void testFromIsNullPredicate()
throws Exception
{
Expression originalExpression = isNull(A);
ExtractionResult result = fromPredicate(originalExpression);
assertEquals(result.getRemainingExpression(), TRUE_LITERAL);
assertEquals(result.getTupleDomain(), withColumnDomains(ImmutableMap.of(A, Domain.onlyNull(BIGINT))));
originalExpression = isNull(K);
result = fromPredicate(originalExpression);
assertEquals(result.getRemainingExpression(), TRUE_LITERAL);
assertEquals(result.getTupleDomain(), withColumnDomains(ImmutableMap.of(K, Domain.onlyNull(HYPER_LOG_LOG))));
originalExpression = not(isNull(A));
result = fromPredicate(originalExpression);
assertEquals(result.getRemainingExpression(), TRUE_LITERAL);
assertEquals(result.getTupleDomain(), withColumnDomains(ImmutableMap.of(A, Domain.notNull(BIGINT))));
originalExpression = not(isNull(K));
result = fromPredicate(originalExpression);
assertEquals(result.getRemainingExpression(), TRUE_LITERAL);
assertEquals(result.getTupleDomain(), withColumnDomains(ImmutableMap.of(K, Domain.notNull(HYPER_LOG_LOG))));
}
示例15: testFromIsNotNullPredicate
import com.facebook.presto.spi.predicate.Domain; //导入依赖的package包/类
@Test
public void testFromIsNotNullPredicate()
throws Exception
{
Expression originalExpression = isNotNull(A);
ExtractionResult result = fromPredicate(originalExpression);
assertEquals(result.getRemainingExpression(), TRUE_LITERAL);
assertEquals(result.getTupleDomain(), withColumnDomains(ImmutableMap.of(A, Domain.notNull(BIGINT))));
originalExpression = isNotNull(K);
result = fromPredicate(originalExpression);
assertEquals(result.getRemainingExpression(), TRUE_LITERAL);
assertEquals(result.getTupleDomain(), withColumnDomains(ImmutableMap.of(K, Domain.notNull(HYPER_LOG_LOG))));
originalExpression = not(isNotNull(A));
result = fromPredicate(originalExpression);
assertEquals(result.getRemainingExpression(), TRUE_LITERAL);
assertEquals(result.getTupleDomain(), withColumnDomains(ImmutableMap.of(A, Domain.onlyNull(BIGINT))));
originalExpression = not(isNotNull(K));
result = fromPredicate(originalExpression);
assertEquals(result.getRemainingExpression(), TRUE_LITERAL);
assertEquals(result.getTupleDomain(), withColumnDomains(ImmutableMap.of(K, Domain.onlyNull(HYPER_LOG_LOG))));
}