if (freshSpec.compatibleWith(spec)) { specId = spec.specId(); break;
public TableMetadata updatePartitionSpec(PartitionSpec partitionSpec) { PartitionSpec.checkCompatibility(partitionSpec, schema); // if the spec already exists, use the same ID. otherwise, use 1 more than the highest ID. int newDefaultSpecId = INITIAL_SPEC_ID; for (PartitionSpec spec : specs) { if (partitionSpec.compatibleWith(spec)) { newDefaultSpecId = spec.specId(); break; } else if (newDefaultSpecId <= spec.specId()) { newDefaultSpecId = spec.specId() + 1; } } Preconditions.checkArgument(defaultSpecId != newDefaultSpecId, "Cannot set default partition spec to the current default"); ImmutableList.Builder<PartitionSpec> builder = ImmutableList.<PartitionSpec>builder() .addAll(specs); if (!specsById.containsKey(newDefaultSpecId)) { // get a fresh spec to ensure the spec ID is set to the new default builder.add(freshSpec(newDefaultSpecId, schema, partitionSpec)); } return new TableMetadata(ops, null, location, System.currentTimeMillis(), lastColumnId, schema, newDefaultSpecId, builder.build(), properties, currentSnapshotId, snapshots, snapshotLog); }
1, metadata.specs().size()); Assert.assertTrue("PartitionSpec should contain the spec", metadata.specs().get(0).compatibleWith(spec)); Assert.assertEquals("PartitionSpec should have ID TableMetadata.INITIAL_SPEC_ID", TableMetadata.INITIAL_SPEC_ID, metadata.specs().get(0).specId());