當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。