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


Java RelOptUtil类代码示例

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


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

示例1: toRel

import org.apache.calcite.plan.RelOptUtil; //导入依赖的package包/类
@Override
public RelNode toRel(ToRelContext context, RelOptTable relOptTable) {
  ViewExpansionContext.ViewExpansionToken token = null;
  try {
    RelDataType rowType = relOptTable.getRowType();
    RelNode rel;

    if (viewExpansionContext.isImpersonationEnabled()) {
      token = viewExpansionContext.reserveViewExpansionToken(viewOwner);
      rel = context.expandView(rowType, view.getSql(), token.getSchemaTree(), view.getWorkspaceSchemaPath());
    } else {
      rel = context.expandView(rowType, view.getSql(), view.getWorkspaceSchemaPath());
    }

    // If the View's field list is not "*", create a cast.
    if (!view.isDynamic() && !view.hasStar()) {
      rel = RelOptUtil.createCastRel(rel, rowType, true);
    }

    return rel;
  } finally {
    if (token != null) {
      token.release();
    }
  }
}
 
开发者ID:skhalifa,项目名称:QDrill,代码行数:27,代码来源:DrillViewTable.java

示例2: apply

import org.apache.calcite.plan.RelOptUtil; //导入依赖的package包/类
public boolean apply(Join join, JoinRelType joinType, RexNode exp) {
  if (joinType != JoinRelType.INNER) {
    return true;  // In OUTER join, we could not pull-up the filter.
                  // All we can do is keep the filter with JOIN, and
                  // then decide whether the filter could be pushed down
                  // into LEFT/RIGHT.
  }

  List<RexNode> tmpLeftKeys = Lists.newArrayList();
  List<RexNode> tmpRightKeys = Lists.newArrayList();
  List<RelDataTypeField> sysFields = Lists.newArrayList();

  RexNode remaining = RelOptUtil.splitJoinCondition(sysFields, join.getLeft(), join.getRight(), exp, tmpLeftKeys, tmpRightKeys, null, null);

  if (remaining.isAlwaysTrue()) {
    return true;
  }

  return false;
}
 
开发者ID:skhalifa,项目名称:QDrill,代码行数:21,代码来源:DrillFilterJoinRules.java

示例3: onMatch

import org.apache.calcite.plan.RelOptUtil; //导入依赖的package包/类
public void onMatch(RelOptRuleCall call) {
  Filter filterRel = call.rel(0);
  Project projRel = call.rel(1);

  // Don't push Filter past Project if the Filter is referencing an ITEM or a FLATTEN expression
  // from the Project.
  //\TODO: Ideally we should split up the filter conditions into ones that
  // reference the ITEM expression and ones that don't and push the latter past the Project
  if (findItemOrFlatten(filterRel.getCondition(), projRel.getProjects()) != null) {
    return;
  }

  // convert the filter to one that references the child of the project
  RexNode newCondition =
      RelOptUtil.pushFilterPastProject(filterRel.getCondition(), projRel);

  Filter newFilterRel = LogicalFilter.create(projRel.getInput(), newCondition);

  Project newProjRel =
      (Project) RelOptUtil.createProject(
          newFilterRel,
          projRel.getNamedProjects(),
          false);

  call.transformTo(newProjRel);
}
 
开发者ID:skhalifa,项目名称:QDrill,代码行数:27,代码来源:DrillPushFilterPastProjectRule.java

示例4: onMatch

import org.apache.calcite.plan.RelOptUtil; //导入依赖的package包/类
@Override
public void onMatch(RelOptRuleCall call) {
  final ScanPrel scan = (ScanPrel) call.rel(2);
  final ProjectPrel project = (ProjectPrel) call.rel(1);
  final FilterPrel filter = (FilterPrel) call.rel(0);

  HBaseGroupScan groupScan = (HBaseGroupScan)scan.getGroupScan();
  if (groupScan.isFilterPushedDown()) {
    /*
     * The rule can get triggered again due to the transformed "scan => filter" sequence
     * created by the earlier execution of this rule when we could not do a complete
     * conversion of Optiq Filter's condition to HBase Filter. In such cases, we rely upon
     * this flag to not do a re-processing of the rule on the already transformed call.
     */
     return;
  }

  // convert the filter to one that references the child of the project
  final RexNode condition =  RelOptUtil.pushFilterPastProject(filter.getCondition(), project);

  doPushFilterToScan(call, filter, project, scan, groupScan, condition);
}
 
开发者ID:skhalifa,项目名称:QDrill,代码行数:23,代码来源:HBasePushFilterIntoScan.java

示例5: apply

import org.apache.calcite.plan.RelOptUtil; //导入依赖的package包/类
public boolean apply(Join join, JoinRelType joinType, RexNode exp) {
  if (joinType != JoinRelType.INNER) {
    return true;  // In OUTER join, we could not pull-up the filter.
                  // All we can do is keep the filter with JOIN, and
                  // then decide whether the filter could be pushed down
                  // into LEFT/RIGHT.
  }

  List<RexNode> tmpLeftKeys = Lists.newArrayList();
  List<RexNode> tmpRightKeys = Lists.newArrayList();
  List<RelDataTypeField> sysFields = Lists.newArrayList();
  List<Integer> filterNulls = Lists.newArrayList();

  RexNode remaining = RelOptUtil.splitJoinCondition(sysFields, join.getLeft(), join.getRight(),
      exp, tmpLeftKeys, tmpRightKeys, filterNulls, null);

  return remaining.isAlwaysTrue();
}
 
开发者ID:dremio,项目名称:dremio-oss,代码行数:19,代码来源:FilterJoinRulesUtil.java

示例6: buildJoinConditions

import org.apache.calcite.plan.RelOptUtil; //导入依赖的package包/类
/**
 * Build the list of join conditions for this join.
 * A join condition is built only for equality and IS NOT DISTINCT FROM comparisons. The difference is:
 * null == null is FALSE whereas null IS NOT DISTINCT FROM null is TRUE
 * For a use case of the IS NOT DISTINCT FROM comparison, see
 * {@link org.apache.calcite.rel.rules.RemoveDistinctAggregateRule}
 * @param conditions populated list of join conditions
 * @param leftFields join fields from the left input
 * @param rightFields join fields from the right input
 */
protected void buildJoinConditions(List<JoinCondition> conditions,
    List<String> leftFields,
    List<String> rightFields,
    List<Integer> leftKeys,
    List<Integer> rightKeys) {
  List<RexNode> conjuncts = RelOptUtil.conjunctions(this.getCondition());
  short i=0;

  for (Pair<Integer, Integer> pair : Pair.zip(leftKeys, rightKeys)) {
    final RexNode conditionExpr = conjuncts.get(i++);
    final SqlKind kind  = conditionExpr.getKind();
    if (kind != SqlKind.EQUALS && kind != SqlKind.IS_NOT_DISTINCT_FROM) {
      throw UserException.unsupportedError()
          .message("Unsupported comparator in join condition %s", conditionExpr)
          .build(logger);
    }

    conditions.add(new JoinCondition(kind.toString(),
        FieldReference.getWithQuotedRef(leftFields.get(pair.left)),
        FieldReference.getWithQuotedRef(rightFields.get(pair.right))));
  }
}
 
开发者ID:dremio,项目名称:dremio-oss,代码行数:33,代码来源:JoinPrel.java

示例7: getJoinCategory

import org.apache.calcite.plan.RelOptUtil; //导入依赖的package包/类
public static JoinCategory getJoinCategory(RelNode left, RelNode right, RexNode condition,
    List<Integer> leftKeys, List<Integer> rightKeys, List<Boolean> filterNulls) {
  if (condition.isAlwaysTrue()) {
    return JoinCategory.CARTESIAN;
  }
  leftKeys.clear();
  rightKeys.clear();
  filterNulls.clear();
  RexNode remaining = RelOptUtil.splitJoinCondition(left, right, condition, leftKeys, rightKeys, filterNulls);

  if (!remaining.isAlwaysTrue() || (leftKeys.size() == 0 || rightKeys.size() == 0) ) {
    // for practical purposes these cases could be treated as inequality
    return JoinCategory.INEQUALITY;
  }
  return JoinCategory.EQUALITY;
}
 
开发者ID:dremio,项目名称:dremio-oss,代码行数:17,代码来源:JoinUtils.java

示例8: onMatch

import org.apache.calcite.plan.RelOptUtil; //导入依赖的package包/类
@Override
public void onMatch(RelOptRuleCall call) {
  final OldScanPrel scan = (OldScanPrel) call.rel(2);
  final ProjectPrel project = (ProjectPrel) call.rel(1);
  final FilterPrel filter = (FilterPrel) call.rel(0);

  HBaseGroupScan groupScan = (HBaseGroupScan)scan.getGroupScan();
  if (groupScan.isFilterPushedDown()) {
    /*
     * The rule can get triggered again due to the transformed "scan => filter" sequence
     * created by the earlier execution of this rule when we could not do a complete
     * conversion of Optiq Filter's condition to HBase Filter. In such cases, we rely upon
     * this flag to not do a re-processing of the rule on the already transformed call.
     */
     return;
  }

  // convert the filter to one that references the child of the project
  final RexNode condition =  RelOptUtil.pushPastProject(filter.getCondition(), project);

  doPushFilterToScan(call, filter, project, scan, groupScan, condition);
}
 
开发者ID:dremio,项目名称:dremio-oss,代码行数:23,代码来源:HBasePushFilterIntoScan.java

示例9: trimUnusedFields

import org.apache.calcite.plan.RelOptUtil; //导入依赖的package包/类
/**
 * Walks over a tree of relational expressions, replacing each
 * {@link RelNode} with a 'slimmed down' relational expression that projects
 * only the fields required by its consumer.
 *
 * <p>This may make things easier for the optimizer, by removing crud that
 * would expand the search space, but is difficult for the optimizer itself
 * to do it, because optimizer rules must preserve the number and type of
 * fields. Hence, this transform that operates on the entire tree, similar
 * to the {@link RelStructuredTypeFlattener type-flattening transform}.
 *
 * <p>Currently this functionality is disabled in farrago/luciddb; the
 * default implementation of this method does nothing.
 *
 * @param ordered Whether the relational expression must produce results in
 * a particular order (typically because it has an ORDER BY at top level)
 * @param rootRel Relational expression that is at the root of the tree
 * @return Trimmed relational expression
 */
public RelNode trimUnusedFields(boolean ordered, RelNode rootRel) {
	// Trim fields that are not used by their consumer.
	if (isTrimUnusedFields()) {
		final RelFieldTrimmer trimmer = newFieldTrimmer();
		final List<RelCollation> collations =
			rootRel.getTraitSet().getTraits(RelCollationTraitDef.INSTANCE);
		rootRel = trimmer.trim(rootRel);
		if (!ordered
			&& collations != null
			&& !collations.isEmpty()
			&& !collations.equals(ImmutableList.of(RelCollations.EMPTY))) {
			final RelTraitSet traitSet = rootRel.getTraitSet()
				.replace(RelCollationTraitDef.INSTANCE, collations);
			rootRel = rootRel.copy(traitSet, rootRel.getInputs());
		}
		if (SQL2REL_LOGGER.isDebugEnabled()) {
			SQL2REL_LOGGER.debug(
				RelOptUtil.dumpPlan("Plan after trimming unused fields", rootRel,
					SqlExplainFormat.TEXT, SqlExplainLevel.EXPPLAN_ATTRIBUTES));
		}
	}
	return rootRel;
}
 
开发者ID:axbaretto,项目名称:flink,代码行数:43,代码来源:SqlToRelConverter.java

示例10: decorrelateQuery

import org.apache.calcite.plan.RelOptUtil; //导入依赖的package包/类
/**
 * Decorrelates a query.
 * <p>
 * <p>This is the main entry point to {@code FlinkRelDecorrelator}.
 *
 * @param rootRel Root node of the query
 * @return Equivalent query with all
 * {@link LogicalCorrelate} instances removed
 */
public static RelNode decorrelateQuery(RelNode rootRel) {
	final CorelMap corelMap = new CorelMapBuilder().build(rootRel);
	if (!corelMap.hasCorrelation()) {
		return rootRel;
	}

	final RelOptCluster cluster = rootRel.getCluster();
	final FlinkRelDecorrelator decorrelator = new FlinkRelDecorrelator(cluster, corelMap, cluster.getPlanner().getContext());

	RelNode newRootRel = decorrelator.removeCorrelationViaRule(rootRel);

	if (SQL2REL_LOGGER.isDebugEnabled()) {
		SQL2REL_LOGGER.debug(RelOptUtil.dumpPlan("Plan after removing Correlator", newRootRel, false, SqlExplainLevel.EXPPLAN_ATTRIBUTES));
	}

	if (!decorrelator.cm.mapCorVarToCorRel.isEmpty()) {
		newRootRel = decorrelator.decorrelate(newRootRel);
	}

	return newRootRel;
}
 
开发者ID:axbaretto,项目名称:flink,代码行数:31,代码来源:FlinkRelDecorrelator.java

示例11: apply

import org.apache.calcite.plan.RelOptUtil; //导入依赖的package包/类
public boolean apply(Join join, JoinRelType joinType, RexNode exp) {
  if (joinType != JoinRelType.INNER) {
    return true;  // In OUTER join, we could not pull-up the filter.
                  // All we can do is keep the filter with JOIN, and
                  // then decide whether the filter could be pushed down
                  // into LEFT/RIGHT.
  }

  List<RexNode> tmpLeftKeys = Lists.newArrayList();
  List<RexNode> tmpRightKeys = Lists.newArrayList();
  List<RelDataTypeField> sysFields = Lists.newArrayList();
  List<Integer> filterNulls = Lists.newArrayList();

  RexNode remaining = RelOptUtil.splitJoinCondition(sysFields, join.getLeft(), join.getRight(), exp, tmpLeftKeys, tmpRightKeys, filterNulls, null);

  if (remaining.isAlwaysTrue()) {
    return true;
  }

  return false;
}
 
开发者ID:axbaretto,项目名称:drill,代码行数:22,代码来源:DrillFilterJoinRules.java

示例12: computeSelfCost

import org.apache.calcite.plan.RelOptUtil; //导入依赖的package包/类
@Override
public RelOptCost computeSelfCost(RelOptPlanner planner, RelMetadataQuery mq) {
  if (PrelUtil.getSettings(getCluster()).useDefaultCosting()) {
    return super.computeSelfCost(planner, mq).multiplyBy(.1);
  }
  double leftRowCount = mq.getRowCount(this.getLeft());
  double rightRowCount = mq.getRowCount(this.getRight());
  double nljFactor = PrelUtil.getSettings(getCluster()).getNestedLoopJoinFactor();

  // cpu cost of evaluating each expression in join condition
  int exprNum = RelOptUtil.conjunctions(getCondition()).size() + RelOptUtil.disjunctions(getCondition()).size();
  double joinConditionCost = DrillCostBase.COMPARE_CPU_COST * exprNum;

  double cpuCost = joinConditionCost * (leftRowCount * rightRowCount) * nljFactor;

  DrillCostFactory costFactory = (DrillCostFactory) planner.getCostFactory();
  return costFactory.makeCost(leftRowCount * rightRowCount, cpuCost, 0, 0, 0);
}
 
开发者ID:axbaretto,项目名称:drill,代码行数:19,代码来源:NestedLoopJoinPrel.java

示例13: onMatch

import org.apache.calcite.plan.RelOptUtil; //导入依赖的package包/类
@Override
public void onMatch(RelOptRuleCall call) {
  final ScanPrel scan = (ScanPrel) call.rel(2);
  final ProjectPrel project = (ProjectPrel) call.rel(1);
  final FilterPrel filter = (FilterPrel) call.rel(0);

  HBaseGroupScan groupScan = (HBaseGroupScan)scan.getGroupScan();
  if (groupScan.isFilterPushedDown()) {
    /*
     * The rule can get triggered again due to the transformed "scan => filter" sequence
     * created by the earlier execution of this rule when we could not do a complete
     * conversion of Optiq Filter's condition to HBase Filter. In such cases, we rely upon
     * this flag to not do a re-processing of the rule on the already transformed call.
     */
     return;
  }

  // convert the filter to one that references the child of the project
  final RexNode condition =  RelOptUtil.pushPastProject(filter.getCondition(), project);

  doPushFilterToScan(call, filter, project, scan, groupScan, condition);
}
 
开发者ID:axbaretto,项目名称:drill,代码行数:23,代码来源:HBasePushFilterIntoScan.java

示例14: executeSQL

import org.apache.calcite.plan.RelOptUtil; //导入依赖的package包/类
/**
 * This is the main method takes SQL statement as input and contructs a DAG using contructs registered with this
 * {@link SQLExecEnvironment}.
 *
 * @param sql SQL statement that should be converted to a DAG.
 */
public void executeSQL(DAG dag, String sql)
{
  FrameworkConfig config = buildFrameWorkConfig();
  Planner planner = Frameworks.getPlanner(config);
  try {
    logger.info("Parsing SQL statement: {}", sql);
    SqlNode parsedTree = planner.parse(sql);
    SqlNode validatedTree = planner.validate(parsedTree);
    RelNode relationalTree = planner.rel(validatedTree).rel;
    logger.info("RelNode relationalTree generate from SQL statement is:\n {}",
        Util.toLinux(RelOptUtil.toString(relationalTree)));
    RelNodeVisitor visitor = new RelNodeVisitor(dag, typeFactory);
    visitor.traverse(relationalTree);
  } catch (Exception e) {
    throw Throwables.propagate(e);
  } finally {
    planner.close();
  }
}
 
开发者ID:apache,项目名称:apex-malhar,代码行数:26,代码来源:SQLExecEnvironment.java

示例15: testEndToEndFlatten

import org.apache.calcite.plan.RelOptUtil; //导入依赖的package包/类
@Test
public void testEndToEndFlatten() throws Exception {
  int numMessages = 20;
  TestAvroSystemFactory.messages.clear();
  Map<String, String> staticConfigs = SamzaSqlTestConfig.fetchStaticConfigsWithFactories(numMessages);
  LOG.info(" Class Path : " + RelOptUtil.class.getProtectionDomain().getCodeSource().getLocation().toURI().getPath());
  String sql1 =
      "Insert into testavro.outputTopic select Flatten(array_values) as string_value, id from testavro.COMPLEX1";
  List<String> sqlStmts = Collections.singletonList(sql1);
  staticConfigs.put(SamzaSqlApplicationConfig.CFG_SQL_STMTS_JSON, JsonUtil.toJson(sqlStmts));
  SamzaSqlApplicationRunner runner = new SamzaSqlApplicationRunner(true, new MapConfig(staticConfigs));
  runner.runAndWaitForFinish();

  List<OutgoingMessageEnvelope> outMessages = new ArrayList<>(TestAvroSystemFactory.messages);

  int expectedMessages = 0;
  // Flatten de-normalizes the data. So there is separate record for each entry in the array.
  for (int index = 1; index < numMessages; index++) {
    expectedMessages = expectedMessages + Math.max(1, index);
  }
  Assert.assertEquals(expectedMessages, outMessages.size());
}
 
开发者ID:apache,项目名称:samza,代码行数:23,代码来源:TestSamzaSqlEndToEnd.java


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