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


Java LogicalPlan类代码示例

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


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

示例1: testNotBroadcastJoinTwoLargeTable

import org.apache.tajo.engine.planner.LogicalPlan; //导入依赖的package包/类
@Test
public final void testNotBroadcastJoinTwoLargeTable() throws IOException, PlanningException {
  // This query is not broadcast join
  String query = "select count(*) from large1 " +
      "join large2 on large1_id = large2_id ";

  LogicalPlanner planner = new LogicalPlanner(catalog);
  LogicalOptimizer optimizer = new LogicalOptimizer(conf);
  Expr expr =  analyzer.parse(query);
  LogicalPlan plan = planner.createPlan(LocalTajoTestingUtility.createDummySession(), expr);

  optimizer.optimize(plan);

  QueryId queryId = QueryIdFactory.newQueryId(System.currentTimeMillis(), 0);
  QueryContext queryContext = new QueryContext();
  MasterPlan masterPlan = new MasterPlan(queryId, queryContext, plan);
  GlobalPlanner globalPlanner = new GlobalPlanner(conf, catalog);
  globalPlanner.build(masterPlan);

  ExecutionBlockCursor ebCursor = new ExecutionBlockCursor(masterPlan);
  while (ebCursor.hasNext()) {
    ExecutionBlock eb = ebCursor.nextBlock();
    Collection<String> broadcastTables = eb.getBroadcastTables();
    assertTrue(broadcastTables == null || broadcastTables.isEmpty());
  }
}
 
开发者ID:gruter,项目名称:tajo-cdh,代码行数:27,代码来源:TestBroadcastJoinPlan.java

示例2: rewrite

import org.apache.tajo.engine.planner.LogicalPlan; //导入依赖的package包/类
@Override
public LogicalPlan rewrite(LogicalPlan plan) throws PlanningException {
  boolean containsPartitionedTables;
  for (LogicalPlan.QueryBlock block : plan.getQueryBlocks()) {
    containsPartitionedTables = false;
    for (RelationNode relation : block.getRelations()) {
      if (relation.getType() == NodeType.SCAN) {
        TableDesc table = ((ScanNode)relation).getTableDesc();
        if (table.hasPartition()) {
          containsPartitionedTables = true;
        }
      }
    }
    if (containsPartitionedTables) {
      rewriter.visit(block, plan, block, block.getRoot(), new Stack<LogicalNode>());
    }
  }
  return plan;
}
 
开发者ID:apache,项目名称:incubator-tajo,代码行数:20,代码来源:PartitionedTableRewriter.java

示例3: findJoin

import org.apache.tajo.engine.planner.LogicalPlan; //导入依赖的package包/类
/**
 * Find a join between two logical operator trees
 *
 * @return If there is no join condition between two relation, it returns NULL value.
 */
private static JoinEdge findJoin(LogicalPlan plan, JoinGraph graph, LogicalNode outer, LogicalNode inner) throws PlanningException {
  JoinEdge foundJoinEdge = null;

  for (String outerName : PlannerUtil.getRelationLineageWithinQueryBlock(plan, outer)) {
    for (String innerName : PlannerUtil.getRelationLineageWithinQueryBlock(plan, inner)) {

      // Find all joins between two relations and merge them into one join if possible
      if (graph.hasEdge(outerName, innerName)) {
        JoinEdge existJoinEdge = graph.getEdge(outerName, innerName);
        foundJoinEdge = new JoinEdge(existJoinEdge.getJoinType(), outer, inner, existJoinEdge.getJoinQual());
      }
    }
  }

  if (foundJoinEdge == null) {
    foundJoinEdge = new JoinEdge(JoinType.CROSS, outer, inner);
  }

  return foundJoinEdge;
}
 
开发者ID:apache,项目名称:incubator-tajo,代码行数:26,代码来源:GreedyHeuristicJoinOrderAlgorithm.java

示例4: testGetContainExprs

import org.apache.tajo.engine.planner.LogicalPlan; //导入依赖的package包/类
@Test
public final void testGetContainExprs() throws CloneNotSupportedException, PlanningException {
  Expr expr = analyzer.parse(QUERIES[1]);
  LogicalPlan plan = planner.createPlan(expr, true);
  Target [] targets = plan.getRootBlock().getRawTargets();
  Column col1 = new Column("people.score", TajoDataTypes.Type.INT4);
  Collection<EvalNode> exprs =
      EvalTreeUtil.getContainExpr(targets[0].getEvalTree(), col1);
  EvalNode node = exprs.iterator().next();
  assertEquals(EvalType.LTH, node.getType());
  assertEquals(EvalType.PLUS, node.getLeftExpr().getType());
  assertEquals(new ConstEval(DatumFactory.createInt4(4)), node.getRightExpr());

  Column col2 = new Column("people.age", TajoDataTypes.Type.INT4);
  exprs = EvalTreeUtil.getContainExpr(targets[1].getEvalTree(), col2);
  node = exprs.iterator().next();
  assertEquals(EvalType.GTH, node.getType());
  assertEquals("people.age", node.getLeftExpr().getName());
  assertEquals(new ConstEval(DatumFactory.createInt4(5)), node.getRightExpr());
}
 
开发者ID:apache,项目名称:incubator-tajo,代码行数:21,代码来源:TestEvalTreeUtil.java

示例5: testSimplify

import org.apache.tajo.engine.planner.LogicalPlan; //导入依赖的package包/类
@Test
public final void testSimplify() throws PlanningException {
  Target [] targets = getRawTargets(QUERIES[0]);
  EvalNode node = AlgebraicUtil.eliminateConstantExprs(targets[0].getEvalTree());
  assertEquals(EvalType.CONST, node.getType());
  assertEquals(7, node.eval(null, null).asInt4());
  node = AlgebraicUtil.eliminateConstantExprs(targets[1].getEvalTree());
  assertEquals(EvalType.CONST, node.getType());
  assertTrue(7.0d == node.eval(null, null).asFloat8());

  Expr expr = analyzer.parse(QUERIES[1]);
  LogicalPlan plan = planner.createPlan(expr, true);
  targets = plan.getRootBlock().getRawTargets();
  Column col1 = new Column("people.score", TajoDataTypes.Type.INT4);
  Collection<EvalNode> exprs =
      EvalTreeUtil.getContainExpr(targets[0].getEvalTree(), col1);
  node = exprs.iterator().next();
}
 
开发者ID:apache,项目名称:incubator-tajo,代码行数:19,代码来源:TestEvalTreeUtil.java

示例6: testFindDistinctAggFunctions

import org.apache.tajo.engine.planner.LogicalPlan; //导入依赖的package包/类
@Test
public final void testFindDistinctAggFunctions() throws PlanningException {
  String query = "select sum(score) + max(age) from people";
  Expr expr = analyzer.parse(query);
  LogicalPlan plan = planner.createPlan(expr);
  GroupbyNode groupByNode = plan.getRootBlock().getNode(NodeType.GROUP_BY);
  EvalNode [] aggEvals = groupByNode.getAggFunctions();

  List<AggregationFunctionCallEval> list = new ArrayList<AggregationFunctionCallEval>();
  for (int i = 0; i < aggEvals.length; i++) {
    list.addAll(EvalTreeUtil.findDistinctAggFunction(aggEvals[i]));
  }
  assertEquals(2, list.size());

  Set<String> result = Sets.newHashSet("max", "sum");
  for (AggregationFunctionCallEval eval : list) {
    assertTrue(result.contains(eval.getName()));
  }
}
 
开发者ID:apache,项目名称:incubator-tajo,代码行数:20,代码来源:TestEvalTreeUtil.java

示例7: testNextBlock

import org.apache.tajo.engine.planner.LogicalPlan; //导入依赖的package包/类
@Test
public void testNextBlock() throws Exception {
  Expr context = analyzer.parse(
      "select s_acctbal, s_name, n_name, p_partkey, p_mfgr, s_address, s_phone, s_comment, ps_supplycost, " +
          "r_name, p_type, p_size " +
          "from region join nation on n_regionkey = r_regionkey and r_name = 'AMERICA' " +
          "join supplier on s_nationkey = n_nationkey " +
          "join partsupp on s_suppkey = ps_suppkey " +
          "join part on p_partkey = ps_partkey and p_type like '%BRASS' and p_size = 15");
  LogicalPlan logicalPlan = logicalPlanner.createPlan(context);
  optimizer.optimize(logicalPlan);
  QueryContext queryContext = new QueryContext();
  MasterPlan plan = new MasterPlan(LocalTajoTestingUtility.newQueryId(), queryContext, logicalPlan);
  planner.build(plan);

  ExecutionBlockCursor cursor = new ExecutionBlockCursor(plan);

  int count = 0;
  while(cursor.hasNext()) {
    cursor.nextBlock();
    count++;
  }

  assertEquals(6, count);
}
 
开发者ID:apache,项目名称:incubator-tajo,代码行数:26,代码来源:TestExecutionBlockCursor.java

示例8: testGetContainExprs

import org.apache.tajo.engine.planner.LogicalPlan; //导入依赖的package包/类
@Test
public final void testGetContainExprs() throws CloneNotSupportedException, PlanningException {
  Expr expr = analyzer.parse(QUERIES[1]);
  LogicalPlan plan = planner.createPlan(session, expr, true);
  Target [] targets = plan.getRootBlock().getRawTargets();
  Column col1 = new Column("default.people.score", TajoDataTypes.Type.INT4);
  Collection<EvalNode> exprs =
      EvalTreeUtil.getContainExpr(targets[0].getEvalTree(), col1);
  EvalNode node = exprs.iterator().next();
  assertEquals(EvalType.LTH, node.getType());
  assertEquals(EvalType.PLUS, node.getLeftExpr().getType());
  assertEquals(new ConstEval(DatumFactory.createInt4(4)), node.getRightExpr());

  Column col2 = new Column("default.people.age", TajoDataTypes.Type.INT4);
  exprs = EvalTreeUtil.getContainExpr(targets[1].getEvalTree(), col2);
  node = exprs.iterator().next();
  assertEquals(EvalType.GTH, node.getType());
  assertEquals("default.people.age", node.getLeftExpr().getName());
  assertEquals(new ConstEval(DatumFactory.createInt4(5)), node.getRightExpr());
}
 
开发者ID:gruter,项目名称:tajo-cdh,代码行数:21,代码来源:TestEvalTreeUtil.java

示例9: testSimplify

import org.apache.tajo.engine.planner.LogicalPlan; //导入依赖的package包/类
@Test
public final void testSimplify() throws PlanningException {
  Target [] targets = getRawTargets(QUERIES[0]);
  EvalNode node = AlgebraicUtil.eliminateConstantExprs(targets[0].getEvalTree());
  assertEquals(EvalType.CONST, node.getType());
  assertEquals(7, node.eval(null, null).asInt4());
  node = AlgebraicUtil.eliminateConstantExprs(targets[1].getEvalTree());
  assertEquals(EvalType.CONST, node.getType());
  assertTrue(7.0d == node.eval(null, null).asFloat8());

  Expr expr = analyzer.parse(QUERIES[1]);
  LogicalPlan plan = planner.createPlan(session, expr, true);
  targets = plan.getRootBlock().getRawTargets();
  Column col1 = new Column("default.people.score", TajoDataTypes.Type.INT4);
  Collection<EvalNode> exprs =
      EvalTreeUtil.getContainExpr(targets[0].getEvalTree(), col1);
  node = exprs.iterator().next();
}
 
开发者ID:gruter,项目名称:tajo-cdh,代码行数:19,代码来源:TestEvalTreeUtil.java

示例10: testFindDistinctAggFunctions

import org.apache.tajo.engine.planner.LogicalPlan; //导入依赖的package包/类
@Test
public final void testFindDistinctAggFunctions() throws PlanningException {
  String query = "select sum(score) + max(age) from people";
  Expr expr = analyzer.parse(query);
  LogicalPlan plan = planner.createPlan(session, expr);
  GroupbyNode groupByNode = plan.getRootBlock().getNode(NodeType.GROUP_BY);
  EvalNode [] aggEvals = groupByNode.getAggFunctions();

  List<AggregationFunctionCallEval> list = new ArrayList<AggregationFunctionCallEval>();
  for (int i = 0; i < aggEvals.length; i++) {
    list.addAll(EvalTreeUtil.findDistinctAggFunction(aggEvals[i]));
  }
  assertEquals(2, list.size());

  Set<String> result = Sets.newHashSet("max", "sum");
  for (AggregationFunctionCallEval eval : list) {
    assertTrue(result.contains(eval.getName()));
  }
}
 
开发者ID:gruter,项目名称:tajo-cdh,代码行数:20,代码来源:TestEvalTreeUtil.java

示例11: testNextBlock

import org.apache.tajo.engine.planner.LogicalPlan; //导入依赖的package包/类
@Test
public void testNextBlock() throws Exception {
  Expr context = analyzer.parse(
      "select s_acctbal, s_name, n_name, p_partkey, p_mfgr, s_address, s_phone, s_comment, ps_supplycost, " +
          "r_name, p_type, p_size " +
          "from region join nation on n_regionkey = r_regionkey and r_name = 'AMERICA' " +
          "join supplier on s_nationkey = n_nationkey " +
          "join partsupp on s_suppkey = ps_suppkey " +
          "join part on p_partkey = ps_partkey and p_type like '%BRASS' and p_size = 15");
  LogicalPlan logicalPlan = logicalPlanner.createPlan(LocalTajoTestingUtility.createDummySession(), context);
  optimizer.optimize(logicalPlan);
  QueryContext queryContext = new QueryContext();
  MasterPlan plan = new MasterPlan(LocalTajoTestingUtility.newQueryId(), queryContext, logicalPlan);
  planner.build(plan);

  ExecutionBlockCursor cursor = new ExecutionBlockCursor(plan);

  int count = 0;
  while(cursor.hasNext()) {
    cursor.nextBlock();
    count++;
  }

  assertEquals(6, count);
}
 
开发者ID:gruter,项目名称:tajo-cdh,代码行数:26,代码来源:TestExecutionBlockCursor.java

示例12: rewrite

import org.apache.tajo.engine.planner.LogicalPlan; //导入依赖的package包/类
/**
 * Rewrite a logical plan with all query rewrite rules added to this engine.
 *
 * @param plan The plan to be rewritten with all query rewrite rule.
 * @return The rewritten plan.
 */
public LogicalPlan rewrite(LogicalPlan plan) throws PlanningException {
  RewriteRule rule;
  for (Entry<String, RewriteRule> rewriteRule : rewriteRules.entrySet()) {
    rule = rewriteRule.getValue();
    if (rule.isEligible(plan)) {
      plan = rule.rewrite(plan);
      LOG.info("The rule \"" + rule.getName() + " \" rewrites the query.");
    }
  }

  return plan;
}
 
开发者ID:apache,项目名称:incubator-tajo,代码行数:19,代码来源:BasicQueryRewriteEngine.java

示例13: isEligible

import org.apache.tajo.engine.planner.LogicalPlan; //导入依赖的package包/类
@Override
public boolean isEligible(LogicalPlan plan) {
  for (LogicalPlan.QueryBlock block : plan.getQueryBlocks()) {
    for (RelationNode relation : block.getRelations()) {
      if (relation.getType() == NodeType.SCAN) {
        TableDesc table = ((ScanNode)relation).getTableDesc();
        if (table.hasPartition()) {
          return true;
        }
      }
    }
  }
  return false;
}
 
开发者ID:apache,项目名称:incubator-tajo,代码行数:15,代码来源:PartitionedTableRewriter.java

示例14: visitScan

import org.apache.tajo.engine.planner.LogicalPlan; //导入依赖的package包/类
@Override
public Object visitScan(Object object, LogicalPlan plan, LogicalPlan.QueryBlock block, ScanNode scanNode,
                        Stack<LogicalNode> stack) throws PlanningException {

  TableDesc table = scanNode.getTableDesc();
  if (!table.hasPartition()) {
    return null;
  }

  try {
    Path [] filteredPaths = findFilteredPartitionPaths(scanNode);
    plan.addHistory("PartitionTableRewriter chooses " + filteredPaths.length + " of partitions");
    PartitionedTableScanNode rewrittenScanNode = plan.createNode(PartitionedTableScanNode.class);
    rewrittenScanNode.init(scanNode, filteredPaths);
    updateTableStat(rewrittenScanNode);

    // if it is topmost node, set it as the rootnode of this block.
    if (stack.empty()) {
      block.setRoot(rewrittenScanNode);
    } else {
      PlannerUtil.replaceNode(plan, stack.peek(), scanNode, rewrittenScanNode);
    }
  } catch (IOException e) {
    throw new PlanningException("Partitioned Table Rewrite Failed: \n" + e.getMessage());
  }
  return null;
}
 
开发者ID:apache,项目名称:incubator-tajo,代码行数:28,代码来源:PartitionedTableRewriter.java

示例15: findBestOrder

import org.apache.tajo.engine.planner.LogicalPlan; //导入依赖的package包/类
@Override
public FoundJoinOrder findBestOrder(LogicalPlan plan, LogicalPlan.QueryBlock block, JoinGraph joinGraph,
                                    Set<String> relationsWithoutQual) throws PlanningException {

  // Setup a remain relation set to be joined
  // Why we should use LinkedHashSet? - it should keep the deterministic for the order of joins.
  // Otherwise, join orders can be different even if join costs are the same to each other.
  Set<LogicalNode> remainRelations = new LinkedHashSet<LogicalNode>();
  for (RelationNode relation : block.getRelations()) {
    remainRelations.add(relation);
  }

  LogicalNode latestJoin;
  JoinEdge bestPair;

  while (remainRelations.size() > 1) {
    // Find the best join pair among all joinable operators in candidate set.
    bestPair = getBestPair(plan, joinGraph, remainRelations);

    remainRelations.remove(bestPair.getLeftRelation()); // remainRels = remainRels \ Ti
    remainRelations.remove(bestPair.getRightRelation()); // remainRels = remainRels \ Tj

    latestJoin = createJoinNode(plan, bestPair);
    remainRelations.add(latestJoin);

    // all logical nodes should be registered to corresponding blocks
    block.registerNode(latestJoin);
  }

  JoinNode joinTree = (JoinNode) remainRelations.iterator().next();
  // all generated nodes should be registered to corresponding blocks
  block.registerNode(joinTree);
  return new FoundJoinOrder(joinTree, getCost(joinTree));
}
 
开发者ID:apache,项目名称:incubator-tajo,代码行数:35,代码来源:GreedyHeuristicJoinOrderAlgorithm.java


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