public TableMetadata updatePartitionSpec(PartitionSpec partitionSpec) {
PartitionSpec.checkCompatibility(partitionSpec, schema);
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)) {
builder.add(freshSpec(newDefaultSpecId, schema, partitionSpec));
}
return new TableMetadata(ops, null, location,
System.currentTimeMillis(), lastColumnId, schema, newDefaultSpecId,
builder.build(), properties,
currentSnapshotId, snapshots, snapshotLog);
}