@Test public final void testFindTopNode() throws CloneNotSupportedException, PlanningException { // two relations Expr expr = analyzer.parse(TestLogicalPlanner.QUERIES[1]); LogicalNode plan = planner.createPlan(expr).getRootBlock().getRoot(); assertEquals(NodeType.ROOT, plan.getType()); LogicalRootNode root = (LogicalRootNode) plan; TestLogicalNode.testCloneLogicalNode(root); assertEquals(NodeType.PROJECTION, root.getChild().getType()); ProjectionNode projNode = (ProjectionNode) root.getChild(); assertEquals(NodeType.JOIN, projNode.getChild().getType()); JoinNode joinNode = (JoinNode) projNode.getChild(); assertEquals(NodeType.SCAN, joinNode.getLeftChild().getType()); ScanNode leftNode = (ScanNode) joinNode.getLeftChild(); assertEquals("employee", leftNode.getTableName()); assertEquals(NodeType.SCAN, joinNode.getRightChild().getType()); ScanNode rightNode = (ScanNode) joinNode.getRightChild(); assertEquals("dept", rightNode.getTableName()); LogicalNode node = PlannerUtil.findTopNode(root, NodeType.ROOT); assertEquals(NodeType.ROOT, node.getType()); node = PlannerUtil.findTopNode(root, NodeType.PROJECTION); assertEquals(NodeType.PROJECTION, node.getType()); node = PlannerUtil.findTopNode(root, NodeType.JOIN); assertEquals(NodeType.JOIN, node.getType()); node = PlannerUtil.findTopNode(root, NodeType.SCAN); assertEquals(NodeType.SCAN, node.getType()); }
@Override public LogicalNode visitScan( CompilationContext context, LogicalPlan plan, LogicalPlan.QueryBlock block, ScanNode node, Stack<LogicalNode> stack) throws TajoException { compileProjectableNode(context, node.getInSchema(), node); compileSelectableNode(context, node.getInSchema(), node); return node; }
public void execSimpleQuery( QueryContext queryContext, Session session, String query, LogicalPlan plan, SubmitQueryResponse.Builder response) throws Exception { ScanNode scanNode = plan.getRootBlock().getNode(NodeType.SCAN); TableDesc desc = scanNode.getTableDesc(); if (desc.hasPartition()) { scanNode = plan.getRootBlock().getNode(NodeType.PARTITIONS_SCAN); } int maxRow = Integer.MAX_VALUE; if (plan.getRootBlock().hasNode(NodeType.LIMIT)) { LimitNode limitNode = plan.getRootBlock().getNode(NodeType.LIMIT); maxRow = (int) limitNode.getFetchFirstNum(); } if (desc.getStats().getNumRows() == 0) { desc.getStats().setNumRows(TajoConstants.UNKNOWN_ROW_NUMBER); } QueryInfo queryInfo = context .getQueryJobManager() .createNewSimpleQuery( queryContext, session, query, (LogicalRootNode) plan.getRootBlock().getRoot()); NonForwardQueryResultScanner queryResultScanner = new NonForwardQueryResultFileScanner( context.getConf(), session.getSessionId(), queryInfo.getQueryId(), scanNode, desc, maxRow); queryResultScanner.init(); session.addNonForwardQueryResultScanner(queryResultScanner); response.setState(OK); response.setQueryId(queryInfo.getQueryId().getProto()); response.setResultType(ResultType.ENCLOSED); response.setMaxRowNum(maxRow); response.setTableDesc(desc.getProto()); }