tajo-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hyun...@apache.org
Subject git commit: TAJO-698: Error occurs when FUNCTION and IN statement are used together.
Date Thu, 27 Mar 2014 02:33:46 GMT
Repository: tajo
Updated Branches:
  refs/heads/branch-0.8.0 ad5059352 -> ecb97d400


TAJO-698: Error occurs when FUNCTION and IN statement are used together.


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

Branch: refs/heads/branch-0.8.0
Commit: ecb97d400082e94e8d261dcfa36f56a184f382cb
Parents: ad50593
Author: Hyunsik Choi <hyunsik@apache.org>
Authored: Mon Mar 24 00:01:07 2014 +0900
Committer: Hyunsik Choi <hyunsik@apache.org>
Committed: Thu Mar 27 11:33:27 2014 +0900

----------------------------------------------------------------------
 CHANGES.txt                                     |  8 ++---
 .../org/apache/tajo/engine/eval/InEval.java     | 32 ++++++++------------
 .../tajo/engine/planner/ExprAnnotator.java      |  5 ++-
 .../apache/tajo/engine/eval/TestPredicates.java | 13 ++++++++
 4 files changed, 31 insertions(+), 27 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/tajo/blob/ecb97d40/CHANGES.txt
----------------------------------------------------------------------
diff --git a/CHANGES.txt b/CHANGES.txt
index b76a6b4..37542ad 100644
--- a/CHANGES.txt
+++ b/CHANGES.txt
@@ -283,6 +283,9 @@ Release 0.8.0 - unreleased
 
   BUG FIXES
 
+    TAJO-698: Error occurs when FUNCTION and IN statement are used together.
+    (hyunsik)
+    
     TAJO-692: Missing Null handling for INET4 in RowStoreUtil. (jihoon)
 
     TAJO-701: Invalid bytes when creating BlobDatum with offset. (jinho)
@@ -561,8 +564,6 @@ Release 0.8.0 - unreleased
 
   TASKS
 
-    TAJO-684: Add functions about time. (Alvin Henrick via jihoon)
-
     TAJO-669: Add cluster setup documentation. (hyunsik)
 
     TAJO-681: Embed sphinx rtd theme into tajo-docs. (hyunsik)
@@ -840,9 +841,6 @@ Release 0.2.0 - released
 
   BUG FIXES
 
-    TAJO-682: RangePartitionAlgorithm should be improved to handle empty
-    texts. (hyunsik)
-
     TAJO-511: Sometimes, a query progress becomes higher than 100%. (jihoon)
 
     TAJO-281: 'mvn package -Pdist' generates duplicate Tajo jar files.

http://git-wip-us.apache.org/repos/asf/tajo/blob/ecb97d40/tajo-core/tajo-core-backend/src/main/java/org/apache/tajo/engine/eval/InEval.java
----------------------------------------------------------------------
diff --git a/tajo-core/tajo-core-backend/src/main/java/org/apache/tajo/engine/eval/InEval.java
b/tajo-core/tajo-core-backend/src/main/java/org/apache/tajo/engine/eval/InEval.java
index 189e9dd..51097e6 100644
--- a/tajo-core/tajo-core-backend/src/main/java/org/apache/tajo/engine/eval/InEval.java
+++ b/tajo-core/tajo-core-backend/src/main/java/org/apache/tajo/engine/eval/InEval.java
@@ -19,23 +19,26 @@
 package org.apache.tajo.engine.eval;
 
 
+import com.google.common.collect.Sets;
 import com.google.gson.annotations.Expose;
 import org.apache.tajo.catalog.CatalogUtil;
 import org.apache.tajo.catalog.Schema;
 import org.apache.tajo.common.TajoDataTypes;
 import org.apache.tajo.datum.Datum;
 import org.apache.tajo.datum.DatumFactory;
+import org.apache.tajo.datum.NullDatum;
 import org.apache.tajo.storage.Tuple;
 
+import java.util.Set;
+
 public class InEval extends BinaryEval {
   private static final TajoDataTypes.DataType RES_TYPE = CatalogUtil.newSimpleDataType(TajoDataTypes.Type.BOOLEAN);
 
   @Expose private boolean not;
-  private Integer fieldId = null;
-  Datum [] values;
+  Set<Datum> values;
 
-  public InEval(FieldEval columnRef, RowConstantEval valueList, boolean not) {
-    super(EvalType.IN, columnRef, valueList);
+  public InEval(EvalNode lhs, RowConstantEval valueList, boolean not) {
+    super(EvalType.IN, lhs, valueList);
     this.not = not;
   }
 
@@ -55,26 +58,17 @@ public class InEval extends BinaryEval {
 
   @Override
   public Datum eval(Schema schema, Tuple tuple) {
-    if (fieldId == null) {
-      fieldId = schema.getColumnId(((FieldEval)leftExpr).getColumnRef().getQualifiedName());
-      values = ((RowConstantEval)rightExpr).getValues();
+    if (values == null) {
+      values = Sets.newHashSet(((RowConstantEval)rightExpr).getValues());
     }
 
-    Datum value = tuple.get(fieldId);
-
-    if (value.isNull()) {
-      return value;
-    }
+    Datum leftValue = leftExpr.eval(schema, tuple);
 
-    boolean isIncluded = false;
-    for (Datum datum : values) {
-      if (value.equalsTo(datum).asBool()) {
-        isIncluded = true;
-        break;
-      }
+    if (leftValue.isNull()) {
+      return NullDatum.get();
     }
 
-    return DatumFactory.createBool(not ^ isIncluded);
+    return DatumFactory.createBool(not ^ values.contains(leftValue));
   }
 
   @Override

http://git-wip-us.apache.org/repos/asf/tajo/blob/ecb97d40/tajo-core/tajo-core-backend/src/main/java/org/apache/tajo/engine/planner/ExprAnnotator.java
----------------------------------------------------------------------
diff --git a/tajo-core/tajo-core-backend/src/main/java/org/apache/tajo/engine/planner/ExprAnnotator.java
b/tajo-core/tajo-core-backend/src/main/java/org/apache/tajo/engine/planner/ExprAnnotator.java
index 4c2118e..3d09597 100644
--- a/tajo-core/tajo-core-backend/src/main/java/org/apache/tajo/engine/planner/ExprAnnotator.java
+++ b/tajo-core/tajo-core-backend/src/main/java/org/apache/tajo/engine/planner/ExprAnnotator.java
@@ -212,11 +212,10 @@ public class ExprAnnotator extends BaseAlgebraVisitor<ExprAnnotator.Context,
Eva
   @Override
   public EvalNode visitInPredicate(Context ctx, Stack<Expr> stack, InPredicate expr)
throws PlanningException {
     stack.push(expr);
-    Column predicandColumn = ctx.plan.resolveColumn(ctx.currentBlock, (ColumnReferenceExpr)
expr.getPredicand());
-    FieldEval predicand = new FieldEval(predicandColumn);
+    EvalNode lhs = visit(ctx, stack, expr.getLeft());
     RowConstantEval rowConstantEval = (RowConstantEval) visit(ctx, stack, expr.getInValue());
     stack.pop();
-    return new InEval(predicand, rowConstantEval, expr.isNot());
+    return new InEval(lhs, rowConstantEval, expr.isNot());
   }
 
   @Override

http://git-wip-us.apache.org/repos/asf/tajo/blob/ecb97d40/tajo-core/tajo-core-backend/src/test/java/org/apache/tajo/engine/eval/TestPredicates.java
----------------------------------------------------------------------
diff --git a/tajo-core/tajo-core-backend/src/test/java/org/apache/tajo/engine/eval/TestPredicates.java
b/tajo-core/tajo-core-backend/src/test/java/org/apache/tajo/engine/eval/TestPredicates.java
index b10f2df..db5cfc7 100644
--- a/tajo-core/tajo-core-backend/src/test/java/org/apache/tajo/engine/eval/TestPredicates.java
+++ b/tajo-core/tajo-core-backend/src/test/java/org/apache/tajo/engine/eval/TestPredicates.java
@@ -286,6 +286,19 @@ public class TestPredicates extends ExprTestBase {
     testEval(schema2, "table1", "a,b,c", "select col1 in ('a'), col2 in ('a', 'c') from table1",
new String[]{"t","f"});
     testEval(schema2, "table1", "a,,c", "select col1 in ('a','b','c'), (col2 in ('a', 'c'))
is null from table1",
         new String[]{"t","t"});
+
+    testEval(schema2,
+        "table1",
+        "2014-03-21,2015-04-01,2016-04-01",
+        "select substr(col1,1,4) in ('2014','2015','2016'), substr(col1,6,2)::int4 in (1,2,3)
from table1",
+        new String[]{"t", "t"});
+
+    // null handling test
+    testEval(schema2,
+        "table1",
+        "2014-03-21,,2015-04-01",
+        "select (substr(col2,1,4)::int4 in (2014,2015,2016)) is null from table1",
+        new String[]{"t"});
   }
 
   //////////////////////////////////////////////////////////////////


Mime
View raw message