From 5024b1d1a3980c0ed19a4dbe17b1faedfa63a3c0 Mon Sep 17 00:00:00 2001 From: sunyerui Date: Tue, 26 Jan 2016 21:57:21 +0800 Subject: [PATCH] KYLIN-1372 Query using PrepareStatement failed with multi OR clause --- .../kylin/metadata/filter/CompareTupleFilter.java | 4 +++- .../apache/kylin/query/relnode/OLAPFilterRel.java | 3 +++ .../test/resources/query/sql_dynamic/query03.dat | 2 ++ .../test/resources/query/sql_dynamic/query03.sql | 26 ++++++++++++++++++++++ 4 files changed, 34 insertions(+), 1 deletion(-) create mode 100644 query/src/test/resources/query/sql_dynamic/query03.dat create mode 100644 query/src/test/resources/query/sql_dynamic/query03.sql diff --git a/metadata/src/main/java/org/apache/kylin/metadata/filter/CompareTupleFilter.java b/metadata/src/main/java/org/apache/kylin/metadata/filter/CompareTupleFilter.java index 73fd0fb..b9db9c4 100644 --- a/metadata/src/main/java/org/apache/kylin/metadata/filter/CompareTupleFilter.java +++ b/metadata/src/main/java/org/apache/kylin/metadata/filter/CompareTupleFilter.java @@ -81,7 +81,9 @@ public class CompareTupleFilter extends TupleFilter { } } else if (child instanceof ConstantTupleFilter) { this.conditionValues.addAll(child.getValues()); - this.firstCondValue = this.conditionValues.iterator().next(); + if (!this.conditionValues.isEmpty()) { + this.firstCondValue = this.conditionValues.iterator().next(); + } } else if (child instanceof DynamicTupleFilter) { DynamicTupleFilter dynamicFilter = (DynamicTupleFilter) child; this.dynamicVariables.put(dynamicFilter.getVariableName(), null); diff --git a/query/src/main/java/org/apache/kylin/query/relnode/OLAPFilterRel.java b/query/src/main/java/org/apache/kylin/query/relnode/OLAPFilterRel.java index 667acf8..a2ab413 100644 --- a/query/src/main/java/org/apache/kylin/query/relnode/OLAPFilterRel.java +++ b/query/src/main/java/org/apache/kylin/query/relnode/OLAPFilterRel.java @@ -137,6 +137,7 @@ public class OLAPFilterRel extends Filter implements OLAPRel { List children = filter.getChildren(); TblColRef inColumn = null; List inValues = new LinkedList(); + Map dynamicVariable = new HashMap<>(); for (TupleFilter child : children) { if (child.getOperator() == FilterOperatorEnum.EQ) { CompareTupleFilter compFilter = (CompareTupleFilter) child; @@ -149,6 +150,7 @@ public class OLAPFilterRel extends Filter implements OLAPRel { return null; } inValues.addAll(compFilter.getValues()); + dynamicVariable.putAll(compFilter.getVariables()); } else { return null; } @@ -159,6 +161,7 @@ public class OLAPFilterRel extends Filter implements OLAPRel { CompareTupleFilter inFilter = new CompareTupleFilter(FilterOperatorEnum.IN); inFilter.addChild(new ColumnTupleFilter(inColumn)); inFilter.addChild(new ConstantTupleFilter(inValues)); + inFilter.getVariables().putAll(dynamicVariable); return inFilter; } diff --git a/query/src/test/resources/query/sql_dynamic/query03.dat b/query/src/test/resources/query/sql_dynamic/query03.dat new file mode 100644 index 0000000..fc78596 --- /dev/null +++ b/query/src/test/resources/query/sql_dynamic/query03.dat @@ -0,0 +1,2 @@ +FP-GTC +Others \ No newline at end of file diff --git a/query/src/test/resources/query/sql_dynamic/query03.sql b/query/src/test/resources/query/sql_dynamic/query03.sql new file mode 100644 index 0000000..31d5d0b --- /dev/null +++ b/query/src/test/resources/query/sql_dynamic/query03.sql @@ -0,0 +1,26 @@ +-- +-- 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. +-- + +select test_cal_dt.week_beg_dt,sum(test_kylin_fact.price) as GMV + , count(1) as TRANS_CNT, count(distinct leaf_categ_id) as LEAF_CATEG_CNT + from test_kylin_fact + inner JOIN edw.test_cal_dt as test_cal_dt + ON test_kylin_fact.cal_dt = test_cal_dt.cal_dt + where test_kylin_fact.lstg_format_name in (?, ?) + and test_cal_dt.week_beg_dt between DATE '2013-05-01' and DATE '2013-08-01' + group by test_cal_dt.week_beg_dt \ No newline at end of file -- 2.3.2 (Apple Git-55)