@Override public Object visitScan(Object object, LogicalPlan plan, LogicalPlan.QueryBlock block, ScanNode scanNode, Stack<LogicalNode> stack) throws TajoException { List<AccessPathInfo> accessPaths = block.getAccessInfos(scanNode); AccessPathInfo optimalPath = null; IndexScanNode indexScanNode = new IndexScanNode(plan.newPID(), scanNode, indexScanInfo.getKeySchema(), indexScanInfo.getPredicates(), indexScanInfo.getIndexPath()); if (stack.empty() || block.getRoot().equals(scanNode)) { block.setRoot(indexScanNode); } else { PlannerUtil.replaceNode(plan, stack.peek(), scanNode, indexScanNode); block.registerNode(indexScanNode);
@Test public final void testFindDistinctAggFunctions() throws TajoException { String query = "select sum(score) + max(age) from people"; Expr expr = analyzer.parse(query); LogicalPlan plan = planner.createPlan(defaultContext, expr); GroupbyNode groupByNode = plan.getRootBlock().getNode(NodeType.GROUP_BY); List aggEvals = groupByNode.getAggFunctions(); List<AggregationFunctionCallEval> list = new ArrayList<>(); for (Object aggEval : aggEvals) { list.addAll(EvalTreeUtil.findDistinctAggFunction((EvalNode) aggEval)); } assertEquals(2, list.size()); Set<String> result = Sets.newHashSet("max", "sum"); for (AggregationFunctionCallEval eval : list) { assertTrue(result.contains(eval.getName())); } }
@Override public LogicalNode visitUnion(Context context, LogicalPlan plan, LogicalPlan.QueryBlock block, UnionNode node, Stack<LogicalNode> stack) throws TajoException { LogicalPlan.QueryBlock leftBlock = plan.getBlock(node.getLeftChild()); LogicalPlan.QueryBlock rightBlock = plan.getBlock(node.getRightChild()); Context leftContext = new Context(plan, PlannerUtil.toQualifiedFieldNames(context.requiredSet, leftBlock.getName())); Context rightContext = new Context(plan, PlannerUtil.toQualifiedFieldNames(context.requiredSet, rightBlock.getName())); stack.push(node); visit(leftContext, plan, leftBlock, leftBlock.getRoot(), new Stack<>()); visit(rightContext, plan, rightBlock, rightBlock.getRoot(), new Stack<>()); stack.pop(); return node; }
if (block.isAggregationRequired()) { child = insertGroupbyNode(context, child, stack); if (block.hasWindowSpecs()) { LogicalNode windowAggNode = insertWindowAggNode(context, child, stack, referenceNames, referencesPair.getSecond()); projectionNode = context.queryBlock.getNodeFromExpr(projection); projectionNode.init(projection.isDistinct(), targets); projectionNode.setChild(child); projectionNode.setOutSchema(PlannerUtil.targetToSchema(targets)); if (projection.isDistinct() && block.hasNode(NodeType.GROUP_BY)) { throw makeSyntaxError("Cannot support grouping and distinct at the same time yet"); } else {
} else if (functionType == FunctionType.AGGREGATION || functionType == FunctionType.UDA) { if (!ctx.currentBlock.hasNode(NodeType.GROUP_BY)) { ctx.currentBlock.setAggregationRequire();
public void execNonFromQuery(QueryContext queryContext, Session session, String query, LogicalPlan plan, SubmitQueryResponse.Builder responseBuilder) throws Exception { LogicalRootNode rootNode = plan.getRootBlock().getRoot(); evalContext.setTimeZone(TimeZone.getTimeZone(timezoneId)); List<Target> targets = plan.getRootBlock().getRawTargets(); if (targets == null) { throw new TajoInternalError("no targets"); (LogicalRootNode) plan.getRootBlock().getRoot());
} else if (functionType == FunctionType.AGGREGATION || functionType == FunctionType.UDA) { if (!ctx.currentBlock.hasNode(NodeType.GROUP_BY)) { ctx.currentBlock.setAggregationRequire();
if (block.isAggregationRequired()) { child = insertGroupbyNode(context, child, stack); if (block.hasWindowSpecs()) { LogicalNode windowAggNode = insertWindowAggNode(context, child, stack, referenceNames, referencesPair.getSecond()); projectionNode = context.queryBlock.getNodeFromExpr(projection); projectionNode.init(projection.isDistinct(), targets); projectionNode.setChild(child); projectionNode.setOutSchema(PlannerUtil.targetToSchema(targets)); if (projection.isDistinct() && block.hasNode(NodeType.GROUP_BY)) { throw makeSyntaxError("Cannot support grouping and distinct at the same time yet"); } else {
List<Target> targets = plan.getRootBlock().getRawTargets(); if (targets == null) { throw new RuntimeException("Wrong query statement or query plan: " + parsedResults.get(0).getHistoryStatement());
public void execNonFromQuery(QueryContext queryContext, Session session, String query, LogicalPlan plan, SubmitQueryResponse.Builder responseBuilder) throws Exception { LogicalRootNode rootNode = plan.getRootBlock().getRoot(); evalContext.setTimeZone(TimeZone.getTimeZone(timezoneId)); Target[] targets = plan.getRootBlock().getRawTargets(); if (targets == null) { throw new TajoInternalError("no targets"); (LogicalRootNode) plan.getRootBlock().getRoot());
for (RelationNode relationNode : block.getRelations()) { vertexes.add(new RelationVertex(relationNode)); block.registerNode(joinTree); return new FoundJoinOrder(joinTree, getCost(joinTree));
@Override public Object visitScan(Object object, LogicalPlan plan, LogicalPlan.QueryBlock block, ScanNode scanNode, Stack<LogicalNode> stack) throws TajoException { List<AccessPathInfo> accessPaths = block.getAccessInfos(scanNode); AccessPathInfo optimalPath = null; IndexScanNode indexScanNode = new IndexScanNode(plan.newPID(), scanNode, indexScanInfo.getKeySchema(), indexScanInfo.getPredicates(), indexScanInfo.getIndexPath()); if (stack.empty() || block.getRoot().equals(scanNode)) { block.setRoot(indexScanNode); } else { PlannerUtil.replaceNode(plan, stack.peek(), scanNode, indexScanNode); block.registerNode(indexScanNode);
@Override public LogicalPlan rewrite(LogicalPlanRewriteRuleContext context) throws TajoException { LogicalPlan plan = context.getPlan(); LogicalRootNode rootNode = plan.getRootBlock().getRoot(); plan.getRootBlock().registerNode(sortNode);
LogicalRootNode rootNode = plan.getRootBlock().getRoot(); boolean simpleOperator = rootNode.getChild().getType() == NodeType.LIMIT || rootNode.getChild().getType() == NodeType.SCAN || rootNode.getChild().getType() == NodeType.PARTITIONS_SCAN; boolean noOrderBy = !plan.getRootBlock().hasNode(NodeType.SORT); boolean noGroupBy = !plan.getRootBlock().hasNode(NodeType.GROUP_BY); boolean noWhere = !plan.getRootBlock().hasNode(NodeType.SELECTION); boolean noJoin = !plan.getRootBlock().hasNode(NodeType.JOIN); boolean singleRelation = (plan.getRootBlock().hasNode(NodeType.SCAN) || plan.getRootBlock().hasNode(NodeType.PARTITIONS_SCAN)) && PlannerUtil.getRelationLineage(plan.getRootBlock().getRoot()).length == 1; ScanNode scanNode = plan.getRootBlock().getNode(NodeType.SCAN); if (scanNode == null) { scanNode = plan.getRootBlock().getNode(NodeType.PARTITIONS_SCAN); EvalNode node = ((SelectionNode) plan.getRootBlock().getNode(NodeType.SELECTION)).getQual(); Schema partSchema = scanNode.getTableDesc().getPartitionMethod().getExpressionSchema(); if (EvalTreeUtil.checkIfPartitionSelection(node, partSchema)) {
context.generateUniqueSubQueryName()), setOperationNode); setTargetOfTableSubQuery(context, currentBlock, setOpTableSubQueryNode); currentBlock.registerNode(setOpTableSubQueryNode); currentBlock.addRelation(setOpTableSubQueryNode); setOpGroupbyNode.setTargets(setOpTarget); setOpGroupbyNode.setChild(setOpTableSubQueryNode); currentBlock.registerNode(setOpGroupbyNode); setOpProjectionNode.setTargets(setOpTarget); setOpProjectionNode.setChild(setOpGroupbyNode); currentBlock.registerNode(setOpProjectionNode); setOpBlock.registerNode(setOperationNode); setOpBlock.setRoot(setOperationNode);
LogicalRootNode rootNode = plan.getRootBlock().getRoot(); boolean simpleOperator = rootNode.getChild().getType() == NodeType.LIMIT || rootNode.getChild().getType() == NodeType.SCAN || rootNode.getChild().getType() == NodeType.PARTITIONS_SCAN; boolean noOrderBy = !plan.getRootBlock().hasNode(NodeType.SORT); boolean noGroupBy = !plan.getRootBlock().hasNode(NodeType.GROUP_BY); boolean noWhere = !plan.getRootBlock().hasNode(NodeType.SELECTION); boolean noJoin = !plan.getRootBlock().hasNode(NodeType.JOIN); boolean singleRelation = (plan.getRootBlock().hasNode(NodeType.SCAN) || plan.getRootBlock().hasNode(NodeType.PARTITIONS_SCAN)) && PlannerUtil.getRelationLineage(plan.getRootBlock().getRoot()).length == 1; ScanNode scanNode = plan.getRootBlock().getNode(NodeType.SCAN); if (scanNode == null) { scanNode = plan.getRootBlock().getNode(NodeType.PARTITIONS_SCAN); EvalNode node = ((SelectionNode) plan.getRootBlock().getNode(NodeType.SELECTION)).getQual(); Schema partSchema = scanNode.getTableDesc().getPartitionMethod().getExpressionSchema(); if (EvalTreeUtil.checkIfPartitionSelection(node, partSchema)) {
@Override public LogicalPlan rewrite(LogicalPlanRewriteRuleContext context) throws TajoException { LogicalPlan plan = context.getPlan(); LogicalRootNode rootNode = plan.getRootBlock().getRoot(); plan.getRootBlock().registerNode(sortNode);
dupRemoval.setGroupingColumns(sortNode.getInSchema().toArray()); block.registerNode(dupRemoval); postHook(context, stack, null, dupRemoval); dupRemoval.setGroupingColumns(outSchema.toArray()); block.registerNode(dupRemoval); postHook(context, stack, null, dupRemoval);
dupRemoval.setGroupingColumns(sortNode.getInSchema().toArray()); block.registerNode(dupRemoval); postHook(context, stack, null, dupRemoval); dupRemoval.setGroupingColumns(outSchema.toArray()); block.registerNode(dupRemoval); postHook(context, stack, null, dupRemoval);
public void execSimpleQuery(QueryContext queryContext, Session session, String query, LogicalPlan plan, SubmitQueryResponse.Builder response) throws Exception { ScanNode scanNode = plan.getRootBlock().getNode(NodeType.SCAN); final TableDesc table = scanNode.getTableDesc(); if (table.hasPartition()) { scanNode = plan.getRootBlock().getNode(NodeType.PARTITIONS_SCAN); if (plan.getRootBlock().hasNode(NodeType.LIMIT)) { LimitNode limitNode = plan.getRootBlock().getNode(NodeType.LIMIT); maxRow = (int) limitNode.getFetchFirstNum(); scanNode.setLimit(maxRow); plan.getRootBlock().getRoot());