modified:   core/sql/generator/GenPreCode.cpp
        modified:   core/sql/optimizer/ItemExpr.cpp
        modified:   core/sql/regress/qat/eqatdml03


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

Branch: refs/heads/master
Commit: 5f09acdad81b8a70af70218d79a63908f2d36ea1
Parents: ad74d25
Author: zlei929 <z_lei...@163.com>
Authored: Wed Aug 1 15:54:54 2018 +0800
Committer: zlei929 <z_lei...@163.com>
Committed: Wed Aug 1 15:54:54 2018 +0800

----------------------------------------------------------------------
 core/sql/generator/GenPreCode.cpp | 95 +++++++++++++++++++++++++---------
 core/sql/optimizer/ItemExpr.cpp   |  2 +-
 core/sql/regress/qat/eqatdml03    |  6 ++-
 3 files changed, 75 insertions(+), 28 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/trafodion/blob/5f09acda/core/sql/generator/GenPreCode.cpp
----------------------------------------------------------------------
diff --git a/core/sql/generator/GenPreCode.cpp 
b/core/sql/generator/GenPreCode.cpp
index d12af33..b8f5028 100644
--- a/core/sql/generator/GenPreCode.cpp
+++ b/core/sql/generator/GenPreCode.cpp
@@ -7524,39 +7524,84 @@ ItemExpr *Overlaps::preCodeGen(Generator *generator)
     return getReplacementExpr();
 
   for (Int32 i = 0; i < getArity(); ++i)
-  {
-    if (child(i)) 
     {
-      const NAType &type = 
-        child(i)->getValueId().getType();
-      const DatetimeType *operand = (DatetimeType *)&type;
-
-      if (type.getTypeQualifier() == NA_DATETIME_TYPE
-            && (operand->getPrecision() == SQLDTCODE_DATE))
-      {
-        child(i) = new (generator->wHeap()) 
-          Cast(child(i), new (generator->wHeap()) 
-              SQLTimestamp(generator->wHeap(), TRUE));
+      if (child(i)) 
+        {
+          const NAType &type = 
+            child(i)->getValueId().getType();
+          const DatetimeType *operand = (DatetimeType *)&type;
 
-        child(i)->bindNode(generator->getBindWA());
-      }
+          if (type.getTypeQualifier() == NA_DATETIME_TYPE
+                 && (operand->getPrecision() == SQLDTCODE_DATE))
+            {
+              child(i) = new (generator->wHeap()) 
+                Cast(child(i), new (generator->wHeap()) 
+                     SQLTimestamp(generator->wHeap(), TRUE));
 
+              child(i)->bindNode(generator->getBindWA());
+            }
+        }
     }
-  }
+
+  //General Rules:
+  //1) ... 2) ... 3) ... 
+  //4) if D1(child(0)) is the null value or if E1(child(1))<D1,
+  //   then let S1 = E1 and let T1 = D1.
+  //   Otherwise, let S1 = D1 and let T1 = E1.
+  //
+  ItemExpr *S1 = NULL;
+  ItemExpr *T1 = NULL;
+  S1 = generator->getExpGenerator()->createExprTree(
+      "CASE WHEN (@A2<@A1 OR @A1 IS NULL) THEN @A2 ELSE @A1 END"
+      , 0
+      , 2
+      , child(0), child(1)); 
+  T1 = generator->getExpGenerator()->createExprTree(
+      "CASE WHEN (@A2<@A1 OR @A1 IS NULL) THEN @A1 ELSE @A2 END"
+      , 0
+      , 2
+      , child(0), child(1));
+
+  child(0) = S1->bindNode(generator->getBindWA());
+  child(1) = T1->bindNode(generator->getBindWA());
+
+
+  //General Rules:
+  //1) ... 2) ... 3) ... 4) ... 5) ...
+  //6) if D2(child(2)) is the null value or if E2(child(3))<D2,
+  //   then let S2 = E2 and let T2 = D2.
+  //   Otherwise, let S2 = D2 and let T2 = E2.
+  //
+  ItemExpr *S2 = NULL;
+  ItemExpr *T2 = NULL;
+  S2 = generator->getExpGenerator()->createExprTree(
+      "CASE WHEN (@A2<@A1 OR @A1 IS NULL) THEN @A2 ELSE @A1 END"
+      , 0
+      , 2
+      , child(2), child(3)); 
+  T2 = generator->getExpGenerator()->createExprTree(
+      "CASE WHEN (@A2<@A1 OR @A1 IS NULL) THEN @A1 ELSE @A2 END"
+      , 0
+      , 2
+      , child(2), child(3));
+
+  child(2) = S2->bindNode(generator->getBindWA());
+  child(3) = T2->bindNode(generator->getBindWA());
 
   ItemExpr *newExpr = 
     generator->getExpGenerator()->createExprTree(
-        "(@A1<@A2 AND @A3<@A4 AND ((@A2>@A3 AND @A2<=@A4) OR (@A4>@A1 AND 
@A4<=@A2))) OR"
-        "(@A1<@A2 AND @A3>@A4 AND ((@A2>@A4 AND @A2<=@A3) OR (@A3>@A1 AND 
@A3<=@A2))) OR"
-        "(@A1<@A2 AND @A3=@A4 AND (@A3>=@A1 AND @A3<@A2)) OR"
-        "(@A1=@A2 AND @A3<@A4 AND (@A1>=@A3 AND @A1<@A4)) OR"
-        "(@A1=@A2 AND @A3>@A4 AND (@A1>=@A4 AND @A1<@A3)) OR"
-        "(@A1=@A2 AND @A3=@A4 AND  @A1=@A3) OR"
-        "(@A1>@A2 AND @A3>@A4 AND ((@A1>@A4 AND @A1<=@A3) OR (@A3>@A2 AND 
@A3<=@A1)))OR"
-        "(@A1>@A2 AND @A3=@A4 AND (@A3>=@A2 AND @A3<@A1)) OR"
-        "(@A1>@A2 AND @A3<@A4 AND ((@A1>@A3 AND @A1<=@A4) OR (@A4>@A2 AND 
@A4<=@A1)))"
+  //General Rules:
+  //1) ... 2) ... 3) ... 4) ... 5) ... 6) ...
+  //7) The result of the <overlaps predicate> is 
+  //   the result of the following expression:
+        "(@A1 > @A3 AND NOT (@A1 >= @A4 AND @A2 >= @A4))"
+        " OR "
+        "(@A3 > @A1 AND NOT (@A3 >= @A2 AND @A4 >= @A2))"
+        " OR "
+        "(@A1 = @A3 AND (@A2 <> @A4 OR @A2=@A4))"
         , 0
-        , 4, child(0), child(1), child(2), child(3));
+        , 4
+        , child(0), child(1), child(2), child(3));
 
   newExpr->bindNode(generator->getBindWA());
   setReplacementExpr(newExpr->preCodeGen(generator));

http://git-wip-us.apache.org/repos/asf/trafodion/blob/5f09acda/core/sql/optimizer/ItemExpr.cpp
----------------------------------------------------------------------
diff --git a/core/sql/optimizer/ItemExpr.cpp b/core/sql/optimizer/ItemExpr.cpp
index fff5607..7ae9b9d 100644
--- a/core/sql/optimizer/ItemExpr.cpp
+++ b/core/sql/optimizer/ItemExpr.cpp
@@ -11982,7 +11982,7 @@ ItemExpr * Overlaps::copyTopNode(ItemExpr *derivedNode, 
CollHeap* outHeap)
   else
     result - derivedNode;
 
-  return BuiltinFunction::copyTopNode(result, outHeap);
+  return CacheableBuiltinFunction::copyTopNode(result, outHeap);
 }
 
 void Overlaps::unparse(NAString &result

http://git-wip-us.apache.org/repos/asf/trafodion/blob/5f09acda/core/sql/regress/qat/eqatdml03
----------------------------------------------------------------------
diff --git a/core/sql/regress/qat/eqatdml03 b/core/sql/regress/qat/eqatdml03
index cee285d..048bc98 100755
--- a/core/sql/regress/qat/eqatdml03
+++ b/core/sql/regress/qat/eqatdml03
@@ -2529,6 +2529,7 @@ COL_DATE
 ----------
 
 2018-02-03
+?
 1997-05-13
 1988-08-17
 2017-09-29
@@ -2536,7 +2537,7 @@ COL_DATE
 2010-07-27
 2018-02-03
 
---- 7 row(s) selected.
+--- 8 row(s) selected.
 >>
 >>--    <ufi-input>
 >>      select col_date
@@ -2749,9 +2750,10 @@ COL_TIME  COL_HTOS
 --------  ----------------
 
 02:23:00    1:02:03.000000
+03:53:00    ?
 04:26:10    1:02:03.000000
 
---- 2 row(s) selected.
+--- 3 row(s) selected.
 >>
 >>--    <comment> hybird test
 >>--    <ufi-input>

Reply via email to