提交 b2d2c6f9 编写于 作者: J JingShang Lu

fix for 5565

上级 9339d39e
<!--
~ 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.
-->
<dataset>
<metadata>
<column name="order_id" />
<column name="user_id" />
<column name="status" />
<column name="itemid" />
<column name="stateName" />
</metadata>
<row values="1000,10,init_slave,100000,null" />
</dataset>
<!--
~ 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.
-->
<dataset>
<metadata>
<column name="order_id" />
<column name="user_id" />
<column name="status" />
<column name="itemid" />
<column name="stateName" />
</metadata>
<row values="1000,10,init_slave,100001,null" />
</dataset>
<!--
~ 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.
-->
<dataset>
<metadata>
<column name="order_id" />
<column name="user_id" />
<column name="status" />
<column name="itemid" />
<column name="stateName" />
</metadata>
<row values="1000,10,init,100001,已启用" />
</dataset>
<!--
~ 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.
-->
<dataset>
<metadata>
<column name="order_id" />
<column name="user_id" />
<column name="status" />
<column name="itemid" />
<column name="stateName" />
</metadata>
<row values="1000,10,init,100000,已启用" />
</dataset>
......@@ -512,4 +512,8 @@
<dql-test-case sql-case-id="select_for_update">
<assertion parameters="10:int" expected-data-file="select_for_update.xml" />
</dql-test-case>
<dql-test-case sql-case-id="select_with_case_expression">
<assertion expected-data-file="select_with_case_expression.xml" />
</dql-test-case>
</integrate-test-cases>
......@@ -20,4 +20,6 @@
<sql-case id="select_with_expression" value="SELECT o.order_id + 1 * 2 as exp FROM t_order AS o ORDER BY o.order_id" />
<sql-case id="select_with_date_function" value="SELECT DATE(i.creation_date) AS creation_date FROM `t_order_item` AS i ORDER BY DATE(i.creation_date) DESC" db-types="MySQL" />
<sql-case id="select_with_regexp" value="SELECT * FROM t_order_item t WHERE t.status REGEXP ? AND t.item_id IN (?, ?)" db-types="MySQL" />
<sql-case id="select_with_case_expression" value="select t.*,o.item_id as itemid,(case when t.status = 'init' then '已启用' when t.status = 'failed' then '已停用' end) as stateName
from t_order t left join t_order_item as o on o.order_id =t.order_id where t.order_id=1000 limit 1" db-types="MySQL,H2" />
</sql-cases>
......@@ -582,7 +582,7 @@ public abstract class MySQLVisitor extends MySQLStatementBaseVisitor<ASTNode> {
@Override
public final ASTNode visitCaseExpression(final CaseExpressionContext ctx) {
return visit(ctx.simpleExpr());
return new OtherLiteralValue(ctx.getText());
}
@Override
......
......@@ -73,4 +73,35 @@
</and-predicate>
</where>
</select>
<select sql-case-id="select_with_case_expression" >
<projections start-index="7" stop-index="123">
<shorthand-projection start-index="7" stop-index="9">
<owner start-index="7" stop-index="7" name="t"/>
</shorthand-projection>
<column-projection start-index="11" stop-index="19" name="item_id" alias="itemid">
<owner start-index="11" stop-index="11" name="o"/>
</column-projection>
<expression-projection start-index="32" stop-index="109" alias="stateName" />
</projections>
<tables>
<simple-table start-index="134" stop-index="140" name="t_order" alias="t"/>
<simple-table start-index="154" stop-index="165" name="t_order_item" alias="o"/>
</tables>
<where start-index="198" stop-index="218">
<and-predicate>
<predicate start-index="204" stop-index="218" >
<operator type="="/>
<column-left-value name="order_id" start-index="204" stop-index="213" >
<owner name="t" start-index="204" stop-index="204" />
</column-left-value>
<compare-right-value operator="=">
<literal-expression value="1000" start-index="215" stop-index="218"/>
</compare-right-value>
</predicate>
</and-predicate>
</where>
<limit start-index="220" stop-index="226">
<row-count value="1" start-index="226" stop-index="226" />
</limit>
</select>
</sql-parser-test-cases>
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册