Author: shawkins
Date: 2011-06-28 15:58:01 -0400 (Tue, 28 Jun 2011)
New Revision: 3285
Modified:
branches/7.4.x/engine/src/main/java/org/teiid/query/sql/symbol/QueryString.java
branches/7.4.x/engine/src/main/java/org/teiid/query/validator/AggregateValidationVisitor.java
branches/7.4.x/engine/src/main/resources/org/teiid/query/i18n.properties
branches/7.4.x/engine/src/test/java/org/teiid/query/validator/TestValidator.java
Log:
TEIID-1661 fix for aggregate validation
Modified: branches/7.4.x/engine/src/main/java/org/teiid/query/sql/symbol/QueryString.java
===================================================================
---
branches/7.4.x/engine/src/main/java/org/teiid/query/sql/symbol/QueryString.java 2011-06-28
14:44:55 UTC (rev 3284)
+++
branches/7.4.x/engine/src/main/java/org/teiid/query/sql/symbol/QueryString.java 2011-06-28
19:58:01 UTC (rev 3285)
@@ -30,7 +30,7 @@
import org.teiid.query.sql.visitor.SQLStringVisitor;
/**
- * Represents XMLATTRIBUTES name value pairs
+ * Represents query string name value pairs
*/
public class QueryString implements Expression {
Modified:
branches/7.4.x/engine/src/main/java/org/teiid/query/validator/AggregateValidationVisitor.java
===================================================================
---
branches/7.4.x/engine/src/main/java/org/teiid/query/validator/AggregateValidationVisitor.java 2011-06-28
14:44:55 UTC (rev 3284)
+++
branches/7.4.x/engine/src/main/java/org/teiid/query/validator/AggregateValidationVisitor.java 2011-06-28
19:58:01 UTC (rev 3285)
@@ -28,6 +28,13 @@
import org.teiid.core.types.DataTypeManager;
import org.teiid.query.QueryPlugin;
import org.teiid.query.sql.LanguageObject;
+import org.teiid.query.sql.lang.BetweenCriteria;
+import org.teiid.query.sql.lang.CompareCriteria;
+import org.teiid.query.sql.lang.CompoundCriteria;
+import org.teiid.query.sql.lang.IsNullCriteria;
+import org.teiid.query.sql.lang.MatchCriteria;
+import org.teiid.query.sql.lang.NotCriteria;
+import org.teiid.query.sql.lang.SetCriteria;
import org.teiid.query.sql.navigator.PreOrderNavigator;
import org.teiid.query.sql.symbol.AggregateSymbol;
import org.teiid.query.sql.symbol.CaseExpression;
@@ -35,7 +42,13 @@
import org.teiid.query.sql.symbol.Expression;
import org.teiid.query.sql.symbol.ExpressionSymbol;
import org.teiid.query.sql.symbol.Function;
+import org.teiid.query.sql.symbol.QueryString;
import org.teiid.query.sql.symbol.SearchedCaseExpression;
+import org.teiid.query.sql.symbol.XMLElement;
+import org.teiid.query.sql.symbol.XMLForest;
+import org.teiid.query.sql.symbol.XMLParse;
+import org.teiid.query.sql.symbol.XMLQuery;
+import org.teiid.query.sql.symbol.XMLSerialize;
import org.teiid.query.sql.symbol.AggregateSymbol.Type;
import org.teiid.query.sql.visitor.AggregateSymbolCollectorVisitor;
import org.teiid.query.sql.visitor.ElementCollectorVisitor;
@@ -112,6 +125,70 @@
validateExpression(obj);
}
+ public void visit(NotCriteria obj) {
+ validateExpression(obj);
+ }
+
+ @Override
+ public void visit(CompoundCriteria obj) {
+ validateExpression(obj);
+ }
+
+ @Override
+ public void visit(CompareCriteria obj) {
+ validateExpression(obj);
+ }
+
+ @Override
+ public void visit(SetCriteria obj) {
+ validateExpression(obj);
+ }
+
+ @Override
+ public void visit(IsNullCriteria obj) {
+ validateExpression(obj);
+ }
+
+ @Override
+ public void visit(MatchCriteria obj) {
+ validateExpression(obj);
+ }
+
+ @Override
+ public void visit(BetweenCriteria obj) {
+ validateExpression(obj);
+ }
+
+ @Override
+ public void visit(QueryString obj) {
+ validateExpression(obj);
+ }
+
+ @Override
+ public void visit(XMLElement obj) {
+ validateExpression(obj);
+ }
+
+ @Override
+ public void visit(XMLForest obj) {
+ validateExpression(obj);
+ }
+
+ @Override
+ public void visit(XMLParse obj) {
+ validateExpression(obj);
+ }
+
+ @Override
+ public void visit(XMLQuery obj) {
+ validateExpression(obj);
+ }
+
+ @Override
+ public void visit(XMLSerialize obj) {
+ validateExpression(obj);
+ }
+
private void validateExpression(Expression symbol) {
if (ElementCollectorVisitor.getElements(symbol, false).isEmpty()) {
validateBelow = false;
Modified: branches/7.4.x/engine/src/main/resources/org/teiid/query/i18n.properties
===================================================================
--- branches/7.4.x/engine/src/main/resources/org/teiid/query/i18n.properties 2011-06-28
14:44:55 UTC (rev 3284)
+++ branches/7.4.x/engine/src/main/resources/org/teiid/query/i18n.properties 2011-06-28
19:58:01 UTC (rev 3285)
@@ -204,8 +204,8 @@
ERR.015.012.0033 = Metadata does not allow updates on the group: {0}
ERR.015.012.0034 = Queries involving UNIONs, INTERSECTs and EXCEPTs not allowed on XML
documents
ERR.015.012.0035 = Queries combined with the set operator {0} must have the same number
of output elements.
-ERR.015.012.0037 = Invalid symbol: {0}. When an aggregate function is used in the SELECT
clause and no GROUP BY clause is specified, the SELECT clause may contain only aggregate
functions and constants.
-ERR.015.012.0038 = Invalid symbol: {0}. When a GROUP BY clause is used, all elements in
the SELECT clause must be declared in the GROUP BY clause.
+ERR.015.012.0037 = Non-constant, non-aggregate expression {0} cannot be mixed with
aggregate functions and implicit grouping.
+ERR.015.012.0038 = Non-constant, non-aggregate expression {0} is not declared in the
GROUP BY clause.
ERR.015.012.0039 = Nested aggregate expressions are not allowed: {0}
ERR.015.012.0041 = The aggregate function {0} cannot be used with non-numeric
expressions: {1}
AggregateValidationVisitor.non_comparable = The aggregate function {0} cannot be used
with non-comparable expressions: {1}
Modified:
branches/7.4.x/engine/src/test/java/org/teiid/query/validator/TestValidator.java
===================================================================
---
branches/7.4.x/engine/src/test/java/org/teiid/query/validator/TestValidator.java 2011-06-28
14:44:55 UTC (rev 3284)
+++
branches/7.4.x/engine/src/test/java/org/teiid/query/validator/TestValidator.java 2011-06-28
19:58:01 UTC (rev 3285)
@@ -419,6 +419,14 @@
new String[] {"COUNT(DISTINCT ObjectValue)"},
RealMetadataFactory.exampleBQTCached() ); //$NON-NLS-1$
}
+ /**
+ * previously failed on stringkey, which is not entirely correct
+ */
+ @Test public void testInvalidAggregate10() {
+ helpValidate("SELECT xmlparse(document stringkey) FROM BQT1.SmallA GROUP BY
xmlparse(document stringkey)", //$NON-NLS-1$
+ new String[] {"XMLPARSE(DOCUMENT stringkey)"},
RealMetadataFactory.exampleBQTCached() ); //$NON-NLS-1$
+ }
+
@Test public void testInvalidAggregateIssue190644() {
helpValidate("SELECT e3 + 1 from pm1.g1 GROUP BY e2 + 1 HAVING e2 + 1 =
5", new String[] {"e3"}, RealMetadataFactory.example1Cached());
//$NON-NLS-1$ //$NON-NLS-2$
}
@@ -436,6 +444,11 @@
"FROM BQT1.SmallA GROUP BY case when IntKey>=5000 then '5000
+' else '0-999' end", //$NON-NLS-1$
new String[] {}, RealMetadataFactory.exampleBQTCached());
}
+
+ @Test public void testValidAggregate4() {
+ helpValidate("SELECT max(e1), e2 is null from pm1.g1 GROUP BY e2 is
null", new String[] {}, RealMetadataFactory.example1Cached()); //$NON-NLS-1$
+ }
+
@Test public void testInvalidHaving1() {
helpValidate("SELECT e3 FROM test.group HAVING e3 > 0", new String[]
{"e3"}, exampleMetadata()); //$NON-NLS-1$ //$NON-NLS-2$
}