drill-dev mailing list archives

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

    https://github.com/apache/drill/pull/193#discussion_r45406832
  
    --- 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 --
    
    FindLimit0Visitor.containsLimit0(relNode) is called when relNode is LogicalRel.  Can we
create LogicalValue with empty list of tuple, in stead of creating DrillValues with one tuple
followed by a DrillLimit(0) ? 
    
    I think LogicalValue would allow an empty list of tuple, right?


---
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