当前位置: 首页>>代码示例>>Java>>正文


Java RelOptUtil.toString方法代码示例

本文整理汇总了Java中org.apache.calcite.plan.RelOptUtil.toString方法的典型用法代码示例。如果您正苦于以下问题:Java RelOptUtil.toString方法的具体用法?Java RelOptUtil.toString怎么用?Java RelOptUtil.toString使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.calcite.plan.RelOptUtil的用法示例。


在下文中一共展示了RelOptUtil.toString方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: checkParsedRelString

import org.apache.calcite.plan.RelOptUtil; //导入方法依赖的package包/类
public static void checkParsedRelString(String sql,
                                        Properties info,
                                        ImmutableList<String> expected,
                                        ImmutableList<String> unexpected)
    throws QuarkException, SQLException {
  SqlQueryParser parser = new SqlQueryParser(info);
  RelNode relNode = parser.parse(sql).getRelNode();
  String relStr = RelOptUtil.toString(relNode);

  for (String expectedPlan : expected) {
    assertTrue("Final Plan should use table " + expectedPlan,
        relStr.contains(expectedPlan));
  }

  for (String unexpectedPlan : unexpected) {
    assertFalse("Final Plan should not use table " + unexpectedPlan,
        relStr.contains(unexpectedPlan));
  }
}
 
开发者ID:qubole,项目名称:quark,代码行数:20,代码来源:QuarkTestUtil.java

示例2: setRoot

import org.apache.calcite.plan.RelOptUtil; //导入方法依赖的package包/类
public void setRoot(RelNode rel) {
  // We're registered all the rules, and therefore RelNode classes,
  // we're interested in, and have not yet started calling metadata providers.
  // So now is a good time to tell the metadata layer what to expect.
  registerMetadataRels();

  this.root = registerImpl(rel, null);
  if (this.originalRoot == null) {
    this.originalRoot = rel;
  }
  this.originalRootString =
      RelOptUtil.toString(root, SqlExplainLevel.ALL_ATTRIBUTES);

  // Making a node the root changes its importance.
  this.ruleQueue.recompute(this.root);
  ensureRootConverters();
}
 
开发者ID:apache,项目名称:calcite,代码行数:18,代码来源:VolcanoPlanner.java

示例3: checkTpchQuery

import org.apache.calcite.plan.RelOptUtil; //导入方法依赖的package包/类
public String checkTpchQuery(String tpchTestQuery) throws Exception {
  final SchemaPlus schema =
      Frameworks.createRootSchema(true).add("tpch",
          new ReflectiveSchema(new TpchSchema()));

  final FrameworkConfig config = Frameworks.newConfigBuilder()
      .parserConfig(SqlParser.configBuilder().setLex(Lex.MYSQL).build())
      .defaultSchema(schema)
      .programs(Programs.ofRules(Programs.RULE_SET))
      .build();
  String plan;
  try (Planner p = Frameworks.getPlanner(config)) {
    SqlNode n = p.parse(tpchTestQuery);
    n = p.validate(n);
    RelNode r = p.rel(n).project();
    plan = RelOptUtil.toString(r);
  }
  return plan;
}
 
开发者ID:apache,项目名称:calcite,代码行数:20,代码来源:PlannerTest.java

示例4: assertConvertsTo

import org.apache.calcite.plan.RelOptUtil; //导入方法依赖的package包/类
public void assertConvertsTo(
    String sql,
    String plan,
    boolean trim) {
  String sql2 = getDiffRepos().expand("sql", sql);
  RelNode rel = convertSqlToRel(sql2).project();

  assertTrue(rel != null);
  assertValid(rel);

  if (trim) {
    final RelBuilder relBuilder =
        RelFactories.LOGICAL_BUILDER.create(rel.getCluster(), null);
    final RelFieldTrimmer trimmer = createFieldTrimmer(relBuilder);
    rel = trimmer.trim(rel);
    assertTrue(rel != null);
    assertValid(rel);
  }

  // NOTE jvs 28-Mar-2006:  insert leading newline so
  // that plans come out nicely stacked instead of first
  // line immediately after CDATA start
  String actual = NL + RelOptUtil.toString(rel);
  diffRepos.assertEquals("plan", plan, actual);
}
 
开发者ID:apache,项目名称:calcite,代码行数:26,代码来源:SqlToRelTestBase.java

示例5: LogicalExplain

import org.apache.calcite.plan.RelOptUtil; //导入方法依赖的package包/类
public LogicalExplain(RelNode node, SqlExplainLevel level, QueryContext context) {
  this.text = RelOptUtil.toString(node, level);
  DrillImplementor implementor = new DrillImplementor(new DrillParseContext(context.getPlannerSettings()), ResultMode.LOGICAL);
  implementor.go( (DrillRel) node);
  LogicalPlan plan = implementor.getPlan();
  this.json = plan.unparse(context.getConfig());
}
 
开发者ID:skhalifa,项目名称:QDrill,代码行数:8,代码来源:ExplainHandler.java

示例6: log

import org.apache.calcite.plan.RelOptUtil; //导入方法依赖的package包/类
public static void log(final String description, final RelNode node, final Logger logger, Stopwatch watch) {
  if (logger.isDebugEnabled()) {
    final String plan = RelOptUtil.toString(node, SqlExplainLevel.ALL_ATTRIBUTES);
    final String time = watch == null ? "" : String.format(" (%dms)", watch.elapsed(TimeUnit.MILLISECONDS));
    logger.debug(String.format("%s%s:\n%s", description, time, plan));
  }
}
 
开发者ID:dremio,项目名称:dremio-oss,代码行数:8,代码来源:PrelTransformer.java

示例7: checkConvertedType

import org.apache.calcite.plan.RelOptUtil; //导入方法依赖的package包/类
private void checkConvertedType(SqlNode query, RelNode result) {
	if (query.isA(SqlKind.DML)) {
		return;
	}
	// Verify that conversion from SQL to relational algebra did
	// not perturb any type information.  (We can't do this if the
	// SQL statement is something like an INSERT which has no
	// validator type information associated with its result,
	// hence the namespace check above.)
	final List<RelDataTypeField> validatedFields =
		validator.getValidatedNodeType(query).getFieldList();
	final RelDataType validatedRowType =
		validator.getTypeFactory().createStructType(
			Pair.right(validatedFields),
			SqlValidatorUtil.uniquify(Pair.left(validatedFields),
				catalogReader.nameMatcher().isCaseSensitive()));

	final List<RelDataTypeField> convertedFields =
		result.getRowType().getFieldList().subList(0, validatedFields.size());
	final RelDataType convertedRowType =
		validator.getTypeFactory().createStructType(convertedFields);

	if (!RelOptUtil.equal("validated row type", validatedRowType,
		"converted row type", convertedRowType, Litmus.IGNORE)) {
		throw new AssertionError("Conversion to relational algebra failed to "
			+ "preserve datatypes:\n"
			+ "validated type:\n"
			+ validatedRowType.getFullTypeString()
			+ "\nconverted type:\n"
			+ convertedRowType.getFullTypeString()
			+ "\nrel:\n"
			+ RelOptUtil.toString(result));
	}
}
 
开发者ID:axbaretto,项目名称:flink,代码行数:35,代码来源:SqlToRelConverter.java

示例8: log

import org.apache.calcite.plan.RelOptUtil; //导入方法依赖的package包/类
protected void log(final String description, final RelNode node, final Logger logger, Stopwatch watch) {
  if (logger.isDebugEnabled()) {
    final String plan = RelOptUtil.toString(node, SqlExplainLevel.ALL_ATTRIBUTES);
    final String time = watch == null ? "" : String.format(" (%dms)", watch.elapsed(TimeUnit.MILLISECONDS));
    logger.debug(String.format("%s%s:\n%s", description, time, plan));
  }
}
 
开发者ID:axbaretto,项目名称:drill,代码行数:8,代码来源:DefaultSqlHandler.java

示例9: LogicalExplain

import org.apache.calcite.plan.RelOptUtil; //导入方法依赖的package包/类
public LogicalExplain(RelNode node, SqlExplainLevel level, QueryContext context) {
  this.text = RelOptUtil.toString(node, level);
  DrillImplementor implementor = new DrillImplementor(new DrillParseContext(context.getPlannerSettings()), ResultMode.LOGICAL);
  implementor.go( (DrillRel) node);
  LogicalPlan plan = implementor.getPlan();
  this.json = plan.unparse(context.getLpPersistence());
}
 
开发者ID:axbaretto,项目名称:drill,代码行数:8,代码来源:ExplainHandler.java

示例10: checkConvertedType

import org.apache.calcite.plan.RelOptUtil; //导入方法依赖的package包/类
private void checkConvertedType(SqlNode query, RelNode result) {
  if (query.isA(SqlKind.DML)) {
    return;
  }
  // Verify that conversion from SQL to relational algebra did
  // not perturb any type information.  (We can't do this if the
  // SQL statement is something like an INSERT which has no
  // validator type information associated with its result,
  // hence the namespace check above.)
  final List<RelDataTypeField> validatedFields =
      validator.getValidatedNodeType(query).getFieldList();
  final RelDataType validatedRowType =
      validator.getTypeFactory().createStructType(
          Pair.right(validatedFields),
          SqlValidatorUtil.uniquify(Pair.left(validatedFields),
              catalogReader.nameMatcher().isCaseSensitive()));

  final List<RelDataTypeField> convertedFields =
      result.getRowType().getFieldList().subList(0, validatedFields.size());
  final RelDataType convertedRowType =
      validator.getTypeFactory().createStructType(convertedFields);

  if (!RelOptUtil.equal("validated row type", validatedRowType,
      "converted row type", convertedRowType, Litmus.IGNORE)) {
    throw new AssertionError("Conversion to relational algebra failed to "
        + "preserve datatypes:\n"
        + "validated type:\n"
        + validatedRowType.getFullTypeString()
        + "\nconverted type:\n"
        + convertedRowType.getFullTypeString()
        + "\nrel:\n"
        + RelOptUtil.toString(result));
  }
}
 
开发者ID:apache,项目名称:kylin,代码行数:35,代码来源:SqlToRelConverter.java

示例11: testOrderByNonSelectColumn

import org.apache.calcite.plan.RelOptUtil; //导入方法依赖的package包/类
/** Test case for
 * <a href="https://issues.apache.org/jira/browse/CALCITE-569">[CALCITE-569]
 * ArrayIndexOutOfBoundsException when deducing collation</a>. */
@Test public void testOrderByNonSelectColumn() throws Exception {
  final SchemaPlus schema = Frameworks.createRootSchema(true)
      .add("tpch", new ReflectiveSchema(new TpchSchema()));

  String query = "select t.psPartkey from \n"
      + "(select ps.psPartkey from `tpch`.`partsupp` ps \n"
      + "order by ps.psPartkey, ps.psSupplyCost) t \n"
      + "order by t.psPartkey";

  List<RelTraitDef> traitDefs = new ArrayList<>();
  traitDefs.add(ConventionTraitDef.INSTANCE);
  traitDefs.add(RelCollationTraitDef.INSTANCE);
  final SqlParser.Config parserConfig =
      SqlParser.configBuilder().setLex(Lex.MYSQL).build();
  FrameworkConfig config = Frameworks.newConfigBuilder()
      .parserConfig(parserConfig)
      .defaultSchema(schema)
      .traitDefs(traitDefs)
      .programs(Programs.ofRules(Programs.RULE_SET))
      .build();
  String plan;
  try (Planner p = Frameworks.getPlanner(config)) {
    SqlNode n = p.parse(query);
    n = p.validate(n);
    RelNode r = p.rel(n).project();
    plan = RelOptUtil.toString(r);
    plan = Util.toLinux(plan);
  }
  assertThat(plan,
      equalTo("LogicalSort(sort0=[$0], dir0=[ASC])\n"
      + "  LogicalProject(psPartkey=[$0])\n"
      + "    LogicalProject(psPartkey=[$0])\n"
      + "      LogicalSort(sort0=[$0], sort1=[$1], dir0=[ASC], dir1=[ASC])\n"
      + "        LogicalProject(psPartkey=[$0], psSupplyCost=[$1])\n"
      + "          EnumerableTableScan(table=[[tpch, partsupp]])\n"));
}
 
开发者ID:apache,项目名称:calcite,代码行数:40,代码来源:PlannerTest.java

示例12: explainQuery

import org.apache.calcite.plan.RelOptUtil; //导入方法依赖的package包/类
/**
 * Returns a human readable representation of the query execution plan.
 */
public String explainQuery(String sqlString) throws Exception {
  BeamRelNode exeTree = env.getPlanner().convertToBeamRel(sqlString);
  String beamPlan = RelOptUtil.toString(exeTree);
  return beamPlan;
}
 
开发者ID:apache,项目名称:beam,代码行数:9,代码来源:BeamSqlCli.java

示例13: checkConvertMutableRel

import org.apache.calcite.plan.RelOptUtil; //导入方法依赖的package包/类
/** Verifies that after conversion to and from a MutableRel, the new
 * RelNode remains identical to the original RelNode. */
private static void checkConvertMutableRel(
    String rel, String sql, boolean decorrelate, List<RelOptRule> rules) {
  final SqlToRelTestBase test = new SqlToRelTestBase() {
  };
  RelNode origRel = test.createTester().convertSqlToRel(sql).rel;
  if (decorrelate) {
    origRel = RelDecorrelator.decorrelateQuery(origRel);
  }
  if (rules != null) {
    final HepProgram hepProgram =
        new HepProgramBuilder().addRuleCollection(rules).build();
    final HepPlanner hepPlanner = new HepPlanner(hepProgram);
    hepPlanner.setRoot(origRel);
    origRel = hepPlanner.findBestExp();
  }
  // Convert to and from a mutable rel.
  final MutableRel mutableRel = MutableRels.toMutable(origRel);
  final RelNode newRel = MutableRels.fromMutable(mutableRel);

  // Check if the mutable rel digest contains the target rel.
  final String mutableRelStr = mutableRel.deep();
  final String msg1 =
      "Mutable rel: " + mutableRelStr + " does not contain target rel: " + rel;
  Assert.assertTrue(msg1, mutableRelStr.contains(rel));

  // Check if the mutable rel's row-type is identical to the original
  // rel's row-type.
  final RelDataType origRelType = origRel.getRowType();
  final RelDataType mutableRelType = mutableRel.rowType;
  final String msg2 =
      "Mutable rel's row type does not match with the original rel.\n"
      + "Original rel type: " + origRelType
      + ";\nMutable rel type: " + mutableRelType;
  Assert.assertTrue(
      msg2,
      RelOptUtil.equal(
          "origRelType", origRelType,
          "mutableRelType", mutableRelType,
          Litmus.IGNORE));

  // Check if the new rel converted from the mutable rel is identical
  // to the original rel.
  final String origRelStr = RelOptUtil.toString(origRel);
  final String newRelStr = RelOptUtil.toString(newRel);
  final String msg3 =
      "The converted new rel is different from the original rel.\n"
      + "Original rel: " + origRelStr + ";\nNew rel: " + newRelStr;
  Assert.assertEquals(msg3, origRelStr, newRelStr);
}
 
开发者ID:apache,项目名称:calcite,代码行数:52,代码来源:MutableRelTest.java

示例14: checkPlanning

import org.apache.calcite.plan.RelOptUtil; //导入方法依赖的package包/类
/**
 * Checks the plan for a SQL statement before/after executing a given rule,
 * with a pre-program to prepare the tree.
 *
 * @param tester     Tester
 * @param preProgram Program to execute before comparing before state
 * @param planner    Planner
 * @param sql        SQL query
 * @param unchanged  Whether the rule is to have no effect
 */
protected void checkPlanning(Tester tester, HepProgram preProgram,
    RelOptPlanner planner, String sql, boolean unchanged) {
  final DiffRepository diffRepos = getDiffRepos();
  String sql2 = diffRepos.expand("sql", sql);
  final RelRoot root = tester.convertSqlToRel(sql2);
  final RelNode relInitial = root.rel;

  assertTrue(relInitial != null);

  List<RelMetadataProvider> list = Lists.newArrayList();
  list.add(DefaultRelMetadataProvider.INSTANCE);
  planner.registerMetadataProviders(list);
  RelMetadataProvider plannerChain =
      ChainedRelMetadataProvider.of(list);
  relInitial.getCluster().setMetadataProvider(plannerChain);

  RelNode relBefore;
  if (preProgram == null) {
    relBefore = relInitial;
  } else {
    HepPlanner prePlanner = new HepPlanner(preProgram);
    prePlanner.setRoot(relInitial);
    relBefore = prePlanner.findBestExp();
  }

  assertThat(relBefore, notNullValue());

  final String planBefore = NL + RelOptUtil.toString(relBefore);
  diffRepos.assertEquals("planBefore", "${planBefore}", planBefore);
  SqlToRelTestBase.assertValid(relBefore);

  planner.setRoot(relBefore);
  RelNode r = planner.findBestExp();
  if (tester.isLateDecorrelate()) {
    final String planMid = NL + RelOptUtil.toString(r);
    diffRepos.assertEquals("planMid", "${planMid}", planMid);
    SqlToRelTestBase.assertValid(r);
    r = RelDecorrelator.decorrelateQuery(r);
  }
  final String planAfter = NL + RelOptUtil.toString(r);
  if (unchanged) {
    assertThat(planAfter, is(planBefore));
  } else {
    diffRepos.assertEquals("planAfter", "${planAfter}", planAfter);
    if (planBefore.equals(planAfter)) {
      throw new AssertionError("Expected plan before and after is the same.\n"
          + "You must use unchanged=true or call checkPlanUnchanged");
    }
  }
  SqlToRelTestBase.assertValid(r);
}
 
开发者ID:apache,项目名称:calcite,代码行数:62,代码来源:RelOptTestBase.java

示例15: testSemiJoinTrim

import org.apache.calcite.plan.RelOptUtil; //导入方法依赖的package包/类
@Test public void testSemiJoinTrim() throws Exception {
  final DiffRepository diffRepos = getDiffRepos();
  String sql = diffRepos.expand(null, "${sql}");

  TesterImpl t = (TesterImpl) tester;
  final RelDataTypeFactory typeFactory = t.getTypeFactory();
  final Prepare.CatalogReader catalogReader =
      t.createCatalogReader(typeFactory);
  final SqlValidator validator =
      t.createValidator(
          catalogReader, typeFactory);
  SqlToRelConverter converter =
      t.createSqlToRelConverter(
          validator,
          catalogReader,
          typeFactory,
          SqlToRelConverter.Config.DEFAULT);

  final SqlNode sqlQuery = t.parseQuery(sql);
  final SqlNode validatedQuery = validator.validate(sqlQuery);
  RelRoot root =
      converter.convertQuery(validatedQuery, false, true);
  root = root.withRel(converter.decorrelate(sqlQuery, root.rel));

  final HepProgram program =
      HepProgram.builder()
          .addRuleInstance(FilterProjectTransposeRule.INSTANCE)
          .addRuleInstance(FilterJoinRule.FILTER_ON_JOIN)
          .addRuleInstance(ProjectMergeRule.INSTANCE)
          .addRuleInstance(SemiJoinRule.PROJECT)
          .build();

  HepPlanner planner = new HepPlanner(program);
  planner.setRoot(root.rel);
  root = root.withRel(planner.findBestExp());

  String planBefore = NL + RelOptUtil.toString(root.rel);
  diffRepos.assertEquals("planBefore", "${planBefore}", planBefore);
  converter = t.createSqlToRelConverter(validator, catalogReader, typeFactory,
      SqlToRelConverter.configBuilder().withTrimUnusedFields(true).build());
  root = root.withRel(converter.trimUnusedFields(false, root.rel));
  String planAfter = NL + RelOptUtil.toString(root.rel);
  diffRepos.assertEquals("planAfter", "${planAfter}", planAfter);
}
 
开发者ID:apache,项目名称:calcite,代码行数:45,代码来源:RelOptRulesTest.java


注:本文中的org.apache.calcite.plan.RelOptUtil.toString方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。