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/954a4a1b Tree: http://git-wip-us.apache.org/repos/asf/phoenix/tree/954a4a1b Diff: http://git-wip-us.apache.org/repos/asf/phoenix/diff/954a4a1b Branch: refs/heads/4.x-HBase-1.1 Commit: 954a4a1b615e6c42dfaecbf2ff6b8174261ccea6 Parents: 89ab41c Author: Gabriel Reid <gr...@apache.org> Authored: Sun Jul 19 17:46:48 2015 +0200 Committer: Gabriel Reid <gabri...@ngdata.com> Committed: Mon Jul 20 15:24:57 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/954a4a1b/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/954a4a1b/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