You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hive.apache.org by kg...@apache.org on 2017/11/27 14:12:21 UTC
hive git commit: HIVE-18141: Fix StatsUtils.combineRange to combine
intervals (Zoltan Haindrich, reviewed by Ashutosh Chauhan)
Repository: hive
Updated Branches:
refs/heads/master d9924ab3e -> be1f84733
HIVE-18141: Fix StatsUtils.combineRange to combine intervals (Zoltan Haindrich, reviewed by Ashutosh Chauhan)
Signed-off-by: Zoltan Haindrich <ki...@rxd.hu>
Project: http://git-wip-us.apache.org/repos/asf/hive/repo
Commit: http://git-wip-us.apache.org/repos/asf/hive/commit/be1f8473
Tree: http://git-wip-us.apache.org/repos/asf/hive/tree/be1f8473
Diff: http://git-wip-us.apache.org/repos/asf/hive/diff/be1f8473
Branch: refs/heads/master
Commit: be1f847334a6ce559f1b07f8930568217333a77e
Parents: d9924ab
Author: Zoltan Haindrich <ki...@rxd.hu>
Authored: Mon Nov 27 08:34:20 2017 +0100
Committer: Zoltan Haindrich <ki...@rxd.hu>
Committed: Mon Nov 27 08:34:20 2017 +0100
----------------------------------------------------------------------
.../apache/hadoop/hive/ql/stats/StatsUtils.java | 5 +-
.../hadoop/hive/ql/stats/TestStatsUtils.java | 71 ++++++++++++++++++++
2 files changed, 73 insertions(+), 3 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/hive/blob/be1f8473/ql/src/java/org/apache/hadoop/hive/ql/stats/StatsUtils.java
----------------------------------------------------------------------
diff --git a/ql/src/java/org/apache/hadoop/hive/ql/stats/StatsUtils.java b/ql/src/java/org/apache/hadoop/hive/ql/stats/StatsUtils.java
index ed628ae..20c2f94 100644
--- a/ql/src/java/org/apache/hadoop/hive/ql/stats/StatsUtils.java
+++ b/ql/src/java/org/apache/hadoop/hive/ql/stats/StatsUtils.java
@@ -1981,15 +1981,14 @@ public class StatsUtils {
long min2 = range2.minValue.longValue();
long max2 = range2.maxValue.longValue();
- if ( (min1 < min2 && max1 < max2)
- || (min1 > min2 && max1 > max2)) {
+ if (max1 < min2 || max2 < min1) {
// No overlap between the two ranges
return null;
} else {
// There is an overlap of ranges - create combined range.
return new ColStatistics.Range(
Math.min(min1, min2),
- Math.max(max1, max2));
+ Math.max(max1, max2));
}
}
return null;
http://git-wip-us.apache.org/repos/asf/hive/blob/be1f8473/ql/src/test/org/apache/hadoop/hive/ql/stats/TestStatsUtils.java
----------------------------------------------------------------------
diff --git a/ql/src/test/org/apache/hadoop/hive/ql/stats/TestStatsUtils.java b/ql/src/test/org/apache/hadoop/hive/ql/stats/TestStatsUtils.java
new file mode 100644
index 0000000..eee9a31
--- /dev/null
+++ b/ql/src/test/org/apache/hadoop/hive/ql/stats/TestStatsUtils.java
@@ -0,0 +1,71 @@
+/**
+ * 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.hadoop.hive.ql.stats;
+
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+
+import org.apache.hadoop.hive.ql.plan.ColStatistics.Range;
+import org.junit.Test;
+
+public class TestStatsUtils {
+
+ @Test
+ public void testCombinedRange1() {
+ Range r1 = new Range(0, 1);
+ Range r2 = new Range(1, 11);
+ Range r3 = StatsUtils.combineRange(r1, r2);
+ assertNotNull(r3);
+ rangeContains(r3, 0);
+ rangeContains(r3, 1);
+ rangeContains(r3, 11);
+ }
+
+ @Test
+ public void testCombinedRange2() {
+ checkCombinedRange(false, new Range(-2, -1), new Range(0, 10));
+ checkCombinedRange(true, new Range(-2, 1), new Range(0, 10));
+ checkCombinedRange(true, new Range(-2, 11), new Range(0, 10));
+ checkCombinedRange(true, new Range(1, 2), new Range(0, 10));
+ checkCombinedRange(true, new Range(1, 11), new Range(0, 10));
+ checkCombinedRange(false, new Range(11, 12), new Range(0, 10));
+ }
+
+
+ private void checkCombinedRange(boolean valid, Range r1, Range r2) {
+ Range r3a = StatsUtils.combineRange(r1, r2);
+ Range r3b = StatsUtils.combineRange(r2, r1);
+ if (valid) {
+ assertNotNull(r3a);
+ assertNotNull(r3b);
+ } else {
+ assertNull(r3a);
+ assertNull(r3b);
+ }
+ }
+
+ private boolean rangeContains(Range range, Number f) {
+ double m = range.minValue.doubleValue();
+ double M = range.maxValue.doubleValue();
+ double v = f.doubleValue();
+ return m <= v && v <= M;
+ }
+
+
+}
\ No newline at end of file