This is an automated email from the ASF dual-hosted git repository.
roryqi pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/gravitino.git
The following commit(s) were added to refs/heads/main by this push:
new 789f88dfa1 [#7609] feat(api): Add partition statistics interfaces
(#7610)
789f88dfa1 is described below
commit 789f88dfa14f7d63b831d8d1cad583a9d50f34e2
Author: roryqi <[email protected]>
AuthorDate: Thu Aug 7 19:45:57 2025 +0800
[#7609] feat(api): Add partition statistics interfaces (#7610)
### What changes were proposed in this pull request?
Add partition statsitics interfaces
### Why are the changes needed?
Fix: #7609
### Does this PR introduce _any_ user-facing change?
No need.
### How was this patch tested?
No.
---
.../gravitino/rel/expressions/NamedReference.java | 51 +++++
.../org/apache/gravitino/stats/PartitionRange.java | 212 +++++++++++++++++++++
.../gravitino/stats/PartitionStatistics.java | 37 ++++
.../gravitino/stats/PartitionStatisticsDrop.java | 68 +++++++
.../gravitino/stats/PartitionStatisticsUpdate.java | 67 +++++++
.../stats/SupportsPartitionStatistics.java | 63 ++++++
.../apache/gravitino/stats/TestPartitionRange.java | 91 +++++++++
7 files changed, 589 insertions(+)
diff --git
a/api/src/main/java/org/apache/gravitino/rel/expressions/NamedReference.java
b/api/src/main/java/org/apache/gravitino/rel/expressions/NamedReference.java
index eb91071a05..1bf7e8211c 100644
--- a/api/src/main/java/org/apache/gravitino/rel/expressions/NamedReference.java
+++ b/api/src/main/java/org/apache/gravitino/rel/expressions/NamedReference.java
@@ -50,6 +50,17 @@ public interface NamedReference extends Expression {
return field(new String[] {columnName});
}
+ /**
+ * Returns a {@link MetadataField} for the given field name(s). The array of
field name(s) is used
+ * to reference metadata fields.
+ *
+ * @param fieldNames the field name(s)
+ * @return a {@link MetadataField} for the given field name(s)
+ */
+ static MetadataField metadataField(String[] fieldNames) {
+ return new MetadataField(fieldNames);
+ }
+
/**
* Returns the referenced field name as an array of String parts.
*
@@ -105,4 +116,44 @@ public interface NamedReference extends Expression {
return String.join(".", fieldName);
}
}
+
+ /** A {@link NamedReference} that references a metadata field. */
+ final class MetadataField implements NamedReference {
+ /** A metadata field that represents the name of a partition in a
partitioned table. */
+ public static final MetadataField PARTITION_NAME_FIELD =
+ new MetadataField(new String[] {"partition_name"});
+
+ private final String[] fieldName;
+
+ MetadataField(String[] fieldName) {
+ this.fieldName = fieldName;
+ }
+
+ @Override
+ public String[] fieldName() {
+ return fieldName;
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) {
+ return true;
+ }
+ if (o == null || getClass() != o.getClass()) {
+ return false;
+ }
+ MetadataField that = (MetadataField) o;
+ return Arrays.equals(fieldName, that.fieldName);
+ }
+
+ @Override
+ public int hashCode() {
+ return Arrays.hashCode(fieldName);
+ }
+
+ @Override
+ public String toString() {
+ return String.join(".", fieldName);
+ }
+ }
}
diff --git a/api/src/main/java/org/apache/gravitino/stats/PartitionRange.java
b/api/src/main/java/org/apache/gravitino/stats/PartitionRange.java
new file mode 100644
index 0000000000..6726d06fda
--- /dev/null
+++ b/api/src/main/java/org/apache/gravitino/stats/PartitionRange.java
@@ -0,0 +1,212 @@
+/*
+ * 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 com.google.common.base.Preconditions;
+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 DEFAULT_COMPARATOR =
+ SortOrders.of(NamedReference.MetadataField.PARTITION_NAME_FIELD,
SortDirection.ASCENDING);
+ private Optional<String> lowerPartitionName = Optional.empty();
+ private Optional<BoundType> lowerBoundType = Optional.empty();
+ private Optional<String> upperPartitionName = Optional.empty();
+ private 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, DEFAULT_COMPARATOR);
+ }
+
+ /**
+ * 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) {
+ Preconditions.checkArgument(upperPartitionName != null, "Upper partition
name cannot be null");
+ Preconditions.checkArgument(upperBoundType != null, "Upper bound type
cannot be null");
+ Preconditions.checkArgument(
+ !upperPartitionName.isEmpty(), "Upper partition name cannot be empty");
+ 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, DEFAULT_COMPARATOR);
+ }
+
+ /**
+ * 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) {
+ Preconditions.checkArgument(lowerPartitionName != null, "Lower partition
name cannot be null");
+ Preconditions.checkArgument(lowerBoundType != null, "Lower bound type
cannot be null");
+ Preconditions.checkArgument(comparator != null, "Comparator cannot be
null");
+ PartitionRange partitionRange = new PartitionRange();
+ partitionRange.lowerPartitionName = Optional.of(lowerPartitionName);
+ partitionRange.lowerBoundType = Optional.of(lowerBoundType);
+ partitionRange.comparator = comparator;
+ return partitionRange;
+ }
+
+ /**
+ * Creates a PartitionRange which has both lower and upper partition names.
+ *
+ * @param lowerPartitionName the lower partition name.
+ * @param lowerBoundType the type of the lower bound (open or closed).
+ * @param upperPartitionName the upper partition name.
+ * @param upperBoundType the type of the upper bound (open or closed).
+ * @return a PartitionRange with both lower and upper partition names.
+ */
+ public static PartitionRange between(
+ String lowerPartitionName,
+ BoundType lowerBoundType,
+ String upperPartitionName,
+ BoundType upperBoundType) {
+ return between(
+ lowerPartitionName, lowerBoundType, upperPartitionName,
upperBoundType, DEFAULT_COMPARATOR);
+ }
+
+ /**
+ * Creates a PartitionRange which has both lower and upper partition names
with a specific
+ * comparator type.
+ *
+ * @param lowerPartitionName the lower partition name.
+ * @param lowerBoundType the type of the lower bound (open or closed).
+ * @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 both lower and upper partition names and
the specified comparator
+ * type.
+ */
+ public static PartitionRange between(
+ String lowerPartitionName,
+ BoundType lowerBoundType,
+ String upperPartitionName,
+ BoundType upperBoundType,
+ SortOrder comparator) {
+ Preconditions.checkArgument(lowerPartitionName != null, "Lower partition
name cannot be null");
+ Preconditions.checkArgument(upperPartitionName != null, "Upper partition
name cannot be null");
+ Preconditions.checkArgument(lowerBoundType != null, "Lower bound type
cannot be null");
+ Preconditions.checkArgument(upperBoundType != null, "Upper bound type
cannot be null");
+ Preconditions.checkArgument(comparator != null, "Comparator cannot be
null");
+ PartitionRange partitionRange = new PartitionRange();
+ partitionRange.upperPartitionName = Optional.of(upperPartitionName);
+ partitionRange.lowerPartitionName = Optional.of(lowerPartitionName);
+ partitionRange.upperBoundType = Optional.of(upperBoundType);
+ partitionRange.lowerBoundType = Optional.of(lowerBoundType);
+ partitionRange.comparator = comparator;
+ return partitionRange;
+ }
+
+ /**
+ * Returns the lower partition name if it exists.
+ *
+ * @return an Optional containing the lower partition name if it exists,
otherwise an empty
+ * Optional.
+ */
+ public Optional<String> lowerPartitionName() {
+ return lowerPartitionName;
+ }
+
+ /**
+ * Returns the upper partition name if it exists.
+ *
+ * @return an Optional containing the upper partition name if it exists,
otherwise an empty
+ * Optional.
+ */
+ public Optional<String> upperPartitionName() {
+ return upperPartitionName;
+ }
+
+ /**
+ * Returns the type of the lower bound if it exists.
+ *
+ * @return an Optional containing the BoundType of the lower bound if it
exists, otherwise an
+ * empty Optional.
+ */
+ public Optional<BoundType> lowerBoundType() {
+ return lowerBoundType;
+ }
+
+ /**
+ * Returns the type of the upper bound if it exists.
+ *
+ * @return an Optional containing the BoundType of the upper bound if it
exists, otherwise an
+ * empty Optional.
+ */
+ public Optional<BoundType> upperBoundType() {
+ return upperBoundType;
+ }
+
+ /**
+ * Returns a comparator for comparing partitions within this range.
+ *
+ * @return a PartitionComparator that can be used to compare partitions.
+ */
+ public SortOrder comparator() {
+ return comparator;
+ }
+
+ /** Enum representing the type of bounds for a partition range. */
+ public enum BoundType {
+ /** Indicates that the bound is exclusive */
+ OPEN,
+ /** Indicates that the bound is inclusive */
+ CLOSED
+ }
+}
diff --git
a/api/src/main/java/org/apache/gravitino/stats/PartitionStatistics.java
b/api/src/main/java/org/apache/gravitino/stats/PartitionStatistics.java
new file mode 100644
index 0000000000..f44be6c953
--- /dev/null
+++ b/api/src/main/java/org/apache/gravitino/stats/PartitionStatistics.java
@@ -0,0 +1,37 @@
+/*
+ * 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;
+
+/** PartitionStatistics represents statistics for a specific partition in a
data source. */
+public interface PartitionStatistics {
+
+ /**
+ * Returns the name of the partition for which these statistics are
applicable.
+ *
+ * @return the name of the partition
+ */
+ String name();
+
+ /**
+ * Returns the statistics for the partition.
+ *
+ * @return a array of statistics applicable to the partition
+ */
+ Statistic[] statistics();
+}
diff --git
a/api/src/main/java/org/apache/gravitino/stats/PartitionStatisticsDrop.java
b/api/src/main/java/org/apache/gravitino/stats/PartitionStatisticsDrop.java
new file mode 100644
index 0000000000..4e4cc1b170
--- /dev/null
+++ b/api/src/main/java/org/apache/gravitino/stats/PartitionStatisticsDrop.java
@@ -0,0 +1,68 @@
+/*
+ * 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.List;
+
+/**
+ * PartitionDropStatistics represents the statistics related to dropping
partitions in a data
+ * source. It is used to manage and track the statistics that are relevant
when partitions are
+ * dropped.
+ */
+public class PartitionStatisticsDrop {
+
+ private final String partitionName;
+ private final List<String> statisticNames;
+
+ /**
+ * Creates a PartitionDropStatistics instance with the specified partition
name and statistic
+ * names.
+ *
+ * @param partitionName the name of the partition.
+ * @param statisticNames a list of statistic names that are relevant to the
partition being
+ * dropped.
+ * @return a PartitionDropStatistics instance
+ */
+ public static PartitionStatisticsDrop of(String partitionName, List<String>
statisticNames) {
+ return new PartitionStatisticsDrop(partitionName, statisticNames);
+ }
+
+ private PartitionStatisticsDrop(String partitionName, List<String>
statisticNames) {
+ this.partitionName = partitionName;
+ this.statisticNames = statisticNames;
+ }
+
+ /**
+ * Returns the name of the partition for which these statistics are
applicable.
+ *
+ * @return the name of the partition
+ */
+ public String partitionName() {
+ return partitionName;
+ }
+
+ /**
+ * Returns the names of the statistics that are relevant to the partition
being dropped.
+ *
+ * @return a list of statistic names
+ */
+ public List<String> statisticNames() {
+ return statisticNames;
+ }
+}
diff --git
a/api/src/main/java/org/apache/gravitino/stats/PartitionStatisticsUpdate.java
b/api/src/main/java/org/apache/gravitino/stats/PartitionStatisticsUpdate.java
new file mode 100644
index 0000000000..7a8f493506
--- /dev/null
+++
b/api/src/main/java/org/apache/gravitino/stats/PartitionStatisticsUpdate.java
@@ -0,0 +1,67 @@
+/*
+ * 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.Map;
+
+/**
+ * PartitionUpdateStatistics represents the statistics for a specific
partition that can be updated.
+ * It contains the partition name and a map of statistic names to their values.
+ */
+public class PartitionStatisticsUpdate {
+
+ private final String partitionName;
+ private final Map<String, StatisticValue<?>> statistics;
+
+ /**
+ * Creates a PartitionUpdateStatistics instance with the specified partition
name and statistics.
+ *
+ * @param partitionName the name of the partition
+ * @param statistics a map of statistic names to their values to be updated
+ * @return a PartitionUpdateStatistics instance
+ */
+ public static PartitionStatisticsUpdate of(
+ String partitionName, Map<String, StatisticValue<?>> statistics) {
+ return new PartitionStatisticsUpdate(partitionName, statistics);
+ }
+
+ private PartitionStatisticsUpdate(
+ String partitionName, Map<String, StatisticValue<?>> statistics) {
+ this.partitionName = partitionName;
+ this.statistics = statistics;
+ }
+
+ /**
+ * Returns the name of the partition for which these statistics are
applicable.
+ *
+ * @return the name of the partition.
+ */
+ public String partitionName() {
+ return partitionName;
+ }
+
+ /**
+ * Returns the statistics to be updated for the partition.
+ *
+ * @return a map where the key is the statistic name and the value is the
statistic value.
+ */
+ public Map<String, StatisticValue<?>> statistics() {
+ return statistics;
+ }
+}
diff --git
a/api/src/main/java/org/apache/gravitino/stats/SupportsPartitionStatistics.java
b/api/src/main/java/org/apache/gravitino/stats/SupportsPartitionStatistics.java
new file mode 100644
index 0000000000..a63eb9c948
--- /dev/null
+++
b/api/src/main/java/org/apache/gravitino/stats/SupportsPartitionStatistics.java
@@ -0,0 +1,63 @@
+/*
+ * 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.List;
+import org.apache.gravitino.annotation.Unstable;
+import org.apache.gravitino.exceptions.UnmodifiableStatisticException;
+
+/** SupportsPartitionStatistics provides methods to list and update statistics
for partitions. */
+@Unstable
+interface SupportsPartitionStatistics {
+
+ /**
+ * Lists statistics for partitions from one partition name to another
partition name.
+ *
+ * @param range the range of partitions to list statistics for, which can be
defined by.
+ * @return a list of PartitionStatistics, where each PartitionStatistics
contains the partition
+ * name and a list of statistics applicable to that partition.
+ */
+ List<PartitionStatistics> listStatistics(PartitionRange range);
+
+ /**
+ * Updates statistics with the provided values. If the statistic exists, it
will be updated with
+ * the new value. If the statistic does not exist, it will be created. If
the statistic is
+ * unmodifiable, it will throw an UnmodifiableStatisticException.
+ *
+ * @param statisticsToUpdate a list of PartitionUpdateStatistics, where each
+ * PartitionStatisticsUpdate contains the partition name and a map of
statistic names to their
+ * values to be updated.
+ * @return a list of updated PartitionStatistics, where each
PartitionStatistics contains the
+ * partition name and a list of statistics applicable to that partition.
+ * @throws UnmodifiableStatisticException if any of the statistics to be
updated are unmodifiable
+ */
+ List<PartitionStatistics> updateStatistics(List<PartitionStatisticsUpdate>
statisticsToUpdate)
+ throws UnmodifiableStatisticException;
+
+ /**
+ * Drops statistics for the specified partitions. If the statistic is
unmodifiable, it will throw
+ * an UnmodifiableStatisticException.
+ *
+ * @param statisticsToDrop a list of PartitionStatisticsDrop, where each
PartitionStatisticsDrop
+ * @return true if the statistics were successfully dropped.
+ * @throws UnmodifiableStatisticException if any of the statistics to be
dropped are unmodifiable
+ */
+ boolean dropStatistics(List<PartitionStatisticsDrop> statisticsToDrop)
+ throws UnmodifiableStatisticException;
+}
diff --git
a/api/src/test/java/org/apache/gravitino/stats/TestPartitionRange.java
b/api/src/test/java/org/apache/gravitino/stats/TestPartitionRange.java
new file mode 100644
index 0000000000..e93aaa5ee3
--- /dev/null
+++ b/api/src/test/java/org/apache/gravitino/stats/TestPartitionRange.java
@@ -0,0 +1,91 @@
+/*
+ * 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 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;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+
+public class TestPartitionRange {
+
+ @Test
+ public void testPartitionRange() {
+ SortOrder defaultSortOrder =
+ SortOrders.of(NamedReference.MetadataField.PARTITION_NAME_FIELD,
SortDirection.ASCENDING);
+
+ PartitionRange range1 = PartitionRange.upTo("upper",
PartitionRange.BoundType.OPEN);
+ Assertions.assertTrue(range1.upperPartitionName().isPresent());
+ Assertions.assertFalse(range1.lowerPartitionName().isPresent());
+ Assertions.assertEquals("upper", range1.upperPartitionName().get());
+ Assertions.assertEquals(defaultSortOrder, range1.comparator());
+ Assertions.assertEquals(PartitionRange.BoundType.OPEN,
range1.upperBoundType().get());
+
+ PartitionRange range2 = PartitionRange.downTo("lower",
PartitionRange.BoundType.CLOSED);
+ Assertions.assertFalse(range2.upperPartitionName().isPresent());
+ Assertions.assertTrue(range2.lowerPartitionName().isPresent());
+ Assertions.assertEquals("lower", range2.lowerPartitionName().get());
+ Assertions.assertEquals(defaultSortOrder, defaultSortOrder);
+ Assertions.assertEquals(PartitionRange.BoundType.CLOSED,
range2.lowerBoundType().get());
+
+ PartitionRange range3 =
+ PartitionRange.downTo("lower", PartitionRange.BoundType.CLOSED,
defaultSortOrder);
+ Assertions.assertTrue(range3.lowerPartitionName().isPresent());
+ Assertions.assertFalse(range3.upperPartitionName().isPresent());
+ Assertions.assertEquals("lower", range3.lowerPartitionName().get());
+ Assertions.assertEquals(range3.comparator(), defaultSortOrder);
+ Assertions.assertEquals(PartitionRange.BoundType.CLOSED,
range3.lowerBoundType().get());
+
+ PartitionRange range4 =
+ PartitionRange.upTo("upper", PartitionRange.BoundType.OPEN,
defaultSortOrder);
+ Assertions.assertTrue(range4.upperPartitionName().isPresent());
+ Assertions.assertFalse(range4.lowerPartitionName().isPresent());
+ Assertions.assertEquals("upper", range4.upperPartitionName().get());
+ Assertions.assertEquals(range4.comparator(), defaultSortOrder);
+ Assertions.assertEquals(PartitionRange.BoundType.OPEN,
range4.upperBoundType().get());
+
+ PartitionRange range5 =
+ PartitionRange.between(
+ "lower",
+ PartitionRange.BoundType.OPEN,
+ "upper",
+ PartitionRange.BoundType.CLOSED,
+ defaultSortOrder);
+ Assertions.assertTrue(range5.lowerPartitionName().isPresent());
+ Assertions.assertTrue(range5.upperPartitionName().isPresent());
+ Assertions.assertEquals("lower", range5.lowerPartitionName().get());
+ Assertions.assertEquals("upper", range5.upperPartitionName().get());
+ Assertions.assertEquals(defaultSortOrder, range5.comparator());
+ Assertions.assertEquals(PartitionRange.BoundType.OPEN,
range5.lowerBoundType().get());
+ Assertions.assertEquals(PartitionRange.BoundType.CLOSED,
range5.upperBoundType().get());
+
+ PartitionRange range6 =
+ PartitionRange.between(
+ "lower", PartitionRange.BoundType.CLOSED, "upper",
PartitionRange.BoundType.OPEN);
+ Assertions.assertTrue(range6.lowerPartitionName().isPresent());
+ Assertions.assertTrue(range6.upperPartitionName().isPresent());
+ Assertions.assertEquals("lower", range6.lowerPartitionName().get());
+ Assertions.assertEquals("upper", range6.upperPartitionName().get());
+ Assertions.assertEquals(defaultSortOrder, range6.comparator());
+ Assertions.assertEquals(PartitionRange.BoundType.CLOSED,
range6.lowerBoundType().get());
+ Assertions.assertEquals(PartitionRange.BoundType.OPEN,
range6.upperBoundType().get());
+ }
+}