From b8fa22ddd32426cf5268f09f2c761d5c3ac2c1ae Mon Sep 17 00:00:00 2001 From: chenhao7253886 <510341142@qq.com> Date: Mon, 12 Mar 2018 18:11:54 +0800 Subject: [PATCH] distinguish limit 0 in analyze (#186) --- fe/src/com/baidu/palo/analysis/LimitElement.java | 6 ++++++ fe/src/com/baidu/palo/analysis/QueryStmt.java | 11 ++++++++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/fe/src/com/baidu/palo/analysis/LimitElement.java b/fe/src/com/baidu/palo/analysis/LimitElement.java index 10c6056dde47d6..6443d8f582836c 100644 --- a/fe/src/com/baidu/palo/analysis/LimitElement.java +++ b/fe/src/com/baidu/palo/analysis/LimitElement.java @@ -91,7 +91,13 @@ public String toSql() { sb.append("" + limit); return sb.toString(); } + + public void analyze(Analyzer analyzer) { + if (limit == 0) analyzer.setHasEmptyResultSet(); + } public void reset() { + limit = -1; + offset = 0; } } diff --git a/fe/src/com/baidu/palo/analysis/QueryStmt.java b/fe/src/com/baidu/palo/analysis/QueryStmt.java index fd11ec36cfceb3..84361697263269 100644 --- a/fe/src/com/baidu/palo/analysis/QueryStmt.java +++ b/fe/src/com/baidu/palo/analysis/QueryStmt.java @@ -110,10 +110,19 @@ public abstract class QueryStmt extends StatementBase { public void analyze(Analyzer analyzer) throws AnalysisException, InternalException { if (isAnalyzed()) return; super.analyze(analyzer); - // analyzeLimit(analyzer); + analyzeLimit(analyzer); if (hasWithClause()) withClause_.analyze(analyzer); } + private void analyzeLimit(Analyzer analyzer) throws AnalysisException { + // TODO chenhao + if (limitElement.getOffset() > 0 && !hasOrderByClause()) { + throw new AnalysisException("OFFSET requires an ORDER BY clause: " + + limitElement.toSql().trim()); + } + limitElement.analyze(analyzer); + } + /** * Returns a list containing all the materialized tuple ids that this stmt is * correlated with (i.e., those tuple ids from outer query blocks that TableRefs