This is an automated email from the ASF dual-hosted git repository. luozenglin pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/doris.git
The following commit(s) were added to refs/heads/master by this push: new 9533918d4f [fix](delete) Fix parsing error of delete where date statement (#22690) 9533918d4f is described below commit 9533918d4f127eb30c560e59a4559716f041f296 Author: luozenglin <luozeng...@baidu.com> AuthorDate: Wed Aug 9 12:33:03 2023 +0800 [fix](delete) Fix parsing error of delete where date statement (#22690) --- .../src/main/java/org/apache/doris/analysis/Analyzer.java | 2 +- .../main/java/org/apache/doris/analysis/BinaryPredicate.java | 10 ++++++++-- .../src/main/java/org/apache/doris/analysis/DeleteStmt.java | 6 ++++-- .../src/main/java/org/apache/doris/analysis/StringLiteral.java | 4 ++-- .../main/java/org/apache/doris/qe/cache/PartitionRange.java | 4 +++- .../src/test/java/org/apache/doris/qe/PartitionCacheTest.java | 10 +++++----- 6 files changed, 23 insertions(+), 13 deletions(-) diff --git a/fe/fe-core/src/main/java/org/apache/doris/analysis/Analyzer.java b/fe/fe-core/src/main/java/org/apache/doris/analysis/Analyzer.java index 761aae1442..5e49061bb7 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/analysis/Analyzer.java +++ b/fe/fe-core/src/main/java/org/apache/doris/analysis/Analyzer.java @@ -2135,7 +2135,7 @@ public class Analyzer { for (int i = 1; i < exprs.size(); ++i) { exprs.get(i).analyze(this); if (compatibleType.isDateV2() && exprs.get(i) instanceof StringLiteral - && ((StringLiteral) exprs.get(i)).canConvertToDateV2(compatibleType)) { + && ((StringLiteral) exprs.get(i)).canConvertToDateType(compatibleType)) { // If string literal can be converted to dateV2, we use datev2 as the compatible type // instead of datetimev2. } else if (exprs.get(i).isConstantImpl()) { diff --git a/fe/fe-core/src/main/java/org/apache/doris/analysis/BinaryPredicate.java b/fe/fe-core/src/main/java/org/apache/doris/analysis/BinaryPredicate.java index 8587d801e8..dd9253109e 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/analysis/BinaryPredicate.java +++ b/fe/fe-core/src/main/java/org/apache/doris/analysis/BinaryPredicate.java @@ -379,14 +379,14 @@ public class BinaryPredicate extends Predicate implements Writable { return getChild(1).getType(); } else if (getChild(0).getType().isDateV2() && (getChild(1).getType().isStringType() && getChild(1) instanceof StringLiteral)) { - if (((StringLiteral) getChild(1)).canConvertToDateV2(Type.DATEV2)) { + if (((StringLiteral) getChild(1)).canConvertToDateType(Type.DATEV2)) { return Type.DATEV2; } else { return Type.DATETIMEV2; } } else if (getChild(1).getType().isDateV2() && (getChild(0).getType().isStringType() && getChild(0) instanceof StringLiteral)) { - if (((StringLiteral) getChild(0)).canConvertToDateV2(Type.DATEV2)) { + if (((StringLiteral) getChild(0)).canConvertToDateType(Type.DATEV2)) { return Type.DATEV2; } else { return Type.DATETIMEV2; @@ -397,6 +397,12 @@ public class BinaryPredicate extends Predicate implements Writable { } else if (getChild(1).getType().isDatetimeV2() && (getChild(0).getType().isStringType() && getChild(0) instanceof StringLiteral)) { return getChild(1).getType(); + } else if (getChild(0).getType().isDate() + && (getChild(1).getType().isStringType() && getChild(1) instanceof StringLiteral)) { + return ((StringLiteral) getChild(1)).canConvertToDateType(Type.DATE) ? Type.DATE : Type.DATETIME; + } else if (getChild(1).getType().isDate() + && (getChild(0).getType().isStringType() && getChild(0) instanceof StringLiteral)) { + return ((StringLiteral) getChild(0)).canConvertToDateType(Type.DATE) ? Type.DATE : Type.DATETIME; } else { return Type.DATETIME; } diff --git a/fe/fe-core/src/main/java/org/apache/doris/analysis/DeleteStmt.java b/fe/fe-core/src/main/java/org/apache/doris/analysis/DeleteStmt.java index f3699af3d5..4e8e4ad2dd 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/analysis/DeleteStmt.java +++ b/fe/fe-core/src/main/java/org/apache/doris/analysis/DeleteStmt.java @@ -240,12 +240,14 @@ public class DeleteStmt extends DdlStmt { Expr leftExpr = binaryPredicate.getChild(0); if (!(leftExpr instanceof SlotRef)) { throw new AnalysisException( - "Left expr of binary predicate should be column name, predicate=" + binaryPredicate.toSql()); + "Left expr of binary predicate should be column name, predicate: " + binaryPredicate.toSql() + + ", left expr type:" + leftExpr.getType()); } Expr rightExpr = binaryPredicate.getChild(1); if (!(rightExpr instanceof LiteralExpr)) { throw new AnalysisException( - "Right expr of binary predicate should be value, predicate=" + binaryPredicate.toSql()); + "Right expr of binary predicate should be value, predicate: " + binaryPredicate.toSql() + + ", right expr type:" + rightExpr.getType()); } deleteConditions.add(binaryPredicate); } else if (predicate instanceof CompoundPredicate) { diff --git a/fe/fe-core/src/main/java/org/apache/doris/analysis/StringLiteral.java b/fe/fe-core/src/main/java/org/apache/doris/analysis/StringLiteral.java index 26665f77ac..2e552824d6 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/analysis/StringLiteral.java +++ b/fe/fe-core/src/main/java/org/apache/doris/analysis/StringLiteral.java @@ -199,9 +199,9 @@ public class StringLiteral extends LiteralExpr { return newLiteral; } - public boolean canConvertToDateV2(Type targetType) { + public boolean canConvertToDateType(Type targetType) { try { - Preconditions.checkArgument(targetType.isDateV2()); + Preconditions.checkArgument(targetType.isDateType()); new DateLiteral(value, targetType); return true; } catch (AnalysisException e) { diff --git a/fe/fe-core/src/main/java/org/apache/doris/qe/cache/PartitionRange.java b/fe/fe-core/src/main/java/org/apache/doris/qe/cache/PartitionRange.java index 23f6390d0e..0c36cb69e7 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/qe/cache/PartitionRange.java +++ b/fe/fe-core/src/main/java/org/apache/doris/qe/cache/PartitionRange.java @@ -37,6 +37,7 @@ import org.apache.doris.common.AnalysisException; import org.apache.doris.common.Config; import org.apache.doris.planner.PartitionColumnFilter; +import com.google.common.base.Preconditions; import com.google.common.collect.Lists; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; @@ -245,7 +246,8 @@ public class PartitionRange { } private Date getDateValue(LiteralExpr expr) { - value = expr.getLongValue() / 1000000; + Preconditions.checkArgument(expr.getType() == Type.DATE || expr.getType() == Type.DATEV2); + value = expr.getLongValue(); Date dt = null; try { dt = Date.from(LocalDate.parse(String.valueOf(value), df8).atStartOfDay().atZone(ZoneId.systemDefault()) diff --git a/fe/fe-core/src/test/java/org/apache/doris/qe/PartitionCacheTest.java b/fe/fe-core/src/test/java/org/apache/doris/qe/PartitionCacheTest.java index c4c103e786..87345bcfa6 100644 --- a/fe/fe-core/src/test/java/org/apache/doris/qe/PartitionCacheTest.java +++ b/fe/fe-core/src/test/java/org/apache/doris/qe/PartitionCacheTest.java @@ -1057,9 +1057,9 @@ public class PartitionCacheTest { SqlCache sqlCache = (SqlCache) ca.getCache(); String cacheKey = sqlCache.getSqlWithViewStmt(); - Assert.assertEquals(cacheKey, "SELECT <slot 2> `eventdate` AS `eventdate`, <slot 3> count(`userid`) " - + "AS `count(``userid``)` FROM `testCluster:testDb`.`appevent` WHERE `eventdate` " - + ">= '2020-01-12 00:00:00' AND `eventdate` <= '2020-01-14 00:00:00' GROUP BY `eventdate`|"); + Assert.assertEquals(cacheKey, "SELECT <slot 2> `eventdate` AS `eventdate`, <slot 3> count(`userid`) AS " + + "`count(``userid``)` FROM `testCluster:testDb`.`appevent` WHERE `eventdate` >= '2020-01-12' AND " + + "`eventdate` <= '2020-01-14' GROUP BY `eventdate`|"); } @Test @@ -1121,8 +1121,8 @@ public class PartitionCacheTest { String cacheKey = sqlCache.getSqlWithViewStmt(); Assert.assertEquals(cacheKey, "SELECT `origin`.`eventdate` AS `eventdate`, `origin`.`userid` AS " + "`userid` FROM (SELECT `view2`.`eventdate` AS `eventdate`, `view2`.`userid` AS `userid` FROM " - + "`testCluster:testDb`.`view2` view2 WHERE `view2`.`eventdate` >= '2020-01-12 00:00:00' AND `view2`.`eventdate`" - + " <= '2020-01-14 00:00:00') origin|select eventdate, userid FROM appevent"); + + "`testCluster:testDb`.`view2` view2 WHERE `view2`.`eventdate` >= '2020-01-12' AND `view2`.`eventdate` " + + "<= '2020-01-14') origin|select eventdate, userid FROM appevent"); } @Test --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org For additional commands, e-mail: commits-h...@doris.apache.org