@Override public PhysicalPlan getPlan(SqlHandlerConfig config, String sql, SqlNode sqlNode) throws Exception { try{ final ConvertedRelNode convertedRelNode = PrelTransformer.validateAndConvert(config, sqlNode); final RelDataType validatedRowType = convertedRelNode.getValidatedRowType(); final RelNode queryRelNode = convertedRelNode.getConvertedNode(); final Rel drel = PrelTransformer.convertToDrel(config, queryRelNode, validatedRowType); final Pair<Prel, String> convertToPrel = PrelTransformer.convertToPrel(config, drel); final Prel prel = convertToPrel.getKey(); textPlan = convertToPrel.getValue(); final PhysicalOperator pop = PrelTransformer.convertToPop(config, prel); final PhysicalPlan plan = PrelTransformer.convertToPlan(config, pop); logger.debug("Final Physical Plan {}", textPlan); PrelTransformer.log(config, "Dremio Plan", plan, logger); return plan; }catch(Exception ex){ throw SqlExceptionHelper.coerceException(logger, sql, ex, true); } }
/** * Return Dremio Logical RelNode tree for a SELECT statement, when it is executed / explained directly. * * @param relNode : root RelNode corresponds to Calcite Logical RelNode. * @param validatedRowType : the rowType for the final field names. A rename project may be placed on top of the root. * @return * @throws RelConversionException * @throws SqlUnsupportedException */ public static Rel convertToDrel(SqlHandlerConfig config, RelNode relNode, RelDataType validatedRowType) throws RelConversionException, SqlUnsupportedException { Rel convertedRelNode = convertToDrel(config, relNode); // Put a non-trivial topProject to ensure the final output field name is preserved, when necessary. convertedRelNode = addRenamedProject(config, convertedRelNode, validatedRowType); convertedRelNode = SqlHandlerUtil.storeQueryResultsIfNeeded(config.getConverter().getParserConfig(), config.getContext(), convertedRelNode); return new ScreenRel(convertedRelNode.getCluster(), convertedRelNode.getTraitSet(), convertedRelNode); }
drel = PrelTransformer.convertToDrel(config, queryRelNode, validatedRowType);
private static Rel convertToDrel( SqlHandlerConfig config, RelNode relNode, Catalog catalog, NamespaceKey key, WriterOptions options, RelDataType queryRowType, final Map<String, Object> storageOptions) throws RelConversionException, SqlUnsupportedException { Rel convertedRelNode = PrelTransformer.convertToDrel(config, relNode); // Put a non-trivial topProject to ensure the final output field name is preserved, when necessary. // Only insert project when the field count from the child is same as that of the queryRowType. convertedRelNode = new WriterRel(convertedRelNode.getCluster(), convertedRelNode.getCluster().traitSet().plus(Rel.LOGICAL), convertedRelNode, catalog.createNewTable(key, options, storageOptions), queryRowType); convertedRelNode = SqlHandlerUtil.storeQueryResultsIfNeeded(config.getConverter().getParserConfig(), config.getContext(), convertedRelNode); return new ScreenRel(convertedRelNode.getCluster(), convertedRelNode.getTraitSet(), convertedRelNode); }
final Rel drel = PrelTransformer.convertToDrel(config, initial); final Set<String> fields = ImmutableSet.copyOf(drel.getRowType().getFieldNames()); final long ringCount = config.getContext().getOptions().getOption(PlannerSettings.RING_COUNT);
final Rel drel = PrelTransformer.convertToDrel(config, initial); final Set<String> fields = ImmutableSet.copyOf(drel.getRowType().getFieldNames());
final RelNode queryRelNode = convertedRelNode.getConvertedNode(); final Rel drel = PrelTransformer.convertToDrel(config, queryRelNode, validatedRowType);
final RelNode queryRelNode = convertedRelNode.getConvertedNode(); final Rel drel = PrelTransformer.convertToDrel(config, queryRelNode, validatedRowType);