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.


---

Reply via email to