Author: shawkins
Date: 2010-07-27 13:15:15 -0400 (Tue, 27 Jul 2010)
New Revision: 2379
Added:
trunk/engine/src/main/java/org/teiid/query/metadata/TempCapabilitiesFinder.java
Modified:
trunk/engine/src/main/java/org/teiid/common/buffer/SPage.java
trunk/engine/src/main/java/org/teiid/common/buffer/STree.java
trunk/engine/src/main/java/org/teiid/dqp/internal/process/Request.java
trunk/engine/src/main/java/org/teiid/query/metadata/TempMetadataAdapter.java
trunk/engine/src/main/java/org/teiid/query/metadata/TempMetadataID.java
trunk/engine/src/main/java/org/teiid/query/optimizer/QueryOptimizer.java
trunk/engine/src/main/java/org/teiid/query/optimizer/relational/AliasGenerator.java
trunk/engine/src/main/java/org/teiid/query/optimizer/relational/PlanToProcessConverter.java
trunk/engine/src/main/java/org/teiid/query/optimizer/relational/rules/FrameUtil.java
trunk/engine/src/main/java/org/teiid/query/optimizer/relational/rules/RuleCollapseSource.java
trunk/engine/src/main/java/org/teiid/query/optimizer/relational/rules/RuleRaiseAccess.java
trunk/engine/src/main/java/org/teiid/query/processor/relational/ListNestedSortComparator.java
trunk/engine/src/main/java/org/teiid/query/processor/relational/RelationalNode.java
trunk/engine/src/main/java/org/teiid/query/rewriter/QueryRewriter.java
trunk/engine/src/main/java/org/teiid/query/tempdata/TempTable.java
trunk/engine/src/main/java/org/teiid/query/tempdata/TempTableStore.java
trunk/engine/src/test/java/org/teiid/query/optimizer/TestDependentJoins.java
trunk/engine/src/test/java/org/teiid/query/optimizer/TestLimit.java
trunk/engine/src/test/java/org/teiid/query/optimizer/TestOptimizer.java
trunk/engine/src/test/java/org/teiid/query/optimizer/TestStoredProcedurePlanning.java
trunk/engine/src/test/java/org/teiid/query/optimizer/relational/TestAliasGenerator.java
trunk/engine/src/test/java/org/teiid/query/processor/TestProcessor.java
trunk/engine/src/test/java/org/teiid/query/processor/TestTempTables.java
Log:
TEIID-1167 adding support for ordering by the index. also updating the alias generation
logic to support stripping aliases for sources that don't support expression
projection.
Modified: trunk/engine/src/main/java/org/teiid/common/buffer/SPage.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/common/buffer/SPage.java 2010-07-27 14:22:24 UTC
(rev 2378)
+++ trunk/engine/src/main/java/org/teiid/common/buffer/SPage.java 2010-07-27 17:15:15 UTC
(rev 2379)
@@ -72,8 +72,6 @@
}
}
- static int unnecessaryReads;
-
static SearchResult search(SPage page, List k, LinkedList<SearchResult> parent)
throws TeiidComponentException {
TupleBatch previousValues = null;
for (;;) {
@@ -81,7 +79,6 @@
int index = Collections.binarySearch(values.getTuples(), k, page.stree.comparator);
int flippedIndex = - index - 1;
if (previousValues != null) {
- unnecessaryReads++;
if (flippedIndex == 0) {
//systemic weakness of the algorithm
return new SearchResult(-previousValues.getTuples().size() - 1, page.prev,
previousValues);
@@ -207,7 +204,7 @@
result.append(tb.getBeginRow());
if (children == null) {
if (tb.getTuples().size() <= 1) {
- result.append(values);
+ result.append(tb.getTuples());
} else {
result.append("[").append(tb.getTuples().get(0)).append(" .
").append(tb.getTuples().size()). //$NON-NLS-1$ //$NON-NLS-2$
append(" . ").append(tb.getTuples().get(tb.getTuples().size() -
1)).append("]"); //$NON-NLS-1$ //$NON-NLS-2$
Modified: trunk/engine/src/main/java/org/teiid/common/buffer/STree.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/common/buffer/STree.java 2010-07-27 14:22:24 UTC
(rev 2378)
+++ trunk/engine/src/main/java/org/teiid/common/buffer/STree.java 2010-07-27 17:15:15 UTC
(rev 2379)
@@ -65,7 +65,6 @@
int keyLength,
String[] types) {
randomSeed = seedGenerator.nextInt() | 0x00000100; // ensure nonzero
- //randomSeed=-1031212234;
this.manager = recman;
this.comparator = comparator;
this.pageSize = Math.max(pageSize, SPage.MIN_PERSISTENT_SIZE);
@@ -115,13 +114,11 @@
*/
private List find(List n, LinkedList<SearchResult> places) throws
TeiidComponentException {
SPage x = null;
- SearchResult parent = null;
for (int i = header.length - 1; i >= 0; i--) {
if (x == null) {
x = header[i];
}
SearchResult s = SPage.search(x, n, places);
- parent = s;
if (places != null) {
places.add(s);
}
@@ -209,6 +206,9 @@
}
nextPage.next = page.next;
nextPage.prev = page;
+ if (nextPage.next != null) {
+ nextPage.next.prev = nextPage;
+ }
page.next = nextPage;
boolean inNext = false;
if (index <= pageSize/2) {
@@ -314,7 +314,7 @@
}
public TupleBrowser browse(List lowerBound, List upperBound, boolean direction) {
- return new TupleBrowser();
+ return new TupleBrowser(direction);
}
public int truncate() {
@@ -337,7 +337,17 @@
int index;
TupleBatch values;
boolean updated;
+ boolean direction;
+ public TupleBrowser(boolean direction) {
+ this.direction = direction;
+ if (!direction) {
+ while (page.prev != null) {
+ page = page.prev;
+ }
+ }
+ }
+
public boolean matchedLower() {
return false;
}
@@ -350,23 +360,37 @@
for (;;) {
if (values == null) {
values = page.getValues();
+ if (direction) {
+ index = 0;
+ } else {
+ index = values.getTuples().size() - 1;
+ }
}
- if (index < values.getTuples().size()) {
- return values.getTuples().get(index++);
+ if (index >= 0 && index < values.getTuples().size()) {
+ List result = values.getTuples().get(index);
+ index+=getOffset();
+ return result;
}
if (updated) {
page.setValues(values);
}
+ updated = false;
values = null;
- index = 0;
- page = page.next;
- updated = false;
+ if (direction) {
+ page = page.next;
+ } else {
+ page = page.prev;
+ }
if (page == null) {
return null;
}
}
}
+ private int getOffset() {
+ return direction?1:-1;
+ }
+
/**
* Perform an in-place update of the tuple just returned by the next method
* WARNING - this must not change the key value
@@ -374,7 +398,7 @@
* @throws TeiidComponentException
*/
public void update(List tuple) throws TeiidComponentException {
- values.getTuples().set(index - 1, tuple);
+ values.getTuples().set(index - getOffset(), tuple);
updated = true;
}
@@ -382,7 +406,7 @@
* Notify the browser that the last value was deleted.
*/
public void removed() {
- index--;
+ index-=getOffset();
}
}
Modified: trunk/engine/src/main/java/org/teiid/dqp/internal/process/Request.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/dqp/internal/process/Request.java 2010-07-27
14:22:24 UTC (rev 2378)
+++ trunk/engine/src/main/java/org/teiid/dqp/internal/process/Request.java 2010-07-27
17:15:15 UTC (rev 2379)
@@ -59,6 +59,7 @@
import org.teiid.query.analysis.AnalysisRecord;
import org.teiid.query.eval.SecurityFunctionEvaluator;
import org.teiid.query.metadata.QueryMetadataInterface;
+import org.teiid.query.metadata.TempCapabilitiesFinder;
import org.teiid.query.metadata.TempMetadataAdapter;
import org.teiid.query.metadata.TempMetadataStore;
import org.teiid.query.optimizer.QueryOptimizer;
@@ -172,7 +173,7 @@
}
// Prepare dependencies for running the optimizer
this.capabilitiesFinder = new CachedFinder(this.connectorManagerRepo,
workContext.getVDB());
-
+ this.capabilitiesFinder = new TempCapabilitiesFinder(this.capabilitiesFinder);
metadata = workContext.getVDB().getAttachment(QueryMetadataInterface.class);
Added: trunk/engine/src/main/java/org/teiid/query/metadata/TempCapabilitiesFinder.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/metadata/TempCapabilitiesFinder.java
(rev 0)
+++
trunk/engine/src/main/java/org/teiid/query/metadata/TempCapabilitiesFinder.java 2010-07-27
17:15:15 UTC (rev 2379)
@@ -0,0 +1,54 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA.
+ */
+
+package org.teiid.query.metadata;
+
+import org.teiid.core.TeiidComponentException;
+import org.teiid.query.optimizer.capabilities.BasicSourceCapabilities;
+import org.teiid.query.optimizer.capabilities.CapabilitiesFinder;
+import org.teiid.query.optimizer.capabilities.SourceCapabilities;
+import org.teiid.query.optimizer.capabilities.SourceCapabilities.Capability;
+
+public class TempCapabilitiesFinder implements CapabilitiesFinder {
+
+ private static BasicSourceCapabilities tempCaps;
+ private final CapabilitiesFinder delegate;
+
+ public TempCapabilitiesFinder(CapabilitiesFinder delegate) {
+ this.delegate = delegate;
+ }
+
+ @Override
+ public SourceCapabilities findCapabilities(String modelName)
+ throws TeiidComponentException {
+ if (TempMetadataAdapter.TEMP_MODEL.getID().equals(modelName)) {
+ if (tempCaps == null) {
+ tempCaps = new BasicSourceCapabilities();
+ tempCaps.setCapabilitySupport(Capability.BULK_UPDATE, true);
+ tempCaps.setCapabilitySupport(Capability.QUERY_ORDERBY, true);
+ }
+ return tempCaps;
+ }
+ return delegate.findCapabilities(modelName);
+ }
+
+}
Property changes on:
trunk/engine/src/main/java/org/teiid/query/metadata/TempCapabilitiesFinder.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified: trunk/engine/src/main/java/org/teiid/query/metadata/TempMetadataAdapter.java
===================================================================
---
trunk/engine/src/main/java/org/teiid/query/metadata/TempMetadataAdapter.java 2010-07-27
14:22:24 UTC (rev 2378)
+++
trunk/engine/src/main/java/org/teiid/query/metadata/TempMetadataAdapter.java 2010-07-27
17:15:15 UTC (rev 2379)
@@ -53,7 +53,7 @@
public class TempMetadataAdapter extends BasicQueryMetadataWrapper {
private static final String SEPARATOR = "."; //$NON-NLS-1$
- private static final TempMetadataID TEMP_MODEL = new
TempMetadataID("__TEMP__", Collections.EMPTY_LIST); //$NON-NLS-1$
+ public static final TempMetadataID TEMP_MODEL = new
TempMetadataID("__TEMP__", Collections.EMPTY_LIST); //$NON-NLS-1$
private TempMetadataStore tempStore;
private Map materializationTables;
@@ -322,7 +322,7 @@
throws TeiidComponentException, QueryMetadataException {
if(modelID.equals(TEMP_MODEL)) {
- return true;
+ return false;
}
return this.actualMetadata.isVirtualModel(modelID);
}
Modified: trunk/engine/src/main/java/org/teiid/query/metadata/TempMetadataID.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/metadata/TempMetadataID.java 2010-07-27
14:22:24 UTC (rev 2378)
+++ trunk/engine/src/main/java/org/teiid/query/metadata/TempMetadataID.java 2010-07-27
17:15:15 UTC (rev 2379)
@@ -168,7 +168,7 @@
return true;
}
- if(obj == null || !(obj instanceof TempMetadataID)) {
+ if(!(obj instanceof TempMetadataID)) {
return false;
}
return this.getID().equals( ((TempMetadataID) obj).getID());
Modified: trunk/engine/src/main/java/org/teiid/query/optimizer/QueryOptimizer.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/optimizer/QueryOptimizer.java 2010-07-27
14:22:24 UTC (rev 2378)
+++ trunk/engine/src/main/java/org/teiid/query/optimizer/QueryOptimizer.java 2010-07-27
17:15:15 UTC (rev 2379)
@@ -33,6 +33,7 @@
import org.teiid.core.id.IntegerIDFactory;
import org.teiid.query.analysis.AnalysisRecord;
import org.teiid.query.metadata.QueryMetadataInterface;
+import org.teiid.query.metadata.TempCapabilitiesFinder;
import org.teiid.query.metadata.TempMetadataAdapter;
import org.teiid.query.metadata.TempMetadataStore;
import org.teiid.query.optimizer.batch.BatchedUpdatePlanner;
@@ -76,6 +77,10 @@
context = new CommandContext();
}
+ if (!(capFinder instanceof TempCapabilitiesFinder)) {
+ capFinder = new TempCapabilitiesFinder(capFinder);
+ }
+
boolean debug = analysisRecord.recordDebug();
Map tempMetadata = command.getTemporaryMetadata();
Modified:
trunk/engine/src/main/java/org/teiid/query/optimizer/relational/AliasGenerator.java
===================================================================
---
trunk/engine/src/main/java/org/teiid/query/optimizer/relational/AliasGenerator.java 2010-07-27
14:22:24 UTC (rev 2378)
+++
trunk/engine/src/main/java/org/teiid/query/optimizer/relational/AliasGenerator.java 2010-07-27
17:15:15 UTC (rev 2379)
@@ -186,12 +186,18 @@
}
private NamingVisitor visitor;
- private int groupIndex = 0;
- private int viewIndex = 0;
+ private int groupIndex;
+ private int viewIndex;
+ private boolean stripColumnAliases;
public AliasGenerator(boolean aliasGroups) {
+ this(aliasGroups, false);
+ }
+
+ public AliasGenerator(boolean aliasGroups, boolean stripColumnAliases) {
super(new NamingVisitor(aliasGroups));
this.visitor = (NamingVisitor)this.getVisitor();
+ this.stripColumnAliases = stripColumnAliases;
}
/**
@@ -209,15 +215,16 @@
}
public void visit(Select obj) {
+ super.visit(obj);
List selectSymbols = obj.getSymbols();
HashMap<SingleElementSymbol, String> symbols = new
HashMap<SingleElementSymbol, String>(selectSymbols.size());
for (int i = 0; i < selectSymbols.size(); i++) {
SingleElementSymbol symbol = (SingleElementSymbol)selectSymbols.get(i);
+
+ boolean needsAlias = visitor.namingContext.aliasColumns;
String newAlias = "c_" + i; //$NON-NLS-1$
- boolean needsAlias = true;
-
Expression expr = SymbolMap.getExpression(symbol);
SingleElementSymbol newSymbol = symbol;
@@ -225,11 +232,12 @@
if (!(expr instanceof SingleElementSymbol)) {
newSymbol = new ExpressionSymbol(newSymbol.getShortName(), expr);
} else if (expr instanceof ElementSymbol) {
- if (!needsAlias(newAlias, (ElementSymbol)expr)) {
- needsAlias = false;
- ((ElementSymbol)expr).setOutputName(newAlias);
+ newSymbol = (ElementSymbol)expr;
+ if (!needsAlias) {
+ newAlias = newSymbol.getOutputName();
+ } else {
+ needsAlias &= needsAlias(newAlias, (ElementSymbol)expr);
}
- newSymbol = (ElementSymbol)expr;
} else {
newSymbol = (SingleElementSymbol)expr;
}
@@ -242,7 +250,6 @@
selectSymbols.set(i, newSymbol);
}
- super.visit(obj);
visitor.namingContext.currentSymbols = symbols;
}
@@ -256,7 +263,7 @@
*/
public void visit(Query obj) {
if (obj.getOrderBy() != null || obj.getLimit() != null) {
- visitor.namingContext.aliasColumns = true;
+ visitor.namingContext.aliasColumns = true && !stripColumnAliases;
}
visitNode(obj.getFrom());
visitNode(obj.getCriteria());
@@ -337,15 +344,15 @@
continue;
}
String name = visitor.namingContext.getElementName(element, false);
+ boolean needsAlias = visitor.namingContext.aliasColumns;
if (name != null) {
- boolean needsAlias = true;
Expression expr = SymbolMap.getExpression(element);
if (!(expr instanceof SingleElementSymbol)) {
expr = new ExpressionSymbol(element.getShortName(), expr);
} else if (expr instanceof ElementSymbol) {
- needsAlias = needsAlias(name, (ElementSymbol)expr);
+ needsAlias &= needsAlias(name, (ElementSymbol)expr);
}
if (needsAlias) {
@@ -355,11 +362,9 @@
element.setOutputName(name);
}
- visitNode(element);
-
- if (name != null && element instanceof ElementSymbol) {
-
element.setOutputName(SingleElementSymbol.getShortName(element.getOutputName()));
- }
+ if (!(element instanceof ElementSymbol)) {
+ visitNode(element);
+ }
}
}
Modified:
trunk/engine/src/main/java/org/teiid/query/optimizer/relational/PlanToProcessConverter.java
===================================================================
---
trunk/engine/src/main/java/org/teiid/query/optimizer/relational/PlanToProcessConverter.java 2010-07-27
14:22:24 UTC (rev 2378)
+++
trunk/engine/src/main/java/org/teiid/query/optimizer/relational/PlanToProcessConverter.java 2010-07-27
17:15:15 UTC (rev 2379)
@@ -309,7 +309,7 @@
//-- special handling for temp tables. currently they cannot
perform projection
try {
if (command instanceof Query) {
- processNode = correctProjectionInternalTables(node,
aNode, (Query)command);
+ processNode = correctProjectionInternalTables(node,
aNode);
}
} catch (QueryMetadataException err) {
throw new TeiidComponentException(err);
@@ -319,7 +319,9 @@
try {
command = (Command)command.clone();
- command.acceptVisitor(new AliasGenerator(modelID != null
&& CapabilitiesUtil.supportsGroupAliases(modelID, metadata, capFinder)));
+ boolean aliasGroups = modelID != null &&
CapabilitiesUtil.supportsGroupAliases(modelID, metadata, capFinder);
+ boolean aliasColumns = modelID != null &&
CapabilitiesUtil.supports(Capability.QUERY_SELECT_EXPRESSION, modelID, metadata,
capFinder);
+ command.acceptVisitor(new AliasGenerator(aliasGroups,
!aliasColumns));
} catch (QueryMetadataException err) {
throw new TeiidComponentException(err);
}
@@ -461,7 +463,7 @@
}
private RelationalNode correctProjectionInternalTables(PlanNode node,
- AccessNode aNode, Query
query) throws QueryMetadataException,
+ AccessNode aNode) throws
QueryMetadataException,
TeiidComponentException {
if (node.getGroups().size() != 1) {
return aNode;
Modified:
trunk/engine/src/main/java/org/teiid/query/optimizer/relational/rules/FrameUtil.java
===================================================================
---
trunk/engine/src/main/java/org/teiid/query/optimizer/relational/rules/FrameUtil.java 2010-07-27
14:22:24 UTC (rev 2378)
+++
trunk/engine/src/main/java/org/teiid/query/optimizer/relational/rules/FrameUtil.java 2010-07-27
17:15:15 UTC (rev 2379)
@@ -435,15 +435,17 @@
* @return
*/
static ProcessorPlan getNestedPlan(PlanNode accessNode) {
- ProcessorPlan plan = null;
PlanNode sourceNode = accessNode.getFirstChild();
+ if (sourceNode == null) {
+ return null;
+ }
if(sourceNode.getType() != NodeConstants.Types.SOURCE) {
sourceNode = sourceNode.getFirstChild();
}
- if(sourceNode.getType() == NodeConstants.Types.SOURCE) {
- plan = (ProcessorPlan)
sourceNode.getProperty(NodeConstants.Info.PROCESSOR_PLAN);
+ if(sourceNode != null && sourceNode.getType() ==
NodeConstants.Types.SOURCE) {
+ return (ProcessorPlan)
sourceNode.getProperty(NodeConstants.Info.PROCESSOR_PLAN);
}
- return plan;
+ return null;
}
/**
@@ -454,23 +456,19 @@
* @return The actual stored procedure
*/
static Command getNonQueryCommand(PlanNode node) {
- if (node.getChildCount() == 0) {
- return null;
- }
PlanNode sourceNode = node.getFirstChild();
+ if (sourceNode == null) {
+ return null;
+ }
if(sourceNode.getType() != NodeConstants.Types.SOURCE) {
- if (sourceNode.getChildCount() == 0) {
- return null;
- }
sourceNode = sourceNode.getFirstChild();
}
- if(sourceNode.getType() == NodeConstants.Types.SOURCE) {
+ if(sourceNode != null && sourceNode.getType() ==
NodeConstants.Types.SOURCE) {
Command command = (Command)
sourceNode.getProperty(NodeConstants.Info.VIRTUAL_COMMAND);
if(! (command instanceof QueryCommand)) {
return command;
}
}
-
return null;
}
Modified:
trunk/engine/src/main/java/org/teiid/query/optimizer/relational/rules/RuleCollapseSource.java
===================================================================
---
trunk/engine/src/main/java/org/teiid/query/optimizer/relational/rules/RuleCollapseSource.java 2010-07-27
14:22:24 UTC (rev 2378)
+++
trunk/engine/src/main/java/org/teiid/query/optimizer/relational/rules/RuleCollapseSource.java 2010-07-27
17:15:15 UTC (rev 2379)
@@ -24,6 +24,7 @@
import java.util.ArrayList;
import java.util.LinkedHashSet;
+import java.util.LinkedList;
import java.util.List;
import org.teiid.api.exception.query.QueryMetadataException;
@@ -56,6 +57,7 @@
import org.teiid.query.sql.lang.JoinType;
import org.teiid.query.sql.lang.Limit;
import org.teiid.query.sql.lang.OrderBy;
+import org.teiid.query.sql.lang.OrderByItem;
import org.teiid.query.sql.lang.Query;
import org.teiid.query.sql.lang.QueryCommand;
import org.teiid.query.sql.lang.Select;
@@ -417,7 +419,15 @@
}
private void processOrderBy(PlanNode node, QueryCommand query) {
- query.setOrderBy((OrderBy)node.getProperty(NodeConstants.Info.SORT_ORDER));
+ OrderBy orderBy = (OrderBy)node.getProperty(NodeConstants.Info.SORT_ORDER);
+ query.setOrderBy(orderBy);
+ if (query instanceof Query) {
+ List<SingleElementSymbol> cols = query.getProjectedSymbols();
+ for (OrderByItem item : orderBy.getOrderByItems()) {
+ item.setExpressionPosition(cols.indexOf(item.getSymbol()));
+ }
+ QueryRewriter.rewriteOrderBy(query, orderBy, query.getProjectedSymbols(), new
LinkedList<OrderByItem>());
+ }
}
/**
Modified:
trunk/engine/src/main/java/org/teiid/query/optimizer/relational/rules/RuleRaiseAccess.java
===================================================================
---
trunk/engine/src/main/java/org/teiid/query/optimizer/relational/rules/RuleRaiseAccess.java 2010-07-27
14:22:24 UTC (rev 2378)
+++
trunk/engine/src/main/java/org/teiid/query/optimizer/relational/rules/RuleRaiseAccess.java 2010-07-27
17:15:15 UTC (rev 2379)
@@ -121,6 +121,16 @@
return null;
}
}
+
+ /*
+ * TODO: this creates an extraneous project node in many circumstances.
+ * However we don't actually support project in this case, so
allowing it to be pushed
+ * causes problems with stored procedures and the assumptions made for
proc/relational
+ * planning.
+ */
+ if (FrameUtil.isProcedure(parentNode)) {
+ return null;
+ }
return performRaise(rootNode, accessNode, parentNode);
}
Modified:
trunk/engine/src/main/java/org/teiid/query/processor/relational/ListNestedSortComparator.java
===================================================================
---
trunk/engine/src/main/java/org/teiid/query/processor/relational/ListNestedSortComparator.java 2010-07-27
14:22:24 UTC (rev 2378)
+++
trunk/engine/src/main/java/org/teiid/query/processor/relational/ListNestedSortComparator.java 2010-07-27
17:15:15 UTC (rev 2379)
@@ -84,7 +84,7 @@
* order.
*/
public ListNestedSortComparator( int[] sortParameters ) {
- this( sortParameters, false );
+ this( sortParameters, true );
}
/**
Modified:
trunk/engine/src/main/java/org/teiid/query/processor/relational/RelationalNode.java
===================================================================
---
trunk/engine/src/main/java/org/teiid/query/processor/relational/RelationalNode.java 2010-07-27
14:22:24 UTC (rev 2378)
+++
trunk/engine/src/main/java/org/teiid/query/processor/relational/RelationalNode.java 2010-07-27
17:15:15 UTC (rev 2379)
@@ -44,6 +44,7 @@
import org.teiid.query.processor.QueryProcessor;
import org.teiid.query.processor.BatchCollector.BatchProducer;
import org.teiid.query.sql.symbol.AliasSymbol;
+import org.teiid.query.sql.symbol.Expression;
import org.teiid.query.sql.symbol.SingleElementSymbol;
import org.teiid.query.util.CommandContext;
@@ -344,11 +345,11 @@
/**
* Helper method for all the node that will filter the elements needed for the next
node.
*/
- public static int[] getProjectionIndexes(Map<SingleElementSymbol, Integer>
tupleElements, List<SingleElementSymbol> projectElements) {
+ public static int[] getProjectionIndexes(Map<SingleElementSymbol, Integer>
tupleElements, List<? extends Expression> projectElements) {
int[] result = new int[projectElements.size()];
int i = 0;
- for (SingleElementSymbol symbol : projectElements) {
+ for (Expression symbol : projectElements) {
Integer index = tupleElements.get(symbol);
Assertion.isNotNull(index);
result[i++] = index;
Modified: trunk/engine/src/main/java/org/teiid/query/rewriter/QueryRewriter.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/rewriter/QueryRewriter.java 2010-07-27
14:22:24 UTC (rev 2378)
+++ trunk/engine/src/main/java/org/teiid/query/rewriter/QueryRewriter.java 2010-07-27
17:15:15 UTC (rev 2379)
@@ -790,34 +790,13 @@
}
Select select = queryCommand.getProjectedQuery().getSelect();
final List projectedSymbols = select.getProjectedSymbols();
- HashSet<Expression> previousExpressions = new HashSet<Expression>();
- boolean hasUnrelatedExpression = false;
-
LinkedList<OrderByItem> unrelatedItems = new
LinkedList<OrderByItem>();
- for (int i = 0; i < orderBy.getVariableCount(); i++) {
- SingleElementSymbol querySymbol = orderBy.getVariable(i);
- int index = orderBy.getExpressionPosition(i);
- if (index == -1) {
- unrelatedItems.add(orderBy.getOrderByItems().get(i));
- hasUnrelatedExpression |= (querySymbol instanceof ExpressionSymbol);
- continue; // must be unrelated
- }
- querySymbol = (SingleElementSymbol)projectedSymbols.get(index);
- Expression expr = SymbolMap.getExpression(querySymbol);
- if (!previousExpressions.add(expr) || (queryCommand instanceof Query &&
EvaluatableVisitor.isFullyEvaluatable(expr, true))) {
- orderBy.removeOrderByItem(i--);
- } else {
-
orderBy.getOrderByItems().get(i).setSymbol((SingleElementSymbol)querySymbol.clone());
- }
- }
- if (orderBy.getVariableCount() == 0) {
- queryCommand.setOrderBy(null);
- return queryCommand;
- }
+ boolean hasUnrelatedExpression = rewriteOrderBy(queryCommand, orderBy,
+ projectedSymbols, unrelatedItems);
- if (!hasUnrelatedExpression) {
+ if (orderBy.getVariableCount() == 0 || !hasUnrelatedExpression) {
return queryCommand;
}
@@ -860,6 +839,33 @@
top.setOrderBy(orderBy);
return top;
}
+
+ public static boolean rewriteOrderBy(QueryCommand queryCommand,
+ final OrderBy orderBy, final List projectedSymbols,
+ LinkedList<OrderByItem> unrelatedItems) {
+ boolean hasUnrelatedExpression = false;
+ HashSet<Expression> previousExpressions = new HashSet<Expression>();
+ for (int i = 0; i < orderBy.getVariableCount(); i++) {
+ SingleElementSymbol querySymbol = orderBy.getVariable(i);
+ int index = orderBy.getExpressionPosition(i);
+ if (index == -1) {
+ unrelatedItems.add(orderBy.getOrderByItems().get(i));
+ hasUnrelatedExpression |= (querySymbol instanceof ExpressionSymbol);
+ continue; // must be unrelated
+ }
+ querySymbol = (SingleElementSymbol)projectedSymbols.get(index);
+ Expression expr = SymbolMap.getExpression(querySymbol);
+ if (!previousExpressions.add(expr) || (queryCommand instanceof Query &&
EvaluatableVisitor.isFullyEvaluatable(expr, true))) {
+ orderBy.removeOrderByItem(i--);
+ } else {
+
orderBy.getOrderByItems().get(i).setSymbol((SingleElementSymbol)querySymbol.clone());
+ }
+ }
+ if (orderBy.getVariableCount() == 0) {
+ queryCommand.setOrderBy(null);
+ }
+ return hasUnrelatedExpression;
+ }
/**
* This method will alias each of the select into elements to the corresponding
column name in the
Modified: trunk/engine/src/main/java/org/teiid/query/tempdata/TempTable.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/tempdata/TempTable.java 2010-07-27 14:22:24
UTC (rev 2378)
+++ trunk/engine/src/main/java/org/teiid/query/tempdata/TempTable.java 2010-07-27 17:15:15
UTC (rev 2379)
@@ -46,10 +46,14 @@
import org.teiid.query.eval.Evaluator;
import org.teiid.query.processor.CollectionTupleSource;
import org.teiid.query.processor.relational.RelationalNode;
+import org.teiid.query.processor.relational.SortUtility;
+import org.teiid.query.processor.relational.SortUtility.Mode;
import org.teiid.query.sql.lang.Command;
import org.teiid.query.sql.lang.Criteria;
import org.teiid.query.sql.lang.OrderBy;
+import org.teiid.query.sql.lang.OrderByItem;
import org.teiid.query.sql.lang.SetClauseList;
+import org.teiid.query.sql.symbol.AliasSymbol;
import org.teiid.query.sql.symbol.ElementSymbol;
import org.teiid.query.sql.symbol.Expression;
import org.teiid.query.sql.symbol.SingleElementSymbol;
@@ -61,6 +65,35 @@
*/
class TempTable {
+ private class TupleBrowserTupleSource implements TupleSource {
+ private final TupleBrowser browser;
+
+ private TupleBrowserTupleSource(TupleBrowser browser) {
+ this.browser = browser;
+ }
+
+ @Override
+ public List<?> nextTuple() throws TeiidComponentException,
+ TeiidProcessingException {
+ return browser.next();
+ }
+
+ @Override
+ public List<? extends Expression> getSchema() {
+ return columns;
+ }
+
+ @Override
+ public void closeSource() {
+
+ }
+
+ @Override
+ public int available() {
+ return 0;
+ }
+ }
+
private abstract class UpdateTupleSource implements TupleSource {
private TupleSource ts;
protected final Map lookup;
@@ -154,8 +187,7 @@
ElementSymbol id = new ElementSymbol("rowId"); //$NON-NLS-1$
id.setType(DataTypeManager.DefaultDataClasses.INTEGER);
columns.add(0, id);
- //we start at max, since the default sort order is ascending
- rowId = new AtomicInteger(Integer.MAX_VALUE);
+ rowId = new AtomicInteger();
tree = bm.createSTree(columns, sessionID, TupleSourceType.PROCESSOR, 1);
} else {
tree = bm.createSTree(columns, sessionID, TupleSourceType.PROCESSOR,
primaryKeyLength);
@@ -164,39 +196,113 @@
this.sessionID = sessionID;
}
- public TupleSource createTupleSource(List<SingleElementSymbol> projectedCols,
List<Criteria> conditions, OrderBy orderBy) throws TeiidComponentException {
- TupleBrowser browser = createTupleBrower(conditions, orderBy);
- TupleBuffer tb = bm.createTupleBuffer(getColumns(), sessionID,
TupleSourceType.PROCESSOR);
+ public TupleSource createTupleSource(List<SingleElementSymbol> cols, Criteria
condition, OrderBy orderBy) throws TeiidComponentException, TeiidProcessingException {
Map map = RelationalNode.createLookupMap(getColumns());
- int[] indexes = RelationalNode.getProjectionIndexes(map, projectedCols);
- boolean project = false;
- if (indexes.length == getColumns().size()) {
- for (int i = 0; i < indexes.length; i++) {
- if (indexes[i] != i) {
- project = true;
- break;
+ Boolean direction = null;
+ boolean orderByUsingIndex = false;
+ if (orderBy != null && rowId == null) {
+ int[] orderByIndexes = RelationalNode.getProjectionIndexes(map,
orderBy.getSortKeys());
+ if (orderByIndexes.length < tree.getKeyLength()) {
+ orderByUsingIndex = false;
+ } else {
+ orderByUsingIndex = true;
+ for (int i = 0; i < tree.getKeyLength(); i++) {
+ if (orderByIndexes[i] != i) {
+ orderByUsingIndex = false;
+ break;
+ }
}
+ if (orderByUsingIndex) {
+ for (int i = 0; i < tree.getKeyLength(); i++) {
+ OrderByItem item = orderBy.getOrderByItems().get(i);
+ if (item.getNullOrdering() != null) {
+ orderByUsingIndex = false;
+ break;
+ }
+ if (item.isAscending()) {
+ if (direction == null) {
+ direction = OrderBy.ASC;
+ } else if (direction != OrderBy.ASC) {
+ orderByUsingIndex = false;
+ break;
+ }
+ } else if (direction == null) {
+ direction = OrderBy.DESC;
+ } else if (direction != OrderBy.DESC) {
+ orderByUsingIndex = false;
+ break;
+ }
+ }
+ }
}
- } else {
- project = true;
}
- List next = null;
- while ((next = browser.next()) != null) {
- if (rowId != null) {
- next = next.subList(1, next.size());
+ if (!orderByUsingIndex) {
+ direction = OrderBy.ASC;
+ }
+ TupleBrowser browser = createTupleBrower(null, direction);
+
+ final int[] indexes = RelationalNode.getProjectionIndexes(map, cols);
+ final ArrayList<SingleElementSymbol> projectedCols = new
ArrayList<SingleElementSymbol>(cols);
+ for (SingleElementSymbol singleElementSymbol : projectedCols) {
+ if (singleElementSymbol instanceof AliasSymbol) {
+
}
- if (project) {
- next = RelationalNode.projectTuple(indexes, next);
+ }
+ final boolean project = shouldProject(indexes);
+ TupleSource ts = new TupleBrowserTupleSource(browser) {
+
+ @Override
+ public List<?> nextTuple() throws TeiidComponentException,
+ TeiidProcessingException {
+ List<?> next = super.nextTuple();
+ if (next == null) {
+ return null;
+ }
+ if (rowId != null) {
+ next = next.subList(1, next.size());
+ }
+ if (project) {
+ next = RelationalNode.projectTuple(indexes, next);
+ }
+ return next;
}
- tb.addTuple(next);
+
+ @Override
+ public List<? extends Expression> getSchema() {
+ return projectedCols;
+ }
+ };
+
+ TupleBuffer tb = null;
+ if (!orderByUsingIndex && orderBy != null) {
+ SortUtility sort = new SortUtility(ts, orderBy.getOrderByItems(), Mode.SORT, bm,
sessionID);
+ tb = sort.sort();
+ } else {
+ tb = bm.createTupleBuffer(getColumns(), sessionID, TupleSourceType.PROCESSOR);
+ List next = null;
+ while ((next = ts.nextTuple()) != null) {
+ tb.addTuple(next);
+ }
}
tb.close();
tb.setForwardOnly(true);
return tb.createIndexedTupleSource(true);
}
+
+ private boolean shouldProject(final int[] indexes) {
+ if (indexes.length == getColumns().size()) {
+ for (int i = 0; i < indexes.length; i++) {
+ if (indexes[i] != i) {
+ return true;
+ }
+ }
+ return false;
+ }
+ return true;
+ }
- private TupleBrowser createTupleBrower(List<Criteria> conditions, OrderBy orderBy)
throws TeiidComponentException {
- return tree.browse(null, null, OrderBy.ASC);
+ private TupleBrowser createTupleBrower(List<Criteria> conditions, boolean
direction) {
+ return tree.browse(null, null, direction);
}
public int getRowCount() {
@@ -224,7 +330,7 @@
protected void tuplePassed(List tuple)
throws BlockedException, TeiidComponentException, TeiidProcessingException {
if (rowId != null) {
- tuple.add(0, rowId.getAndAdd(-1));
+ tuple.add(0, rowId.getAndAdd(1));
}
insertTuple(tuple);
}
@@ -238,36 +344,10 @@
return uts;
}
- private TupleSource asTupleSource(final TupleBrowser browser) {
- return new TupleSource() {
-
- @Override
- public List<?> nextTuple() throws TeiidComponentException,
- TeiidProcessingException {
- return browser.next();
- }
-
- @Override
- public List<? extends Expression> getSchema() {
- return columns;
- }
-
- @Override
- public void closeSource() {
-
- }
-
- @Override
- public int available() {
- return 0;
- }
- };
- }
-
public TupleSource update(Criteria crit, final SetClauseList update) throws
TeiidComponentException {
final boolean primaryKeyChangePossible = canChangePrimaryKey(update);
- final TupleBrowser browser = createTupleBrower(null, null);
- UpdateTupleSource uts = new UpdateTupleSource(crit, asTupleSource(browser)) {
+ final TupleBrowser browser = createTupleBrower(null, OrderBy.ASC);
+ UpdateTupleSource uts = new UpdateTupleSource(crit, new
TupleBrowserTupleSource(browser)) {
protected TupleBuffer changeSet;
protected TupleSource changeSetProcessor;
@@ -355,8 +435,8 @@
}
public TupleSource delete(Criteria crit) throws TeiidComponentException {
- final TupleBrowser browser = createTupleBrower(null, null);
- UpdateTupleSource uts = new UpdateTupleSource(crit, asTupleSource(browser)) {
+ final TupleBrowser browser = createTupleBrower(null, OrderBy.ASC);
+ UpdateTupleSource uts = new UpdateTupleSource(crit, new
TupleBrowserTupleSource(browser)) {
@Override
protected void tuplePassed(List tuple)
throws ExpressionEvaluationException,
Modified: trunk/engine/src/main/java/org/teiid/query/tempdata/TempTableStore.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/tempdata/TempTableStore.java 2010-07-27
14:22:24 UTC (rev 2378)
+++ trunk/engine/src/main/java/org/teiid/query/tempdata/TempTableStore.java 2010-07-27
17:15:15 UTC (rev 2379)
@@ -118,19 +118,24 @@
if (!group.isTempGroupSymbol()) {
return null;
}
- TempTable table = getTempTable(group.getNonCorrelationName().toUpperCase(),
command);
+ final String tableName = group.getNonCorrelationName().toUpperCase();
+ TempTable table = getTempTable(tableName, command);
//convert to the actual table symbols (this is typically handled by the
languagebridgefactory
ExpressionMappingVisitor emv = new ExpressionMappingVisitor(null) {
@Override
public Expression replaceExpression(Expression element) {
if (element instanceof ElementSymbol) {
- ((ElementSymbol) element).setName(((ElementSymbol)
element).getOutputName());
+ ElementSymbol es = (ElementSymbol)element;
+ ((ElementSymbol) element).setName(tableName + ElementSymbol.SEPARATOR +
es.getShortName());
}
return element;
}
};
PostOrderNavigator.doVisit(query.getSelect(), emv);
- return table.createTupleSource(command.getProjectedSymbols(),
Criteria.separateCriteriaByAnd(query.getCriteria()), query.getOrderBy());
+ if (query.getOrderBy() != null) {
+ PostOrderNavigator.doVisit(query.getOrderBy(), emv);
+ }
+ return table.createTupleSource(command.getProjectedSymbols(),
query.getCriteria(), query.getOrderBy());
}
if (command instanceof ProcedureContainer) {
GroupSymbol group = ((ProcedureContainer)command).getGroup();
Modified: trunk/engine/src/test/java/org/teiid/query/optimizer/TestDependentJoins.java
===================================================================
---
trunk/engine/src/test/java/org/teiid/query/optimizer/TestDependentJoins.java 2010-07-27
14:22:24 UTC (rev 2378)
+++
trunk/engine/src/test/java/org/teiid/query/optimizer/TestDependentJoins.java 2010-07-27
17:15:15 UTC (rev 2379)
@@ -648,6 +648,7 @@
caps.setCapabilitySupport(Capability.QUERY_FROM_GROUP_ALIAS, true);
caps.setCapabilitySupport(Capability.QUERY_ORDERBY, true);
caps.setCapabilitySupport(Capability.QUERY_AGGREGATES_COUNT, true);
+ caps.setCapabilitySupport(Capability.QUERY_SELECT_EXPRESSION, true);
caps.setSourceProperty(Capability.MAX_IN_CRITERIA_SIZE, new Integer(1000));
capFinder.addCapabilities("pm1", caps); //$NON-NLS-1$
@@ -690,6 +691,7 @@
caps.setCapabilitySupport(Capability.QUERY_FROM_GROUP_ALIAS, true);
caps.setCapabilitySupport(Capability.QUERY_ORDERBY, true);
caps.setCapabilitySupport(Capability.QUERY_AGGREGATES_COUNT, true);
+ caps.setCapabilitySupport(Capability.QUERY_SELECT_EXPRESSION, true);
caps.setSourceProperty(Capability.MAX_IN_CRITERIA_SIZE, new Integer(1000));
capFinder.addCapabilities("pm1", caps); //$NON-NLS-1$
Modified: trunk/engine/src/test/java/org/teiid/query/optimizer/TestLimit.java
===================================================================
--- trunk/engine/src/test/java/org/teiid/query/optimizer/TestLimit.java 2010-07-27
14:22:24 UTC (rev 2378)
+++ trunk/engine/src/test/java/org/teiid/query/optimizer/TestLimit.java 2010-07-27
17:15:15 UTC (rev 2379)
@@ -268,7 +268,7 @@
String sql = "SELECT * FROM pm1.g1 limit 50, 100";//$NON-NLS-1$
String[] expectedSql = new String[] {
- "SELECT pm1.g1.e1 AS c_0, pm1.g1.e2 AS c_1, pm1.g1.e3 AS c_2, pm1.g1.e4
AS c_3 FROM pm1.g1 LIMIT (100 + 50)" //$NON-NLS-1$
+ "SELECT pm1.g1.e1, pm1.g1.e2, pm1.g1.e3, pm1.g1.e4 FROM pm1.g1 LIMIT
(100 + 50)" //$NON-NLS-1$
};
ProcessorPlan plan = TestOptimizer.helpPlan(sql,
FakeMetadataFactory.example1Cached(),
null, capFinder, expectedSql,
TestOptimizer.ComparisonMode.EXACT_COMMAND_STRING);
@@ -529,6 +529,7 @@
BasicSourceCapabilities caps = new BasicSourceCapabilities();
caps.setCapabilitySupport(Capability.ROW_LIMIT, true);
caps.setCapabilitySupport(Capability.ROW_OFFSET, true);
+ caps.setCapabilitySupport(Capability.QUERY_SELECT_EXPRESSION, true);
// pm1 model supports order by
capFinder.addCapabilities("pm1", caps); //$NON-NLS-1$
@@ -596,6 +597,7 @@
FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
BasicSourceCapabilities caps = new BasicSourceCapabilities();
caps.setCapabilitySupport(Capability.ROW_LIMIT, true);
+ caps.setCapabilitySupport(Capability.QUERY_SELECT_EXPRESSION, true);
// pm1 model supports order by
capFinder.addCapabilities("pm1", caps); //$NON-NLS-1$
@@ -630,6 +632,7 @@
BasicSourceCapabilities caps = new BasicSourceCapabilities();
caps.setCapabilitySupport(Capability.ROW_LIMIT, true);
caps.setCapabilitySupport(Capability.ROW_OFFSET, true);
+ caps.setCapabilitySupport(Capability.QUERY_SELECT_EXPRESSION, true);
// pm1 model supports order by
capFinder.addCapabilities("pm1", caps); //$NON-NLS-1$
Modified: trunk/engine/src/test/java/org/teiid/query/optimizer/TestOptimizer.java
===================================================================
--- trunk/engine/src/test/java/org/teiid/query/optimizer/TestOptimizer.java 2010-07-27
14:22:24 UTC (rev 2378)
+++ trunk/engine/src/test/java/org/teiid/query/optimizer/TestOptimizer.java 2010-07-27
17:15:15 UTC (rev 2379)
@@ -92,7 +92,7 @@
import org.teiid.query.validator.ValidatorReport;
import org.teiid.translator.SourceSystemFunctions;
-@SuppressWarnings("nls")
+@SuppressWarnings({"nls", "unchecked"})
public class TestOptimizer {
public interface DependentJoin {}
@@ -268,7 +268,8 @@
final GroupSymbol symbol = (GroupSymbol)groups.iterator().next();
Object modelId = md.getModelID(symbol.getMetadataID());
boolean supportsGroupAliases =
CapabilitiesUtil.supportsGroupAliases(modelId, md, capFinder);
- command.acceptVisitor(new AliasGenerator(supportsGroupAliases));
+ boolean supportsProjection =
CapabilitiesUtil.supports(Capability.QUERY_SELECT_EXPRESSION, modelId, md, capFinder);
+ command.acceptVisitor(new AliasGenerator(supportsGroupAliases,
!supportsProjection));
expectedQueries.add(command.toString());
} catch (Exception err) {
throw new RuntimeException(err);
@@ -5504,7 +5505,7 @@
}
/**
- * Since can now guarantee unique select column names, it's ok to have repeated
entries in the order by clause.
+ * A final rewrite will ensure the correct order by
*/
@Test public void testOrderByDuplicates() throws Exception {
FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
@@ -5527,7 +5528,7 @@
ProcessorPlan plan = helpPlan(sql,
metadata,
null, capFinder,
- new String[] {"SELECT g_0.intkey AS c_0,
g_0.intkey AS c_1 FROM bqt1.smalla AS g_0 ORDER BY c_1, c_0"}, //$NON-NLS-1$
+ new String[] {"SELECT g_0.intkey, g_0.intkey
FROM bqt1.smalla AS g_0 ORDER BY g_0.intkey"}, //$NON-NLS-1$
ComparisonMode.EXACT_COMMAND_STRING );
checkNodeTypes(plan, FULL_PUSHDOWN);
@@ -5743,8 +5744,8 @@
null,
capFinder,
new String[] {
- "SELECT bqt2.smallb.intkey AS c_0, bqt2.smalla.intkey AS c_1
FROM bqt2.smalla, bqt2.smallb WHERE bqt2.smalla.stringkey = bqt2.smallb.stringkey ORDER BY
c_0, c_1", //$NON-NLS-1$
- "SELECT bqt1.smalla.intkey AS c_0 FROM bqt1.smalla ORDER BY
c_0"}, //$NON-NLS-1$
+ "SELECT bqt2.smallb.intkey, bqt2.smalla.intkey FROM
bqt2.smalla, bqt2.smallb WHERE bqt2.smalla.stringkey = bqt2.smallb.stringkey ORDER BY
bqt2.smallb.intkey, bqt2.smalla.intkey", //$NON-NLS-1$
+ "SELECT bqt1.smalla.intkey FROM bqt1.smalla ORDER BY
bqt1.smalla.intkey"}, //$NON-NLS-1$
ComparisonMode.EXACT_COMMAND_STRING);
}
Modified:
trunk/engine/src/test/java/org/teiid/query/optimizer/TestStoredProcedurePlanning.java
===================================================================
---
trunk/engine/src/test/java/org/teiid/query/optimizer/TestStoredProcedurePlanning.java 2010-07-27
14:22:24 UTC (rev 2378)
+++
trunk/engine/src/test/java/org/teiid/query/optimizer/TestStoredProcedurePlanning.java 2010-07-27
17:15:15 UTC (rev 2379)
@@ -348,7 +348,22 @@
ProcessorPlan plan = TestOptimizer.helpPlan("EXEC pm1.sp3()", new
TempMetadataAdapter(FakeMetadataFactory.example1Cached(), new TempMetadataStore()),
//$NON-NLS-1$
new String[] { "EXEC pm1.sp3()" }); //$NON-NLS-1$
- TestOptimizer.checkNodeTypes(plan, TestOptimizer.FULL_PUSHDOWN);
+ TestOptimizer.checkNodeTypes(plan, new int[] {
+ 1, // Access
+ 0, // DependentAccess
+ 0, // DependentSelect
+ 0, // DependentProject
+ 0, // DupRemove
+ 0, // Grouping
+ 0, // NestedLoopJoinStrategy
+ 0, // MergeJoinStrategy
+ 0, // Null
+ 0, // PlanExecution
+ 1, // Project
+ 0, // Select
+ 0, // Sort
+ 0 // UnionAll
+ });
}
// test implicit type conversion of argument
Modified:
trunk/engine/src/test/java/org/teiid/query/optimizer/relational/TestAliasGenerator.java
===================================================================
---
trunk/engine/src/test/java/org/teiid/query/optimizer/relational/TestAliasGenerator.java 2010-07-27
14:22:24 UTC (rev 2378)
+++
trunk/engine/src/test/java/org/teiid/query/optimizer/relational/TestAliasGenerator.java 2010-07-27
17:15:15 UTC (rev 2379)
@@ -45,10 +45,10 @@
private Command helpTest(String sql,
String expected,
boolean aliasGroups,
- QueryMetadataInterface metadata) throws
TeiidComponentException, TeiidProcessingException {
+ boolean stripColumnAliases, QueryMetadataInterface metadata)
throws TeiidComponentException, TeiidProcessingException {
Command command = TestResolver.helpResolve(sql, metadata, null);
command = QueryRewriter.rewrite(command, metadata, null);
- command.acceptVisitor(new AliasGenerator(aliasGroups));
+ command.acceptVisitor(new AliasGenerator(aliasGroups, stripColumnAliases));
assertEquals(expected, command.toString());
return command;
}
@@ -67,13 +67,13 @@
@Test public void testLongOrderByAlias() throws Exception {
String sql = "select pm1.g1.e1 || pm1.g1.e2 as
asfasdfadfasdfasdfadfasdfadsfasdfasdfasdfasdfasdfadfa, pm1.g1.e2 from pm1.g1 order by
asfasdfadfasdfasdfadfasdfadsfasdfasdfasdfasdfasdfadfa"; //$NON-NLS-1$
String expected = "SELECT concat(g_0.e1, g_0.e2) AS c_0, g_0.e2 AS c_1 FROM
pm1.g1 AS g_0 ORDER BY c_0"; //$NON-NLS-1$
- helpTest(sql, expected, true, FakeMetadataFactory.example1Cached());
+ helpTest(sql, expected, true, false, FakeMetadataFactory.example1Cached());
}
@Test public void testOrderBySymbolName() throws Exception {
String sql = "select e1 from pm1.g1 order by e1"; //$NON-NLS-1$
String expected = "SELECT g_0.e1 AS c_0 FROM pm1.g1 AS g_0 ORDER BY
c_0"; //$NON-NLS-1$
- Query command = (Query)helpTest(sql, expected, true,
FakeMetadataFactory.example1Cached());
+ Query command = (Query)helpTest(sql, expected, true, false,
FakeMetadataFactory.example1Cached());
assertEquals(command.getOrderBy().getSortKeys().get(0).getName(),
"e1"); //$NON-NLS-1$
assertEquals(((SingleElementSymbol)command.getProjectedSymbols().get(0)).getShortName(),
"e1"); //$NON-NLS-1$
}
@@ -81,73 +81,85 @@
@Test public void testInlineViewWithSubQuery() throws Exception {
String sql = "select intnum from (select intnum from bqt1.smallb where
intnum in (select intnum a from bqt1.smalla)) b"; //$NON-NLS-1$
String expected = "SELECT v_0.c_0 FROM (SELECT g_0.intnum AS c_0 FROM
bqt1.smallb AS g_0 WHERE g_0.intnum IN (SELECT g_1.intnum FROM bqt1.smalla AS g_1)) AS
v_0"; //$NON-NLS-1$
- helpTest(sql, expected, true, FakeMetadataFactory.exampleBQTCached());
+ helpTest(sql, expected, true, false, FakeMetadataFactory.exampleBQTCached());
}
@Test public void testInlineViewOrderBy() throws Exception {
String sql = "select intnum from (select intnum from bqt1.smallb) b order by
b.intnum"; //$NON-NLS-1$
String expected = "SELECT v_0.c_0 FROM (SELECT g_0.intnum AS c_0 FROM
bqt1.smallb AS g_0) AS v_0 ORDER BY c_0"; //$NON-NLS-1$
- helpTest(sql, expected, true, FakeMetadataFactory.exampleBQTCached());
+ helpTest(sql, expected, true, false, FakeMetadataFactory.exampleBQTCached());
}
@Test public void testNestedInlineViewOrderBy() throws Exception {
String sql = "select x from (select intnum x from (select intnum from
bqt1.smallb) b order by x) y order by x"; //$NON-NLS-1$
String expected = "SELECT v_1.c_0 FROM (SELECT v_0.c_0 FROM (SELECT
g_0.intnum AS c_0 FROM bqt1.smallb AS g_0) AS v_0) AS v_1 ORDER BY c_0";
//$NON-NLS-1$
- helpTest(sql, expected, true, FakeMetadataFactory.exampleBQTCached());
+ helpTest(sql, expected, true, false, FakeMetadataFactory.exampleBQTCached());
}
@Test public void testInlineViewWithOnClause() throws Exception {
String sql = "select abcd.efg from (select intkey as efg from bqt1.smalla)
abcd inner join (select intnum from bqt1.smallb) b on (b.intnum = abcd.efg)";
//$NON-NLS-1$
String expected = "SELECT v_0.c_0 FROM (SELECT g_0.intkey AS c_0 FROM
bqt1.smalla AS g_0) AS v_0 INNER JOIN (SELECT g_1.intnum AS c_0 FROM bqt1.smallb AS g_1)
AS v_1 ON v_1.c_0 = v_0.c_0"; //$NON-NLS-1$
- helpTest(sql, expected, true, FakeMetadataFactory.exampleBQTCached());
+ helpTest(sql, expected, true, false, FakeMetadataFactory.exampleBQTCached());
}
@Test public void testUnionOrderBy() throws Exception {
String sql = "select e1, e2 as c_0 from pm1.g1 union all select 1, e1 from
pm1.g2 order by e1"; //$NON-NLS-1$
String expected = "SELECT g_1.e1 AS c_0, g_1.e2 AS c_1 FROM pm1.g1 AS g_1
UNION ALL SELECT '1' AS c_0, g_0.e1 AS c_1 FROM pm1.g2 AS g_0 ORDER BY c_0";
//$NON-NLS-1$
- helpTest(sql, expected, true, FakeMetadataFactory.example1Cached());
+ helpTest(sql, expected, true, false, FakeMetadataFactory.example1Cached());
}
@Test public void testDuplicateShortElementName() throws Exception {
String sql = "select pm1.g1.e1, pm1.g2.e1 from pm1.g1, pm1.g2 order by
pm1.g1.e1, pm1.g2.e1"; //$NON-NLS-1$
String expected = "SELECT g_0.e1 AS c_0, g_1.e1 AS c_1 FROM pm1.g1 AS g_0,
pm1.g2 AS g_1 ORDER BY c_0, c_1"; //$NON-NLS-1$
- helpTest(sql, expected, true, FakeMetadataFactory.example1Cached());
+ helpTest(sql, expected, true, false, FakeMetadataFactory.example1Cached());
}
@Test public void testCorrelatedRefernce() throws Exception {
String sql = "select intnum, stringnum from (select intnum, stringnum from
bqt1.smallb) b where intnum in (select b.stringnum || b.intnum from (select intnum from
bqt1.smalla) b) "; //$NON-NLS-1$
String expected = "SELECT v_0.c_0, v_0.c_1 FROM (SELECT g_0.intnum AS c_0,
g_0.stringnum AS c_1 FROM bqt1.smallb AS g_0) AS v_0 WHERE v_0.c_0 IN (SELECT
concat(v_0.c_1, v_1.c_0) FROM (SELECT g_1.intnum AS c_0 FROM bqt1.smalla AS g_1) AS
v_1)"; //$NON-NLS-1$
- helpTest(sql, expected, true, FakeMetadataFactory.exampleBQTCached());
+ helpTest(sql, expected, true, false, FakeMetadataFactory.exampleBQTCached());
}
@Test public void testCorrelatedRefernce1() throws Exception {
String sql = "select intnum, stringnum from bqt1.smallb where intnum in (select
stringnum || b.intnum from (select intnum from bqt1.smalla) b) "; //$NON-NLS-1$
String expected = "SELECT g_0.intnum, g_0.stringnum FROM bqt1.smallb AS g_0
WHERE g_0.intnum IN (SELECT concat(g_0.stringnum, v_0.c_0) FROM (SELECT g_1.intnum AS c_0
FROM bqt1.smalla AS g_1) AS v_0)"; //$NON-NLS-1$
- helpTest(sql, expected, true, FakeMetadataFactory.exampleBQTCached());
+ helpTest(sql, expected, true, false, FakeMetadataFactory.exampleBQTCached());
}
@Test public void testGroupAliasNotSupported() throws Exception {
String sql = "select b.intkey from bqt1.smalla b"; //$NON-NLS-1$
String expected = "SELECT bqt1.smalla.intkey FROM bqt1.smalla";
//$NON-NLS-1$
- helpTest(sql, expected, false, FakeMetadataFactory.exampleBQTCached());
+ helpTest(sql, expected, false, false, FakeMetadataFactory.exampleBQTCached());
}
@Test public void testUnionAliasing() throws Exception {
String sql = "SELECT IntKey FROM BQT1.SmallA UNION ALL SELECT IntNum FROM
BQT1.SmallA"; //$NON-NLS-1$
String expected = "SELECT BQT1.SmallA.IntKey AS c_0 FROM BQT1.SmallA UNION
ALL SELECT BQT1.SmallA.IntNum AS c_0 FROM BQT1.SmallA"; //$NON-NLS-1$
- helpTest(sql, expected, false, FakeMetadataFactory.exampleBQTCached());
+ helpTest(sql, expected, false, false, FakeMetadataFactory.exampleBQTCached());
}
@Test public void testUnrelatedOrderBy() throws Exception {
String sql = "SELECT b.IntKey FROM BQT1.SmallA a, BQT1.SmallA b ORDER BY
a.StringKey"; //$NON-NLS-1$
String expected = "SELECT g_1.IntKey AS c_0 FROM BQT1.SmallA AS g_0,
BQT1.SmallA AS g_1 ORDER BY g_0.StringKey"; //$NON-NLS-1$
- helpTest(sql, expected, true, FakeMetadataFactory.exampleBQTCached());
+ helpTest(sql, expected, true, false, FakeMetadataFactory.exampleBQTCached());
}
@Test public void testUnrelatedOrderBy1() throws Exception {
String sql = "SELECT b.IntKey FROM (select intkey, stringkey from BQT1.SmallA)
a, (select intkey, stringkey from BQT1.SmallA) b ORDER BY a.StringKey";
//$NON-NLS-1$
String expected = "SELECT v_1.c_0 FROM (SELECT g_0.intkey AS c_0,
g_0.stringkey AS c_1 FROM BQT1.SmallA AS g_0) AS v_0, (SELECT g_1.intkey AS c_0,
g_1.stringkey AS c_1 FROM BQT1.SmallA AS g_1) AS v_1 ORDER BY v_0.c_1";
//$NON-NLS-1$
- helpTest(sql, expected, true, FakeMetadataFactory.exampleBQTCached());
+ helpTest(sql, expected, true, false, FakeMetadataFactory.exampleBQTCached());
}
+ @Test public void testStripAliases() throws Exception {
+ String sql = "select intkey as a, stringkey as b from BQT1.SmallA ORDER BY a,
b"; //$NON-NLS-1$
+ String expected = "SELECT g_0.intkey, g_0.stringkey FROM BQT1.SmallA AS g_0
ORDER BY g_0.intkey, g_0.stringkey"; //$NON-NLS-1$
+ helpTest(sql, expected, true, true, FakeMetadataFactory.exampleBQTCached());
+ }
+
+ @Test public void testStripAliases1() throws Exception {
+ String sql = "select intkey as a, stringkey as b from BQT1.SmallA ORDER BY a,
b"; //$NON-NLS-1$
+ String expected = "SELECT BQT1.SmallA.intkey, BQT1.SmallA.stringkey FROM
BQT1.SmallA ORDER BY BQT1.SmallA.intkey, BQT1.SmallA.stringkey"; //$NON-NLS-1$
+ helpTest(sql, expected, false, true, FakeMetadataFactory.exampleBQTCached());
+ }
+
}
Modified: trunk/engine/src/test/java/org/teiid/query/processor/TestProcessor.java
===================================================================
--- trunk/engine/src/test/java/org/teiid/query/processor/TestProcessor.java 2010-07-27
14:22:24 UTC (rev 2378)
+++ trunk/engine/src/test/java/org/teiid/query/processor/TestProcessor.java 2010-07-27
17:15:15 UTC (rev 2379)
@@ -7342,7 +7342,7 @@
FakeDataManager dataManager = new FakeDataManager();
sampleData2(dataManager);
- ProcessorPlan plan = TestOptimizer.helpPlan(sql,
FakeMetadataFactory.example1Cached(), null, capFinder, new String[] {"SELECT
pm1.g1.e1 AS c_0 FROM pm1.g1 LIMIT (5 + 1)"},
TestOptimizer.ComparisonMode.EXACT_COMMAND_STRING); //$NON-NLS-1$
+ ProcessorPlan plan = TestOptimizer.helpPlan(sql,
FakeMetadataFactory.example1Cached(), null, capFinder, new String[] {"SELECT
pm1.g1.e1 FROM pm1.g1 LIMIT (5 + 1)"},
TestOptimizer.ComparisonMode.EXACT_COMMAND_STRING); //$NON-NLS-1$
helpProcess(plan, dataManager, expected);
}
Modified: trunk/engine/src/test/java/org/teiid/query/processor/TestTempTables.java
===================================================================
--- trunk/engine/src/test/java/org/teiid/query/processor/TestTempTables.java 2010-07-27
14:22:24 UTC (rev 2378)
+++ trunk/engine/src/test/java/org/teiid/query/processor/TestTempTables.java 2010-07-27
17:15:15 UTC (rev 2379)
@@ -143,4 +143,18 @@
execute("select e2, e1 from x where e2 = 1", new List[] {Arrays.asList(1,
"one")}); //$NON-NLS-1$
}
+ @Test public void testOrderByWithIndex() throws Exception {
+ execute("create local temporary table x (e1 string, e2 integer, primary key
(e2))", new List[] {Arrays.asList(0)}); //$NON-NLS-1$
+ execute("insert into x (e2, e1) values (3, 'one')", new List[]
{Arrays.asList(1)}); //$NON-NLS-1$
+ execute("insert into x (e2, e1) values (2, 'one')", new List[]
{Arrays.asList(1)}); //$NON-NLS-1$
+ execute("select * from x as y order by e2 desc", new List[]
{Arrays.asList("one", 3), Arrays.asList("one", 2)}); //$NON-NLS-1$
+ }
+
+ @Test public void testOrderByWithoutIndex() throws Exception {
+ execute("create local temporary table x (e1 string, e2 integer, primary key
(e2))", new List[] {Arrays.asList(0)}); //$NON-NLS-1$
+ execute("insert into x (e2, e1) values (3, 'a')", new List[]
{Arrays.asList(1)}); //$NON-NLS-1$
+ execute("insert into x (e2, e1) values (2, 'b')", new List[]
{Arrays.asList(1)}); //$NON-NLS-1$
+ execute("select * from x order by e1", new List[]
{Arrays.asList("a", 3), Arrays.asList("b", 2)}); //$NON-NLS-1$
+ }
+
}