From d8a6cd65ac03af6795d59973d09bc59c54b34087 Mon Sep 17 00:00:00 2001 From: qiaojialingithub <646274302@qq.com> Date: Wed, 24 May 2017 22:44:06 +0800 Subject: [PATCH] fix qp DNF bug and remove hasReserved --- src/main/java/cn/edu/thu/tsfile/spark/QueryProcessor.java | 2 +- .../java/cn/edu/thu/tsfile/spark/common/BasicOperator.java | 3 --- .../cn/edu/thu/tsfile/spark/common/FilterOperator.java | 7 ------- .../edu/thu/tsfile/spark/optimizer/DNFFilterOptimizer.java | 3 --- src/test/scala/cn/edu/thu/tsfile/spark/TSFileSuit.scala | 7 +++++++ 5 files changed, 8 insertions(+), 14 deletions(-) diff --git a/src/main/java/cn/edu/thu/tsfile/spark/QueryProcessor.java b/src/main/java/cn/edu/thu/tsfile/spark/QueryProcessor.java index 541d383..46ec8b3 100755 --- a/src/main/java/cn/edu/thu/tsfile/spark/QueryProcessor.java +++ b/src/main/java/cn/edu/thu/tsfile/spark/QueryProcessor.java @@ -39,6 +39,7 @@ public List generatePlans(FilterOperator filter, List paths DNFFilterOptimizer dnf = new DNFFilterOptimizer(); filter = dnf.optimize(filter); + MergeSingleFilterOptimizer merge = new MergeSingleFilterOptimizer(); filter = merge.optimize(filter); @@ -53,7 +54,6 @@ public List generatePlans(FilterOperator filter, List paths } else { queryPlans.addAll(new PhysicalOptimizer().optimize(null, paths, in, start, end)); } - return queryPlans; } diff --git a/src/main/java/cn/edu/thu/tsfile/spark/common/BasicOperator.java b/src/main/java/cn/edu/thu/tsfile/spark/common/BasicOperator.java index 37bed16..14476cf 100755 --- a/src/main/java/cn/edu/thu/tsfile/spark/common/BasicOperator.java +++ b/src/main/java/cn/edu/thu/tsfile/spark/common/BasicOperator.java @@ -30,9 +30,6 @@ public BasicOperator(int tokenIntType, String path, String value) { this.seriesValue = value; this.isLeaf = true; this.isSingle = true; - if(path.equals(SQLConstant.RESERVED_DELTA_OBJECT) || path.equals(SQLConstant.RESERVED_TIME)) { - hasReserve = true; - } } public void setReversedTokenIntType() throws BasicOperatorException { diff --git a/src/main/java/cn/edu/thu/tsfile/spark/common/FilterOperator.java b/src/main/java/cn/edu/thu/tsfile/spark/common/FilterOperator.java index 71db442..dbf8760 100755 --- a/src/main/java/cn/edu/thu/tsfile/spark/common/FilterOperator.java +++ b/src/main/java/cn/edu/thu/tsfile/spark/common/FilterOperator.java @@ -28,8 +28,6 @@ public class FilterOperator extends Operator implements Comparable getAllPaths() { public void setChildrenList(List children) { this.childOperators = children; - for(FilterOperator child: children) { - hasReserve |= child.hasReserve; - } } public void setIsSingle(boolean b) { @@ -92,7 +87,6 @@ public String getSinglePath() { public void addChildOPerator(FilterOperator op) { childOperators.add(op); - hasReserve |= op.hasReserve; } @@ -140,7 +134,6 @@ public FilterOperator clone() { ret.tokenSymbol=tokenSymbol; ret.isLeaf = isLeaf; ret.isSingle = isSingle; - ret.hasReserve = hasReserve; if(singlePath != null) ret.singlePath = singlePath; for (FilterOperator filterOperator : this.childOperators) { diff --git a/src/main/java/cn/edu/thu/tsfile/spark/optimizer/DNFFilterOptimizer.java b/src/main/java/cn/edu/thu/tsfile/spark/optimizer/DNFFilterOptimizer.java index 24b7a89..2654eb8 100755 --- a/src/main/java/cn/edu/thu/tsfile/spark/optimizer/DNFFilterOptimizer.java +++ b/src/main/java/cn/edu/thu/tsfile/spark/optimizer/DNFFilterOptimizer.java @@ -28,9 +28,6 @@ public FilterOperator optimize(FilterOperator filter) throws DNFOptimizeExceptio } private FilterOperator getDNF(FilterOperator filter) throws DNFOptimizeException { - if(!filter.hasReserve) { - return filter; - } if (filter.isLeaf()) return filter; List children = filter.getChildren(); diff --git a/src/test/scala/cn/edu/thu/tsfile/spark/TSFileSuit.scala b/src/test/scala/cn/edu/thu/tsfile/spark/TSFileSuit.scala index 525957b..d21dcbf 100644 --- a/src/test/scala/cn/edu/thu/tsfile/spark/TSFileSuit.scala +++ b/src/test/scala/cn/edu/thu/tsfile/spark/TSFileSuit.scala @@ -44,6 +44,13 @@ class TSFileSuit extends FunSuite with BeforeAndAfterAll { } } + test("qp") { + val df = spark.read.format("cn.edu.thu.tsfile.spark").load(tsfileFolder) + df.createOrReplaceTempView("tsfile_table") + val newDf = spark.sql("select s1,s2 from tsfile_table where delta_object = 'root.car.d1' and time <= 10 and (time > 5 or s1 > 10)") + Assert.assertEquals(0, newDf.count()) + } + test("testMultiFilesNoneExistDelta_object") { val df = spark.read.format("cn.edu.thu.tsfile.spark").load(tsfileFolder) df.createOrReplaceTempView("tsfile_table")