You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@phoenix.apache.org by ja...@apache.org on 2014/12/17 01:18:09 UTC

phoenix git commit: PHOENIX-1362 Min/max aggregate query on CHAR and BINARY types always return null (Dave Hacker)

Repository: phoenix
Updated Branches:
  refs/heads/master 62b12d99d -> cc479e57b


PHOENIX-1362 Min/max aggregate query on CHAR and BINARY types always return null (Dave Hacker)


Project: http://git-wip-us.apache.org/repos/asf/phoenix/repo
Commit: http://git-wip-us.apache.org/repos/asf/phoenix/commit/cc479e57
Tree: http://git-wip-us.apache.org/repos/asf/phoenix/tree/cc479e57
Diff: http://git-wip-us.apache.org/repos/asf/phoenix/diff/cc479e57

Branch: refs/heads/master
Commit: cc479e57b05a5dec515d1dbf280b5f5cb3d6c81e
Parents: 62b12d9
Author: James Taylor <jt...@salesforce.com>
Authored: Tue Dec 16 16:16:40 2014 -0800
Committer: James Taylor <jt...@salesforce.com>
Committed: Tue Dec 16 16:17:49 2014 -0800

----------------------------------------------------------------------
 .../end2end/MinMaxAggregateFunctionIT.java      | 86 ++++++++++++++++++++
 .../function/MaxAggregateFunction.java          | 15 ++--
 .../function/MinAggregateFunction.java          | 14 ++--
 3 files changed, 105 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/phoenix/blob/cc479e57/phoenix-core/src/it/java/org/apache/phoenix/end2end/MinMaxAggregateFunctionIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/MinMaxAggregateFunctionIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/MinMaxAggregateFunctionIT.java
new file mode 100644
index 0000000..ca7a676
--- /dev/null
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/MinMaxAggregateFunctionIT.java
@@ -0,0 +1,86 @@
+/*
+ * 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.phoenix.end2end;
+
+import static org.apache.phoenix.util.TestUtil.TEST_PROPERTIES;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.util.Properties;
+
+import org.apache.phoenix.util.PropertiesUtil;
+import org.junit.Test;
+
+public class MinMaxAggregateFunctionIT extends BaseHBaseManagedTimeIT {
+
+    @Test
+    public void testMinMaxAggregateFunctions() throws SQLException {
+        Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
+        Connection conn = DriverManager.getConnection(getUrl(), props);
+        conn.setAutoCommit(false);
+        try {
+            conn.prepareStatement(
+                "create table TT("
+                        + "VAL1 integer not null, "
+                        + "VAL2 char(2), "
+                        + "VAL3 varchar, "
+                        + "VAL4 varchar "
+                        + "constraint PK primary key (VAL1))").execute();
+            conn.commit();
+
+            conn.prepareStatement("upsert into TT values (0, '00', '00', '0')").execute();
+            conn.prepareStatement("upsert into TT values (1, '01', '01', '1')").execute();
+            conn.prepareStatement("upsert into TT values (2, '02', '02', '2')").execute();
+            conn.commit();
+
+            ResultSet rs = conn.prepareStatement("select min(VAL2) from TT").executeQuery();
+            assertTrue(rs.next());
+            assertEquals("00", rs.getString(1));
+
+            rs = conn.prepareStatement("select min(VAL3) from TT").executeQuery();
+            assertTrue(rs.next());
+            assertEquals("00", rs.getString(1));
+
+            rs = conn.prepareStatement("select max(VAL2)from TT").executeQuery();
+            assertTrue(rs.next());
+            assertEquals("02", rs.getString(1));
+
+            rs = conn.prepareStatement("select max(VAL3)from TT").executeQuery();
+            assertTrue(rs.next());
+            assertEquals("02", rs.getString(1));
+
+            rs =
+                    conn.prepareStatement(
+                        "select min(VAL1), min(VAL2), min(VAL3), min(VAL4) from TT").executeQuery();
+            assertTrue(rs.next());
+            assertEquals(0, rs.getInt(1));
+            assertEquals("00", rs.getString(2));
+            assertEquals("00", rs.getString(3));
+            assertEquals("0", rs.getString(4));
+
+            rs =
+                    conn.prepareStatement(
+                        "select max(VAL1), max(VAL2), max(VAL3), max(VAL4) from TT").executeQuery();
+
+            assertTrue(rs.next());
+            assertEquals(2, rs.getInt(1));
+            assertEquals("02", rs.getString(2));
+            assertEquals("02", rs.getString(3));
+            assertEquals("2", rs.getString(4));
+        } finally {
+            conn.close();
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/phoenix/blob/cc479e57/phoenix-core/src/main/java/org/apache/phoenix/expression/function/MaxAggregateFunction.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/expression/function/MaxAggregateFunction.java b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/MaxAggregateFunction.java
index a7da0aa..d33f41c 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/expression/function/MaxAggregateFunction.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/MaxAggregateFunction.java
@@ -20,15 +20,14 @@ package org.apache.phoenix.expression.function;
 import java.util.List;
 
 import org.apache.hadoop.conf.Configuration;
-
 import org.apache.phoenix.expression.Expression;
 import org.apache.phoenix.expression.aggregator.Aggregator;
 import org.apache.phoenix.expression.aggregator.MaxAggregator;
 import org.apache.phoenix.parse.FunctionParseNode.Argument;
 import org.apache.phoenix.parse.FunctionParseNode.BuiltInFunction;
 import org.apache.phoenix.parse.MaxAggregateParseNode;
-import org.apache.phoenix.schema.SortOrder;
 import org.apache.phoenix.schema.PDataType;
+import org.apache.phoenix.schema.SortOrder;
 
 
 
@@ -51,13 +50,19 @@ public class MaxAggregateFunction extends MinAggregateFunction {
 
     @Override 
     public Aggregator newServerAggregator(Configuration conf) {
-        final PDataType type = getAggregatorExpression().getDataType();
-        SortOrder sortOrder = getAggregatorExpression().getSortOrder();
-        return new MaxAggregator(sortOrder) {
+        Expression child = getAggregatorExpression();
+        final PDataType type = child.getDataType();
+        final Integer maxLength = child.getMaxLength();
+        return new MaxAggregator(child.getSortOrder()) {
             @Override
             public PDataType getDataType() {
                 return type;
             }
+
+            @Override
+            public Integer getMaxLength() {
+                return maxLength;
+            }
         };
     }
     

http://git-wip-us.apache.org/repos/asf/phoenix/blob/cc479e57/phoenix-core/src/main/java/org/apache/phoenix/expression/function/MinAggregateFunction.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/expression/function/MinAggregateFunction.java b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/MinAggregateFunction.java
index 4a80a62..00c87cb 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/expression/function/MinAggregateFunction.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/expression/function/MinAggregateFunction.java
@@ -21,15 +21,14 @@ import java.util.List;
 
 import org.apache.hadoop.conf.Configuration;
 import org.apache.hadoop.hbase.io.ImmutableBytesWritable;
-
 import org.apache.phoenix.expression.Expression;
 import org.apache.phoenix.expression.aggregator.Aggregator;
 import org.apache.phoenix.expression.aggregator.MinAggregator;
 import org.apache.phoenix.parse.FunctionParseNode.Argument;
 import org.apache.phoenix.parse.FunctionParseNode.BuiltInFunction;
 import org.apache.phoenix.parse.MinAggregateParseNode;
-import org.apache.phoenix.schema.SortOrder;
 import org.apache.phoenix.schema.PDataType;
+import org.apache.phoenix.schema.SortOrder;
 import org.apache.phoenix.schema.tuple.Tuple;
 
 
@@ -65,13 +64,18 @@ public class MinAggregateFunction extends DelegateConstantToCountAggregateFuncti
 
     @Override 
     public Aggregator newServerAggregator(Configuration conf) {
-        final PDataType type = getAggregatorExpression().getDataType();
-        SortOrder sortOrder = getAggregatorExpression().getSortOrder();
-        return new MinAggregator(sortOrder) {
+        Expression child = getAggregatorExpression();
+        final PDataType type = child.getDataType();
+        final Integer maxLength = child.getMaxLength();
+        return new MinAggregator(child.getSortOrder()) {
             @Override
             public PDataType getDataType() {
                 return type;
             }
+            @Override
+            public Integer getMaxLength() {
+            	return maxLength;
+            }
         };
     }