Пример #1
0
  private static Set<List<Comparable<?>>> getPartitionKeysSet(
      CassandraTable table, TupleDomain<ColumnHandle> tupleDomain) {
    ImmutableList.Builder<Set<Comparable<?>>> partitionColumnValues = ImmutableList.builder();
    for (CassandraColumnHandle columnHandle : table.getPartitionKeyColumns()) {
      Domain domain = tupleDomain.getDomains().get(columnHandle);

      // if there is no constraint on a partition key, return an empty set
      if (domain == null) {
        return ImmutableSet.of();
      }

      // todo does cassandra allow null partition keys?
      if (domain.isNullAllowed()) {
        return ImmutableSet.of();
      }

      ImmutableSet.Builder<Comparable<?>> columnValues = ImmutableSet.builder();
      for (Range range : domain.getRanges()) {
        // if the range is not a single value, we can not perform partition pruning
        if (!range.isSingleValue()) {
          return ImmutableSet.of();
        }
        Comparable<?> value = range.getSingleValue();

        CassandraType valueType = columnHandle.getCassandraType();
        columnValues.add(valueType.getValueForPartitionKey(value));
      }
      partitionColumnValues.add(columnValues.build());
    }
    return Sets.cartesianProduct(partitionColumnValues.build());
  }