/** * Builds the default partition schema for a schema. * @param schema the schema * @return a default partition schema */ private PartitionSchema defaultPartitionSchema(Schema schema) { List<Integer> columnIds = new ArrayList<>(); for (int i = 0; i < schema.getPrimaryKeyColumnCount(); i++) { // Schema does not provide a way to lookup a column ID by column index, // so instead we assume that the IDs for the primary key columns match // their respective index, which holds up when the schema is created // with buildSchema. columnIds.add(i); } return new PartitionSchema( new PartitionSchema.RangeSchema(columnIds), ImmutableList.<PartitionSchema.HashBucketSchema>of(), schema); }
/** * Factory method for creating a {@code PartitionSchema} from a protobuf message. * * @param pb the partition schema protobuf message * @return a partition instance */ static PartitionSchema pbToPartitionSchema(Common.PartitionSchemaPB pb, Schema schema) { List<Integer> rangeColumns = pbToIds(pb.getRangeSchema().getColumnsList()); PartitionSchema.RangeSchema rangeSchema = new PartitionSchema.RangeSchema(rangeColumns); ImmutableList.Builder<PartitionSchema.HashBucketSchema> hashSchemas = ImmutableList.builder(); for (Common.PartitionSchemaPB.HashBucketSchemaPB hashBucketSchemaPB : pb.getHashBucketSchemasList()) { List<Integer> hashColumnIds = pbToIds(hashBucketSchemaPB.getColumnsList()); PartitionSchema.HashBucketSchema hashSchema = new PartitionSchema.HashBucketSchema(hashColumnIds, hashBucketSchemaPB.getNumBuckets(), hashBucketSchemaPB.getSeed()); hashSchemas.add(hashSchema); } return new PartitionSchema(rangeSchema, hashSchemas.build(), schema); }
new PartitionSchema(new RangeSchema(ImmutableList.of(0, 1, 2)), ImmutableList.of( new HashBucketSchema(ImmutableList.of(0, 1), 32, 0),