private TupleBatch outputPhase() throws BlockedException, TeiidComponentException, TeiidProcessingException { if (!this.output.isFinal()) { this.phase = SORT; } else if (!usingOutput) { this.output.setForwardOnly(true); } List<?> tuple = null; try { while ((tuple = this.outputTs.nextTuple()) != null) { //resize to remove unrelated columns if (this.getElements().size() < tuple.size()) { tuple = new ArrayList<Object>(tuple.subList(0, this.getElements().size())); } addBatchRow(tuple); if (this.isBatchFull()) { return pullBatch(); } } } catch (BlockedException e) { if (this.hasPendingRows()) { return this.pullBatch(); } throw e; } this.terminateBatches(); return this.pullBatch(); }
@Override public TupleBuffer getBufferDirect(int maxRows) throws BlockedException, TeiidComponentException, TeiidProcessingException { if (this.isClosed()) { throw new AssertionError("called after close"); //$NON-NLS-1$ } this.rowLimit = maxRows; if (this.output == null) { sortPhase(); } usingOutput = true; TupleBuffer result = this.output; if (this.output.isFinal()) { this.output = null; close(); } return result; }
@Override public boolean hasBuffer() { if (this.getElements().size() == this.getChildren()[0].getElements().size()) { return true; } return false; }
dataNode.initialize(context, mgr, null); SortNode sortNode = new SortNode(1); sortNode.setSortElements(new OrderBy(sortElements, sortTypes).getOrderByItems()); sortNode.setMode(mode); sortNode.setElements(elements); sortNode.addChild(dataNode); sortNode.initialize(context, mgr, null); sortNode.open(); assertTrue(sortNode.hasBuffer()); int currentRow = 1; while(true) { try { TupleBatch batch = sortNode.nextBatch(); for(int row = currentRow; row <= batch.getEndRow(); row++) { assertEquals("Rows don't match at " + row, expected[row-1], batch.getTuple(row)); //$NON-NLS-1$
processNode = new DupRemoveNode(getID()); } else { SortNode sortNode = new SortNode(getID()); OrderBy orderBy = (OrderBy) node.getProperty(NodeConstants.Info.SORT_ORDER); if (orderBy != null) { sortNode.setSortElements(orderBy.getOrderByItems()); sortNode.setMode(Mode.DUP_REMOVE_SORT); processNode = new DupRemoveNode(getID()); } else { SortNode sNode = new SortNode(getID()); sNode.setMode(Mode.DUP_REMOVE_SORT); processNode = sNode;
private void sortPhase() throws BlockedException, TeiidComponentException, TeiidProcessingException { if (this.sortUtility == null) { TupleSource ts = null; TupleBuffer working = null; if (!getChildren()[0].hasBuffer()) { ts = new BatchIterator(getChildren()[0]); } else { working = getChildren()[0].getBuffer(-1); } this.sortUtility = new SortUtility(ts, items, this.mode, getBufferManager(), getConnectionID(), getChildren()[0].getElements()); if (ts == null) { this.sortUtility.setWorkingBuffer(working); } } this.output = this.sortUtility.sort(rowLimit); if (this.outputTs == null) { this.outputTs = this.output.createIndexedTupleSource(); } this.phase = OUTPUT; }
@Test public void testSortAliasWithSameName() throws Exception { String sql = "select e1 from (select distinct pm1.g1.e1 as e1 from pm1.g1) x order by e1"; //$NON-NLS-1$ FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder(); BasicSourceCapabilities caps = new BasicSourceCapabilities(); caps.setCapabilitySupport(Capability.QUERY_FROM_GROUP_ALIAS, true); capFinder.addCapabilities("pm1", caps); //$NON-NLS-1$ RelationalPlan plan = (RelationalPlan)TestOptimizer.helpPlan(sql, RealMetadataFactory.example1Cached(), new String[] {"SELECT g_0.e1 FROM pm1.g1 AS g_0"}, capFinder, TestOptimizer.ComparisonMode.EXACT_COMMAND_STRING); //$NON-NLS-1$ SortNode node = (SortNode)plan.getRootNode(); assertTrue("Alias was not accounted for in sort node", node.getElements().get(0).equals(node.getSortElements().get(0).getSymbol())); //$NON-NLS-1$ }
processNode = new DupRemoveNode(getID()); } else { SortNode sortNode = new SortNode(getID()); OrderBy orderBy = (OrderBy) node.getProperty(NodeConstants.Info.SORT_ORDER); if (orderBy != null) { sortNode.setSortElements(orderBy.getOrderByItems()); sortNode.setMode(Mode.DUP_REMOVE_SORT); processNode = new DupRemoveNode(getID()); } else { SortNode sNode = new SortNode(getID()); sNode.setMode(Mode.DUP_REMOVE_SORT); processNode = sNode;
private void sortPhase() throws BlockedException, TeiidComponentException, TeiidProcessingException { if (this.sortUtility == null) { TupleSource ts = null; TupleBuffer working = null; if (!getChildren()[0].hasBuffer()) { ts = new BatchIterator(getChildren()[0]); } else { working = getChildren()[0].getBuffer(-1); } this.sortUtility = new SortUtility(ts, items, this.mode, getBufferManager(), getConnectionID(), getChildren()[0].getElements()); if (ts == null) { this.sortUtility.setWorkingBuffer(working); } } this.output = this.sortUtility.sort(rowLimit); if (this.outputTs == null) { this.outputTs = this.output.createIndexedTupleSource(); } this.phase = OUTPUT; }
@Override public boolean hasBuffer() { if (this.getElements().size() == this.getChildren()[0].getElements().size()) { return true; } return false; }
@Test public void testSortAliasWithSameNameUnion() throws Exception { String sql = "select e1 from (select distinct pm1.g1.e1 as e1 from pm1.g1) x union all select e1 from pm1.g2 order by e1"; //$NON-NLS-1$ FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder(); BasicSourceCapabilities caps = new BasicSourceCapabilities(); caps.setCapabilitySupport(Capability.QUERY_FROM_GROUP_ALIAS, true); capFinder.addCapabilities("pm1", caps); //$NON-NLS-1$ RelationalPlan plan = (RelationalPlan)TestOptimizer.helpPlan(sql, RealMetadataFactory.example1Cached(), new String[] {"SELECT g_0.e1 FROM pm1.g1 AS g_0", "SELECT g_0.e1 FROM pm1.g2 AS g_0"}, capFinder, TestOptimizer.ComparisonMode.EXACT_COMMAND_STRING); //$NON-NLS-1$ SortNode node = (SortNode)plan.getRootNode(); assertTrue("Alias was not accounted for in sort node", node.getElements().get(0).equals(node.getSortElements().get(0).getSymbol())); //$NON-NLS-1$ }
private TupleBatch outputPhase() throws BlockedException, TeiidComponentException, TeiidProcessingException { if (!this.output.isFinal()) { this.phase = SORT; } else if (!usingOutput) { this.output.setForwardOnly(true); } List<?> tuple = null; try { while ((tuple = this.outputTs.nextTuple()) != null) { //resize to remove unrelated columns if (this.getElements().size() < tuple.size()) { tuple = new ArrayList<Object>(tuple.subList(0, this.getElements().size())); } addBatchRow(tuple); if (this.isBatchFull()) { return pullBatch(); } } } catch (BlockedException e) { if (this.hasPendingRows()) { return this.pullBatch(); } throw e; } this.terminateBatches(); return this.pullBatch(); }
processNode = new DupRemoveNode(getID()); } else { SortNode sortNode = new SortNode(getID()); OrderBy orderBy = (OrderBy) node.getProperty(NodeConstants.Info.SORT_ORDER); if (orderBy != null) { sortNode.setSortElements(orderBy.getOrderByItems()); sortNode.setMode(Mode.DUP_REMOVE_SORT); processNode = new DupRemoveNode(getID()); } else { SortNode sNode = new SortNode(getID()); sNode.setMode(Mode.DUP_REMOVE_SORT); processNode = sNode;
@Override public TupleBuffer getBufferDirect(int maxRows) throws BlockedException, TeiidComponentException, TeiidProcessingException { if (this.isClosed()) { throw new AssertionError("called after close"); //$NON-NLS-1$ } this.rowLimit = maxRows; if (this.output == null) { sortPhase(); } usingOutput = true; TupleBuffer result = this.output; if (this.output.isFinal()) { this.output = null; close(); } return result; }
private void sortPhase() throws BlockedException, TeiidComponentException, TeiidProcessingException { if (this.sortUtility == null) { TupleSource ts = null; TupleBuffer working = null; if (!getChildren()[0].hasBuffer()) { ts = new BatchIterator(getChildren()[0]); } else { working = getChildren()[0].getBuffer(-1); } this.sortUtility = new SortUtility(ts, items, this.mode, getBufferManager(), getConnectionID(), getChildren()[0].getElements()); if (ts == null) { this.sortUtility.setWorkingBuffer(working); } } this.output = this.sortUtility.sort(rowLimit); if (this.outputTs == null) { this.outputTs = this.output.createIndexedTupleSource(); } this.phase = OUTPUT; }
@Override public boolean hasBuffer() { if (this.getElements().size() == this.getChildren()[0].getElements().size()) { return true; } return false; }
private TupleBatch outputPhase() throws BlockedException, TeiidComponentException, TeiidProcessingException { if (!this.output.isFinal()) { this.phase = SORT; } else if (!usingOutput) { this.output.setForwardOnly(true); } List<?> tuple = null; try { while ((tuple = this.outputTs.nextTuple()) != null) { //resize to remove unrelated columns if (this.getElements().size() < tuple.size()) { tuple = new ArrayList<Object>(tuple.subList(0, this.getElements().size())); } addBatchRow(tuple); if (this.isBatchFull()) { return pullBatch(); } } } catch (BlockedException e) { if (this.hasPendingRows()) { return this.pullBatch(); } throw e; } this.terminateBatches(); return this.pullBatch(); }
@Override public TupleBuffer getBufferDirect(int maxRows) throws BlockedException, TeiidComponentException, TeiidProcessingException { if (this.isClosed()) { throw new AssertionError("called after close"); //$NON-NLS-1$ } this.rowLimit = maxRows; if (this.output == null) { sortPhase(); } usingOutput = true; TupleBuffer result = this.output; if (this.output.isFinal()) { this.output = null; close(); } return result; }