drill-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sudheeshkatkam <...@git.apache.org>
Subject [GitHub] drill pull request: DRILL-3623: Use shorter query path for LIMIT 0...
Date Thu, 19 Nov 2015 22:11:54 GMT
Github user sudheeshkatkam commented on a diff in the pull request:

    https://github.com/apache/drill/pull/193#discussion_r45408655
  
    --- Diff: exec/java-exec/src/main/java/org/apache/drill/exec/planner/sql/handlers/FindLimit0Visitor.java
---
    @@ -36,16 +48,62 @@
      * executing a schema-only query.
      */
     public class FindLimit0Visitor extends RelShuttleImpl {
    -  private static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(FindLimit0Visitor.class);
    +//  private static final org.slf4j.Logger logger = org.slf4j.LoggerFactory.getLogger(FindLimit0Visitor.class);
    +
    +  /**
    +   * Values in the {@link DrillConstExecutor#DRILL_TO_CALCITE_TYPE_MAPPING} map.
    +   * + without {@link SqlTypeName#ANY} (avoid late binding)
    +   * + without {@link SqlTypeName#VARBINARY} ({@link DrillValuesRel values} does not
support this)
    +   * + with {@link SqlTypeName#CHAR} ({@link DrillValuesRel values} supports this, but
the above mapping does not
    +   *   contain this type.
    +   */
    +  private static final ImmutableSet<SqlTypeName> TYPES = ImmutableSet.<SqlTypeName>builder()
    +      .add(SqlTypeName.INTEGER, SqlTypeName.BIGINT, SqlTypeName.FLOAT, SqlTypeName.DOUBLE,
SqlTypeName.VARCHAR,
    +          SqlTypeName.BOOLEAN, SqlTypeName.DATE, SqlTypeName.DECIMAL, SqlTypeName.TIME,
SqlTypeName.TIMESTAMP,
    +          SqlTypeName.INTERVAL_YEAR_MONTH, SqlTypeName.INTERVAL_DAY_TIME, SqlTypeName.MAP,
SqlTypeName.ARRAY,
    +          SqlTypeName.TINYINT, SqlTypeName.SMALLINT, SqlTypeName.CHAR)
    +      .build();
     
       private boolean contains = false;
     
    +  /**
    +   * Checks if the root portion of the RelNode tree contains a limit 0 pattern.
    +   */
       public static boolean containsLimit0(RelNode rel) {
         FindLimit0Visitor visitor = new FindLimit0Visitor();
         rel.accept(visitor);
         return visitor.isContains();
       }
     
    +  /**
    +   * If all field types of the given node are {@link #TYPES recognized types}, then this
method returns the tree:
    +   *   DrillLimitRel(0)
    +   *     \
    +   *     DrillValuesRel(field types)
    +   * Otherwise, the method returns null.
    +   */
    +  public static DrillRel getValuesRelIfFullySchemaed(final RelNode rel) {
    +    final List<RelDataTypeField> fieldList = rel.getRowType().getFieldList();
    +    final ImmutableList.Builder<RexLiteral> tupleBuilder = new ImmutableList.Builder<>();
    +    final RexBuilder literalBuilder = new RexBuilder(rel.getCluster().getTypeFactory());
    +    for (final RelDataTypeField field : fieldList) {
    +      if (!TYPES.contains(field.getType().getSqlTypeName())) {
    +        return null;
    +      } else {
    +        tupleBuilder.add((RexLiteral) literalBuilder.makeLiteral(null, field.getType(),
false));
    +      }
    +    }
    +
    +    final ImmutableList<ImmutableList<RexLiteral>> tuples = new ImmutableList.Builder<ImmutableList<RexLiteral>>()
    +        .add(tupleBuilder.build())
    +        .build();
    +    final RelTraitSet traits = rel.getTraitSet().plus(DrillRel.DRILL_LOGICAL);
    +    // TODO: ideally, we want the limit to be pushed into values
    +    final DrillValuesRel values = new DrillValuesRel(rel.getCluster(), rel.getRowType(),
tuples, traits);
    --- End diff --
    
    I did this to avoid logical transformation completely, as this is an exceptional case.
    
    LogicalValues [allows an empty list of tuples](https://github.com/apache/calcite/blob/master/core/src/main/java/org/apache/calcite/rel/logical/LogicalValues.java#L101)
but as Jacques pointed out Drill does not handle that well (we use data to encode types).


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

Mime
View raw message