surekhasaharan commented on a change in pull request #8507: Rename partition spec fields URL: https://github.com/apache/incubator-druid/pull/8507#discussion_r325935516
########## File path: core/src/main/java/org/apache/druid/indexer/partitions/SingleDimensionPartitionsSpec.java ########## @@ -21,76 +21,158 @@ import com.fasterxml.jackson.annotation.JsonCreator; +import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonProperty; +import com.google.common.annotations.VisibleForTesting; import com.google.common.base.Preconditions; import javax.annotation.Nullable; +import javax.validation.constraints.NotNull; import java.util.Collections; import java.util.List; import java.util.Objects; +/** + * Partition a segment by a single dimension. + */ public class SingleDimensionPartitionsSpec implements DimensionBasedPartitionsSpec { - private final int maxRowsPerSegment; - private final int maxPartitionSize; - @Nullable + static final String NAME = "single_dim"; + static final String OLD_NAME = "dimension"; // for backward compatibility + + private static final String MAX_PARTITION_SIZE = "maxPartitionSize"; + + private final Integer targetRowsPerSegment; + private final Integer maxRowsPerSegment; private final String partitionDimension; private final boolean assumeGrouped; - public SingleDimensionPartitionsSpec( - int maxRowsPerSegment, - @Nullable Integer maxPartitionSize, - @Nullable String partitionDimension, - boolean assumeGrouped - ) - { - this(null, maxRowsPerSegment, maxPartitionSize, partitionDimension, assumeGrouped); - } + // Values for these fields are derived from the one above: + private final int resolvedMaxRowPerSegment; @JsonCreator public SingleDimensionPartitionsSpec( - @JsonProperty("targetPartitionSize") @Nullable Integer targetPartitionSize, - @JsonProperty("maxRowsPerSegment") @Nullable Integer maxRowsPerSegment, - @JsonProperty("maxPartitionSize") @Nullable Integer maxPartitionSize, + @JsonProperty(DimensionBasedPartitionsSpec.TARGET_ROWS_PER_SEGMENT) @Nullable Integer targetRowsPerSegment, + @JsonProperty(PartitionsSpec.MAX_ROWS_PER_SEGMENT) @Nullable Integer maxRowsPerSegment, @JsonProperty("partitionDimension") @Nullable String partitionDimension, - @JsonProperty("assumeGrouped") boolean assumeGrouped // false by default + @JsonProperty("assumeGrouped") boolean assumeGrouped, // false by default + + // Deprecated properties preserved for backward compatibility: + @Deprecated @JsonProperty(DimensionBasedPartitionsSpec.TARGET_PARTITION_SIZE) @Nullable + Integer targetPartitionSize, // prefer targetRowsPerSegment + @Deprecated @JsonProperty(MAX_PARTITION_SIZE) @Nullable + Integer maxPartitionSize // prefer maxRowsPerSegment ) { - Preconditions.checkArgument( - PartitionsSpec.isEffectivelyNull(targetPartitionSize) || PartitionsSpec.isEffectivelyNull(maxRowsPerSegment), - "Can't set both targetPartitionSize and maxRowsPerSegment" + Property<Integer> target = checkAtMostOneNotNull( + TARGET_ROWS_PER_SEGMENT, + targetRowsPerSegment, + TARGET_PARTITION_SIZE, + targetPartitionSize + ); + + Property<Integer> max = checkAtMostOneNotNull( + MAX_ROWS_PER_SEGMENT, + maxRowsPerSegment, + MAX_PARTITION_SIZE, + maxPartitionSize ); + Preconditions.checkArgument( - !PartitionsSpec.isEffectivelyNull(targetPartitionSize) || !PartitionsSpec.isEffectivelyNull(maxRowsPerSegment), - "Either targetPartitionSize or maxRowsPerSegment must be specified" + (target.value == null) != (max.value == null), + "Exactly one of " + target.name + " or " + max.name + " must be present" Review comment: That's the style i have seen mostly used in codebase and looks better in my opinion. ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org With regards, Apache Git Services --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@druid.apache.org For additional commands, e-mail: commits-h...@druid.apache.org