public static PartitionDesign getPartitionDesign(KuduTable table) { Schema schema = table.getSchema(); PartitionDesign partitionDesign = new PartitionDesign(); PartitionSchema partitionSchema = table.getPartitionSchema(); List<HashPartitionDefinition> hashPartitions = partitionSchema.getHashBucketSchemas().stream() .map(hashBucketSchema -> { HashPartitionDefinition hash = new HashPartitionDefinition(); List<String> cols = hashBucketSchema.getColumnIds().stream() .map(idx -> schema.getColumnByIndex(idx).getName()).collect(toImmutableList()); hash.setColumns(cols); hash.setBuckets(hashBucketSchema.getNumBuckets()); return hash; }).collect(toImmutableList()); partitionDesign.setHash(hashPartitions); List<Integer> rangeColumns = partitionSchema.getRangeSchema().getColumns(); if (!rangeColumns.isEmpty()) { RangePartitionDefinition definition = new RangePartitionDefinition(); definition.setColumns(rangeColumns.stream() .map(i -> schema.getColumns().get(i).getName()) .collect(ImmutableList.toImmutableList())); partitionDesign.setRange(definition); } return partitionDesign; }
/** * Decodes a partition key into a list of hash buckets and range key * * @param schema the schema of the table * @param partitionSchema the partition schema of the table * @param key the encoded partition key * @return the decoded buckets and range key */ public static Pair<List<Integer>, PartialRow> decodePartitionKey(Schema schema, PartitionSchema partitionSchema, byte[] key) { ByteBuffer buf = ByteBuffer.wrap(key); buf.order(ByteOrder.BIG_ENDIAN); List<Integer> buckets = new ArrayList<>(); for (HashBucketSchema hashSchema : partitionSchema.getHashBucketSchemas()) { if (buf.hasRemaining()) { buckets.add(buf.getInt()); } else { buckets.add(0); } } return new Pair<>(buckets, decodeRangePartitionKey(schema, partitionSchema, buf)); }
/** * Encodes the provided row into a partition key according to the partition schema. * * @param row the row to encode * @param partitionSchema the partition schema describing the table's partitioning * @return an encoded partition key */ public static byte[] encodePartitionKey(PartialRow row, PartitionSchema partitionSchema) { ByteVec buf = ByteVec.create(); if (!partitionSchema.getHashBucketSchemas().isEmpty()) { for (final HashBucketSchema hashSchema : partitionSchema.getHashBucketSchemas()) { encodeHashBucket(getHashBucket(row, hashSchema), buf); } } encodeColumns(row, partitionSchema.getRangeSchema().getColumns(), buf); return buf.toArray(); }
byte[] upperBound) { if (partitionSchema.getRangeSchema().getColumns().isEmpty() && partitionSchema.getHashBucketSchemas().isEmpty()) { assert lowerBound.length == 0 && upperBound.length == 0; return "<no-partitioning>";
public static PartitionDesign getPartitionDesign(KuduTable table) { Schema schema = table.getSchema(); PartitionDesign partitionDesign = new PartitionDesign(); PartitionSchema partitionSchema = table.getPartitionSchema(); List<HashPartitionDefinition> hashPartitions = partitionSchema.getHashBucketSchemas().stream() .map(hashBucketSchema -> { HashPartitionDefinition hash = new HashPartitionDefinition(); List<String> cols = hashBucketSchema.getColumnIds().stream() .map(idx -> schema.getColumnByIndex(idx).getName()).collect(toImmutableList()); hash.setColumns(cols); hash.setBuckets(hashBucketSchema.getNumBuckets()); return hash; }).collect(toImmutableList()); partitionDesign.setHash(hashPartitions); List<Integer> rangeColumns = partitionSchema.getRangeSchema().getColumns(); if (!rangeColumns.isEmpty()) { RangePartitionDefinition definition = new RangePartitionDefinition(); definition.setColumns(rangeColumns.stream() .map(i -> schema.getColumns().get(i).getName()) .collect(ImmutableList.toImmutableList())); partitionDesign.setRange(definition); } return partitionDesign; }
public static PartitionDesign getPartitionDesign(KuduTable table) { Schema schema = table.getSchema(); PartitionDesign partitionDesign = new PartitionDesign(); PartitionSchema partitionSchema = table.getPartitionSchema(); List<HashPartitionDefinition> hashPartitions = partitionSchema.getHashBucketSchemas().stream() .map(hashBucketSchema -> { HashPartitionDefinition hash = new HashPartitionDefinition(); List<String> cols = hashBucketSchema.getColumnIds().stream() .map(idx -> schema.getColumnByIndex(idx).getName()).collect(toImmutableList()); hash.setColumns(cols); hash.setBuckets(hashBucketSchema.getNumBuckets()); return hash; }).collect(toImmutableList()); partitionDesign.setHash(hashPartitions); List<Integer> rangeColumns = partitionSchema.getRangeSchema().getColumns(); if (!rangeColumns.isEmpty()) { RangePartitionDefinition definition = new RangePartitionDefinition(); definition.setColumns(rangeColumns.stream() .map(i -> schema.getColumns().get(i).getName()) .collect(ImmutableList.toImmutableList())); partitionDesign.setRange(definition); } return partitionDesign; }
List<BitSet> hashComponents = new ArrayList<>(partitionSchema.getHashBucketSchemas().size()); for (PartitionSchema.HashBucketSchema hashSchema : partitionSchema.getHashBucketSchemas()) { hashComponents.add(pruneHashComponent(schema, hashSchema, predicates)); constrainedIndex = partitionSchema.getHashBucketSchemas().size(); } else { int numBuckets = partitionSchema.getHashBucketSchemas().get(i - 1).getNumBuckets(); BitSet hashBuckets = hashComponents.get(i - 1); if (hashBuckets.nextClearBit(0) < numBuckets) {