jerqi commented on code in PR #7610: URL: https://github.com/apache/gravitino/pull/7610#discussion_r2259526372
########## api/src/main/java/org/apache/gravitino/stats/PartitionRange.java: ########## @@ -0,0 +1,199 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.gravitino.stats; + +import java.util.Optional; +import org.apache.gravitino.rel.expressions.NamedReference; +import org.apache.gravitino.rel.expressions.sorts.SortDirection; +import org.apache.gravitino.rel.expressions.sorts.SortOrder; +import org.apache.gravitino.rel.expressions.sorts.SortOrders; + +/** PartitionRange represents a range of partitions defined by lower and upper partition names. */ +public class PartitionRange { + private static final SortOrder defaultSortOrder = + SortOrders.of(NamedReference.MetadataField.PARTITION_NAME_FIELD, SortDirection.ASCENDING); + Optional<String> lowerPartitionName = Optional.empty(); + Optional<BoundType> lowerBoundType = Optional.empty(); + Optional<String> upperPartitionName = Optional.empty(); + Optional<BoundType> upperBoundType = Optional.empty(); + + private SortOrder comparator; + + private PartitionRange() {} + + /** + * Creates a PartitionRange which only has upper bound partition name. + * + * @param upperPartitionName the upper partition name. + * @param upperBoundType the type of the upper bound (open or closed). + * @return a PartitionRange with the upper partition name. + */ + public static PartitionRange upTo(String upperPartitionName, BoundType upperBoundType) { + return upTo(upperPartitionName, upperBoundType, defaultSortOrder); + } + + /** + * Creates a PartitionRange which only has upper bound partition name with a specific comparator + * type. + * + * @param upperPartitionName the upper partition name. + * @param upperBoundType the type of the upper bound (open or closed). + * @param comparator the comparator to use for this range. + * @return a PartitionRange with the upper partition name and the specified comparator type. + */ + public static PartitionRange upTo( + String upperPartitionName, BoundType upperBoundType, SortOrder comparator) { + PartitionRange partitionRange = new PartitionRange(); + partitionRange.upperPartitionName = Optional.of(upperPartitionName); + partitionRange.upperBoundType = Optional.of(upperBoundType); + partitionRange.comparator = comparator; + return partitionRange; + } + + /** + * Creates a PartitionRange which only has lower bound partition name. + * + * @param lowerPartitionName the lower partition name. + * @param lowerBoundType the type of the lower bound (open or closed). + * @return a PartitionRange with the lower partition name. + */ + public static PartitionRange downTo(String lowerPartitionName, BoundType lowerBoundType) { + return downTo(lowerPartitionName, lowerBoundType, defaultSortOrder); + } + + /** + * Creates a PartitionRange which only has lower bound partition name with a specific comparator + * type. + * + * @param lowerPartitionName the lower partition name. + * @param lowerBoundType the type of the lower bound (open or closed). + * @param comparator the comparator to use for this range. + * @return a PartitionRange with the lower partition name and the specified comparator type. + */ + public static PartitionRange downTo( + String lowerPartitionName, BoundType lowerBoundType, SortOrder comparator) { + PartitionRange partitionRange = new PartitionRange(); + partitionRange.lowerPartitionName = Optional.of(lowerPartitionName); + partitionRange.lowerBoundType = Optional.of(lowerBoundType); + partitionRange.comparator = comparator; Review Comment: Optional.of will throw NullPointerException. It don't allow null value. -- 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. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
