io.prestosql.spi.predicate.Range.equal()方法的使用及代码示例

x33g5p2x  于2022-01-29 转载在 其他  
字(12.3k)|赞(0)|评价(0)|浏览(200)

本文整理了Java中io.prestosql.spi.predicate.Range.equal方法的一些代码示例,展示了Range.equal的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Range.equal方法的具体详情如下:
包路径:io.prestosql.spi.predicate.Range
类名称:Range
方法名:equal

Range.equal介绍

暂无

代码示例

代码示例来源:origin: prestosql/presto

/**
 * Provided discrete values that are unioned together to form the SortedRangeSet
 */
static SortedRangeSet of(Type type, Object first, Object... rest)
{
  List<Range> ranges = new ArrayList<>(rest.length + 1);
  ranges.add(Range.equal(type, first));
  for (Object value : rest) {
    ranges.add(Range.equal(type, value));
  }
  return copyOf(type, ranges);
}

代码示例来源:origin: prestosql/presto

static ValueSet copyOf(Type type, Collection<Object> values)
{
  if (type.isOrderable()) {
    return SortedRangeSet.copyOf(type, values.stream()
        .map(value -> Range.equal(type, value))
        .collect(toList()));
  }
  if (type.isComparable()) {
    return EquatableValueSet.copyOf(type, values);
  }
  throw new IllegalArgumentException("Cannot create discrete ValueSet with non-comparable type: " + type);
}

代码示例来源:origin: io.prestosql/presto-spi

@Test
public void testGetSingleValue()
{
  assertEquals(Range.equal(BIGINT, 0L).getSingleValue(), 0L);
  try {
    Range.lessThan(BIGINT, 0L).getSingleValue();
    fail();
  }
  catch (IllegalStateException e) {
  }
}

代码示例来源:origin: prestosql/presto

@Test
public void testGetSingleValue()
{
  assertEquals(Range.equal(BIGINT, 0L).getSingleValue(), 0L);
  try {
    Range.lessThan(BIGINT, 0L).getSingleValue();
    fail();
  }
  catch (IllegalStateException e) {
  }
}

代码示例来源:origin: prestosql/presto

@Test
public void testBucketNumberMultipleRanges()
{
  TupleDomain<RaptorColumnHandle> tupleDomain = withColumnDomains(ImmutableMap.of(
      bucketNumberColumnHandle("test"),
      create(SortedRangeSet.copyOf(INTEGER, ImmutableList.of(equal(INTEGER, 1L), equal(INTEGER, 3L))), false)));
  ShardPredicate shardPredicate = ShardPredicate.create(tupleDomain);
  assertEquals(shardPredicate.getPredicate(),
      "(((bucket_number >= ? OR bucket_number IS NULL) AND (bucket_number <= ? OR bucket_number IS NULL))" +
          " OR ((bucket_number >= ? OR bucket_number IS NULL) AND (bucket_number <= ? OR bucket_number IS NULL)))");
}

代码示例来源:origin: prestosql/presto

@Test
public void testIntersect()
{
  assertEquals(Range.greaterThan(BIGINT, 1L).intersect(Range.lessThanOrEqual(BIGINT, 2L)), Range.range(BIGINT, 1L, false, 2L, true));
  assertEquals(Range.range(BIGINT, 1L, true, 3L, false).intersect(Range.equal(BIGINT, 2L)), Range.equal(BIGINT, 2L));
  assertEquals(Range.range(BIGINT, 1L, true, 3L, false).intersect(Range.range(BIGINT, 2L, false, 10L, false)), Range.range(BIGINT, 2L, false, 3L, false));
  assertEquals(Range.range(BIGINT, 1L, true, 3L, true).intersect(Range.range(BIGINT, 3L, true, 10L, false)), Range.equal(BIGINT, 3L));
  assertEquals(Range.all(BIGINT).intersect(Range.equal(BIGINT, Long.MAX_VALUE)), Range.equal(BIGINT, Long.MAX_VALUE));
}

代码示例来源:origin: prestosql/presto

@Test
public void testBuildQueryIn()
{
  TupleDomain<ColumnHandle> tupleDomain = TupleDomain.withColumnDomains(ImmutableMap.of(
      COL2, Domain.create(ValueSet.ofRanges(equal(createUnboundedVarcharType(), utf8Slice("hello")), equal(createUnboundedVarcharType(), utf8Slice("world"))), false)));
  Document query = MongoSession.buildQuery(tupleDomain);
  Document expected = new Document(COL2.getName(), new Document("$in", ImmutableList.of("hello", "world")));
  assertEquals(query, expected);
}

代码示例来源:origin: io.prestosql/presto-spi

@Test
public void testIntersect()
{
  assertEquals(Range.greaterThan(BIGINT, 1L).intersect(Range.lessThanOrEqual(BIGINT, 2L)), Range.range(BIGINT, 1L, false, 2L, true));
  assertEquals(Range.range(BIGINT, 1L, true, 3L, false).intersect(Range.equal(BIGINT, 2L)), Range.equal(BIGINT, 2L));
  assertEquals(Range.range(BIGINT, 1L, true, 3L, false).intersect(Range.range(BIGINT, 2L, false, 10L, false)), Range.range(BIGINT, 2L, false, 3L, false));
  assertEquals(Range.range(BIGINT, 1L, true, 3L, true).intersect(Range.range(BIGINT, 3L, true, 10L, false)), Range.equal(BIGINT, 3L));
  assertEquals(Range.all(BIGINT).intersect(Range.equal(BIGINT, Long.MAX_VALUE)), Range.equal(BIGINT, Long.MAX_VALUE));
}

代码示例来源:origin: prestosql/presto

@Test
public void testDiscreteShardUuidPredicate()
{
  Slice uuid0 = utf8Slice(randomUUID().toString());
  Slice uuid1 = utf8Slice(randomUUID().toString());
  TupleDomain<RaptorColumnHandle> tupleDomain = withColumnDomains(ImmutableMap.of(
      shardUuidColumnHandle("test"),
      create(SortedRangeSet.copyOf(VARCHAR, ImmutableList.of(equal(VARCHAR, uuid0), equal(VARCHAR, uuid1))), false)));
  ShardPredicate shardPredicate = ShardPredicate.create(tupleDomain);
  assertEquals(shardPredicate.getPredicate(), "shard_uuid = ? OR shard_uuid = ?");
  assertEquals(shardPredicate.getTypes(), ImmutableList.of(VARBINARY, VARBINARY));
  assertEquals(ImmutableSet.copyOf(shardPredicate.getValues()), ImmutableSet.of(uuidStringToBytes(uuid0), uuidStringToBytes(uuid1)));
}

代码示例来源:origin: prestosql/presto

@Test
public void testInvalidUuid()
{
  Slice uuid0 = utf8Slice("test1");
  Slice uuid1 = utf8Slice("test2");
  TupleDomain<RaptorColumnHandle> tupleDomain = withColumnDomains(ImmutableMap.of(
      shardUuidColumnHandle("test"),
      create(SortedRangeSet.copyOf(VARCHAR, ImmutableList.of(equal(VARCHAR, uuid0), equal(VARCHAR, uuid1))), false)));
  ShardPredicate shardPredicate = ShardPredicate.create(tupleDomain);
  assertEquals(shardPredicate.getPredicate(), "true");
}

代码示例来源:origin: prestosql/presto

@Test
public void testBucketNumberSingleRange()
{
  TupleDomain<RaptorColumnHandle> tupleDomain = withColumnDomains(ImmutableMap.of(
      bucketNumberColumnHandle("test"),
      create(SortedRangeSet.copyOf(INTEGER, ImmutableList.of(equal(INTEGER, 1L))), false)));
  ShardPredicate shardPredicate = ShardPredicate.create(tupleDomain);
  assertEquals(shardPredicate.getPredicate(), "(((bucket_number >= ? OR bucket_number IS NULL) AND (bucket_number <= ? OR bucket_number IS NULL)))");
}

代码示例来源:origin: io.prestosql/presto-hive

@Test
public void testDateColumn()
{
  IonSqlQueryBuilder queryBuilder = new IonSqlQueryBuilder(new TypeRegistry());
  List<HiveColumnHandle> columns = ImmutableList.of(
      new HiveColumnHandle("t1", HIVE_TIMESTAMP, parseTypeSignature(TIMESTAMP), 0, REGULAR, Optional.empty()),
      new HiveColumnHandle("t2", HIVE_DATE, parseTypeSignature(StandardTypes.DATE), 1, REGULAR, Optional.empty()));
  TupleDomain<HiveColumnHandle> tupleDomain = withColumnDomains(ImmutableMap.of(
      columns.get(1), Domain.create(SortedRangeSet.copyOf(DATE, ImmutableList.of(Range.equal(DATE, (long) DateTimeUtils.parseDate("2001-08-22")))), false)));
  assertEquals("SELECT s._1, s._2 FROM S3Object s WHERE (case s._2 when '' then null else CAST(s._2 AS TIMESTAMP) end = `2001-08-22`)", queryBuilder.buildSql(columns, tupleDomain));
}

代码示例来源:origin: prestosql/presto

@Test
public void testDateColumn()
{
  IonSqlQueryBuilder queryBuilder = new IonSqlQueryBuilder(new TypeRegistry());
  List<HiveColumnHandle> columns = ImmutableList.of(
      new HiveColumnHandle("t1", HIVE_TIMESTAMP, parseTypeSignature(TIMESTAMP), 0, REGULAR, Optional.empty()),
      new HiveColumnHandle("t2", HIVE_DATE, parseTypeSignature(StandardTypes.DATE), 1, REGULAR, Optional.empty()));
  TupleDomain<HiveColumnHandle> tupleDomain = withColumnDomains(ImmutableMap.of(
      columns.get(1), Domain.create(SortedRangeSet.copyOf(DATE, ImmutableList.of(Range.equal(DATE, (long) DateTimeUtils.parseDate("2001-08-22")))), false)));
  assertEquals("SELECT s._1, s._2 FROM S3Object s WHERE (case s._2 when '' then null else CAST(s._2 AS TIMESTAMP) end = `2001-08-22`)", queryBuilder.buildSql(columns, tupleDomain));
}

代码示例来源:origin: io.prestosql/presto-spi

@Test
public void testOverlaps()
{
  assertTrue(Range.greaterThan(BIGINT, 1L).overlaps(Range.lessThanOrEqual(BIGINT, 2L)));
  assertFalse(Range.greaterThan(BIGINT, 2L).overlaps(Range.lessThan(BIGINT, 2L)));
  assertTrue(Range.range(BIGINT, 1L, true, 3L, false).overlaps(Range.equal(BIGINT, 2L)));
  assertTrue(Range.range(BIGINT, 1L, true, 3L, false).overlaps(Range.range(BIGINT, 2L, false, 10L, false)));
  assertFalse(Range.range(BIGINT, 1L, true, 3L, false).overlaps(Range.range(BIGINT, 3L, true, 10L, false)));
  assertTrue(Range.range(BIGINT, 1L, true, 3L, true).overlaps(Range.range(BIGINT, 3L, true, 10L, false)));
  assertTrue(Range.all(BIGINT).overlaps(Range.equal(BIGINT, Long.MAX_VALUE)));
}

代码示例来源:origin: prestosql/presto

@Test
public void testOverlaps()
{
  assertTrue(Range.greaterThan(BIGINT, 1L).overlaps(Range.lessThanOrEqual(BIGINT, 2L)));
  assertFalse(Range.greaterThan(BIGINT, 2L).overlaps(Range.lessThan(BIGINT, 2L)));
  assertTrue(Range.range(BIGINT, 1L, true, 3L, false).overlaps(Range.equal(BIGINT, 2L)));
  assertTrue(Range.range(BIGINT, 1L, true, 3L, false).overlaps(Range.range(BIGINT, 2L, false, 10L, false)));
  assertFalse(Range.range(BIGINT, 1L, true, 3L, false).overlaps(Range.range(BIGINT, 3L, true, 10L, false)));
  assertTrue(Range.range(BIGINT, 1L, true, 3L, true).overlaps(Range.range(BIGINT, 3L, true, 10L, false)));
  assertTrue(Range.all(BIGINT).overlaps(Range.equal(BIGINT, Long.MAX_VALUE)));
}

代码示例来源:origin: io.prestosql/presto-main

@Test
public void testInPredicateWithNull()
{
  assertPredicateTranslates(
      in(C_BIGINT, Arrays.asList(1L, 2L, null)),
      withColumnDomains(ImmutableMap.of(C_BIGINT, Domain.create(ValueSet.ofRanges(Range.equal(BIGINT, 1L), Range.equal(BIGINT, 2L)), false))));
  assertPredicateIsAlwaysFalse(not(in(C_BIGINT, Arrays.asList(1L, 2L, null))));
  assertPredicateIsAlwaysFalse(in(C_BIGINT, Arrays.asList(new Long[] {null})));
  assertPredicateIsAlwaysFalse(not(in(C_BIGINT, Arrays.asList(new Long[] {null}))));
  assertUnsupportedPredicate(isNull(in(C_BIGINT, Arrays.asList(1L, 2L, null))));
  assertUnsupportedPredicate(isNotNull(in(C_BIGINT, Arrays.asList(1L, 2L, null))));
  assertUnsupportedPredicate(isNull(in(C_BIGINT, Arrays.asList(new Long[] {null}))));
  assertUnsupportedPredicate(isNotNull(in(C_BIGINT, Arrays.asList(new Long[] {null}))));
}

代码示例来源:origin: io.prestosql/presto-spi

@Test
public void testSpan()
{
  assertEquals(Range.greaterThan(BIGINT, 1L).span(Range.lessThanOrEqual(BIGINT, 2L)), Range.all(BIGINT));
  assertEquals(Range.greaterThan(BIGINT, 2L).span(Range.lessThanOrEqual(BIGINT, 0L)), Range.all(BIGINT));
  assertEquals(Range.range(BIGINT, 1L, true, 3L, false).span(Range.equal(BIGINT, 2L)), Range.range(BIGINT, 1L, true, 3L, false));
  assertEquals(Range.range(BIGINT, 1L, true, 3L, false).span(Range.range(BIGINT, 2L, false, 10L, false)), Range.range(BIGINT, 1L, true, 10L, false));
  assertEquals(Range.greaterThan(BIGINT, 1L).span(Range.equal(BIGINT, 0L)), Range.greaterThanOrEqual(BIGINT, 0L));
  assertEquals(Range.greaterThan(BIGINT, 1L).span(Range.greaterThanOrEqual(BIGINT, 10L)), Range.greaterThan(BIGINT, 1L));
  assertEquals(Range.lessThan(BIGINT, 1L).span(Range.lessThanOrEqual(BIGINT, 1L)), Range.lessThanOrEqual(BIGINT, 1L));
  assertEquals(Range.all(BIGINT).span(Range.lessThanOrEqual(BIGINT, 1L)), Range.all(BIGINT));
}

代码示例来源:origin: prestosql/presto

@Test
public void testSpan()
{
  assertEquals(Range.greaterThan(BIGINT, 1L).span(Range.lessThanOrEqual(BIGINT, 2L)), Range.all(BIGINT));
  assertEquals(Range.greaterThan(BIGINT, 2L).span(Range.lessThanOrEqual(BIGINT, 0L)), Range.all(BIGINT));
  assertEquals(Range.range(BIGINT, 1L, true, 3L, false).span(Range.equal(BIGINT, 2L)), Range.range(BIGINT, 1L, true, 3L, false));
  assertEquals(Range.range(BIGINT, 1L, true, 3L, false).span(Range.range(BIGINT, 2L, false, 10L, false)), Range.range(BIGINT, 1L, true, 10L, false));
  assertEquals(Range.greaterThan(BIGINT, 1L).span(Range.equal(BIGINT, 0L)), Range.greaterThanOrEqual(BIGINT, 0L));
  assertEquals(Range.greaterThan(BIGINT, 1L).span(Range.greaterThanOrEqual(BIGINT, 10L)), Range.greaterThan(BIGINT, 1L));
  assertEquals(Range.lessThan(BIGINT, 1L).span(Range.lessThanOrEqual(BIGINT, 1L)), Range.lessThanOrEqual(BIGINT, 1L));
  assertEquals(Range.all(BIGINT).span(Range.lessThanOrEqual(BIGINT, 1L)), Range.all(BIGINT));
}

代码示例来源:origin: io.prestosql/presto-main

@Test
public void testCharComparedToVarcharExpression()
{
  Type charType = createCharType(10);
  // varchar literal is coerced to column (char) type
  testSimpleComparison(equal(C_CHAR, cast(stringLiteral("abc"), charType)), C_CHAR, Range.equal(charType, Slices.utf8Slice("abc")));
  // both sides got coerced to char(11)
  charType = createCharType(11);
  assertUnsupportedPredicate(equal(cast(C_CHAR, charType), cast(stringLiteral("abc12345678"), charType)));
}

代码示例来源:origin: prestosql/presto

@Test
public void testCharComparedToVarcharExpression()
{
  Type charType = createCharType(10);
  // varchar literal is coerced to column (char) type
  testSimpleComparison(equal(C_CHAR, cast(stringLiteral("abc"), charType)), C_CHAR, Range.equal(charType, Slices.utf8Slice("abc")));
  // both sides got coerced to char(11)
  charType = createCharType(11);
  assertUnsupportedPredicate(equal(cast(C_CHAR, charType), cast(stringLiteral("abc12345678"), charType)));
}

相关文章