tajo-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hyun...@apache.org
Subject [4/6] git commit: TAJO-962: Column reference used in LIMIT clause incurs NPE.
Date Wed, 01 Oct 2014 15:38:27 GMT
TAJO-962: Column reference used in LIMIT clause incurs NPE.

Closes #164


Project: http://git-wip-us.apache.org/repos/asf/tajo/repo
Commit: http://git-wip-us.apache.org/repos/asf/tajo/commit/bccac701
Tree: http://git-wip-us.apache.org/repos/asf/tajo/tree/bccac701
Diff: http://git-wip-us.apache.org/repos/asf/tajo/diff/bccac701

Branch: refs/heads/block_iteration
Commit: bccac701d5c3467ec7d7b39a1f1dd10b73cadf76
Parents: 35e49f0
Author: Hyunsik Choi <hyunsik@apache.org>
Authored: Tue Sep 30 23:14:29 2014 -0700
Committer: Hyunsik Choi <hyunsik@apache.org>
Committed: Tue Sep 30 23:15:08 2014 -0700

----------------------------------------------------------------------
 CHANGES                                         |  2 +
 .../engine/planner/PreLogicalPlanVerifier.java  | 14 ++++
 .../org/apache/tajo/master/GlobalEngine.java    | 21 ++++++
 .../planner/TestPreLogicalPlanVerifier.java     | 74 ++++++++++++++++++++
 4 files changed, 111 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tajo/blob/bccac701/CHANGES
----------------------------------------------------------------------
diff --git a/CHANGES b/CHANGES
index ad9a490..67972e5 100644
--- a/CHANGES
+++ b/CHANGES
@@ -155,6 +155,8 @@ Release 0.9.0 - unreleased
 
   BUG FIXES
 
+    TAJO-962: Column reference used in LIMIT clause incurs NPE.
+
     TAJO-1074: Query calculates wrong progress before subquery init. (jinho)
 
     TAJO-1025: Network disconnection during query processing can cause 

http://git-wip-us.apache.org/repos/asf/tajo/blob/bccac701/tajo-core/src/main/java/org/apache/tajo/engine/planner/PreLogicalPlanVerifier.java
----------------------------------------------------------------------
diff --git a/tajo-core/src/main/java/org/apache/tajo/engine/planner/PreLogicalPlanVerifier.java
b/tajo-core/src/main/java/org/apache/tajo/engine/planner/PreLogicalPlanVerifier.java
index 7f5200d..f6d5540 100644
--- a/tajo-core/src/main/java/org/apache/tajo/engine/planner/PreLogicalPlanVerifier.java
+++ b/tajo-core/src/main/java/org/apache/tajo/engine/planner/PreLogicalPlanVerifier.java
@@ -90,6 +90,20 @@ public class PreLogicalPlanVerifier extends BaseAlgebraVisitor <PreLogicalPlanVe
   }
 
   @Override
+  public Expr visitLimit(Context context, Stack<Expr> stack, Limit expr) throws PlanningException
{
+    stack.push(expr);
+
+    if (ExprFinder.finds(expr.getFetchFirstNum(), OpType.Column).size() > 0) {
+      context.state.addVerification("argument of LIMIT must not contain variables");
+    }
+
+    visit(context, stack, expr.getFetchFirstNum());
+    Expr result = visit(context, stack, expr.getChild());
+    stack.pop();
+    return result;
+  }
+
+  @Override
   public Expr visitGroupBy(Context context, Stack<Expr> stack, Aggregation expr) throws
PlanningException {
     super.visitGroupBy(context, stack, expr);
 

http://git-wip-us.apache.org/repos/asf/tajo/blob/bccac701/tajo-core/src/main/java/org/apache/tajo/master/GlobalEngine.java
----------------------------------------------------------------------
diff --git a/tajo-core/src/main/java/org/apache/tajo/master/GlobalEngine.java b/tajo-core/src/main/java/org/apache/tajo/master/GlobalEngine.java
index 504a792..9612eeb 100644
--- a/tajo-core/src/main/java/org/apache/tajo/master/GlobalEngine.java
+++ b/tajo-core/src/main/java/org/apache/tajo/master/GlobalEngine.java
@@ -18,6 +18,7 @@
 
 package org.apache.tajo.master;
 
+import com.google.common.annotations.VisibleForTesting;
 import com.google.common.base.Preconditions;
 import com.google.protobuf.ByteString;
 import org.apache.commons.logging.Log;
@@ -115,6 +116,26 @@ public class GlobalEngine extends AbstractService {
     super.stop();
   }
 
+  @VisibleForTesting
+  public SQLAnalyzer getAnalyzer() {
+    return analyzer;
+  }
+
+  @VisibleForTesting
+  public PreLogicalPlanVerifier getPreLogicalPlanVerifier() {
+    return preVerifier;
+  }
+
+  @VisibleForTesting
+  public LogicalPlanner getLogicalPlanner() {
+    return planner;
+  }
+
+  @VisibleForTesting
+  public LogicalOptimizer getLogicalOptimizer() {
+    return optimizer;
+  }
+
   private QueryContext createQueryContext(Session session) {
     QueryContext newQueryContext =  new QueryContext(context.getConf(), session);
 

http://git-wip-us.apache.org/repos/asf/tajo/blob/bccac701/tajo-core/src/test/java/org/apache/tajo/engine/planner/TestPreLogicalPlanVerifier.java
----------------------------------------------------------------------
diff --git a/tajo-core/src/test/java/org/apache/tajo/engine/planner/TestPreLogicalPlanVerifier.java
b/tajo-core/src/test/java/org/apache/tajo/engine/planner/TestPreLogicalPlanVerifier.java
new file mode 100644
index 0000000..b009785
--- /dev/null
+++ b/tajo-core/src/test/java/org/apache/tajo/engine/planner/TestPreLogicalPlanVerifier.java
@@ -0,0 +1,74 @@
+/*
+ * Lisensed 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.
+ */
+
+package org.apache.tajo.engine.planner;
+
+import org.apache.tajo.LocalTajoTestingUtility;
+import org.apache.tajo.QueryTestCaseBase;
+import org.apache.tajo.algebra.Expr;
+import org.apache.tajo.engine.parser.SQLAnalyzer;
+import org.apache.tajo.engine.query.QueryContext;
+import org.apache.tajo.master.GlobalEngine;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import static org.junit.Assert.fail;
+
+public class TestPreLogicalPlanVerifier extends QueryTestCaseBase {
+
+  private static SQLAnalyzer analyzer;
+  private static PreLogicalPlanVerifier verifier;
+
+  @BeforeClass
+  public static void setUp() {
+    GlobalEngine engine = testingCluster.getMaster().getContext().getGlobalEngine();
+    analyzer = engine.getAnalyzer();
+    verifier = engine.getPreLogicalPlanVerifier();
+  }
+
+  public static VerificationState verify(String query) throws PlanningException {
+
+    VerificationState state = new VerificationState();
+    QueryContext context = LocalTajoTestingUtility.createDummyContext(conf);
+
+    Expr expr = analyzer.parse(query);
+    verifier.verify(context, state, expr);
+
+    return state;
+  }
+
+  public static void valid(String query) throws PlanningException {
+    VerificationState state = verify(query);
+    if (state.errorMessages.size() > 0) {
+      fail(state.getErrorMessages().get(0));
+    }
+  }
+
+  public static void invalid(String query) throws PlanningException {
+    VerificationState state = verify(query);
+    if (state.errorMessages.size() == 0) {
+      fail(PreLogicalPlanVerifier.class.getSimpleName() + " cannot catch any verification
error: " + query);
+    }
+  }
+
+  @Test
+  public void testLimitWithFieldReference() throws PlanningException {
+    valid("select * from lineitem limit 3");
+    invalid("select * from lineitem limit l_orderkey");
+  }
+}


Mime
View raw message