public static String explain(final RelNode rel, SqlExplainLevel detailLevel) { String explain = ""; try { explain = RelOptUtil.toString(rel); } catch (StackOverflowError e) { LOG.error("StackOverflowError occurred while extracting plan. Please report it to the dev@ mailing list."); LOG.error("RelNode " + rel + " ExplainLevel " + detailLevel, e); LOG.error("Forcing plan to empty string and continue... SQL Runner may not working properly after."); } return explain; } }
@Override public Double getRowCount(SemiJoin rel, RelMetadataQuery mq) { PKFKRelationInfo pkfk = analyzeJoinForPKFK(rel, mq); if (pkfk != null) { double selectivity = pkfk.pkInfo.selectivity * pkfk.ndvScalingFactor; selectivity = Math.min(1.0, selectivity); if (LOG.isDebugEnabled()) { LOG.debug("Identified Primary - Foreign Key relation: {} {}", RelOptUtil.toString(rel), pkfk); } return pkfk.fkInfo.rowCount * selectivity; } return super.getRowCount(rel, mq); }
@Override public Double getRowCount(SemiJoin rel, RelMetadataQuery mq) { PKFKRelationInfo pkfk = analyzeJoinForPKFK(rel, mq); if (pkfk != null) { double selectivity = (pkfk.pkInfo.selectivity * pkfk.ndvScalingFactor); selectivity = Math.min(1.0, selectivity); if (LOG.isDebugEnabled()) { LOG.debug("Identified Primary - Foreign Key relation: {} {}", RelOptUtil.toString(rel), pkfk); } return pkfk.fkInfo.rowCount * selectivity; } return super.getRowCount(rel, mq); }
public Double getRowCount(Join join, RelMetadataQuery mq) { PKFKRelationInfo pkfk = analyzeJoinForPKFK(join, mq); if (pkfk != null) { double selectivity = (pkfk.pkInfo.selectivity * pkfk.ndvScalingFactor); selectivity = Math.min(1.0, selectivity); if (LOG.isDebugEnabled()) { LOG.debug("Identified Primary - Foreign Key relation: {} {}",RelOptUtil.toString(join), pkfk); } return pkfk.fkInfo.rowCount * selectivity; } return join.getRows(); }
" Join selectivity: {}\n Residual selectivity: {}\n", RelOptUtil.toString(join), constraintBasedResult.left, rowCount, joinSelectivity, residualSelectivity); selectivity = Math.min(1.0, selectivity); if (LOG.isDebugEnabled()) { LOG.debug("Identified Primary - Foreign Key relation: {} {}", RelOptUtil.toString(join), pkfk); if (LOG.isDebugEnabled()) { LOG.debug("No Primary - Foreign Key relation: \n{} Row count for join: {}\n", RelOptUtil.toString(join), rowCount);
RelNode newTopNode = rel; if (LOG.isDebugEnabled()) { LOG.debug("Original plan for PlanModifier\n " + RelOptUtil.toString(newTopNode)); if (LOG.isDebugEnabled()) { LOG.debug("Plan after top-level introduceDerivedTable\n " + RelOptUtil.toString(newTopNode)); LOG.debug("Plan after nested convertOpTree\n " + RelOptUtil.toString(newTopNode)); newTopNode = propagator.align(newTopNode); if (LOG.isDebugEnabled()) { LOG.debug("Plan after propagating order\n " + RelOptUtil.toString(newTopNode)); PlanModifierUtil.fixTopOBSchema(newTopNode, topSelparentPair, resultSchema, true); if (LOG.isDebugEnabled()) { LOG.debug("Plan after fixTopOBSchema\n " + RelOptUtil.toString(newTopNode)); newTopNode = renameTopLevelSelectInResultSchema(newTopNode, topSelparentPair, resultSchema); if (LOG.isDebugEnabled()) { LOG.debug("Final plan after modifier\n " + RelOptUtil.toString(newTopNode));
RelNode newTopNode = rel; if (LOG.isDebugEnabled()) { LOG.debug("Original plan for PlanModifier\n " + RelOptUtil.toString(newTopNode)); if (LOG.isDebugEnabled()) { LOG.debug("Plan after top-level introduceDerivedTable\n " + RelOptUtil.toString(newTopNode)); LOG.debug("Plan after nested convertOpTree\n " + RelOptUtil.toString(newTopNode)); newTopNode = propagator.align(newTopNode); if (LOG.isDebugEnabled()) { LOG.debug("Plan after propagating order\n " + RelOptUtil.toString(newTopNode)); PlanModifierUtil.fixTopOBSchema(newTopNode, topSelparentPair, resultSchema, true); if (LOG.isDebugEnabled()) { LOG.debug("Plan after fixTopOBSchema\n " + RelOptUtil.toString(newTopNode)); newTopNode = renameTopLevelSelectInResultSchema(newTopNode, topSelparentPair, resultSchema); if (LOG.isDebugEnabled()) { LOG.debug("Final plan after modifier\n " + RelOptUtil.toString(newTopNode));
public RelOptCost getJoinCost(HiveJoin join) { // Select algorithm with min cost JoinAlgorithm joinAlgorithm = null; RelOptCost minJoinCost = null; if (LOG.isTraceEnabled()) { LOG.trace("Join algorithm selection for:\n" + RelOptUtil.toString(join)); } for (JoinAlgorithm possibleAlgorithm : this.joinAlgorithms) { if (!possibleAlgorithm.isExecutable(join)) { continue; } RelOptCost joinCost = possibleAlgorithm.getCost(join); if (LOG.isTraceEnabled()) { LOG.trace(possibleAlgorithm + " cost: " + joinCost); } if (minJoinCost == null || joinCost.isLt(minJoinCost) ) { joinAlgorithm = possibleAlgorithm; minJoinCost = joinCost; } } if (LOG.isTraceEnabled()) { LOG.trace(joinAlgorithm + " selected"); } join.setJoinAlgorithm(joinAlgorithm); join.setJoinCost(minJoinCost); return minJoinCost; }
public RelOptCost getJoinCost(HiveJoin join) { // Select algorithm with min cost JoinAlgorithm joinAlgorithm = null; RelOptCost minJoinCost = null; if (LOG.isTraceEnabled()) { LOG.trace("Join algorithm selection for:\n" + RelOptUtil.toString(join)); } for (JoinAlgorithm possibleAlgorithm : this.joinAlgorithms) { if (!possibleAlgorithm.isExecutable(join)) { continue; } RelOptCost joinCost = possibleAlgorithm.getCost(join); if (LOG.isTraceEnabled()) { LOG.trace(possibleAlgorithm + " cost: " + joinCost); } if (minJoinCost == null || joinCost.isLt(minJoinCost) ) { joinAlgorithm = possibleAlgorithm; minJoinCost = joinCost; } } if (LOG.isTraceEnabled()) { LOG.trace(joinAlgorithm + " selected"); } join.setJoinAlgorithm(joinAlgorithm); join.setJoinCost(minJoinCost); return minJoinCost; }
LOG.debug("Plan before removing subquery:\n" + RelOptUtil.toString(calciteGenPlan)); calciteGenPlan = hepPlan(calciteGenPlan, false, mdProvider.getMetadataProvider(), null, new HiveSubQueryRemoveRule(conf)); LOG.debug("Plan just after removing subquery:\n" + RelOptUtil.toString(calciteGenPlan)); LOG.debug("Plan after decorrelation:\n" + RelOptUtil.toString(calciteGenPlan)); LOG.debug("Original Plan:\n" + RelOptUtil.toString(calciteGenPlan)); LOG.debug("Plan After PPD, PartPruning, ColumnPruning:\n" + RelOptUtil.toString(calcitePreCboPlan)); LOG.debug("Plan After Join Reordering:\n" + RelOptUtil.toString(calciteOptimizedPlan, SqlExplainLevel.ALL_ATTRIBUTES));
@Test public void testIsNull_one() { // @formatter:off final RelNode basePlan = builder .scan("t") .filter( builder.call(SqlStdOperatorTable.IS_NULL, builder.field("_str") ) ) .build(); // @formatter:on statObj.setNumNulls(1); planner.setRoot(basePlan); System.out.println(RelOptUtil.toString(basePlan)); RelNode optimizedRelNode = planner.findBestExp(); System.out.println(RelOptUtil.toString(optimizedRelNode)); assertNotEquals("should not be a literal", SqlKind.LITERAL, optimizedRelNode.getChildExps().get(0).getKind()); }
LOG.debug("Plan before removing subquery:\n" + RelOptUtil.toString(calciteGenPlan)); calciteGenPlan = hepPlan(calciteGenPlan, false, mdProvider.getMetadataProvider(), null, HiveSubQueryRemoveRule.FILTER, HiveSubQueryRemoveRule.PROJECT); LOG.debug("Plan just after removing subquery:\n" + RelOptUtil.toString(calciteGenPlan)); LOG.debug("Plan after decorrelation:\n" + RelOptUtil.toString(calciteGenPlan)); LOG.debug("Original Plan:\n" + RelOptUtil.toString(calciteGenPlan)); LOG.debug("Plan After PPD, PartPruning, ColumnPruning:\n" + RelOptUtil.toString(calcitePreCboPlan)); LOG.debug("Plan After Join Reordering:\n" + RelOptUtil.toString(calciteOptimizedPlan, SqlExplainLevel.ALL_ATTRIBUTES));
@Test public void testIsNull_all() { // @formatter:off final RelNode basePlan = builder .scan("t") .filter( builder.call(SqlStdOperatorTable.IS_NULL, builder.field("_str") ) ) .build(); // @formatter:on statObj.setNumNulls(3); planner.setRoot(basePlan); System.out.println(RelOptUtil.toString(basePlan)); RelNode optimizedRelNode = planner.findBestExp(); System.out.println(RelOptUtil.toString(optimizedRelNode)); assertEquals("missing literal", SqlKind.LITERAL, optimizedRelNode.getChildExps().get(0).getKind()); RexLiteral val = (RexLiteral) optimizedRelNode.getChildExps().get(0); assertEquals(true, val.getValue()); }
@Test public void testIsNotNull() { // @formatter:off final RelNode basePlan = builder .scan("t") .filter( builder.call(SqlStdOperatorTable.IS_NOT_NULL, builder.field("_str") ) ) .build(); // @formatter:on statObj.setNumNulls(0); planner.setRoot(basePlan); System.out.println(RelOptUtil.toString(basePlan)); RelNode optimizedRelNode = planner.findBestExp(); System.out.println(RelOptUtil.toString(optimizedRelNode)); assertEquals("missing literal", SqlKind.LITERAL, optimizedRelNode.getChildExps().get(0).getKind()); RexLiteral val = (RexLiteral) optimizedRelNode.getChildExps().get(0); assertEquals(true, val.getValue()); }
@Test public void testIsNull_zero() { // @formatter:off final RelNode basePlan = builder .scan("t") .filter( builder.call(SqlStdOperatorTable.IS_NULL, builder.field("_str") ) ) .build(); // @formatter:on statObj.setNumNulls(0); planner.setRoot(basePlan); System.out.println(RelOptUtil.toString(basePlan)); RelNode optimizedRelNode = planner.findBestExp(); System.out.println(RelOptUtil.toString(optimizedRelNode)); assertEquals("missing literal", SqlKind.LITERAL, optimizedRelNode.getChildExps().get(0).getKind()); RexLiteral val = (RexLiteral) optimizedRelNode.getChildExps().get(0); assertEquals(false, val.getValue()); }
optimizedOptiqPlan, resultSchema, this.getQB().getTableDesc() != null); LOG.debug("Translating the following plan:\n" + RelOptUtil.toString(modifiedOptimizedOptiqPlan)); Operator<?> hiveRoot = new HiveOpConverter(this, conf, unparseTranslator, topOps) .convert(modifiedOptimizedOptiqPlan);
optimizedOptiqPlan, resultSchema, this.getQB().getTableDesc() != null); LOG.debug("Translating the following plan:\n" + RelOptUtil.toString(modifiedOptimizedOptiqPlan)); Operator<?> hiveRoot = new HiveOpConverter(this, conf, unparseTranslator, topOps) .convert(modifiedOptimizedOptiqPlan);
/** * Converts a relational expression to a string, showing just basic * attributes. */ public static String toString(final RelNode rel) { return toString(rel, SqlExplainLevel.EXPPLAN_ATTRIBUTES); }