Merge lp:~mmcm/akiban-sql-parser/simple-case into lp:~akiban-technologies/akiban-sql-parser/trunk

Proposed by Mike McMahon
Status: Merged
Approved by: Mike McMahon
Approved revision: 304
Merged at revision: 305
Proposed branch: lp:~mmcm/akiban-sql-parser/simple-case
Merge into: lp:~akiban-technologies/akiban-sql-parser/trunk
Diff against target: 513 lines (+323/-64)
9 files modified
pom.xml (+1/-1)
src/main/java/com/akiban/sql/parser/NodeFactoryImpl.java (+18/-15)
src/main/java/com/akiban/sql/parser/NodeNames.java (+17/-15)
src/main/java/com/akiban/sql/parser/NodeTypes.java (+16/-15)
src/main/java/com/akiban/sql/parser/SimpleCaseNode.java (+163/-0)
src/main/java/com/akiban/sql/unparser/NodeToString.java (+19/-0)
src/main/javacc/SQLGrammar.jj (+87/-18)
src/test/resources/com/akiban/sql/unparser/select-16.expected (+1/-0)
src/test/resources/com/akiban/sql/unparser/select-16.sql (+1/-0)
To merge this branch: bzr merge lp:~mmcm/akiban-sql-parser/simple-case
Reviewer Review Type Date Requested Status
Mike McMahon Approve
Thomas Jones-Low Needs Fixing
Nathan Williams Approve
Review via email: mp+177936@code.launchpad.net

Description of the change

Add parsing of simple CASE.

Also restore the version number, which got messed up due to some changes only in /build.

To post a comment you must log in.
Revision history for this message
Nathan Williams (nwilliams) wrote :

As described.

review: Approve
Revision history for this message
Thomas Jones-Low (tjoneslo) wrote :

There was one failure during build/test:

* during merge: merge conflicts while merging lp:~mmcm/akiban-sql-parser/simple-case

review: Needs Fixing
305. By Mike McMahon

Merge from trunk.

Revision history for this message
Mike McMahon (mmcm) wrote :

Conflicts resolved.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'pom.xml'
--- pom.xml 2013-07-31 14:50:41 +0000
+++ pom.xml 2013-08-07 17:46:26 +0000
@@ -13,7 +13,7 @@
1313
14 <groupId>com.akiban</groupId>14 <groupId>com.akiban</groupId>
15 <artifactId>akiban-sql-parser</artifactId>15 <artifactId>akiban-sql-parser</artifactId>
16 <version>1.0.15-SNAPSHOT</version>16 <version>1.0.16-SNAPSHOT</version>
17 <packaging>jar</packaging>17 <packaging>jar</packaging>
1818
19 <name>Akiban SQL Parser</name>19 <name>Akiban SQL Parser</name>
2020
=== modified file 'src/main/java/com/akiban/sql/parser/NodeFactoryImpl.java'
--- src/main/java/com/akiban/sql/parser/NodeFactoryImpl.java 2013-07-31 23:47:55 +0000
+++ src/main/java/com/akiban/sql/parser/NodeFactoryImpl.java 2013-08-07 17:46:26 +0000
@@ -1,18 +1,18 @@
1/**1/**
2 * Copyright 2011-2013 Akiban Technologies, Inc.2 * Copyright 2011-2013 Akiban Technologies, Inc.
3 * 3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at6 * You may obtain a copy of the License at
7 * 7 *
8 * http://www.apache.org/licenses/LICENSE-2.08 * http://www.apache.org/licenses/LICENSE-2.0
9 * 9 *
10 * Unless required by applicable law or agreed to in writing, software10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and13 * See the License for the specific language governing permissions and
14 * limitations under the License.14 * limitations under the License.
15 */15 */
1616
17/* The original from which this derives bore the following: */17/* The original from which this derives bore the following: */
1818
@@ -653,6 +653,9 @@
653 case NodeTypes.DEALLOCATE_STATEMENT_NODE:653 case NodeTypes.DEALLOCATE_STATEMENT_NODE:
654 return NodeNames.DEALLOCATE_STATEMENT_NODE_NAME;654 return NodeNames.DEALLOCATE_STATEMENT_NODE_NAME;
655655
656 case NodeTypes.SIMPLE_CASE_NODE:
657 return NodeNames.SIMPLE_CASE_NODE_NAME;
658
656 case NodeTypes.PARTITION_BY_LIST:659 case NodeTypes.PARTITION_BY_LIST:
657 return NodeNames.PARTITION_BY_LIST_NAME;660 return NodeNames.PARTITION_BY_LIST_NAME;
658661
659662
=== modified file 'src/main/java/com/akiban/sql/parser/NodeNames.java'
--- src/main/java/com/akiban/sql/parser/NodeNames.java 2013-07-31 23:47:55 +0000
+++ src/main/java/com/akiban/sql/parser/NodeNames.java 2013-08-07 17:46:26 +0000
@@ -1,18 +1,18 @@
1/**1/**
2 * Copyright 2011-2013 Akiban Technologies, Inc.2 * Copyright 2011-2013 Akiban Technologies, Inc.
3 * 3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at6 * You may obtain a copy of the License at
7 * 7 *
8 * http://www.apache.org/licenses/LICENSE-2.08 * http://www.apache.org/licenses/LICENSE-2.0
9 * 9 *
10 * Unless required by applicable law or agreed to in writing, software10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and13 * See the License for the specific language governing permissions and
14 * limitations under the License.14 * limitations under the License.
15 */15 */
1616
17/* The original from which this derives bore the following: */17/* The original from which this derives bore the following: */
1818
@@ -327,6 +327,8 @@
327327
328 static final String SET_TRANSACTION_ISOLATION_NODE_NAME = "com.akiban.sql.parser.SetTransactionIsolationNode";328 static final String SET_TRANSACTION_ISOLATION_NODE_NAME = "com.akiban.sql.parser.SetTransactionIsolationNode";
329329
330 static final String SIMPLE_CASE_NODE_NAME = "com.akiban.sql.parser.SimpleCaseNode";
331
330 static final String SIMPLE_STRING_OPERATOR_NODE_NAME = "com.akiban.sql.parser.SimpleStringOperatorNode";332 static final String SIMPLE_STRING_OPERATOR_NODE_NAME = "com.akiban.sql.parser.SimpleStringOperatorNode";
331333
332 static final String SPECIAL_FUNCTION_NODE_NAME = "com.akiban.sql.parser.SpecialFunctionNode";334 static final String SPECIAL_FUNCTION_NODE_NAME = "com.akiban.sql.parser.SpecialFunctionNode";
333335
=== modified file 'src/main/java/com/akiban/sql/parser/NodeTypes.java'
--- src/main/java/com/akiban/sql/parser/NodeTypes.java 2013-07-31 23:47:55 +0000
+++ src/main/java/com/akiban/sql/parser/NodeTypes.java 2013-08-07 17:46:26 +0000
@@ -1,18 +1,18 @@
1/**1/**
2 * Copyright 2011-2013 Akiban Technologies, Inc.2 * Copyright 2011-2013 Akiban Technologies, Inc.
3 * 3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at6 * You may obtain a copy of the License at
7 * 7 *
8 * http://www.apache.org/licenses/LICENSE-2.08 * http://www.apache.org/licenses/LICENSE-2.0
9 * 9 *
10 * Unless required by applicable law or agreed to in writing, software10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and13 * See the License for the specific language governing permissions and
14 * limitations under the License.14 * limitations under the License.
15 */15 */
1616
17/* The original from which this derives bore the following: */17/* The original from which this derives bore the following: */
1818
@@ -217,6 +217,7 @@
217 public static final int GROUP_CONCAT_NODE = 167;217 public static final int GROUP_CONCAT_NODE = 167;
218 public static final int AT_RENAME_NODE = 168;218 public static final int AT_RENAME_NODE = 168;
219 public static final int AT_RENAME_COLUMN_NODE = 169;219 public static final int AT_RENAME_COLUMN_NODE = 169;
220 public static final int SIMPLE_CASE_NODE = 170;
220 public static final int PARTITION_BY_LIST = 171;221 public static final int PARTITION_BY_LIST = 171;
221 public static final int PARTITION_BY_COLUMN = 172;222 public static final int PARTITION_BY_COLUMN = 172;
222 public static final int FULL_OUTER_JOIN_NODE = 173;223 public static final int FULL_OUTER_JOIN_NODE = 173;
223224
=== added file 'src/main/java/com/akiban/sql/parser/SimpleCaseNode.java'
--- src/main/java/com/akiban/sql/parser/SimpleCaseNode.java 1970-01-01 00:00:00 +0000
+++ src/main/java/com/akiban/sql/parser/SimpleCaseNode.java 2013-08-07 17:46:26 +0000
@@ -0,0 +1,163 @@
1/**
2 * Copyright 2011-2013 Akiban Technologies, Inc.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.akiban.sql.parser;
18
19import com.akiban.sql.StandardException;
20
21/**
22 * A SimpleCaseNode represents the CASE <expr> THEN ... form.
23 */
24
25public class SimpleCaseNode extends ValueNode
26{
27 private ValueNode operand;
28 private ValueNodeList caseOperands, resultValues;
29 private ValueNode elseValue;
30
31 /**
32 * Initializer for a SimpleCaseNode
33 *
34 * @param operand The expression being compared
35 */
36
37 public void init(Object operand) throws StandardException {
38 this.operand = (ValueNode)operand;
39 this.caseOperands = (ValueNodeList)getNodeFactory().getNode(NodeTypes.VALUE_NODE_LIST,
40 getParserContext());
41 this.resultValues = (ValueNodeList)getNodeFactory().getNode(NodeTypes.VALUE_NODE_LIST,
42 getParserContext());
43 }
44
45 /**
46 * Fill this node with a deep copy of the given node.
47 */
48 public void copyFrom(QueryTreeNode node) throws StandardException {
49 super.copyFrom(node);
50
51 SimpleCaseNode other = (SimpleCaseNode)node;
52 this.operand = (ValueNode)
53 getNodeFactory().copyNode(other.operand, getParserContext());
54 this.caseOperands = (ValueNodeList)
55 getNodeFactory().copyNode(other.caseOperands, getParserContext());
56 this.resultValues = (ValueNodeList)
57 getNodeFactory().copyNode(other.resultValues, getParserContext());
58 if (other.elseValue == null)
59 this.elseValue = null;
60 else
61 this.elseValue = (ValueNode)
62 getNodeFactory().copyNode(other.elseValue, getParserContext());
63 }
64
65 public ValueNode getOperand() {
66 return operand;
67 }
68
69 public ValueNodeList getCaseOperands() {
70 return caseOperands;
71 }
72
73 public ValueNodeList getResultValues() {
74 return resultValues;
75 }
76
77 public ValueNode getElseValue() {
78 return elseValue;
79 }
80
81 public void setElseValue(ValueNode elseValue) {
82 this.elseValue = elseValue;
83 }
84
85 /** The number of <code>WHEN</code> cases. */
86 public int getNumberOfCases() {
87 return caseOperands.size();
88 }
89
90 /** The <code>WHEN</code> part. */
91 public ValueNode getCaseOperand(int index) {
92 return caseOperands.get(index);
93 }
94
95 /** The <code>THEN</code> part. */
96 public ValueNode getResultValue(int index) {
97 return resultValues.get(index);
98 }
99
100 public void addCase(ValueNode operand, ValueNode result) {
101 caseOperands.add(operand);
102 resultValues.add(result);
103 }
104
105 /**
106 * Prints the sub-nodes of this object. See QueryTreeNode.java for
107 * how tree printing is supposed to work.
108 *
109 * @param depth The depth of this node in the tree
110 */
111
112 public void printSubNodes(int depth) {
113 super.printSubNodes(depth);
114
115 printLabel(depth, "operand: ");
116 operand.treePrint(depth + 1);
117
118 for (int i = 0; i < getNumberOfCases(); i++) {
119 printLabel(depth, "when: ");
120 getCaseOperand(i).treePrint(depth + 1);
121 printLabel(depth, "then: ");
122 getResultValue(i).treePrint(depth + 1);
123 }
124
125 if (elseValue != null) {
126 printLabel(depth, "else: ");
127 elseValue.treePrint(depth + 1);
128 }
129 }
130
131 /**
132 * Accept the visitor for all visitable children of this node.
133 *
134 * @param v the visitor
135 *
136 * @exception StandardException on error
137 */
138 void acceptChildren(Visitor v) throws StandardException {
139 super.acceptChildren(v);
140
141 operand = (ValueNode)operand.accept(v);
142 caseOperands = (ValueNodeList)caseOperands.accept(v);
143 resultValues = (ValueNodeList)resultValues.accept(v);
144 if (elseValue != null)
145 elseValue = (ValueNode)elseValue.accept(v);
146 }
147
148 /**
149 * {@inheritDoc}
150 */
151 protected boolean isEquivalent(ValueNode o) throws StandardException {
152 if (isSameNodeType(o)) {
153 SimpleCaseNode other = (SimpleCaseNode)o;
154 return operand.isEquivalent(other.operand) &&
155 caseOperands.isEquivalent(other.caseOperands) &&
156 resultValues.isEquivalent(other.resultValues) &&
157 ((elseValue == null) ? (other.elseValue == null) :
158 elseValue.isEquivalent(other.elseValue));
159 }
160 return false;
161 }
162
163}
0164
=== modified file 'src/main/java/com/akiban/sql/unparser/NodeToString.java'
--- src/main/java/com/akiban/sql/unparser/NodeToString.java 2013-07-31 23:59:21 +0000
+++ src/main/java/com/akiban/sql/unparser/NodeToString.java 2013-08-07 17:46:26 +0000
@@ -198,6 +198,8 @@
198 return betweenOperatorNode((BetweenOperatorNode)node);198 return betweenOperatorNode((BetweenOperatorNode)node);
199 case NodeTypes.CONDITIONAL_NODE:199 case NodeTypes.CONDITIONAL_NODE:
200 return conditionalNode((ConditionalNode)node);200 return conditionalNode((ConditionalNode)node);
201 case NodeTypes.SIMPLE_CASE_NODE:
202 return simpleCaseNode((SimpleCaseNode)node);
201 case NodeTypes.COALESCE_FUNCTION_NODE:203 case NodeTypes.COALESCE_FUNCTION_NODE:
202 return coalesceFunctionNode((CoalesceFunctionNode)node);204 return coalesceFunctionNode((CoalesceFunctionNode)node);
203 case NodeTypes.AGGREGATE_NODE:205 case NodeTypes.AGGREGATE_NODE:
@@ -1076,6 +1078,23 @@
1076 return str.toString();1078 return str.toString();
1077 }1079 }
10781080
1081 protected String simpleCaseNode(SimpleCaseNode node) throws StandardException {
1082 StringBuilder str = new StringBuilder("CASE ");
1083 str.append(maybeParens(node.getOperand()));
1084 for (int i = 0; i < node.getNumberOfCases(); i++) {
1085 str.append(" WHEN ");
1086 str.append(maybeParens(node.getCaseOperand(i)));
1087 str.append(" THEN ");
1088 str.append(maybeParens(node.getResultValue(i)));
1089 }
1090 if (node.getElseValue() != null) {
1091 str.append(" ELSE ");
1092 str.append(maybeParens(node.getElseValue()));
1093 }
1094 str.append(" END");
1095 return str.toString();
1096 }
1097
1079 protected String coalesceFunctionNode(CoalesceFunctionNode node) 1098 protected String coalesceFunctionNode(CoalesceFunctionNode node)
1080 throws StandardException {1099 throws StandardException {
1081 return functionCall(node.getFunctionName(),1100 return functionCall(node.getFunctionName(),
10821101
=== modified file 'src/main/javacc/SQLGrammar.jj'
--- src/main/javacc/SQLGrammar.jj 2013-08-03 18:34:52 +0000
+++ src/main/javacc/SQLGrammar.jj 2013-08-07 17:46:26 +0000
@@ -12551,7 +12551,7 @@
12551 parserContext);12551 parserContext);
12552 }12552 }
12553|12553|
12554 <CASE> value = whenThenExpression()12554 <CASE> value = caseExpression()
12555 {12555 {
12556 return value;12556 return value;
12557 }12557 }
@@ -12563,26 +12563,16 @@
12563 ValueNode expr;12563 ValueNode expr;
12564}12564}
12565{12565{
12566 <END>12566 LOOKAHEAD ( { getToken(1).kind == WHEN } )
12567 {
12568 ValueNode value = (ValueNode)nodeFactory.getNode(NodeTypes.CAST_NODE,
12569 (ValueNode)nodeFactory.getNode(NodeTypes.UNTYPED_NULL_CONSTANT_NODE,
12570 parserContext),
12571 DataTypeDescriptor.getBuiltInDataTypeDescriptor(Types.CHAR, 1),
12572 parserContext);
12573 ((CastNode)value).setForExternallyGeneratedCASTnode();
12574 return value;
12575 }
12576|
12577 <ELSE> expr = thenElseExpression() <END>
12578 {
12579 return expr;
12580 }
12581|
12582 expr = whenThenExpression()12567 expr = whenThenExpression()
12583 {12568 {
12584 return expr;12569 return expr;
12585 }12570 }
12571|
12572 expr = simpleCaseExpression()
12573 {
12574 return expr;
12575 }
12586}12576}
1258712577
12588ValueNode12578ValueNode
@@ -12596,7 +12586,7 @@
12596 <WHEN> expr = orExpression(null) 12586 <WHEN> expr = orExpression(null)
12597 ( <OR> expr = orExpression(expr) )*12587 ( <OR> expr = orExpression(expr) )*
12598 <THEN> thenExpr = thenElseExpression()12588 <THEN> thenExpr = thenElseExpression()
12599 elseExpr = caseExpression()12589 elseExpr = caseElseExpression()
12600 {12590 {
12601 ValueNodeList thenElseList = (ValueNodeList)nodeFactory.getNode(NodeTypes.VALUE_NODE_LIST, parserContext);12591 ValueNodeList thenElseList = (ValueNodeList)nodeFactory.getNode(NodeTypes.VALUE_NODE_LIST, parserContext);
12602 thenElseList.addValueNode(thenExpr); // then12592 thenElseList.addValueNode(thenExpr); // then
@@ -12634,6 +12624,85 @@
12634 }12624 }
12635}12625}
1263612626
12627ValueNode
12628caseElseExpression() throws StandardException :
12629{
12630 ValueNode expr;
12631}
12632{
12633 <END>
12634 {
12635 ValueNode value = (ValueNode)nodeFactory.getNode(NodeTypes.CAST_NODE,
12636 (ValueNode)nodeFactory.getNode(NodeTypes.UNTYPED_NULL_CONSTANT_NODE,
12637 parserContext),
12638 DataTypeDescriptor.getBuiltInDataTypeDescriptor(Types.CHAR, 1),
12639 parserContext);
12640 ((CastNode)value).setForExternallyGeneratedCASTnode();
12641 return value;
12642 }
12643|
12644 <ELSE> expr = thenElseExpression() <END>
12645 {
12646 return expr;
12647 }
12648|
12649 expr = whenThenExpression()
12650 {
12651 return expr;
12652 }
12653}
12654
12655ValueNode
12656simpleCaseExpression() throws StandardException :
12657{
12658 ValueNode operand;
12659 SimpleCaseNode caseExpr;
12660}
12661{
12662 operand = additiveExpression()
12663 {
12664 caseExpr = (SimpleCaseNode)nodeFactory.getNode(NodeTypes.SIMPLE_CASE_NODE,
12665 operand,
12666 parserContext);
12667 }
12668 simpleCaseWhenThenExpression(caseExpr)
12669 {
12670 return caseExpr;
12671 }
12672}
12673
12674void
12675simpleCaseWhenThenExpression(SimpleCaseNode caseExpr) throws StandardException :
12676{
12677 ValueNode expr;
12678 ValueNode thenExpr;
12679 ValueNode elseExpr;
12680}
12681{
12682 <WHEN> expr = additiveExpression()
12683 <THEN> thenExpr = thenElseExpression()
12684 {
12685 caseExpr.addCase(expr, thenExpr);
12686 }
12687 simpleCaseElseExpression(caseExpr)
12688}
12689
12690void
12691simpleCaseElseExpression(SimpleCaseNode caseExpr) throws StandardException :
12692{
12693 ValueNode expr;
12694}
12695{
12696 <END>
12697|
12698 <ELSE> expr = thenElseExpression() <END>
12699 {
12700 caseExpr.setElseValue(expr);
12701 }
12702|
12703 simpleCaseWhenThenExpression(caseExpr)
12704}
12705
12637void12706void
12638tableConstraintDefinition(TableElementList tableElementList) throws StandardException :12707tableConstraintDefinition(TableElementList tableElementList) throws StandardException :
12639{12708{
1264012709
=== added file 'src/test/resources/com/akiban/sql/unparser/select-16.expected'
--- src/test/resources/com/akiban/sql/unparser/select-16.expected 1970-01-01 00:00:00 +0000
+++ src/test/resources/com/akiban/sql/unparser/select-16.expected 2013-08-07 17:46:26 +0000
@@ -0,0 +1,1 @@
1SELECT (CASE x WHEN y THEN x WHEN z THEN y ELSE w END) FROM t
0\ No newline at end of file2\ No newline at end of file
13
=== added file 'src/test/resources/com/akiban/sql/unparser/select-16.sql'
--- src/test/resources/com/akiban/sql/unparser/select-16.sql 1970-01-01 00:00:00 +0000
+++ src/test/resources/com/akiban/sql/unparser/select-16.sql 2013-08-07 17:46:26 +0000
@@ -0,0 +1,1 @@
1SELECT CASE x WHEN y THEN x WHEN z THEN y ELSE w END FROM t
0\ No newline at end of file2\ No newline at end of file

Subscribers

People subscribed via source and target branches