Author: shawkins
Date: 2009-11-11 16:17:34 -0500 (Wed, 11 Nov 2009)
New Revision: 1548
Modified:
trunk/engine/src/main/java/com/metamatrix/query/validator/AggregateValidationVisitor.java
trunk/engine/src/main/resources/com/metamatrix/query/i18n.properties
trunk/engine/src/test/java/com/metamatrix/query/validator/TestValidator.java
Log:
TEIID-879 adding validation of min/max
Modified:
trunk/engine/src/main/java/com/metamatrix/query/validator/AggregateValidationVisitor.java
===================================================================
---
trunk/engine/src/main/java/com/metamatrix/query/validator/AggregateValidationVisitor.java 2009-11-10
19:46:56 UTC (rev 1547)
+++
trunk/engine/src/main/java/com/metamatrix/query/validator/AggregateValidationVisitor.java 2009-11-11
21:17:34 UTC (rev 1548)
@@ -25,6 +25,7 @@
import java.util.Collection;
import java.util.Set;
+import com.metamatrix.common.types.DataTypeManager;
import com.metamatrix.query.QueryPlugin;
import com.metamatrix.query.sql.LanguageObject;
import com.metamatrix.query.sql.ReservedWords;
@@ -38,7 +39,6 @@
import com.metamatrix.query.sql.symbol.SearchedCaseExpression;
import com.metamatrix.query.sql.visitor.AggregateSymbolCollectorVisitor;
import com.metamatrix.query.sql.visitor.ElementCollectorVisitor;
-import com.metamatrix.query.sql.visitor.SQLStringVisitor;
import com.metamatrix.query.util.ErrorMessageKeys;
@@ -71,11 +71,12 @@
// Verify data type of aggregate expression
String aggregateFunction = obj.getAggregateFunction();
- if(aggregateFunction.equals(ReservedWords.SUM) ||
aggregateFunction.equals(ReservedWords.AVG)) {
- if(obj.getType() == null) {
-
handleValidationError(QueryPlugin.Util.getString(ErrorMessageKeys.VALIDATOR_0041, new
Object[] {aggregateFunction, SQLStringVisitor.getSQLString(obj)}), obj);
- }
- }
+ if((aggregateFunction.equals(ReservedWords.SUM) ||
aggregateFunction.equals(ReservedWords.AVG)) && obj.getType() == null) {
+
handleValidationError(QueryPlugin.Util.getString(ErrorMessageKeys.VALIDATOR_0041, new
Object[] {aggregateFunction, obj}), obj);
+ }
+ if((aggregateFunction.equals(ReservedWords.MIN) ||
aggregateFunction.equals(ReservedWords.MAX)) &&
DataTypeManager.isNonComparable(DataTypeManager.getDataTypeName(aggExp.getType()))) {
+
handleValidationError(QueryPlugin.Util.getString("AggregateValidationVisitor.non_comparable",
new Object[] {aggregateFunction, obj}), obj); //$NON-NLS-1$
+ }
validateBelow = false;
}
Modified: trunk/engine/src/main/resources/com/metamatrix/query/i18n.properties
===================================================================
--- trunk/engine/src/main/resources/com/metamatrix/query/i18n.properties 2009-11-10
19:46:56 UTC (rev 1547)
+++ trunk/engine/src/main/resources/com/metamatrix/query/i18n.properties 2009-11-11
21:17:34 UTC (rev 1548)
@@ -297,6 +297,7 @@
ERR.015.012.0039 = Nested aggregate expressions are not allowed: {0}
ERR.015.012.0040 = Aggregate expression has unknown data type: {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}
ERR.015.012.0042 = Cross join may not have criteria: {0}
ERR.015.012.0043 = Join must have criteria declared in the ON clause: {0}
ERR.015.012.0045 = Elements in this join criteria are not from a group involved in the
join: {0}
Modified: trunk/engine/src/test/java/com/metamatrix/query/validator/TestValidator.java
===================================================================
---
trunk/engine/src/test/java/com/metamatrix/query/validator/TestValidator.java 2009-11-10
19:46:56 UTC (rev 1547)
+++
trunk/engine/src/test/java/com/metamatrix/query/validator/TestValidator.java 2009-11-11
21:17:34 UTC (rev 1548)
@@ -492,6 +492,11 @@
new String[] {"StringKey"},
FakeMetadataFactory.exampleBQTCached() ); //$NON-NLS-1$
}
+ public void testInvalidAggregate8() {
+ helpValidate("SELECT max(ObjectValue) FROM BQT1.SmallA GROUP BY
StringKey", //$NON-NLS-1$
+ new String[] {"MAX(ObjectValue)"},
FakeMetadataFactory.exampleBQTCached() ); //$NON-NLS-1$
+ }
+
public void testInvalidAggregateIssue190644() {
helpValidate("SELECT e3 + 1 from pm1.g1 GROUP BY e2 + 1 HAVING e2 + 1 =
5", new String[] {"e3"}, FakeMetadataFactory.example1Cached());
//$NON-NLS-1$ //$NON-NLS-2$
}
Show replies by date