From f69f8df0ee599eaa76771fd3c9eca308d5770489 Mon Sep 17 00:00:00 2001 From: sunyerui Date: Tue, 26 Jan 2016 23:15:47 +0800 Subject: [PATCH] KYLIN-1372 Query using PrepareStatement failed with multi OR clause --- .../kylin/metadata/filter/CompareTupleFilter.java | 4 ++- .../test/resources/query/sql_dynamic/query03.dat | 2 ++ .../test/resources/query/sql_dynamic/query03.sql | 33 ++++++++++++++++++++++ .../apache/kylin/query/relnode/OLAPFilterRel.java | 5 ++++ 4 files changed, 43 insertions(+), 1 deletion(-) create mode 100644 kylin-it/src/test/resources/query/sql_dynamic/query03.dat create mode 100644 kylin-it/src/test/resources/query/sql_dynamic/query03.sql diff --git a/core-metadata/src/main/java/org/apache/kylin/metadata/filter/CompareTupleFilter.java b/core-metadata/src/main/java/org/apache/kylin/metadata/filter/CompareTupleFilter.java index ef16de2..248ab3b 100644 --- a/core-metadata/src/main/java/org/apache/kylin/metadata/filter/CompareTupleFilter.java +++ b/core-metadata/src/main/java/org/apache/kylin/metadata/filter/CompareTupleFilter.java @@ -82,7 +82,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; if (!this.dynamicVariables.containsKey(dynamicFilter.getVariableName())) { diff --git a/kylin-it/src/test/resources/query/sql_dynamic/query03.dat b/kylin-it/src/test/resources/query/sql_dynamic/query03.dat new file mode 100644 index 0000000..fc78596 --- /dev/null +++ b/kylin-it/src/test/resources/query/sql_dynamic/query03.dat @@ -0,0 +1,2 @@ +FP-GTC +Others \ No newline at end of file diff --git a/kylin-it/src/test/resources/query/sql_dynamic/query03.sql b/kylin-it/src/test/resources/query/sql_dynamic/query03.sql new file mode 100644 index 0000000..90574f7 --- /dev/null +++ b/kylin-it/src/test/resources/query/sql_dynamic/query03.sql @@ -0,0 +1,33 @@ +-- +-- 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 test_kylin_fact.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 + inner JOIN test_category_groupings + on test_kylin_fact.leaf_categ_id = test_category_groupings.leaf_categ_id and + test_kylin_fact.lstg_site_id = test_category_groupings.site_id + inner JOIN edw.test_sites as test_sites + on test_kylin_fact.lstg_site_id = test_sites.site_id + inner JOIN edw.test_seller_type_dim as test_seller_type_dim + on test_kylin_fact.slr_segment_cd = test_seller_type_dim.seller_type_cd + 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 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 8b3e1e5..7b8bfdb 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 @@ -19,8 +19,10 @@ package org.apache.kylin.query.relnode; import java.util.GregorianCalendar; +import java.util.HashMap; import java.util.LinkedList; import java.util.List; +import java.util.Map; import java.util.Set; import org.apache.calcite.adapter.enumerable.EnumerableCalc; @@ -160,6 +162,7 @@ public class OLAPFilterRel extends Filter implements OLAPRel { List children = filter.getChildren(); TblColRef inColumn = null; List inValues = new LinkedList(); + Map dynamicVariables = new HashMap<>(); for (TupleFilter child : children) { if (child.getOperator() == FilterOperatorEnum.EQ) { CompareTupleFilter compFilter = (CompareTupleFilter) child; @@ -172,6 +175,7 @@ public class OLAPFilterRel extends Filter implements OLAPRel { return null; } inValues.addAll(compFilter.getValues()); + dynamicVariables.putAll(compFilter.getVariables()); } else { return null; } @@ -182,6 +186,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(dynamicVariables); return inFilter; } -- 2.3.2 (Apple Git-55)