You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@phoenix.apache.org by gr...@apache.org on 2015/07/20 15:39:11 UTC

phoenix git commit: PHOENIX-2131 Closing paren in CastParseNode SQL

Repository: phoenix
Updated Branches:
  refs/heads/4.4-HBase-0.98 421f851dc -> e9b78da6d


PHOENIX-2131 Closing paren in CastParseNode SQL

Add a missing closing parenthesis in CastParseNode.toSQL.


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

Branch: refs/heads/4.4-HBase-0.98
Commit: e9b78da6d908b0e5408f6c413ec56d833daf1590
Parents: 421f851
Author: Gabriel Reid <gr...@apache.org>
Authored: Sun Jul 19 17:46:48 2015 +0200
Committer: Gabriel Reid <ga...@ngdata.com>
Committed: Mon Jul 20 15:24:00 2015 +0200

----------------------------------------------------------------------
 .../org/apache/phoenix/parse/CastParseNode.java |  2 +-
 .../apache/phoenix/parse/CastParseNodeTest.java | 57 ++++++++++++++++++++
 2 files changed, 58 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/phoenix/blob/e9b78da6/phoenix-core/src/main/java/org/apache/phoenix/parse/CastParseNode.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/parse/CastParseNode.java b/phoenix-core/src/main/java/org/apache/phoenix/parse/CastParseNode.java
index 78be616..3e03613 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/parse/CastParseNode.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/parse/CastParseNode.java
@@ -133,7 +133,7 @@ public class CastParseNode extends UnaryParseNode {
         if (isArray) {
             buf.append(' ');
             buf.append(PDataType.ARRAY_TYPE_SUFFIX);
-            buf.append(' ');
         }
+        buf.append(")");
     }
 }

http://git-wip-us.apache.org/repos/asf/phoenix/blob/e9b78da6/phoenix-core/src/test/java/org/apache/phoenix/parse/CastParseNodeTest.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/test/java/org/apache/phoenix/parse/CastParseNodeTest.java b/phoenix-core/src/test/java/org/apache/phoenix/parse/CastParseNodeTest.java
new file mode 100644
index 0000000..b62d9a9
--- /dev/null
+++ b/phoenix-core/src/test/java/org/apache/phoenix/parse/CastParseNodeTest.java
@@ -0,0 +1,57 @@
+/*
+ * 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.parse;
+
+import org.apache.phoenix.schema.types.PDataType;
+import org.apache.phoenix.schema.types.PDecimal;
+import org.apache.phoenix.schema.types.PDouble;
+import org.apache.phoenix.schema.types.PLong;
+import org.junit.Test;
+
+import static org.junit.Assert.*;
+
+public class CastParseNodeTest {
+
+    @Test
+    public void testToSQL() {
+        ColumnParseNode columnParseNode = new ColumnParseNode(TableName.create("SCHEMA1", "TABLE1"), "V");
+        CastParseNode castParseNode = new CastParseNode(columnParseNode, PLong.INSTANCE, null, null, false);
+        StringBuilder stringBuilder = new StringBuilder();
+        castParseNode.toSQL(null, stringBuilder);
+        assertEquals(" CAST(TABLE1.V AS BIGINT)", stringBuilder.toString());
+    }
+
+    @Test
+    public void testToSQL_WithLengthAndScale() {
+        ColumnParseNode columnParseNode = new ColumnParseNode(TableName.create("SCHEMA1", "TABLE1"), "V");
+        CastParseNode castParseNode = new CastParseNode(columnParseNode, PDecimal.INSTANCE, 5, 3, false);
+        StringBuilder stringBuilder = new StringBuilder();
+        castParseNode.toSQL(null, stringBuilder);
+        assertEquals(" CAST(TABLE1.V AS DECIMAL(5,3))", stringBuilder.toString());
+    }
+
+    @Test
+    public void testToSQL_ArrayType() {
+        ColumnParseNode columnParseNode = new ColumnParseNode(TableName.create("SCHEMA1", "TABLE1"), "V");
+        CastParseNode castParseNode = new CastParseNode(columnParseNode, PLong.INSTANCE, null, null, true);
+        StringBuilder stringBuilder = new StringBuilder();
+        castParseNode.toSQL(null, stringBuilder);
+        assertEquals(" CAST(TABLE1.V AS BIGINT ARRAY)", stringBuilder.toString());
+    }
+}
\ No newline at end of file