phoenix-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gr...@apache.org
Subject phoenix git commit: PHOENIX-2131 Closing paren in CastParseNode SQL
Date Mon, 20 Jul 2015 13:39:40 GMT
Repository: phoenix
Updated Branches:
  refs/heads/4.x-HBase-0.98 73da0fb0d -> 8eb9afeb6


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/8eb9afeb
Tree: http://git-wip-us.apache.org/repos/asf/phoenix/tree/8eb9afeb
Diff: http://git-wip-us.apache.org/repos/asf/phoenix/diff/8eb9afeb

Branch: refs/heads/4.x-HBase-0.98
Commit: 8eb9afeb6d0024265c8a8526218ac1c35076ec80
Parents: 73da0fb
Author: Gabriel Reid <greid@apache.org>
Authored: Sun Jul 19 17:46:48 2015 +0200
Committer: Gabriel Reid <gabrielr@ngdata.com>
Committed: Mon Jul 20 15:24:35 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/8eb9afeb/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/8eb9afeb/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


Mime
View raw message