Uploaded image for project: 'Calcite'
  1. Calcite
  2. CALCITE-1569

Code generation for fields of type java.sql.Date

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 1.10.0
    • Fix Version/s: 1.12.0
    • Component/s: None
    • Labels:
      None

      Description

      Date condition can generates Integer == Integer, which is always false. Therefore a join condition that should match values fails to match them. Run the below query on calcite 1.10.

      select 
        l.cal_dt
        , sum(left_join_gvm) as left_join_sum
        , sum(inner_join_gvm) as inner_join_sum
      from
        (
          select test_kylin_fact.cal_dt, sum(price) as left_join_gvm
           from test_kylin_fact
          group by test_kylin_fact.cal_dt
        ) l
        ,
        (
          select test_kylin_fact.cal_dt, sum(price) as inner_join_gvm
           from test_kylin_fact
          group by test_kylin_fact.cal_dt
        ) i
      where
        l.cal_dt = i.cal_dt    -- this condition
      group by
        l.cal_dt
      

      The where condition generates Baz code like below.

      /* 284 */   final org.apache.calcite.linq4j.AbstractEnumerable child1 = new org.apache.calcite.linq4j.AbstractEnumerable(){
      /* 285 */     public org.apache.calcite.linq4j.Enumerator enumerator() {
      /* 286 */       return new org.apache.calcite.linq4j.Enumerator(){
      /* 287 */           public final org.apache.calcite.linq4j.Enumerator inputEnumerator = _inputEnumerable1.enumerator();
      /* 288 */           public void reset() {
      /* 289 */             inputEnumerator.reset();
      /* 290 */           }
      /* 291 */ 
      /* 292 */           public boolean moveNext() {
      /* 293 */             while (inputEnumerator.moveNext()) {
      /* 294 */               final Object[] current = (Object[]) inputEnumerator.current();
      /* 295 */               final Integer inp0_ = (Integer) current[0];
      /* 296 */               final Integer inp2_ = (Integer) current[2];
      /* 297 */               if (inp0_ != null && inp2_ != null && inp0_ == inp2_) {
      /* 298 */                 return true;
      /* 299 */               }
      /* 300 */             }
      /* 301 */             return false;
      /* 302 */           }
      /* 303 */ 
      /* 304 */           public void close() {
      /* 305 */             inputEnumerator.close();
      /* 306 */           }
      /* 307 */ 
      /* 308 */           public Object current() {
      /* 309 */             final Object[] current = (Object[]) inputEnumerator.current();
      /* 310 */             return new Object[] {
      /* 311 */                 current[0],
      /* 312 */                 current[1],
      /* 313 */                 current[3]};
      /* 314 */           }
      /* 315 */ 
      /* 316 */         };
      /* 317 */     }
      /* 318 */ 
      /* 319 */   };
      

      The problem is

       if (inp0_ != null && inp2_ != null && inp0_ == inp2_) 

      is always false, by using == to compare two Integers.

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                zhenw zhen wang
                Reporter:
                liyang.gmt8@gmail.com liyang
              • Votes:
                0 Vote for this issue
                Watchers:
                5 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: