Author: shawkins
Date: 2011-07-23 07:41:47 -0400 (Sat, 23 Jul 2011)
New Revision: 3331
Added:
trunk/api/src/main/java/org/teiid/language/WindowSpecification.java
trunk/engine/src/main/java/org/teiid/query/sql/symbol/WindowSpecification.java
Removed:
trunk/engine/src/test/java/org/teiid/query/optimizer/TestWindowFunctions.java
Modified:
trunk/api/src/main/java/org/teiid/language/WindowFunction.java
trunk/api/src/main/java/org/teiid/language/visitor/HierarchyVisitor.java
trunk/api/src/main/java/org/teiid/language/visitor/LanguageObjectVisitor.java
trunk/api/src/main/java/org/teiid/language/visitor/SQLStringVisitor.java
trunk/engine/src/main/java/org/teiid/dqp/internal/datamgr/LanguageBridgeFactory.java
trunk/engine/src/main/java/org/teiid/query/sql/LanguageVisitor.java
trunk/engine/src/main/java/org/teiid/query/sql/lang/OrderByItem.java
trunk/engine/src/main/java/org/teiid/query/sql/navigator/PreOrPostOrderNavigator.java
trunk/engine/src/main/java/org/teiid/query/sql/symbol/WindowFunction.java
trunk/engine/src/main/java/org/teiid/query/sql/visitor/ExpressionMappingVisitor.java
trunk/engine/src/main/java/org/teiid/query/sql/visitor/SQLStringVisitor.java
trunk/engine/src/main/java/org/teiid/query/validator/ValidationVisitor.java
trunk/engine/src/main/javacc/org/teiid/query/parser/SQLParser.jj
trunk/engine/src/test/java/org/teiid/query/parser/TestParser.java
Log:
TEIID-1667 correcting unit tests and separating out a windowspecification class
Modified: trunk/api/src/main/java/org/teiid/language/WindowFunction.java
===================================================================
--- trunk/api/src/main/java/org/teiid/language/WindowFunction.java 2011-07-22 21:13:20 UTC
(rev 3330)
+++ trunk/api/src/main/java/org/teiid/language/WindowFunction.java 2011-07-23 11:41:47 UTC
(rev 3331)
@@ -22,8 +22,6 @@
package org.teiid.language;
-import java.util.List;
-
import org.teiid.core.util.EquivalenceUtil;
import org.teiid.core.util.HashCodeUtil;
import org.teiid.language.visitor.LanguageObjectVisitor;
@@ -31,8 +29,7 @@
public class WindowFunction extends BaseLanguageObject implements Expression {
private AggregateFunction function;
- private List<Expression> partition;
- private OrderBy orderBy;
+ private WindowSpecification windowSpecification;
public WindowFunction() {
@@ -46,21 +43,13 @@
this.function = expression;
}
- public List<Expression> getPartition() {
- return partition;
+ public WindowSpecification getWindowSpecification() {
+ return windowSpecification;
}
- public void setPartition(List<Expression> grouping) {
- this.partition = grouping;
+ public void setWindowSpecification(WindowSpecification windowSpecification) {
+ this.windowSpecification = windowSpecification;
}
-
- public OrderBy getOrderBy() {
- return orderBy;
- }
-
- public void setOrderBy(OrderBy orderBy) {
- this.orderBy = orderBy;
- }
@Override
public Class<?> getType() {
@@ -74,7 +63,7 @@
@Override
public int hashCode() {
- return HashCodeUtil.hashCode(function.hashCode(), partition, orderBy);
+ return HashCodeUtil.hashCode(function.hashCode(), windowSpecification);
}
public boolean equals(Object obj) {
@@ -86,8 +75,7 @@
}
WindowFunction other = (WindowFunction)obj;
return EquivalenceUtil.areEqual(this.function, other.function) &&
- EquivalenceUtil.areEqual(this.partition, other.partition) &&
- EquivalenceUtil.areEqual(this.orderBy, other.orderBy);
+ EquivalenceUtil.areEqual(this.windowSpecification, other.windowSpecification);
}
}
Added: trunk/api/src/main/java/org/teiid/language/WindowSpecification.java
===================================================================
--- trunk/api/src/main/java/org/teiid/language/WindowSpecification.java
(rev 0)
+++ trunk/api/src/main/java/org/teiid/language/WindowSpecification.java 2011-07-23
11:41:47 UTC (rev 3331)
@@ -0,0 +1,78 @@
+/*
+ * 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.language;
+
+import java.util.List;
+
+import org.teiid.core.util.EquivalenceUtil;
+import org.teiid.core.util.HashCodeUtil;
+import org.teiid.language.visitor.LanguageObjectVisitor;
+
+public class WindowSpecification extends BaseLanguageObject {
+
+ private List<Expression> partition;
+ private OrderBy orderBy;
+
+ public WindowSpecification() {
+
+ }
+
+ public List<Expression> getPartition() {
+ return partition;
+ }
+
+ public void setPartition(List<Expression> grouping) {
+ this.partition = grouping;
+ }
+
+ public OrderBy getOrderBy() {
+ return orderBy;
+ }
+
+ public void setOrderBy(OrderBy orderBy) {
+ this.orderBy = orderBy;
+ }
+
+ @Override
+ public void acceptVisitor(LanguageObjectVisitor visitor) {
+ visitor.visit(this);
+ }
+
+ @Override
+ public int hashCode() {
+ return HashCodeUtil.hashCode(partition.hashCode(), orderBy);
+ }
+
+ public boolean equals(Object obj) {
+ if (obj == this) {
+ return true;
+ }
+ if (!(obj instanceof WindowSpecification)) {
+ return false;
+ }
+ WindowSpecification other = (WindowSpecification)obj;
+ return EquivalenceUtil.areEqual(this.partition, other.partition) &&
+ EquivalenceUtil.areEqual(this.orderBy, other.orderBy);
+ }
+
+}
Property changes on: trunk/api/src/main/java/org/teiid/language/WindowSpecification.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Modified: trunk/api/src/main/java/org/teiid/language/visitor/HierarchyVisitor.java
===================================================================
--- trunk/api/src/main/java/org/teiid/language/visitor/HierarchyVisitor.java 2011-07-22
21:13:20 UTC (rev 3330)
+++ trunk/api/src/main/java/org/teiid/language/visitor/HierarchyVisitor.java 2011-07-23
11:41:47 UTC (rev 3331)
@@ -52,6 +52,7 @@
import org.teiid.language.SubqueryIn;
import org.teiid.language.Update;
import org.teiid.language.WindowFunction;
+import org.teiid.language.WindowSpecification;
import org.teiid.language.With;
import org.teiid.language.WithItem;
@@ -253,8 +254,13 @@
@Override
public void visit(WindowFunction windowFunction) {
visitNode(windowFunction.getFunction());
- visitNodes(windowFunction.getPartition());
- visitNode(windowFunction.getOrderBy());
+ visitNode(windowFunction.getWindowSpecification());
}
+ @Override
+ public void visit(WindowSpecification windowSpecification) {
+ visitNodes(windowSpecification.getPartition());
+ visitNode(windowSpecification.getOrderBy());
+ }
+
}
Modified: trunk/api/src/main/java/org/teiid/language/visitor/LanguageObjectVisitor.java
===================================================================
---
trunk/api/src/main/java/org/teiid/language/visitor/LanguageObjectVisitor.java 2011-07-22
21:13:20 UTC (rev 3330)
+++
trunk/api/src/main/java/org/teiid/language/visitor/LanguageObjectVisitor.java 2011-07-23
11:41:47 UTC (rev 3331)
@@ -58,6 +58,7 @@
import org.teiid.language.SubqueryIn;
import org.teiid.language.Update;
import org.teiid.language.WindowFunction;
+import org.teiid.language.WindowSpecification;
import org.teiid.language.With;
import org.teiid.language.WithItem;
@@ -102,4 +103,5 @@
public void visit(With obj);
public void visit(WithItem obj);
public void visit(WindowFunction windowFunction);
+ public void visit(WindowSpecification windowSpecification);
}
Modified: trunk/api/src/main/java/org/teiid/language/visitor/SQLStringVisitor.java
===================================================================
--- trunk/api/src/main/java/org/teiid/language/visitor/SQLStringVisitor.java 2011-07-22
21:13:20 UTC (rev 3330)
+++ trunk/api/src/main/java/org/teiid/language/visitor/SQLStringVisitor.java 2011-07-23
11:41:47 UTC (rev 3331)
@@ -73,6 +73,7 @@
import org.teiid.language.TableReference;
import org.teiid.language.Update;
import org.teiid.language.WindowFunction;
+import org.teiid.language.WindowSpecification;
import org.teiid.language.With;
import org.teiid.language.WithItem;
import org.teiid.language.Argument.Direction;
@@ -924,23 +925,28 @@
buffer.append(Tokens.SPACE);
buffer.append(OVER);
buffer.append(Tokens.SPACE);
+ append(windowFunction.getWindowSpecification());
+ }
+
+ @Override
+ public void visit(WindowSpecification windowSpecification) {
buffer.append(Tokens.LPAREN);
boolean needsSpace = false;
- if (windowFunction.getPartition() != null) {
+ if (windowSpecification.getPartition() != null) {
buffer.append(PARTITION);
buffer.append(Tokens.SPACE);
buffer.append(BY);
buffer.append(Tokens.SPACE);
- append(windowFunction.getPartition());
+ append(windowSpecification.getPartition());
needsSpace = true;
}
- if (windowFunction.getOrderBy() != null) {
+ if (windowSpecification.getOrderBy() != null) {
if (needsSpace) {
buffer.append(Tokens.SPACE);
}
- append(windowFunction.getOrderBy());
+ append(windowSpecification.getOrderBy());
}
- buffer.append(Tokens.RPAREN);
+ buffer.append(Tokens.RPAREN);
}
/**
Modified:
trunk/engine/src/main/java/org/teiid/dqp/internal/datamgr/LanguageBridgeFactory.java
===================================================================
---
trunk/engine/src/main/java/org/teiid/dqp/internal/datamgr/LanguageBridgeFactory.java 2011-07-22
21:13:20 UTC (rev 3330)
+++
trunk/engine/src/main/java/org/teiid/dqp/internal/datamgr/LanguageBridgeFactory.java 2011-07-23
11:41:47 UTC (rev 3331)
@@ -63,6 +63,7 @@
import org.teiid.language.SubqueryComparison;
import org.teiid.language.SubqueryIn;
import org.teiid.language.TableReference;
+import org.teiid.language.WindowSpecification;
import org.teiid.language.With;
import org.teiid.language.WithItem;
import org.teiid.language.Argument.Direction;
@@ -461,7 +462,7 @@
Ordering direction = items.get(i).isAscending() ? Ordering.ASC:
Ordering.DESC;
SortSpecification orderByItem = null;
- if(items.get(i).isUnrelated() || (!set && symbol instanceof
ElementSymbol)){
+ if(!set && (items.get(i).isUnrelated() || symbol instanceof
ElementSymbol)){
orderByItem = new SortSpecification(direction, translate(symbol));
} else {
orderByItem = new SortSpecification(direction, new ColumnReference(null,
SingleElementSymbol.getShortName(symbol.getOutputName()), null, symbol.getType()));
@@ -497,14 +498,17 @@
org.teiid.language.WindowFunction translate(WindowFunction windowFunction) {
org.teiid.language.WindowFunction result = new org.teiid.language.WindowFunction();
result.setFunction(translate(windowFunction.getFunction()));
- result.setOrderBy(translate(windowFunction.getOrderBy(), false));
- if (windowFunction.getPartition() != null) {
- ArrayList<org.teiid.language.Expression> partition = new
ArrayList<org.teiid.language.Expression>(windowFunction.getPartition().size());
- for (Expression ex : windowFunction.getPartition()) {
- partition.add(translate(ex));
+ WindowSpecification ws = new WindowSpecification();
+ ws.setOrderBy(translate(windowFunction.getWindowSpecification().getOrderBy(),
false));
+ List<Expression> partition =
windowFunction.getWindowSpecification().getPartition();
+ if (partition != null) {
+ ArrayList<org.teiid.language.Expression> partitionList = new
ArrayList<org.teiid.language.Expression>(partition.size());
+ for (Expression ex : partition) {
+ partitionList.add(translate(ex));
}
- result.setPartition(partition);
+ ws.setPartition(partitionList);
}
+ result.setWindowSpecification(ws);
return result;
}
Modified: trunk/engine/src/main/java/org/teiid/query/sql/LanguageVisitor.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/sql/LanguageVisitor.java 2011-07-22
21:13:20 UTC (rev 3330)
+++ trunk/engine/src/main/java/org/teiid/query/sql/LanguageVisitor.java 2011-07-23
11:41:47 UTC (rev 3331)
@@ -97,6 +97,7 @@
import org.teiid.query.sql.symbol.SearchedCaseExpression;
import org.teiid.query.sql.symbol.TextLine;
import org.teiid.query.sql.symbol.WindowFunction;
+import org.teiid.query.sql.symbol.WindowSpecification;
import org.teiid.query.sql.symbol.XMLAttributes;
import org.teiid.query.sql.symbol.XMLElement;
import org.teiid.query.sql.symbol.XMLForest;
@@ -224,4 +225,5 @@
public void visit(AlterTrigger obj) {}
public void visit(WindowFunction windowFunction) {}
+ public void visit(WindowSpecification windowSpecification) {}
}
Modified: trunk/engine/src/main/java/org/teiid/query/sql/lang/OrderByItem.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/sql/lang/OrderByItem.java 2011-07-22
21:13:20 UTC (rev 3330)
+++ trunk/engine/src/main/java/org/teiid/query/sql/lang/OrderByItem.java 2011-07-23
11:41:47 UTC (rev 3331)
@@ -79,7 +79,7 @@
* @return true if the expression does not appear in the select clause
*/
public boolean isUnrelated() {
- return expressionPosition == null || expressionPosition == -1;
+ return getExpressionPosition() == -1;
}
@Override
Modified:
trunk/engine/src/main/java/org/teiid/query/sql/navigator/PreOrPostOrderNavigator.java
===================================================================
---
trunk/engine/src/main/java/org/teiid/query/sql/navigator/PreOrPostOrderNavigator.java 2011-07-22
21:13:20 UTC (rev 3330)
+++
trunk/engine/src/main/java/org/teiid/query/sql/navigator/PreOrPostOrderNavigator.java 2011-07-23
11:41:47 UTC (rev 3331)
@@ -102,6 +102,7 @@
import org.teiid.query.sql.symbol.SearchedCaseExpression;
import org.teiid.query.sql.symbol.TextLine;
import org.teiid.query.sql.symbol.WindowFunction;
+import org.teiid.query.sql.symbol.WindowSpecification;
import org.teiid.query.sql.symbol.XMLAttributes;
import org.teiid.query.sql.symbol.XMLElement;
import org.teiid.query.sql.symbol.XMLForest;
@@ -700,7 +701,14 @@
public void visit(WindowFunction obj) {
preVisitVisitor(obj);
visitNode(obj.getFunction());
- visitNodes(obj.getPartition());
+ visitNode(obj.getWindowSpecification());
+ postVisitVisitor(obj);
+ }
+
+ @Override
+ public void visit(WindowSpecification obj) {
+ preVisitVisitor(obj);
+ visitNodes(obj.getPartition());
visitNode(obj.getOrderBy());
postVisitVisitor(obj);
}
Modified: trunk/engine/src/main/java/org/teiid/query/sql/symbol/WindowFunction.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/sql/symbol/WindowFunction.java 2011-07-22
21:13:20 UTC (rev 3330)
+++ trunk/engine/src/main/java/org/teiid/query/sql/symbol/WindowFunction.java 2011-07-23
11:41:47 UTC (rev 3331)
@@ -22,20 +22,15 @@
package org.teiid.query.sql.symbol;
-import java.util.List;
-
import org.teiid.core.util.EquivalenceUtil;
import org.teiid.core.util.HashCodeUtil;
-import org.teiid.query.sql.LanguageObject;
import org.teiid.query.sql.LanguageVisitor;
-import org.teiid.query.sql.lang.OrderBy;
import org.teiid.query.sql.visitor.SQLStringVisitor;
public class WindowFunction implements Expression {
private AggregateSymbol function;
- private List<Expression> partition;
- private OrderBy orderBy;
+ private WindowSpecification windowSpecification;
public WindowFunction() {
@@ -50,22 +45,14 @@
this.function.setWindowed(true);
}
- public List<Expression> getPartition() {
- return partition;
+ public WindowSpecification getWindowSpecification() {
+ return windowSpecification;
}
- public void setPartition(List<Expression> grouping) {
- this.partition = grouping;
+ public void setWindowSpecification(WindowSpecification windowSpecification) {
+ this.windowSpecification = windowSpecification;
}
- public OrderBy getOrderBy() {
- return orderBy;
- }
-
- public void setOrderBy(OrderBy orderBy) {
- this.orderBy = orderBy;
- }
-
@Override
public Class<?> getType() {
return function.getType();
@@ -83,7 +70,7 @@
@Override
public int hashCode() {
- return HashCodeUtil.hashCode(function.hashCode(), partition, orderBy);
+ return HashCodeUtil.hashCode(function.hashCode(), windowSpecification);
}
@Override
@@ -96,20 +83,14 @@
}
WindowFunction other = (WindowFunction)obj;
return EquivalenceUtil.areEqual(this.function, other.function) &&
- EquivalenceUtil.areEqual(this.partition, other.partition) &&
- EquivalenceUtil.areEqual(this.orderBy, other.orderBy);
+ EquivalenceUtil.areEqual(this.windowSpecification, other.windowSpecification);
}
@Override
public WindowFunction clone() {
WindowFunction clone = new WindowFunction();
clone.setFunction((AggregateSymbol) this.function.clone());
- if (this.partition != null) {
- clone.setPartition(LanguageObject.Util.deepClone(this.partition, Expression.class));
- }
- if (this.orderBy != null) {
- clone.setOrderBy(this.orderBy.clone());
- }
+ clone.setWindowSpecification(this.windowSpecification.clone());
return clone;
}
Added: trunk/engine/src/main/java/org/teiid/query/sql/symbol/WindowSpecification.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/sql/symbol/WindowSpecification.java
(rev 0)
+++
trunk/engine/src/main/java/org/teiid/query/sql/symbol/WindowSpecification.java 2011-07-23
11:41:47 UTC (rev 3331)
@@ -0,0 +1,99 @@
+/*
+ * 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.sql.symbol;
+
+import java.util.List;
+
+import org.teiid.core.util.EquivalenceUtil;
+import org.teiid.core.util.HashCodeUtil;
+import org.teiid.query.sql.LanguageObject;
+import org.teiid.query.sql.LanguageVisitor;
+import org.teiid.query.sql.lang.OrderBy;
+import org.teiid.query.sql.visitor.SQLStringVisitor;
+
+public class WindowSpecification implements LanguageObject {
+
+ private List<Expression> partition;
+ private OrderBy orderBy;
+
+ public WindowSpecification() {
+
+ }
+
+ public List<Expression> getPartition() {
+ return partition;
+ }
+
+ public void setPartition(List<Expression> grouping) {
+ this.partition = grouping;
+ }
+
+ public OrderBy getOrderBy() {
+ return orderBy;
+ }
+
+ public void setOrderBy(OrderBy orderBy) {
+ this.orderBy = orderBy;
+ }
+
+ @Override
+ public void acceptVisitor(LanguageVisitor visitor) {
+ visitor.visit(this);
+ }
+
+ @Override
+ public int hashCode() {
+ return HashCodeUtil.hashCode(0, partition, orderBy);
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (obj == this) {
+ return true;
+ }
+ if (!(obj instanceof WindowSpecification)) {
+ return false;
+ }
+ WindowSpecification other = (WindowSpecification)obj;
+ return EquivalenceUtil.areEqual(this.partition, other.partition) &&
+ EquivalenceUtil.areEqual(this.orderBy, other.orderBy);
+ }
+
+ @Override
+ public WindowSpecification clone() {
+ WindowSpecification clone = new WindowSpecification();
+ if (this.partition != null) {
+ clone.setPartition(LanguageObject.Util.deepClone(this.partition, Expression.class));
+ }
+ if (this.orderBy != null) {
+ clone.setOrderBy(this.orderBy.clone());
+ }
+ return clone;
+ }
+
+ @Override
+ public String toString() {
+ return SQLStringVisitor.getSQLString(this);
+ }
+
+}
Property changes on:
trunk/engine/src/main/java/org/teiid/query/sql/symbol/WindowSpecification.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Modified:
trunk/engine/src/main/java/org/teiid/query/sql/visitor/ExpressionMappingVisitor.java
===================================================================
---
trunk/engine/src/main/java/org/teiid/query/sql/visitor/ExpressionMappingVisitor.java 2011-07-22
21:13:20 UTC (rev 3330)
+++
trunk/engine/src/main/java/org/teiid/query/sql/visitor/ExpressionMappingVisitor.java 2011-07-23
11:41:47 UTC (rev 3331)
@@ -67,7 +67,7 @@
import org.teiid.query.sql.symbol.QueryString;
import org.teiid.query.sql.symbol.SearchedCaseExpression;
import org.teiid.query.sql.symbol.SingleElementSymbol;
-import org.teiid.query.sql.symbol.WindowFunction;
+import org.teiid.query.sql.symbol.WindowSpecification;
import org.teiid.query.sql.symbol.XMLElement;
import org.teiid.query.sql.symbol.XMLParse;
import org.teiid.query.sql.symbol.XMLSerialize;
@@ -450,11 +450,11 @@
}
@Override
- public void visit(WindowFunction windowFunction) {
- if (windowFunction.getPartition() == null) {
+ public void visit(WindowSpecification windowSpecification) {
+ if (windowSpecification.getPartition() == null) {
return;
}
- List<Expression> partition = windowFunction.getPartition();
+ List<Expression> partition = windowSpecification.getPartition();
for (int i = 0; i < partition.size(); i++) {
partition.set(i, replaceExpression(partition.get(i)));
}
Modified: trunk/engine/src/main/java/org/teiid/query/sql/visitor/SQLStringVisitor.java
===================================================================
---
trunk/engine/src/main/java/org/teiid/query/sql/visitor/SQLStringVisitor.java 2011-07-22
21:13:20 UTC (rev 3330)
+++
trunk/engine/src/main/java/org/teiid/query/sql/visitor/SQLStringVisitor.java 2011-07-23
11:41:47 UTC (rev 3331)
@@ -126,6 +126,7 @@
import org.teiid.query.sql.symbol.SingleElementSymbol;
import org.teiid.query.sql.symbol.TextLine;
import org.teiid.query.sql.symbol.WindowFunction;
+import org.teiid.query.sql.symbol.WindowSpecification;
import org.teiid.query.sql.symbol.XMLAttributes;
import org.teiid.query.sql.symbol.XMLElement;
import org.teiid.query.sql.symbol.XMLForest;
@@ -2056,23 +2057,28 @@
append(SPACE);
append(OVER);
append(SPACE);
+ append(windowFunction.getWindowSpecification());
+ }
+
+ @Override
+ public void visit(WindowSpecification windowSpecification) {
append(Tokens.LPAREN);
boolean needsSpace = false;
- if (windowFunction.getPartition() != null) {
+ if (windowSpecification.getPartition() != null) {
append(PARTITION);
append(SPACE);
append(BY);
append(SPACE);
- registerNodes(windowFunction.getPartition(), 0);
+ registerNodes(windowSpecification.getPartition(), 0);
needsSpace = true;
}
- if (windowFunction.getOrderBy() != null) {
+ if (windowSpecification.getOrderBy() != null) {
if (needsSpace) {
append(SPACE);
}
- append(windowFunction.getOrderBy());
+ append(windowSpecification.getOrderBy());
}
- append(Tokens.RPAREN);
+ append(Tokens.RPAREN);
}
public static String escapeSinglePart( String part ) {
Modified: trunk/engine/src/main/java/org/teiid/query/validator/ValidationVisitor.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/validator/ValidationVisitor.java 2011-07-22
21:13:20 UTC (rev 3330)
+++ trunk/engine/src/main/java/org/teiid/query/validator/ValidationVisitor.java 2011-07-23
11:41:47 UTC (rev 3331)
@@ -1211,7 +1211,7 @@
case RANK:
case DENSE_RANK:
case ROW_NUMBER:
- if (windowFunction.getOrderBy() == null) {
+ if (windowFunction.getWindowSpecification().getOrderBy() == null) {
handleValidationError(QueryPlugin.Util.getString("ValidationVisitor.analytical_requires_order_by",
windowFunction), windowFunction); //$NON-NLS-1$
}
}
Modified: trunk/engine/src/main/javacc/org/teiid/query/parser/SQLParser.jj
===================================================================
--- trunk/engine/src/main/javacc/org/teiid/query/parser/SQLParser.jj 2011-07-22 21:13:20
UTC (rev 3330)
+++ trunk/engine/src/main/javacc/org/teiid/query/parser/SQLParser.jj 2011-07-23 11:41:47
UTC (rev 3331)
@@ -3456,9 +3456,11 @@
<RPAREN>
{
WindowFunction result = new WindowFunction();
+ WindowSpecification ws = new WindowSpecification();
result.setFunction((AggregateSymbol)agg);
- result.setPartition(partitionList);
- result.setOrderBy(orderBy);
+ ws.setPartition(partitionList);
+ ws.setOrderBy(orderBy);
+ result.setWindowSpecification(ws);
return result;
}
}
Deleted: trunk/engine/src/test/java/org/teiid/query/optimizer/TestWindowFunctions.java
===================================================================
---
trunk/engine/src/test/java/org/teiid/query/optimizer/TestWindowFunctions.java 2011-07-22
21:13:20 UTC (rev 3330)
+++
trunk/engine/src/test/java/org/teiid/query/optimizer/TestWindowFunctions.java 2011-07-23
11:41:47 UTC (rev 3331)
@@ -1,49 +0,0 @@
-/*
- * 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.optimizer;
-
-import static org.teiid.query.optimizer.TestOptimizer.*;
-
-import org.junit.Test;
-import org.teiid.query.optimizer.TestOptimizer.ComparisonMode;
-import org.teiid.query.optimizer.capabilities.BasicSourceCapabilities;
-import org.teiid.query.optimizer.capabilities.DefaultCapabilitiesFinder;
-import org.teiid.query.optimizer.capabilities.SourceCapabilities.Capability;
-import org.teiid.query.processor.ProcessorPlan;
-import org.teiid.query.unittest.RealMetadataFactory;
-
-public class TestWindowFunctions {
-
- @Test public void testViewNotRemoved() throws Exception {
- BasicSourceCapabilities caps = getTypicalCapabilities();
- caps.setCapabilitySupport(Capability.ELEMENTARY_OLAP, true);
- caps.setCapabilitySupport(Capability.QUERY_FROM_INLINE_VIEWS, true);
- ProcessorPlan plan = TestOptimizer.helpPlan("SELECT y FROM (select
row_number() over (order by e1) as y from pm1.g1) as x where x.y = 10",
//$NON-NLS-1$
- RealMetadataFactory.example1Cached(), null, new
DefaultCapabilitiesFinder(caps),
- new String[] {
- "SELECT v_0.c_0 FROM (SELECT ROW_NUMBER()
OVER (ORDER BY g_0.e1) AS c_0 FROM pm1.g1 AS g_0) AS v_0 WHERE v_0.c_0 = 10"},
ComparisonMode.EXACT_COMMAND_STRING); //$NON-NLS-1$
-
- checkNodeTypes(plan, FULL_PUSHDOWN);
- }
-
-}
Modified: trunk/engine/src/test/java/org/teiid/query/parser/TestParser.java
===================================================================
--- trunk/engine/src/test/java/org/teiid/query/parser/TestParser.java 2011-07-22 21:13:20
UTC (rev 3330)
+++ trunk/engine/src/test/java/org/teiid/query/parser/TestParser.java 2011-07-23 11:41:47
UTC (rev 3331)
@@ -117,6 +117,7 @@
import org.teiid.query.sql.symbol.TestSearchedCaseExpression;
import org.teiid.query.sql.symbol.TextLine;
import org.teiid.query.sql.symbol.WindowFunction;
+import org.teiid.query.sql.symbol.WindowSpecification;
import org.teiid.query.sql.symbol.XMLAttributes;
import org.teiid.query.sql.symbol.XMLElement;
import org.teiid.query.sql.symbol.XMLForest;
@@ -6850,8 +6851,10 @@
Query query = new Query();
WindowFunction wf = new WindowFunction();
wf.setFunction(new AggregateSymbol("expr", "ROW_NUMBER", false,
null));
- wf.setPartition(new ArrayList<Expression>(Arrays.asList(new
ElementSymbol("x"))));
- wf.setOrderBy(new OrderBy(Arrays.asList(new ElementSymbol("y"))));
+ WindowSpecification ws = new WindowSpecification();
+ ws.setPartition(new ArrayList<Expression>(Arrays.asList(new
ElementSymbol("x"))));
+ ws.setOrderBy(new OrderBy(Arrays.asList(new ElementSymbol("y"))));
+ wf.setWindowSpecification(ws);
query.setSelect(new Select(Arrays.asList(new ExpressionSymbol("x",
wf))));
query.setFrom(new From(Arrays.asList(new UnaryFromClause(new
GroupSymbol("g")))));
helpTest(sql, "SELECT ROW_NUMBER() OVER (PARTITION BY x ORDER BY y) FROM
g", query);