You are viewing a plain text version of this content. The canonical link for it is here.
Posted to codereview@trafodion.apache.org by zlei929 <gi...@git.apache.org> on 2018/07/23 01:37:12 UTC

[GitHub] trafodion pull request #1658: [TRAFODION-3155] implemented the OVERLAPS pred...

GitHub user zlei929 opened a pull request:

    https://github.com/apache/trafodion/pull/1658

    [TRAFODION-3155] implemented the OVERLAPS predicate.

    

You can merge this pull request into a Git repository by running:

    $ git pull https://github.com/zlei929/trafodion TRAFODION-3155

Alternatively you can review and apply these changes as the patch at:

    https://github.com/apache/trafodion/pull/1658.patch

To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:

    This closes #1658
    
----
commit d24805b21ed87a1696325fa8c8521c24bef20936
Author: zlei929 <z_...@...>
Date:   2018-07-20T02:20:40Z

    	modified:   core/sql/parser/sqlparser.y
    	modified:   core/sql/regress/qat/eqatdml03
    	modified:   core/sql/regress/qat/qatdml03

----


---

[GitHub] trafodion pull request #1658: [TRAFODION-3155] implemented the OVERLAPS pred...

Posted by zlei929 <gi...@git.apache.org>.
Github user zlei929 commented on a diff in the pull request:

    https://github.com/apache/trafodion/pull/1658#discussion_r204984946
  
    --- Diff: core/sql/parser/sqlparser.y ---
    @@ -19430,6 +19432,124 @@ exists_predicate : TOK_EXISTS rel_subquery
     				  $$ = new (PARSERHEAP()) Exists($2);
     				}
     
    +overlaps_predicate : value_expression_list_paren TOK_OVERLAPS value_expression_list_paren
    +         {
    +            ItemExprList  exprList1($1, PARSERHEAP());
    +            ItemExprList  exprList2($3, PARSERHEAP());
    +            //Syntax Rules: 
    +            //  1) The degrees of <row value predicand 1> and <row value predicand 2> shall both be 2.
    +            if ((exprList1.entries() != 2)
    +                  || (exprList1.entries() != exprList2.entries()))
    +              {
    +                 *SqlParser_Diags << DgSqlCode(-4077)
    +                     << DgString0("OVERLAPS");
    +                 YYERROR;  // CHANGE TO YYABORT
    +              }
    +
    +            ItemExpr *D1 = (*$1)[0];
    +            ItemExpr *E1 = (*$1)[1];
    +            ItemExpr *D2 = (*$3)[0];
    +            ItemExpr *E2 = (*$3)[1];
    +
    +            NABoolean negate = FALSE;
    +            ItemExpr *tmpItemExpr = E1;
    --- End diff --
    
    Yes, @DaveBirdsall,  Thanks for your reminding, i will changed this.


---

[GitHub] trafodion pull request #1658: [TRAFODION-3155] implemented the OVERLAPS pred...

Posted by DaveBirdsall <gi...@git.apache.org>.
Github user DaveBirdsall commented on a diff in the pull request:

    https://github.com/apache/trafodion/pull/1658#discussion_r206907388
  
    --- Diff: core/sql/generator/GenPreCode.cpp ---
    @@ -7518,6 +7518,53 @@ ItemExpr * AggrMinMax::preCodeGen(Generator * generator)
       return this;
     } // AggrMinMax::preCodeGen()
     
    +ItemExpr *Overlaps::preCodeGen(Generator *generator)
    +{
    +  if (nodeIsPreCodeGenned())
    +    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));
    +
    +        child(i)->bindNode(generator->getBindWA());
    +      }
    +
    +    }
    +  }
    +
    +  ItemExpr *newExpr = 
    +    generator->getExpGenerator()->createExprTree(
    --- End diff --
    
    I agree with @zellerh on the interpretation of the standard.


---

[GitHub] trafodion pull request #1658: [TRAFODION-3155] implemented the OVERLAPS pred...

Posted by zellerh <gi...@git.apache.org>.
Github user zellerh commented on a diff in the pull request:

    https://github.com/apache/trafodion/pull/1658#discussion_r206707222
  
    --- Diff: core/sql/optimizer/ItemExpr.cpp ---
    @@ -11971,6 +11971,43 @@ Exists::copyTopNode(ItemExpr *derivedNode, CollHeap* outHeap)
     // <aviv> END
     
     
    +// --------------------------------------------------------------
    +// member functions for Overlaps operator
    +// --------------------------------------------------------------
    +ItemExpr * Overlaps::copyTopNode(ItemExpr *derivedNode, CollHeap* outHeap)
    +{
    +  ItemExpr *result;
    +  if (derivedNode == NULL)
    +    result = new (outHeap) Overlaps(child(0), child(1), child(2), child(3));
    +  else
    +    result - derivedNode;
    +
    +  return BuiltinFunction::copyTopNode(result, outHeap);
    --- End diff --
    
    This should call CacheableBuiltinFunction::copyTopNode().


---

[GitHub] trafodion pull request #1658: [TRAFODION-3155] implemented the OVERLAPS pred...

Posted by zellerh <gi...@git.apache.org>.
Github user zellerh commented on a diff in the pull request:

    https://github.com/apache/trafodion/pull/1658#discussion_r206737740
  
    --- Diff: core/sql/generator/GenPreCode.cpp ---
    @@ -7518,6 +7518,53 @@ ItemExpr * AggrMinMax::preCodeGen(Generator * generator)
       return this;
     } // AggrMinMax::preCodeGen()
     
    +ItemExpr *Overlaps::preCodeGen(Generator *generator)
    +{
    +  if (nodeIsPreCodeGenned())
    +    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));
    +
    +        child(i)->bindNode(generator->getBindWA());
    +      }
    +
    +    }
    +  }
    +
    +  ItemExpr *newExpr = 
    +    generator->getExpGenerator()->createExprTree(
    --- End diff --
    
    Hi, @zlei929, it is interesting that the standard says this in General Rule 1:
    
    > If the value of <row value predicand 1> is the null value or the value of <row value predicand 2> is the null value, then the result of the <overlaps predicate> is Unknown and no further General Rules of this Subclause are applied.
    
    That sounds like any null value would immediately return a null result, but the other general rules very carefully describe what happens with null values. Therefore, I think this first rule only applies if the value passed in is ```(null, null)```. Maybe others can comment as well on whether that makes sense.


---

[GitHub] trafodion pull request #1658: [TRAFODION-3155] implemented the OVERLAPS pred...

Posted by zlei929 <gi...@git.apache.org>.
Github user zlei929 commented on a diff in the pull request:

    https://github.com/apache/trafodion/pull/1658#discussion_r206800295
  
    --- Diff: core/sql/generator/GenPreCode.cpp ---
    @@ -7518,6 +7518,53 @@ ItemExpr * AggrMinMax::preCodeGen(Generator * generator)
       return this;
     } // AggrMinMax::preCodeGen()
     
    +ItemExpr *Overlaps::preCodeGen(Generator *generator)
    +{
    +  if (nodeIsPreCodeGenned())
    +    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));
    +
    +        child(i)->bindNode(generator->getBindWA());
    +      }
    +
    +    }
    +  }
    +
    +  ItemExpr *newExpr = 
    +    generator->getExpGenerator()->createExprTree(
    --- End diff --
    
    The new changes are belong to this problem, and anther question is the tests already include NULL value test, it's just that I didn't realize the result was wrong.   so i only  changed the expected result of tests.


---

[GitHub] trafodion pull request #1658: [TRAFODION-3155] implemented the OVERLAPS pred...

Posted by zlei929 <gi...@git.apache.org>.
Github user zlei929 commented on a diff in the pull request:

    https://github.com/apache/trafodion/pull/1658#discussion_r206758851
  
    --- Diff: core/sql/generator/GenPreCode.cpp ---
    @@ -7518,6 +7518,53 @@ ItemExpr * AggrMinMax::preCodeGen(Generator * generator)
       return this;
     } // AggrMinMax::preCodeGen()
     
    +ItemExpr *Overlaps::preCodeGen(Generator *generator)
    +{
    +  if (nodeIsPreCodeGenned())
    +    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));
    +
    +        child(i)->bindNode(generator->getBindWA());
    +      }
    +
    +    }
    +  }
    +
    +  ItemExpr *newExpr = 
    +    generator->getExpGenerator()->createExprTree(
    --- End diff --
    
    Hi, @zellerh  May be you are right, i tried to test it on PostgreSql and here is the result:
    ```
    postgres=# select 1 from t2 where (date'2000-01-01', date'2000-01-03') overlaps (date'2000-01-02', null);
     ?column? 
    ----------
            1
    (1 row)
    
    postgres=# 
    ```



---

[GitHub] trafodion pull request #1658: [TRAFODION-3155] implemented the OVERLAPS pred...

Posted by DaveBirdsall <gi...@git.apache.org>.
Github user DaveBirdsall commented on a diff in the pull request:

    https://github.com/apache/trafodion/pull/1658#discussion_r204855585
  
    --- Diff: core/sql/parser/sqlparser.y ---
    @@ -19430,6 +19432,124 @@ exists_predicate : TOK_EXISTS rel_subquery
     				  $$ = new (PARSERHEAP()) Exists($2);
     				}
     
    +overlaps_predicate : value_expression_list_paren TOK_OVERLAPS value_expression_list_paren
    +         {
    +            ItemExprList  exprList1($1, PARSERHEAP());
    +            ItemExprList  exprList2($3, PARSERHEAP());
    +            //Syntax Rules: 
    +            //  1) The degrees of <row value predicand 1> and <row value predicand 2> shall both be 2.
    +            if ((exprList1.entries() != 2)
    +                  || (exprList1.entries() != exprList2.entries()))
    +              {
    +                 *SqlParser_Diags << DgSqlCode(-4077)
    --- End diff --
    
    This is OK to have in the Parser, as it depends only on syntax.


---

[GitHub] trafodion pull request #1658: [TRAFODION-3155] implemented the OVERLAPS pred...

Posted by DaveBirdsall <gi...@git.apache.org>.
Github user DaveBirdsall commented on a diff in the pull request:

    https://github.com/apache/trafodion/pull/1658#discussion_r206722914
  
    --- Diff: core/sql/generator/GenPreCode.cpp ---
    @@ -7518,6 +7518,53 @@ ItemExpr * AggrMinMax::preCodeGen(Generator * generator)
       return this;
     } // AggrMinMax::preCodeGen()
     
    +ItemExpr *Overlaps::preCodeGen(Generator *generator)
    +{
    +  if (nodeIsPreCodeGenned())
    +    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));
    +
    +        child(i)->bindNode(generator->getBindWA());
    +      }
    +
    +    }
    +  }
    +
    +  ItemExpr *newExpr = 
    +    generator->getExpGenerator()->createExprTree(
    --- End diff --
    
    @zellerh, just wanted to check the analysis. I would have thought 2 > 1 and not (2 >=3 and null >= 3) becomes 2 > 1 and not (true and null) which becomes 2 > 1 and not (null) which becomes 2 > 1 and null which becomes true and null which becomes null. So I didn't follow why you thought this evaluates to TRUE. What error am I making?


---

[GitHub] trafodion pull request #1658: [TRAFODION-3155] implemented the OVERLAPS pred...

Posted by zellerh <gi...@git.apache.org>.
Github user zellerh commented on a diff in the pull request:

    https://github.com/apache/trafodion/pull/1658#discussion_r206725352
  
    --- Diff: core/sql/generator/GenPreCode.cpp ---
    @@ -7518,6 +7518,53 @@ ItemExpr * AggrMinMax::preCodeGen(Generator * generator)
       return this;
     } // AggrMinMax::preCodeGen()
     
    +ItemExpr *Overlaps::preCodeGen(Generator *generator)
    +{
    +  if (nodeIsPreCodeGenned())
    +    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));
    +
    +        child(i)->bindNode(generator->getBindWA());
    +      }
    +
    +    }
    +  }
    +
    +  ItemExpr *newExpr = 
    +    generator->getExpGenerator()->createExprTree(
    --- End diff --
    
    These formulas are hard to figure out. I thought this would be "2 > 1 and not ( false and null )".


---

[GitHub] trafodion pull request #1658: [TRAFODION-3155] implemented the OVERLAPS pred...

Posted by DaveBirdsall <gi...@git.apache.org>.
Github user DaveBirdsall commented on a diff in the pull request:

    https://github.com/apache/trafodion/pull/1658#discussion_r206726135
  
    --- Diff: core/sql/generator/GenPreCode.cpp ---
    @@ -7518,6 +7518,53 @@ ItemExpr * AggrMinMax::preCodeGen(Generator * generator)
       return this;
     } // AggrMinMax::preCodeGen()
     
    +ItemExpr *Overlaps::preCodeGen(Generator *generator)
    +{
    +  if (nodeIsPreCodeGenned())
    +    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));
    +
    +        child(i)->bindNode(generator->getBindWA());
    +      }
    +
    +    }
    +  }
    +
    +  ItemExpr *newExpr = 
    +    generator->getExpGenerator()->createExprTree(
    --- End diff --
    
    Indeed! I see my error. Thanks.


---

[GitHub] trafodion pull request #1658: [TRAFODION-3155] implemented the OVERLAPS pred...

Posted by zlei929 <gi...@git.apache.org>.
Github user zlei929 commented on a diff in the pull request:

    https://github.com/apache/trafodion/pull/1658#discussion_r206795424
  
    --- Diff: core/sql/generator/GenPreCode.cpp ---
    @@ -7518,6 +7518,98 @@ ItemExpr * AggrMinMax::preCodeGen(Generator * generator)
       return this;
     } // AggrMinMax::preCodeGen()
     
    +ItemExpr *Overlaps::preCodeGen(Generator *generator)
    +{
    +  if (nodeIsPreCodeGenned())
    +    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));
    +
    +              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());
    +
    +
    --- End diff --
    
    This time i‘m strictly in accordance with the ANSI standard to implement the OVERLAPS predicate. maybe that would be easier to understand than the logic that preceded it.


---

[GitHub] trafodion pull request #1658: [TRAFODION-3155] implemented the OVERLAPS pred...

Posted by zellerh <gi...@git.apache.org>.
Github user zellerh commented on a diff in the pull request:

    https://github.com/apache/trafodion/pull/1658#discussion_r206719109
  
    --- Diff: core/sql/generator/GenPreCode.cpp ---
    @@ -7518,6 +7518,53 @@ ItemExpr * AggrMinMax::preCodeGen(Generator * generator)
       return this;
     } // AggrMinMax::preCodeGen()
     
    +ItemExpr *Overlaps::preCodeGen(Generator *generator)
    +{
    +  if (nodeIsPreCodeGenned())
    +    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));
    +
    +        child(i)->bindNode(generator->getBindWA());
    +      }
    +
    +    }
    +  }
    +
    +  ItemExpr *newExpr = 
    +    generator->getExpGenerator()->createExprTree(
    --- End diff --
    
    When I look at the ANSI/ISO standard, it has some cases where the OVERLAPS predicate returns TRUE, even though some of the values are NULL. Example: ```(date '2000-01-01', date '2000-01-03') overlaps (date '2000-01-02', cast(null as date))``` should return TRUE, as far as I understand the General Rules:
    
    - S1: 1-01
    - T1: 1-03
    - S2: 1-02
    - T2: null
    
    So, the predicate ```S2 > S1 and not ( S2 >= T1 and T2 >= T1 )``` becomes ``` 2 > 1 and not ( 2 >= 3 and null >= 3)``` which is TRUE.
    
    I don't think the formula below would ever return TRUE if any of the 4 arguments were NULL.


---

[GitHub] trafodion pull request #1658: [TRAFODION-3155] implemented the OVERLAPS pred...

Posted by zlei929 <gi...@git.apache.org>.
Github user zlei929 commented on a diff in the pull request:

    https://github.com/apache/trafodion/pull/1658#discussion_r206735360
  
    --- Diff: core/sql/generator/GenPreCode.cpp ---
    @@ -7518,6 +7518,53 @@ ItemExpr * AggrMinMax::preCodeGen(Generator * generator)
       return this;
     } // AggrMinMax::preCodeGen()
     
    +ItemExpr *Overlaps::preCodeGen(Generator *generator)
    +{
    +  if (nodeIsPreCodeGenned())
    +    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));
    +
    +        child(i)->bindNode(generator->getBindWA());
    +      }
    +
    +    }
    +  }
    +
    +  ItemExpr *newExpr = 
    +    generator->getExpGenerator()->createExprTree(
    --- End diff --
    
    @zellerh Thanks for your reminding. Before see your comments, i've always thought that the result of any expression that contains a null value should be null, and also implemented the OVERLAPS predicate with this view.  This seems to be wrong,  and i will fixed this issue later. Sincerely thanks again~!


---

[GitHub] trafodion pull request #1658: [TRAFODION-3155] implemented the OVERLAPS pred...

Posted by asfgit <gi...@git.apache.org>.
Github user asfgit closed the pull request at:

    https://github.com/apache/trafodion/pull/1658


---

[GitHub] trafodion pull request #1658: [TRAFODION-3155] implemented the OVERLAPS pred...

Posted by DaveBirdsall <gi...@git.apache.org>.
Github user DaveBirdsall commented on a diff in the pull request:

    https://github.com/apache/trafodion/pull/1658#discussion_r204855399
  
    --- Diff: core/sql/parser/sqlparser.y ---
    @@ -19430,6 +19432,124 @@ exists_predicate : TOK_EXISTS rel_subquery
     				  $$ = new (PARSERHEAP()) Exists($2);
     				}
     
    +overlaps_predicate : value_expression_list_paren TOK_OVERLAPS value_expression_list_paren
    +         {
    +            ItemExprList  exprList1($1, PARSERHEAP());
    +            ItemExprList  exprList2($3, PARSERHEAP());
    +            //Syntax Rules: 
    +            //  1) The degrees of <row value predicand 1> and <row value predicand 2> shall both be 2.
    +            if ((exprList1.entries() != 2)
    +                  || (exprList1.entries() != exprList2.entries()))
    +              {
    +                 *SqlParser_Diags << DgSqlCode(-4077)
    +                     << DgString0("OVERLAPS");
    +                 YYERROR;  // CHANGE TO YYABORT
    +              }
    +
    +            ItemExpr *D1 = (*$1)[0];
    +            ItemExpr *E1 = (*$1)[1];
    +            ItemExpr *D2 = (*$3)[0];
    +            ItemExpr *E2 = (*$3)[1];
    +
    +            NABoolean negate = FALSE;
    +            ItemExpr *tmpItemExpr = E1;
    --- End diff --
    
    This logic should be in the Binder, not in the Parser. The Parser does not know the datatypes of anything except constants. And I don't think you want to limit OVERLAPS to operating only on constants.


---

[GitHub] trafodion pull request #1658: [TRAFODION-3155] implemented the OVERLAPS pred...

Posted by zlei929 <gi...@git.apache.org>.
Github user zlei929 commented on a diff in the pull request:

    https://github.com/apache/trafodion/pull/1658#discussion_r206795654
  
    --- Diff: core/sql/generator/GenPreCode.cpp ---
    @@ -7518,6 +7518,98 @@ ItemExpr * AggrMinMax::preCodeGen(Generator * generator)
       return this;
     } // AggrMinMax::preCodeGen()
     
    +ItemExpr *Overlaps::preCodeGen(Generator *generator)
    +{
    +  if (nodeIsPreCodeGenned())
    +    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));
    +
    +              child(i)->bindNode(generator->getBindWA());
    +            }
    +        }
    +    }
    +
    --- End diff --
    
    This time i‘m strictly in accordance with the ANSI standard to implement the OVERLAPS predicate. maybe that would be easier to understand than the logic that preceded it.


---