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

Fast-path for EnumerableCalc in case of trivial program

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Duplicate
    • None
    • 1.0.0-incubating
    • None

    Description

      It looks like in case when row type differs just in the column names, enumerable is still processed.

      JdbcTest.testInnerJoinValues, ...SELECT * FROM (VALUES (10, 'SameName')) AS t (id, desc)...
      Note how input "VALUES" is passed through custom enumerable that has no meaning.
      This should be optimized.

      /*   5 */   final org.apache.calcite.linq4j.Enumerable _inputEnumerable = org.apache.calcite.linq4j.Linq4j.asEnumerable(new Object[] {
      /*   6 */     new Object[] {
      /*   7 */       10,
      /*   8 */       "SameName"}});
      ...
      /*  25 */           public Object current() {
      /*  26 */             final Object[] current = (Object[]) inputEnumerator.current();
      /*  27 */             return new Object[] {
      /*  28 */                 current[0],
      /*  29 */                 current[1]};
      /*  30 */           }
      

      Full code

      /*   1 */ org.apache.calcite.DataContext root;
      /*   2 */ 
      /*   3 */ public org.apache.calcite.linq4j.Enumerable bind(final org.apache.calcite.DataContext root0) {
      /*   4 */   root = root0;
      /*   5 */   final org.apache.calcite.linq4j.Enumerable _inputEnumerable = org.apache.calcite.linq4j.Linq4j.asEnumerable(new Object[] {
      /*   6 */     new Object[] {
      /*   7 */       10,
      /*   8 */       "SameName"}});
      /*   9 */   final org.apache.calcite.linq4j.AbstractEnumerable left = new org.apache.calcite.linq4j.AbstractEnumerable(){
      /*  10 */     public org.apache.calcite.linq4j.Enumerator enumerator() {
      /*  11 */       return new org.apache.calcite.linq4j.Enumerator(){
      /*  12 */           public final org.apache.calcite.linq4j.Enumerator inputEnumerator = _inputEnumerable.enumerator();
      /*  13 */           public void reset() {
      /*  14 */             inputEnumerator.reset();
      /*  15 */           }
      /*  16 */ 
      /*  17 */           public boolean moveNext() {
      /*  18 */             return inputEnumerator.moveNext();
      /*  19 */           }
      /*  20 */ 
      /*  21 */           public void close() {
      /*  22 */             inputEnumerator.close();
      /*  23 */           }
      /*  24 */ 
      /*  25 */           public Object current() {
      /*  26 */             final Object[] current = (Object[]) inputEnumerator.current();
      /*  27 */             return new Object[] {
      /*  28 */                 current[0],
      /*  29 */                 current[1]};
      /*  30 */           }
      /*  31 */ 
      /*  32 */         };
      /*  33 */     }
      /*  34 */ 
      /*  35 */   };
      /*  36 */   final org.apache.calcite.linq4j.Enumerable _inputEnumerable0 = left.join(org.apache.calcite.linq4j.Linq4j.asEnumerable(((org.apache.calcite.test.JdbcTest.LingualSchema) ((org.apache.calcite.adapter.java.ReflectiveSchema) root.getRootSchema().getSubSchema("SALES").unwrap(org.apache.calcite.adapter.java.ReflectiveSchema.class)).getTarget()).EMPS), new org.apache.calcite.linq4j.function.Function1() {
      /*  37 */     public java.util.List apply(Object[] v1) {
      /*  38 */       return java.util.Collections.EMPTY_LIST;
      /*  39 */     }
      /*  40 */     public Object apply(Object v1) {
      /*  41 */       return apply(
      /*  42 */         (Object[]) v1);
      /*  43 */     }
      /*  44 */   }
      /*  45 */   , new org.apache.calcite.linq4j.function.Function1() {
      /*  46 */     public java.util.List apply(org.apache.calcite.test.JdbcTest.LingualEmp v1) {
      /*  47 */       return java.util.Collections.EMPTY_LIST;
      /*  48 */     }
      /*  49 */     public Object apply(Object v1) {
      /*  50 */       return apply(
      /*  51 */         (org.apache.calcite.test.JdbcTest.LingualEmp) v1);
      /*  52 */     }
      /*  53 */   }
      /*  54 */   , new org.apache.calcite.linq4j.function.Function2() {
      /*  55 */     public Object[] apply(Object[] left, org.apache.calcite.test.JdbcTest.LingualEmp right) {
      /*  56 */       return new Object[] {
      /*  57 */           left[0],
      /*  58 */           left[1],
      /*  59 */           right.EMPNO,
      /*  60 */           right.DEPTNO};
      /*  61 */     }
      /*  62 */     public Object[] apply(Object left, Object right) {
      /*  63 */       return apply(
      /*  64 */         (Object[]) left,
      /*  65 */         (org.apache.calcite.test.JdbcTest.LingualEmp) right);
      /*  66 */     }
      /*  67 */   }
      /*  68 */   , null, false, false);
      /*  69 */   final org.apache.calcite.linq4j.AbstractEnumerable child = new org.apache.calcite.linq4j.AbstractEnumerable(){
      /*  70 */     public org.apache.calcite.linq4j.Enumerator enumerator() {
      /*  71 */       return new org.apache.calcite.linq4j.Enumerator(){
      /*  72 */           public final org.apache.calcite.linq4j.Enumerator inputEnumerator = _inputEnumerable0.enumerator();
      /*  73 */           public void reset() {
      /*  74 */             inputEnumerator.reset();
      /*  75 */           }
      /*  76 */ 
      /*  77 */           public boolean moveNext() {
      /*  78 */             while (inputEnumerator.moveNext()) {
      /*  79 */               final Object[] current = (Object[]) inputEnumerator.current();
      /*  80 */               if (org.apache.calcite.runtime.SqlFunctions.toInt(current[3]) == org.apache.calcite.runtime.SqlFunctions.toInt(current[0]) && org.apache.calcite.runtime.SqlFunctions.eq(current[1] == null ? (String) null : current[1].toString(), "SameName")) {
      /*  81 */                 return true;
      /*  82 */               }
      /*  83 */             }
      /*  84 */             return false;
      /*  85 */           }
      /*  86 */ 
      /*  87 */           public void close() {
      /*  88 */             inputEnumerator.close();
      /*  89 */           }
      /*  90 */ 
      /*  91 */           public Object current() {
      /*  92 */             final Object[] current = (Object[]) inputEnumerator.current();
      /*  93 */             return new Object[] {
      /*  94 */                 current[2],
      /*  95 */                 current[1]};
      /*  96 */           }
      /*  97 */ 
      /*  98 */         };
      /*  99 */     }
      /* 100 */ 
      /* 101 */   };
      /* 102 */   return child.distinct(org.apache.calcite.linq4j.function.Functions.arrayComparer());
      /* 103 */ }
      /* 104 */ 
      /* 105 */ 
      /* 106 */ public java.lang.reflect.Type getElementType() {
      /* 107 */   return java.lang.Object[].class;
      /* 108 */ }
      /* 109 */ 
      /* 110 */ 
      

      Attachments

        Issue Links

          Activity

            People

              vladimirsitnikov Vladimir Sitnikov
              vladimirsitnikov Vladimir Sitnikov
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: