Author: shawkins
Date: 2010-06-22 14:58:30 -0400 (Tue, 22 Jun 2010)
New Revision: 2276
Added:
trunk/engine/src/main/java/org/teiid/query/function/aggregate/StatsFunction.java
Removed:
trunk/engine/src/main/java/org/teiid/api/exception/query/CriteriaEvaluationException.java
trunk/test-integration/common/src/test/resources/xquery/
Modified:
trunk/api/src/main/java/org/teiid/language/AggregateFunction.java
trunk/api/src/main/java/org/teiid/language/SQLConstants.java
trunk/api/src/main/java/org/teiid/translator/ExecutionFactory.java
trunk/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/access/AccessExecutionFactory.java
trunk/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/db2/DB2ExecutionFactory.java
trunk/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/h2/H2ExecutionFactory.java
trunk/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/hsql/HsqlExecutionFactory.java
trunk/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/mysql/MySQL5ExecutionFactory.java
trunk/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/oracle/OracleExecutionFactory.java
trunk/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/postgresql/PostgreSQLExecutionFactory.java
trunk/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/sqlserver/SQLServerExecutionFactory.java
trunk/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/sybase/SybaseExecutionFactory.java
trunk/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/teiid/TeiidExecutionFactory.java
trunk/documentation/developer-guide/src/main/docbook/en-US/content/translator-api.xml
trunk/documentation/reference/src/main/docbook/en-US/content/sql_support.xml
trunk/documentation/reference/src/main/docbook/en-US/content/translators.xml
trunk/engine/src/main/java/org/teiid/dqp/internal/datamgr/impl/CapabilitiesConverter.java
trunk/engine/src/main/java/org/teiid/dqp/internal/datamgr/language/LanguageBridgeFactory.java
trunk/engine/src/main/java/org/teiid/dqp/internal/process/MetaDataProcessor.java
trunk/engine/src/main/java/org/teiid/query/eval/Evaluator.java
trunk/engine/src/main/java/org/teiid/query/function/aggregate/Count.java
trunk/engine/src/main/java/org/teiid/query/optimizer/capabilities/SourceCapabilities.java
trunk/engine/src/main/java/org/teiid/query/optimizer/relational/rules/CapabilitiesUtil.java
trunk/engine/src/main/java/org/teiid/query/optimizer/relational/rules/RuleCleanCriteria.java
trunk/engine/src/main/java/org/teiid/query/optimizer/relational/rules/RulePushAggregates.java
trunk/engine/src/main/java/org/teiid/query/optimizer/relational/rules/RuleRemoveOptionalJoins.java
trunk/engine/src/main/java/org/teiid/query/parser/ParseInfo.java
trunk/engine/src/main/java/org/teiid/query/parser/SQLParserUtil.java
trunk/engine/src/main/java/org/teiid/query/processor/relational/AccessNode.java
trunk/engine/src/main/java/org/teiid/query/processor/relational/GroupingNode.java
trunk/engine/src/main/java/org/teiid/query/processor/relational/JoinNode.java
trunk/engine/src/main/java/org/teiid/query/processor/relational/JoinStrategy.java
trunk/engine/src/main/java/org/teiid/query/processor/relational/MergeJoinStrategy.java
trunk/engine/src/main/java/org/teiid/query/processor/relational/NestedTableJoinStrategy.java
trunk/engine/src/main/java/org/teiid/query/processor/relational/PartitionedSortJoin.java
trunk/engine/src/main/java/org/teiid/query/processor/relational/RelationalNodeUtil.java
trunk/engine/src/main/java/org/teiid/query/processor/xml/CriteriaCondition.java
trunk/engine/src/main/java/org/teiid/query/rewriter/QueryRewriter.java
trunk/engine/src/main/java/org/teiid/query/sql/lang/MatchCriteria.java
trunk/engine/src/main/java/org/teiid/query/sql/symbol/AggregateSymbol.java
trunk/engine/src/main/java/org/teiid/query/sql/visitor/SQLStringVisitor.java
trunk/engine/src/main/java/org/teiid/query/validator/AggregateValidationVisitor.java
trunk/engine/src/main/javacc/org/teiid/query/parser/SQLParser.jj
trunk/engine/src/main/resources/org/teiid/query/i18n.properties
trunk/engine/src/test/java/org/teiid/query/optimizer/TestAggregatePushdown.java
trunk/engine/src/test/java/org/teiid/query/processor/FakeDataManager.java
trunk/engine/src/test/java/org/teiid/query/processor/TestAggregateProcessing.java
trunk/engine/src/test/java/org/teiid/query/processor/TestProcessor.java
trunk/engine/src/test/java/org/teiid/query/processor/TestVirtualDepJoin.java
trunk/engine/src/test/java/org/teiid/query/processor/eval/TestCriteriaEvaluator.java
trunk/engine/src/test/java/org/teiid/query/validator/TestValidator.java
Log:
TEIID-886 adding support for any/some/every/stddev_pop/stddev_samp/var_pop/var_samp - agg
pushdown is supported, but no compensation was added if the source doesn't support,
but does support standard aggs. also reducing lookaheads in the parser and removing
criteriaevaluationexception (I was going to allow boolean value expression to include
criteria, but named proc properties then become ambiguous).
Modified: trunk/api/src/main/java/org/teiid/language/AggregateFunction.java
===================================================================
--- trunk/api/src/main/java/org/teiid/language/AggregateFunction.java 2010-06-22 17:21:54
UTC (rev 2275)
+++ trunk/api/src/main/java/org/teiid/language/AggregateFunction.java 2010-06-22 18:58:30
UTC (rev 2276)
@@ -34,6 +34,10 @@
public static final String SUM = "SUM"; //$NON-NLS-1$
public static final String MIN = "MIN"; //$NON-NLS-1$
public static final String MAX = "MAX"; //$NON-NLS-1$
+ public static final String STDDEV_POP = "STDDEV_POP"; //$NON-NLS-1$
+ public static final String STDDEV_SAMP = "STDDEV_SAMP"; //$NON-NLS-1$
+ public static final String VAR_SAMP = "VAR_SAMP"; //$NON-NLS-1$
+ public static final String VAR_POP = "VAR_POP"; //$NON-NLS-1$
private Expression expression;
private String aggName;
@@ -50,11 +54,6 @@
/**
* Get the name of the aggregate function. This will be one of the constants
defined
* in this class.
- * @see #COUNT
- * @see #AVG
- * @see #SUM
- * @see #MIN
- * @see #MAX
*/
public String getName() {
return this.aggName;
@@ -88,11 +87,6 @@
* Set the name of the aggregate function. This will be one of the constants
defined
* in this class.
* @param name New aggregate function name
- * @see #COUNT
- * @see #AVG
- * @see #SUM
- * @see #MIN
- * @see #MAX
*/
public void setName(String name) {
this.aggName = name;
Modified: trunk/api/src/main/java/org/teiid/language/SQLConstants.java
===================================================================
--- trunk/api/src/main/java/org/teiid/language/SQLConstants.java 2010-06-22 17:21:54 UTC
(rev 2275)
+++ trunk/api/src/main/java/org/teiid/language/SQLConstants.java 2010-06-22 18:58:30 UTC
(rev 2276)
@@ -86,6 +86,12 @@
public static final String QUERYSTRING = "QUERYSTRING"; //$NON-NLS-1$
//xmlparse
public static final String WELLFORMED = "WELLFORMED"; //$NON-NLS-1$
+ //agg
+ public static final String EVERY = "EVERY"; //$NON-NLS-1$
+ public static final String STDDEV_POP = "STDDEV_POP"; //$NON-NLS-1$
+ public static final String STDDEV_SAMP = "STDDEV_SAMP"; //$NON-NLS-1$
+ public static final String VAR_SAMP = "VAR_SAMP"; //$NON-NLS-1$
+ public static final String VAR_POP = "VAR_POP"; //$NON-NLS-1$
}
public interface Reserved {
Modified: trunk/api/src/main/java/org/teiid/translator/ExecutionFactory.java
===================================================================
--- trunk/api/src/main/java/org/teiid/translator/ExecutionFactory.java 2010-06-22 17:21:54
UTC (rev 2275)
+++ trunk/api/src/main/java/org/teiid/translator/ExecutionFactory.java 2010-06-22 18:58:30
UTC (rev 2276)
@@ -533,6 +533,14 @@
public boolean supportsAggregatesDistinct() {
return false;
}
+
+ /**
+ * Support indicates connector can accept STDDEV_POP, STDDEV_VAR, VAR_POP, VAR_SAMP
+ * @since 7.1
+ */
+ public boolean supportsAggregatesEnhancedNumeric() {
+ return false;
+ }
/**
* Support indicates connector can accept scalar subqueries in the SELECT, WHERE,
and
Modified:
trunk/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/access/AccessExecutionFactory.java
===================================================================
---
trunk/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/access/AccessExecutionFactory.java 2010-06-22
17:21:54 UTC (rev 2275)
+++
trunk/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/access/AccessExecutionFactory.java 2010-06-22
18:58:30 UTC (rev 2276)
@@ -26,6 +26,9 @@
import java.util.List;
+import org.teiid.language.AggregateFunction;
+import org.teiid.language.LanguageObject;
+import org.teiid.translator.ExecutionContext;
import org.teiid.translator.Translator;
import org.teiid.translator.jdbc.JDBCExecutionFactory;
import org.teiid.translator.jdbc.sybase.SybaseExecutionFactory;
@@ -46,6 +49,23 @@
}
@Override
+ public List<?> translate(LanguageObject obj, ExecutionContext context) {
+ if (obj instanceof AggregateFunction) {
+ AggregateFunction af = (AggregateFunction)obj;
+ if (af.getName().equals(AggregateFunction.STDDEV_POP)) {
+ af.setName("StDevP"); //$NON-NLS-1$
+ } else if (af.getName().equals(AggregateFunction.STDDEV_SAMP)) {
+ af.setName("StDev"); //$NON-NLS-1$
+ } else if (af.getName().equals(AggregateFunction.VAR_POP)) {
+ af.setName("VarP"); //$NON-NLS-1$
+ } else if (af.getName().equals(AggregateFunction.VAR_SAMP)) {
+ af.setName("Var"); //$NON-NLS-1$
+ }
+ }
+ return super.translate(obj, context);
+ }
+
+ @Override
public boolean addSourceComment() {
return false;
}
@@ -84,4 +104,9 @@
public List<String> getSupportedFunctions() {
return getDefaultSupportedFunctions();
}
+
+ @Override
+ public boolean supportsAggregatesEnhancedNumeric() {
+ return true;
+ }
}
Modified:
trunk/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/db2/DB2ExecutionFactory.java
===================================================================
---
trunk/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/db2/DB2ExecutionFactory.java 2010-06-22
17:21:54 UTC (rev 2275)
+++
trunk/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/db2/DB2ExecutionFactory.java 2010-06-22
18:58:30 UTC (rev 2276)
@@ -244,5 +244,10 @@
@Override
public boolean supportsIntersect() {
return true;
+ }
+
+ @Override
+ public boolean supportsAggregatesEnhancedNumeric() {
+ return true;
}
}
Modified:
trunk/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/h2/H2ExecutionFactory.java
===================================================================
---
trunk/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/h2/H2ExecutionFactory.java 2010-06-22
17:21:54 UTC (rev 2275)
+++
trunk/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/h2/H2ExecutionFactory.java 2010-06-22
18:58:30 UTC (rev 2276)
@@ -189,5 +189,10 @@
@Override
public boolean supportsIntersect() {
return true;
- }
+ }
+
+ @Override
+ public boolean supportsAggregatesEnhancedNumeric() {
+ return true;
+ }
}
Modified:
trunk/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/hsql/HsqlExecutionFactory.java
===================================================================
---
trunk/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/hsql/HsqlExecutionFactory.java 2010-06-22
17:21:54 UTC (rev 2275)
+++
trunk/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/hsql/HsqlExecutionFactory.java 2010-06-22
18:58:30 UTC (rev 2276)
@@ -180,4 +180,9 @@
public boolean supportsIntersect() {
return true;
}
+
+ @Override
+ public boolean supportsAggregatesEnhancedNumeric() {
+ return true;
+ }
}
Modified:
trunk/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/mysql/MySQL5ExecutionFactory.java
===================================================================
---
trunk/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/mysql/MySQL5ExecutionFactory.java 2010-06-22
17:21:54 UTC (rev 2275)
+++
trunk/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/mysql/MySQL5ExecutionFactory.java 2010-06-22
18:58:30 UTC (rev 2276)
@@ -60,5 +60,10 @@
public boolean supportsInlineViews() {
return true;
}
+
+ @Override
+ public boolean supportsAggregatesEnhancedNumeric() {
+ return true;
+ }
}
Modified:
trunk/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/oracle/OracleExecutionFactory.java
===================================================================
---
trunk/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/oracle/OracleExecutionFactory.java 2010-06-22
17:21:54 UTC (rev 2275)
+++
trunk/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/oracle/OracleExecutionFactory.java 2010-06-22
18:58:30 UTC (rev 2276)
@@ -536,5 +536,10 @@
@Override
public boolean supportsIntersect() {
return true;
- }
+ }
+
+ @Override
+ public boolean supportsAggregatesEnhancedNumeric() {
+ return true;
+ }
}
Modified:
trunk/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/postgresql/PostgreSQLExecutionFactory.java
===================================================================
---
trunk/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/postgresql/PostgreSQLExecutionFactory.java 2010-06-22
17:21:54 UTC (rev 2275)
+++
trunk/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/postgresql/PostgreSQLExecutionFactory.java 2010-06-22
18:58:30 UTC (rev 2276)
@@ -457,4 +457,9 @@
return true;
}
+ @Override
+ public boolean supportsAggregatesEnhancedNumeric() {
+ return getDatabaseVersion().compareTo(EIGHT_2) >= 0;
+ }
+
}
Modified:
trunk/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/sqlserver/SQLServerExecutionFactory.java
===================================================================
---
trunk/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/sqlserver/SQLServerExecutionFactory.java 2010-06-22
17:21:54 UTC (rev 2275)
+++
trunk/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/sqlserver/SQLServerExecutionFactory.java 2010-06-22
18:58:30 UTC (rev 2276)
@@ -28,6 +28,7 @@
import java.util.Arrays;
import java.util.List;
+import org.teiid.language.AggregateFunction;
import org.teiid.language.ColumnReference;
import org.teiid.language.Function;
import org.teiid.language.LanguageObject;
@@ -62,6 +63,17 @@
if (TypeFacility.RUNTIME_TYPES.STRING.equals(elem.getType()) &&
elem.getMetadataObject() != null &&
"uniqueidentifier".equalsIgnoreCase(elem.getMetadataObject().getNativeType())) {
//$NON-NLS-1$
return Arrays.asList("cast(", elem, " as char(36))");
//$NON-NLS-1$ //$NON-NLS-2$
}
+ } else if (obj instanceof AggregateFunction) {
+ AggregateFunction af = (AggregateFunction)obj;
+ if (af.getName().equals(AggregateFunction.STDDEV_POP)) {
+ af.setName("STDDEVP"); //$NON-NLS-1$
+ } else if (af.getName().equals(AggregateFunction.STDDEV_SAMP)) {
+ af.setName("STDDEV"); //$NON-NLS-1$
+ } else if (af.getName().equals(AggregateFunction.VAR_POP)) {
+ af.setName("VARP"); //$NON-NLS-1$
+ } else if (af.getName().equals(AggregateFunction.VAR_SAMP)) {
+ af.setName("VAR"); //$NON-NLS-1$
+ }
}
return super.translate(obj, context);
}
@@ -170,6 +182,11 @@
@Override
public int getMaxInCriteriaSize() {
return JDBCExecutionFactory.DEFAULT_MAX_IN_CRITERIA;
- }
+ }
+
+ @Override
+ public boolean supportsAggregatesEnhancedNumeric() {
+ return true;
+ }
}
Modified:
trunk/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/sybase/SybaseExecutionFactory.java
===================================================================
---
trunk/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/sybase/SybaseExecutionFactory.java 2010-06-22
17:21:54 UTC (rev 2275)
+++
trunk/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/sybase/SybaseExecutionFactory.java 2010-06-22
18:58:30 UTC (rev 2276)
@@ -46,7 +46,15 @@
@Translator(name="sybase")
-public class SybaseExecutionFactory extends JDBCExecutionFactory {
+public class SybaseExecutionFactory extends JDBCExecutionFactory {
+
+ public static final String TWELVE_5 = "12.5"; //$NON-NLS-1$
+ public static final String FIFTEEN_0_2 = "15.0.2"; //$NON-NLS-1$
+ public static final String FIFTEEN_5 = "15.5"; //$NON-NLS-1$
+
+ public SybaseExecutionFactory() {
+ setDatabaseVersion(TWELVE_5);
+ }
public void start() throws TranslatorException {
super.start();
@@ -288,5 +296,10 @@
@Override
public int getMaxFromGroups() {
return 50;
- }
+ }
+
+ @Override
+ public boolean supportsAggregatesEnhancedNumeric() {
+ return getDatabaseVersion().compareTo(FIFTEEN_0_2) >= 0;
+ }
}
Modified:
trunk/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/teiid/TeiidExecutionFactory.java
===================================================================
---
trunk/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/teiid/TeiidExecutionFactory.java 2010-06-22
17:21:54 UTC (rev 2275)
+++
trunk/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/teiid/TeiidExecutionFactory.java 2010-06-22
18:58:30 UTC (rev 2276)
@@ -36,6 +36,13 @@
*/
@Translator(name="teiid")
public class TeiidExecutionFactory extends JDBCExecutionFactory {
+
+ public static final String SEVEN_0 = "7.0"; //$NON-NLS-1$
+ public static final String SEVEN_1 = "7.1"; //$NON-NLS-1$
+
+ public TeiidExecutionFactory() {
+ setDatabaseVersion(SEVEN_0);
+ }
@Override
public List<String> getSupportedFunctions() {
@@ -160,4 +167,9 @@
public boolean supportsIntersect() {
return true;
}
+
+ @Override
+ public boolean supportsAggregatesEnhancedNumeric() {
+ return getDatabaseVersion().compareTo(SEVEN_1) >= 0;
+ }
}
Modified:
trunk/documentation/developer-guide/src/main/docbook/en-US/content/translator-api.xml
===================================================================
---
trunk/documentation/developer-guide/src/main/docbook/en-US/content/translator-api.xml 2010-06-22
17:21:54 UTC (rev 2275)
+++
trunk/documentation/developer-guide/src/main/docbook/en-US/content/translator-api.xml 2010-06-22
18:58:30 UTC (rev 2276)
@@ -1077,6 +1077,17 @@
</row>
<row>
<entry>
+ <para>AggregatesEnhancedNumeric</para>
+ </entry>
+ <entry>
+ <para/>
+ </entry>
+ <entry>
+ <para>Translator can support the VAR_SAMP, VAR_POP, STDDEV_SAMP,
STDDEV_POP aggregate functions.</para>
+ </entry>
+ </row>
+ <row>
+ <entry>
<para>ScalarSubqueries</para>
</entry>
<entry>
Modified: trunk/documentation/reference/src/main/docbook/en-US/content/sql_support.xml
===================================================================
---
trunk/documentation/reference/src/main/docbook/en-US/content/sql_support.xml 2010-06-22
17:21:54 UTC (rev 2275)
+++
trunk/documentation/reference/src/main/docbook/en-US/content/sql_support.xml 2010-06-22
18:58:30 UTC (rev 2276)
@@ -206,23 +206,41 @@
<para>COUNT(*) – count the number of values (including nulls and
duplicates) in a group</para>
</listitem>
<listitem>
- <para>COUNT(expression) – count the number of values (excluding nulls) in
a group</para>
+ <para>COUNT(x) – count the number of values (excluding nulls) in a
group</para>
</listitem>
<listitem>
- <para>SUM(expression) – sum of the values (excluding nulls) in a
group</para>
+ <para>SUM(x) – sum of the values (excluding nulls) in a
group</para>
</listitem>
<listitem>
- <para>AVG(expression) – average of the values (excluding nulls) in a
group</para>
+ <para>AVG(x) – average of the values (excluding nulls) in a
group</para>
</listitem>
<listitem>
- <para>MIN(expression) – minimum value in a group (excluding
null)</para>
+ <para>MIN(x) – minimum value in a group (excluding null)</para>
</listitem>
<listitem>
- <para>MAX(expression) – maximum value in a group (excluding
null)</para>
+ <para>MAX(x) – maximum value in a group (excluding null)</para>
</listitem>
<listitem>
- <para>XMLAGG(xml expression <link
linkend="orderby_clause">[ORDER BY ...]</link>) – xml concatination of
all xml expressions in a group (excluding null)</para>
+ <para>ANY(x)/SOME(x) – returns TRUE if any value in the group is TRUE
(excluding null)</para>
</listitem>
+ <listitem>
+ <para>EVERY(x) – returns TRUE if every value in the group is TRUE
(excluding null)</para>
+ </listitem>
+ <listitem>
+ <para>VAR_POP(x) – biased variance (excluding null) logically equals
(sum(x^2) - sum(x)^2/count(x))/count(x); returns a double; null if count = 0</para>
+ </listitem>
+ <listitem>
+ <para>VAR_SAMP(x) – sample variance (excluding null) logically equals
(sum(x^2) - sum(x)^2/count(x))/(count(x) - 1); returns a double; null if count <
2</para>
+ </listitem>
+ <listitem>
+ <para>STDDEV_POP(x) – standard deviation (excluding null) logically
equals SQRT(VAR_POP(x))</para>
+ </listitem>
+ <listitem>
+ <para>STDDEV_SAMP(x) – sample standar deviation (excluding null)
logically equals SQRT(VAR_SAMP(x))</para>
+ </listitem>
+ <listitem>
+ <para>XMLAGG(xml_expr <link
linkend="orderby_clause">[ORDER BY ...]</link>) – xml concatination of
all xml expressions in a group (excluding null)</para>
+ </listitem>
</itemizedlist>
<itemizedlist>
<para>Syntax Rules:
Modified: trunk/documentation/reference/src/main/docbook/en-US/content/translators.xml
===================================================================
---
trunk/documentation/reference/src/main/docbook/en-US/content/translators.xml 2010-06-22
17:21:54 UTC (rev 2275)
+++
trunk/documentation/reference/src/main/docbook/en-US/content/translators.xml 2010-06-22
18:58:30 UTC (rev 2276)
@@ -122,7 +122,7 @@
<para><emphasis>db2</emphasis> - for use with DB2 8 or
later.</para>
</listitem>
<listitem>
-<para><emphasis>derby</emphasis> - for use with Derby 10.1 or later.
Setting the specific 10.x version improves pushdown support - see the DatabaseVersion
execution property.</para>
+<para><emphasis>derby</emphasis> - for use with Derby 10.1 or
later.</para>
</listitem>
<listitem>
<para><emphasis>h2</emphasis> - for use with H2 version 1.1 or
later.</para>
@@ -146,7 +146,7 @@
<para><emphasis>oracle</emphasis> - for use with Oracle 9i or
later.</para>
</listitem>
<listitem>
-<para><emphasis>postgresql</emphasis> - for use with 8.0 or later
clients and 7.1 or later server. Setting the specific 8.x version improves pushdown
support - see the DatabaseVersion execution property.</para>
+<para><emphasis>postgresql</emphasis> - for use with 8.0 or later
clients and 7.1 or later server.</para>
</listitem>
<listitem>
<para><emphasis>sybase</emphasis> - for use with Sybase version 12.5 or
later.</para>
Deleted:
trunk/engine/src/main/java/org/teiid/api/exception/query/CriteriaEvaluationException.java
===================================================================
---
trunk/engine/src/main/java/org/teiid/api/exception/query/CriteriaEvaluationException.java 2010-06-22
17:21:54 UTC (rev 2275)
+++
trunk/engine/src/main/java/org/teiid/api/exception/query/CriteriaEvaluationException.java 2010-06-22
18:58:30 UTC (rev 2276)
@@ -1,79 +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.api.exception.query;
-
-import org.teiid.core.TeiidProcessingException;
-
-/**
- * This exception is thrown when an error occurs while evaluating a SQL criteria.
- */
-public class CriteriaEvaluationException extends TeiidProcessingException {
-
- /**
- * No-arg constructor required by Externalizable semantics.
- */
- public CriteriaEvaluationException() {
- super();
- }
-
- /**
- * Construct an instance with the message specified.
- *
- * @param message A message describing the exception
- */
- public CriteriaEvaluationException( String message ) {
- super( message );
- }
-
- /**
- * Construct an instance with the message and error code specified.
- *
- * @param message A message describing the exception
- * @param code The error code
- */
- public CriteriaEvaluationException( String code, String message ) {
- super( code, message );
- }
-
- /**
- * Construct an instance from a message and an exception to chain to this one.
- *
- * @param message A message describing the exception
- * @param e An exception to nest within this one
- */
- public CriteriaEvaluationException( Throwable e, String message ) {
- super( e, message );
- }
-
- /**
- * Construct an instance from a message and a code and an exception to
- * chain to this one.
- *
- * @param e An exception to nest within this one
- * @param message A message describing the exception
- * @param code A code denoting the exception
- */
- public CriteriaEvaluationException( Throwable e, String code, String message ) {
- super( e, code, message );
- }
-}
Modified:
trunk/engine/src/main/java/org/teiid/dqp/internal/datamgr/impl/CapabilitiesConverter.java
===================================================================
---
trunk/engine/src/main/java/org/teiid/dqp/internal/datamgr/impl/CapabilitiesConverter.java 2010-06-22
17:21:54 UTC (rev 2275)
+++
trunk/engine/src/main/java/org/teiid/dqp/internal/datamgr/impl/CapabilitiesConverter.java 2010-06-22
18:58:30 UTC (rev 2276)
@@ -94,6 +94,7 @@
tgtCaps.setCapabilitySupport(Capability.QUERY_HAVING, srcCaps.supportsHaving());
tgtCaps.setCapabilitySupport(Capability.INSERT_WITH_QUERYEXPRESSION,
srcCaps.supportsInsertWithQueryExpression());
tgtCaps.setCapabilitySupport(Capability.QUERY_ORDERBY_UNRELATED,
srcCaps.supportsOrderByUnrelated());
+ tgtCaps.setCapabilitySupport(Capability.QUERY_AGGREGATES_ENHANCED_NUMERIC,
srcCaps.supportsAggregatesEnhancedNumeric());
List functions = srcCaps.getSupportedFunctions();
if(functions != null && functions.size() > 0) {
Modified:
trunk/engine/src/main/java/org/teiid/dqp/internal/datamgr/language/LanguageBridgeFactory.java
===================================================================
---
trunk/engine/src/main/java/org/teiid/dqp/internal/datamgr/language/LanguageBridgeFactory.java 2010-06-22
17:21:54 UTC (rev 2275)
+++
trunk/engine/src/main/java/org/teiid/dqp/internal/datamgr/language/LanguageBridgeFactory.java 2010-06-22
18:58:30 UTC (rev 2276)
@@ -516,7 +516,7 @@
}
AggregateFunction translate(AggregateSymbol symbol) {
- return new AggregateFunction(symbol.getAggregateFunction(),
+ return new AggregateFunction(symbol.getAggregateFunction().name(),
symbol.isDistinct(),
translate(symbol.getExpression()),
symbol.getType());
Modified:
trunk/engine/src/main/java/org/teiid/dqp/internal/process/MetaDataProcessor.java
===================================================================
---
trunk/engine/src/main/java/org/teiid/dqp/internal/process/MetaDataProcessor.java 2010-06-22
17:21:54 UTC (rev 2275)
+++
trunk/engine/src/main/java/org/teiid/dqp/internal/process/MetaDataProcessor.java 2010-06-22
18:58:30 UTC (rev 2276)
@@ -61,6 +61,7 @@
import org.teiid.query.sql.symbol.GroupSymbol;
import org.teiid.query.sql.symbol.Reference;
import org.teiid.query.sql.symbol.SingleElementSymbol;
+import org.teiid.query.sql.symbol.AggregateSymbol.Type;
import org.teiid.query.sql.visitor.ReferenceCollectorVisitor;
import org.teiid.query.tempdata.TempTableStore;
@@ -307,8 +308,8 @@
AggregateSymbol symbol) throws
QueryMetadataException, TeiidComponentException {
Expression expression = symbol.getExpression();
- String function = symbol.getAggregateFunction();
- if(function.equals(NonReserved.MIN) || function.equals(NonReserved.MAX)){
+ Type function = symbol.getAggregateFunction();
+ if(function == Type.MIN || function == Type.MAX){
if(expression instanceof ElementSymbol) {
return createColumnMetadata(shortColumnName, (ElementSymbol)expression);
}
Modified: trunk/engine/src/main/java/org/teiid/query/eval/Evaluator.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/eval/Evaluator.java 2010-06-22 17:21:54 UTC
(rev 2275)
+++ trunk/engine/src/main/java/org/teiid/query/eval/Evaluator.java 2010-06-22 18:58:30 UTC
(rev 2276)
@@ -44,14 +44,12 @@
import net.sf.saxon.om.SequenceIterator;
import net.sf.saxon.trans.XPathException;
-import org.teiid.api.exception.query.CriteriaEvaluationException;
import org.teiid.api.exception.query.ExpressionEvaluationException;
import org.teiid.api.exception.query.FunctionExecutionException;
import org.teiid.common.buffer.BlockedException;
import org.teiid.core.ComponentNotFoundException;
import org.teiid.core.TeiidComponentException;
import org.teiid.core.TeiidProcessingException;
-import org.teiid.core.types.BaseLob;
import org.teiid.core.types.BlobType;
import org.teiid.core.types.ClobImpl;
import org.teiid.core.types.ClobType;
@@ -178,7 +176,7 @@
protected ProcessorDataManager dataMgr;
protected CommandContext context;
- public static boolean evaluate(Criteria criteria) throws CriteriaEvaluationException,
BlockedException, TeiidComponentException {
+ public static boolean evaluate(Criteria criteria) throws
ExpressionEvaluationException, BlockedException, TeiidComponentException {
return new Evaluator(Collections.emptyMap(), null, null).evaluate(criteria,
Collections.emptyList());
}
@@ -198,13 +196,13 @@
}
public boolean evaluate(Criteria criteria, List<?> tuple)
- throws CriteriaEvaluationException, BlockedException, TeiidComponentException {
+ throws ExpressionEvaluationException, BlockedException, TeiidComponentException
{
return Boolean.TRUE.equals(evaluateTVL(criteria, tuple));
}
public Boolean evaluateTVL(Criteria criteria, List<?> tuple)
- throws CriteriaEvaluationException, BlockedException, TeiidComponentException {
+ throws ExpressionEvaluationException, BlockedException, TeiidComponentException
{
if(criteria instanceof CompoundCriteria) {
return evaluate((CompoundCriteria)criteria, tuple);
@@ -223,12 +221,12 @@
} else if(criteria instanceof ExistsCriteria) {
return Boolean.valueOf(evaluate((ExistsCriteria)criteria, tuple));
} else {
- throw new CriteriaEvaluationException(ErrorMessageKeys.PROCESSOR_0010,
QueryPlugin.Util.getString(ErrorMessageKeys.PROCESSOR_0010, criteria));
+ throw new ExpressionEvaluationException(ErrorMessageKeys.PROCESSOR_0010,
QueryPlugin.Util.getString(ErrorMessageKeys.PROCESSOR_0010, criteria));
}
}
public Boolean evaluate(CompoundCriteria criteria, List<?> tuple)
- throws CriteriaEvaluationException, BlockedException, TeiidComponentException {
+ throws ExpressionEvaluationException, BlockedException, TeiidComponentException {
List subCrits = criteria.getCriteria();
Iterator subCritIter = subCrits.iterator();
@@ -252,7 +250,7 @@
}
public Boolean evaluate(NotCriteria criteria, List<?> tuple)
- throws CriteriaEvaluationException, BlockedException, TeiidComponentException {
+ throws ExpressionEvaluationException, BlockedException, TeiidComponentException {
Criteria subCrit = criteria.getCriteria();
Boolean result = evaluateTVL(subCrit, tuple);
@@ -266,14 +264,14 @@
}
public Boolean evaluate(CompareCriteria criteria, List<?> tuple)
- throws CriteriaEvaluationException, BlockedException, TeiidComponentException {
+ throws ExpressionEvaluationException, BlockedException, TeiidComponentException {
// Evaluate left expression
Object leftValue = null;
try {
leftValue = evaluate(criteria.getLeftExpression(), tuple);
} catch(ExpressionEvaluationException e) {
- throw new CriteriaEvaluationException(e, ErrorMessageKeys.PROCESSOR_0011,
QueryPlugin.Util.getString(ErrorMessageKeys.PROCESSOR_0011, new Object[]
{"left", criteria})); //$NON-NLS-1$
+ throw new ExpressionEvaluationException(e, ErrorMessageKeys.PROCESSOR_0011,
QueryPlugin.Util.getString(ErrorMessageKeys.PROCESSOR_0011, new Object[]
{"left", criteria})); //$NON-NLS-1$
}
// Shortcut if null
@@ -286,7 +284,7 @@
try {
rightValue = evaluate(criteria.getRightExpression(), tuple);
} catch(ExpressionEvaluationException e) {
- throw new CriteriaEvaluationException(e, ErrorMessageKeys.PROCESSOR_0011,
QueryPlugin.Util.getString(ErrorMessageKeys.PROCESSOR_0011, new
Object[]{"right", criteria})); //$NON-NLS-1$
+ throw new ExpressionEvaluationException(e, ErrorMessageKeys.PROCESSOR_0011,
QueryPlugin.Util.getString(ErrorMessageKeys.PROCESSOR_0011, new
Object[]{"right", criteria})); //$NON-NLS-1$
}
// Shortcut if null
@@ -309,7 +307,7 @@
case CompareCriteria.GE:
return Boolean.valueOf((compareValues(leftValue, rightValue) >= 0));
default:
- throw new CriteriaEvaluationException(ErrorMessageKeys.PROCESSOR_0012,
QueryPlugin.Util.getString(ErrorMessageKeys.PROCESSOR_0012, criteria.getOperator()));
+ throw new ExpressionEvaluationException(ErrorMessageKeys.PROCESSOR_0012,
QueryPlugin.Util.getString(ErrorMessageKeys.PROCESSOR_0012, criteria.getOperator()));
}
}
@@ -323,7 +321,7 @@
}
public Boolean evaluate(MatchCriteria criteria, List<?> tuple)
- throws CriteriaEvaluationException, BlockedException, TeiidComponentException {
+ throws ExpressionEvaluationException, BlockedException, TeiidComponentException {
boolean result = false;
// Evaluate left expression
@@ -331,7 +329,7 @@
try {
value = evaluate(criteria.getLeftExpression(), tuple);
} catch(ExpressionEvaluationException e) {
- throw new CriteriaEvaluationException(e, ErrorMessageKeys.PROCESSOR_0011,
QueryPlugin.Util.getString(ErrorMessageKeys.PROCESSOR_0011, new Object[]{"left",
criteria})); //$NON-NLS-1$
+ throw new ExpressionEvaluationException(e, ErrorMessageKeys.PROCESSOR_0011,
QueryPlugin.Util.getString(ErrorMessageKeys.PROCESSOR_0011, new Object[]{"left",
criteria})); //$NON-NLS-1$
}
// Shortcut if null
@@ -347,7 +345,7 @@
try {
leftValue = ((Sequencable)value).getCharSequence();
} catch (SQLException err) {
- throw new CriteriaEvaluationException(err, err.getMessage());
+ throw new ExpressionEvaluationException(err, err.getMessage());
}
}
@@ -356,7 +354,7 @@
try {
rightValue = (String) evaluate(criteria.getRightExpression(), tuple);
} catch(ExpressionEvaluationException e) {
- throw new CriteriaEvaluationException(e, ErrorMessageKeys.PROCESSOR_0011,
QueryPlugin.Util.getString(ErrorMessageKeys.PROCESSOR_0011, new
Object[]{"right", criteria})); //$NON-NLS-1$
+ throw new ExpressionEvaluationException(e, ErrorMessageKeys.PROCESSOR_0011,
QueryPlugin.Util.getString(ErrorMessageKeys.PROCESSOR_0011, new
Object[]{"right", criteria})); //$NON-NLS-1$
}
// Shortcut if null
@@ -370,7 +368,7 @@
}
private boolean match(String pattern, char escape, CharSequence search)
- throws CriteriaEvaluationException {
+ throws ExpressionEvaluationException {
StringBuffer rePattern = LIKE_TO_REGEX.translate(pattern, escape);
@@ -383,19 +381,19 @@
Matcher matcher = patternRegex.matcher(search);
return matcher.matches();
} catch(PatternSyntaxException e) {
- throw new CriteriaEvaluationException(e, ErrorMessageKeys.PROCESSOR_0014,
QueryPlugin.Util.getString(ErrorMessageKeys.PROCESSOR_0014, new Object[]{pattern,
e.getMessage()}));
+ throw new ExpressionEvaluationException(e, ErrorMessageKeys.PROCESSOR_0014,
QueryPlugin.Util.getString(ErrorMessageKeys.PROCESSOR_0014, new Object[]{pattern,
e.getMessage()}));
}
}
private Boolean evaluate(AbstractSetCriteria criteria, List<?> tuple)
- throws CriteriaEvaluationException, BlockedException, TeiidComponentException {
+ throws ExpressionEvaluationException, BlockedException, TeiidComponentException {
// Evaluate expression
Object leftValue = null;
try {
leftValue = evaluate(criteria.getExpression(), tuple);
} catch(ExpressionEvaluationException e) {
- throw new CriteriaEvaluationException(e, ErrorMessageKeys.PROCESSOR_0015,
QueryPlugin.Util.getString(ErrorMessageKeys.PROCESSOR_0015, criteria));
+ throw new ExpressionEvaluationException(e, ErrorMessageKeys.PROCESSOR_0015,
QueryPlugin.Util.getString(ErrorMessageKeys.PROCESSOR_0015, criteria));
}
// Shortcut if null
@@ -414,7 +412,7 @@
try {
values = vis.getCachedSet(ref.getValueExpression());
} catch (TeiidProcessingException e) {
- throw new CriteriaEvaluationException(e, e.getMessage());
+ throw new ExpressionEvaluationException(e, e.getMessage());
}
if (values != null) {
return values.contains(leftValue);
@@ -426,7 +424,7 @@
try {
valueIter = evaluateSubquery((SubquerySetCriteria)criteria, tuple);
} catch (TeiidProcessingException e) {
- throw new CriteriaEvaluationException(e, e.getMessage());
+ throw new ExpressionEvaluationException(e, e.getMessage());
}
} else {
throw new AssertionError("unknown set criteria type"); //$NON-NLS-1$
@@ -438,7 +436,7 @@
try {
value = evaluate((Expression) possibleValue, tuple);
} catch(ExpressionEvaluationException e) {
- throw new CriteriaEvaluationException(e,
ErrorMessageKeys.PROCESSOR_0015,
QueryPlugin.Util.getString(ErrorMessageKeys.PROCESSOR_0015, possibleValue));
+ throw new ExpressionEvaluationException(e,
ErrorMessageKeys.PROCESSOR_0015,
QueryPlugin.Util.getString(ErrorMessageKeys.PROCESSOR_0015, possibleValue));
}
} else {
value = possibleValue;
@@ -461,28 +459,28 @@
}
public boolean evaluate(IsNullCriteria criteria, List<?> tuple)
- throws CriteriaEvaluationException, BlockedException, TeiidComponentException {
+ throws ExpressionEvaluationException, BlockedException, TeiidComponentException {
// Evaluate expression
Object value = null;
try {
value = evaluate(criteria.getExpression(), tuple);
} catch(ExpressionEvaluationException e) {
- throw new CriteriaEvaluationException(e, ErrorMessageKeys.PROCESSOR_0015,
QueryPlugin.Util.getString(ErrorMessageKeys.PROCESSOR_0015, criteria));
+ throw new ExpressionEvaluationException(e, ErrorMessageKeys.PROCESSOR_0015,
QueryPlugin.Util.getString(ErrorMessageKeys.PROCESSOR_0015, criteria));
}
return (value == null ^ criteria.isNegated());
}
private Boolean evaluate(SubqueryCompareCriteria criteria, List<?> tuple)
- throws CriteriaEvaluationException, BlockedException, TeiidComponentException {
+ throws ExpressionEvaluationException, BlockedException, TeiidComponentException
{
// Evaluate expression
Object leftValue = null;
try {
leftValue = evaluate(criteria.getLeftExpression(), tuple);
} catch(ExpressionEvaluationException e) {
- throw new CriteriaEvaluationException(e, ErrorMessageKeys.PROCESSOR_0015,
QueryPlugin.Util.getString(ErrorMessageKeys.PROCESSOR_0015, criteria));
+ throw new ExpressionEvaluationException(e, ErrorMessageKeys.PROCESSOR_0015,
QueryPlugin.Util.getString(ErrorMessageKeys.PROCESSOR_0015, criteria));
}
// Shortcut if null
@@ -504,7 +502,7 @@
try {
valueIter = evaluateSubquery(criteria, tuple);
} catch (TeiidProcessingException e) {
- throw new CriteriaEvaluationException(e, e.getMessage());
+ throw new ExpressionEvaluationException(e, e.getMessage());
}
while(valueIter.hasNext()) {
Object value = valueIter.next();
@@ -532,7 +530,7 @@
result = Boolean.valueOf((compareValues(leftValue, value) >=
0));
break;
default:
- throw new
CriteriaEvaluationException(ErrorMessageKeys.PROCESSOR_0012,
QueryPlugin.Util.getString(ErrorMessageKeys.PROCESSOR_0012, criteria.getOperator()));
+ throw new
ExpressionEvaluationException(ErrorMessageKeys.PROCESSOR_0012,
QueryPlugin.Util.getString(ErrorMessageKeys.PROCESSOR_0012, criteria.getOperator()));
}
switch(criteria.getPredicateQuantifier()) {
@@ -550,11 +548,11 @@
if (valueIter.hasNext()){
// The subquery should be scalar, but has produced
// more than one result value - this is an exception case
- throw new
CriteriaEvaluationException(ErrorMessageKeys.PROCESSOR_0056,
QueryPlugin.Util.getString(ErrorMessageKeys.PROCESSOR_0056, criteria));
+ throw new
ExpressionEvaluationException(ErrorMessageKeys.PROCESSOR_0056,
QueryPlugin.Util.getString(ErrorMessageKeys.PROCESSOR_0056, criteria));
}
return result;
default:
- throw new
CriteriaEvaluationException(ErrorMessageKeys.PROCESSOR_0057,
QueryPlugin.Util.getString(ErrorMessageKeys.PROCESSOR_0057,
criteria.getPredicateQuantifier()));
+ throw new
ExpressionEvaluationException(ErrorMessageKeys.PROCESSOR_0057,
QueryPlugin.Util.getString(ErrorMessageKeys.PROCESSOR_0057,
criteria.getPredicateQuantifier()));
}
} else { // value is null
@@ -570,12 +568,12 @@
if (valueIter.hasNext()){
// The subquery should be scalar, but has produced
// more than one result value - this is an exception case
- throw new
CriteriaEvaluationException(ErrorMessageKeys.PROCESSOR_0056,
QueryPlugin.Util.getString(ErrorMessageKeys.PROCESSOR_0056, criteria));
+ throw new
ExpressionEvaluationException(ErrorMessageKeys.PROCESSOR_0056,
QueryPlugin.Util.getString(ErrorMessageKeys.PROCESSOR_0056, criteria));
}
// null value means unknown for the single-value comparison
return null;
default:
- throw new
CriteriaEvaluationException(ErrorMessageKeys.PROCESSOR_0057,
QueryPlugin.Util.getString(ErrorMessageKeys.PROCESSOR_0057,
criteria.getPredicateQuantifier()));
+ throw new
ExpressionEvaluationException(ErrorMessageKeys.PROCESSOR_0057,
QueryPlugin.Util.getString(ErrorMessageKeys.PROCESSOR_0057,
criteria.getPredicateQuantifier()));
}
}
@@ -586,13 +584,13 @@
}
public boolean evaluate(ExistsCriteria criteria, List<?> tuple)
- throws BlockedException, TeiidComponentException, CriteriaEvaluationException {
+ throws BlockedException, TeiidComponentException, ExpressionEvaluationException
{
ValueIterator valueIter;
try {
valueIter = evaluateSubquery(criteria, tuple);
} catch (TeiidProcessingException e) {
- throw new CriteriaEvaluationException(e, e.getMessage());
+ throw new ExpressionEvaluationException(e, e.getMessage());
}
if(valueIter.hasNext()) {
return true;
@@ -647,6 +645,8 @@
return internalEvaluate(ref.getExpression(), tuple);
} else if(expression instanceof ScalarSubquery) {
return evaluate((ScalarSubquery) expression, tuple);
+ } else if (expression instanceof Criteria) {
+ return evaluate((Criteria)expression, tuple);
} else if (expression instanceof XMLElement){
return evaluateXMLElement(tuple, (XMLElement)expression);
} else if (expression instanceof XMLForest){
@@ -904,7 +904,7 @@
if (evaluate(expr.getWhenCriteria(i), tuple)) {
return internalEvaluate(expr.getThenExpression(i), tuple);
}
- } catch (CriteriaEvaluationException e) {
+ } catch (ExpressionEvaluationException e) {
throw new ExpressionEvaluationException(e, ErrorMessageKeys.PROCESSOR_0033,
QueryPlugin.Util.getString(ErrorMessageKeys.PROCESSOR_0033, "CASE",
expr.getWhenCriteria(i))); //$NON-NLS-1$
}
}
Modified: trunk/engine/src/main/java/org/teiid/query/function/aggregate/Count.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/function/aggregate/Count.java 2010-06-22
17:21:54 UTC (rev 2275)
+++ trunk/engine/src/main/java/org/teiid/query/function/aggregate/Count.java 2010-06-22
18:58:30 UTC (rev 2276)
@@ -46,7 +46,7 @@
* @see org.teiid.query.function.aggregate.AggregateFunction#getResult()
*/
public Object getResult() {
- return new Integer(count);
+ return Integer.valueOf(count);
}
}
Added: trunk/engine/src/main/java/org/teiid/query/function/aggregate/StatsFunction.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/function/aggregate/StatsFunction.java
(rev 0)
+++
trunk/engine/src/main/java/org/teiid/query/function/aggregate/StatsFunction.java 2010-06-22
18:58:30 UTC (rev 2276)
@@ -0,0 +1,88 @@
+/*
+ * 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.function.aggregate;
+
+import java.util.List;
+
+import org.teiid.api.exception.query.ExpressionEvaluationException;
+import org.teiid.api.exception.query.FunctionExecutionException;
+import org.teiid.core.TeiidComponentException;
+import org.teiid.query.sql.symbol.AggregateSymbol.Type;
+
+public class StatsFunction extends AggregateFunction {
+
+ private double sum = 0;
+ private double sumSq = 0;
+ private int count = 0;
+ private Type type;
+
+ public StatsFunction(Type function) {
+ this.type = function;
+ }
+
+ @Override
+ public void reset() {
+ sum = 0;
+ sumSq = 0;
+ count = 0;
+ }
+
+ @Override
+ public void addInputDirect(Object input, List<?> tuple)
+ throws FunctionExecutionException, ExpressionEvaluationException,
+ TeiidComponentException {
+ sum += ((Number)input).doubleValue();
+ sumSq += Math.pow(((Number)input).doubleValue(), 2);
+ count++;
+ }
+
+ @Override
+ public Object getResult() throws FunctionExecutionException,
+ ExpressionEvaluationException, TeiidComponentException {
+ double result = 0;
+ switch (type) {
+ case STDDEV_POP:
+ case VAR_POP:
+ if (count == 0) {
+ return null;
+ }
+ result = (sumSq - sum * sum / count) / count;
+ if (type == Type.STDDEV_POP) {
+ result = Math.sqrt(result);
+ }
+ break;
+ case STDDEV_SAMP:
+ case VAR_SAMP:
+ if (count < 2) {
+ return null;
+ }
+ result = (sumSq - sum * sum / count) / (count - 1);
+ if (type == Type.STDDEV_SAMP) {
+ result = Math.sqrt(result);
+ }
+ break;
+ }
+ return result;
+ }
+
+}
Property changes on:
trunk/engine/src/main/java/org/teiid/query/function/aggregate/StatsFunction.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified:
trunk/engine/src/main/java/org/teiid/query/optimizer/capabilities/SourceCapabilities.java
===================================================================
---
trunk/engine/src/main/java/org/teiid/query/optimizer/capabilities/SourceCapabilities.java 2010-06-22
17:21:54 UTC (rev 2275)
+++
trunk/engine/src/main/java/org/teiid/query/optimizer/capabilities/SourceCapabilities.java 2010-06-22
18:58:30 UTC (rev 2276)
@@ -202,6 +202,12 @@
*/
QUERY_AGGREGATES_MAX,
/**
+ * Support indicates connector can accept the enhanced numeric aggregates
+ *
+ * @since 3.1 SP2
+ */
+ QUERY_AGGREGATES_ENHANCED_NUMERIC,
+ /**
* Support indicates connector can accept the COUNT aggregate function
*
* @since 3.1 SP2
Modified:
trunk/engine/src/main/java/org/teiid/query/optimizer/relational/rules/CapabilitiesUtil.java
===================================================================
---
trunk/engine/src/main/java/org/teiid/query/optimizer/relational/rules/CapabilitiesUtil.java 2010-06-22
17:21:54 UTC (rev 2275)
+++
trunk/engine/src/main/java/org/teiid/query/optimizer/relational/rules/CapabilitiesUtil.java 2010-06-22
18:58:30 UTC (rev 2276)
@@ -30,7 +30,6 @@
import org.teiid.api.exception.query.QueryMetadataException;
import org.teiid.core.TeiidComponentException;
import org.teiid.core.types.DataTypeManager;
-import org.teiid.language.SQLConstants.NonReserved;
import org.teiid.query.function.FunctionLibrary;
import org.teiid.query.metadata.QueryMetadataInterface;
import org.teiid.query.optimizer.capabilities.CapabilitiesFinder;
@@ -44,6 +43,7 @@
import org.teiid.query.sql.symbol.ElementSymbol;
import org.teiid.query.sql.symbol.Expression;
import org.teiid.query.sql.symbol.Function;
+import org.teiid.query.sql.symbol.AggregateSymbol.Type;
import org.teiid.query.sql.visitor.ElementCollectorVisitor;
import org.teiid.translator.ExecutionFactory.SupportedJoinCriteria;
@@ -144,8 +144,9 @@
SourceCapabilities caps = getCapabilities(modelID, metadata, capFinder);
// Check particular function
- String func = aggregate.getAggregateFunction();
- if(func.equals(NonReserved.COUNT)) {
+ Type func = aggregate.getAggregateFunction();
+ switch (func) {
+ case COUNT:
if(aggregate.getExpression() == null) {
if(! caps.supportsCapability(Capability.QUERY_AGGREGATES_COUNT_STAR)) {
return false;
@@ -155,22 +156,36 @@
return false;
}
}
- } else if(func.equals(NonReserved.SUM)) {
+ break;
+ case SUM:
if(! caps.supportsCapability(Capability.QUERY_AGGREGATES_SUM)) {
return false;
}
- } else if(func.equals(NonReserved.AVG)) {
+ break;
+ case AVG:
if(! caps.supportsCapability(Capability.QUERY_AGGREGATES_AVG)) {
return false;
}
- } else if(func.equals(NonReserved.MIN)) {
+ break;
+ case MIN:
if(! caps.supportsCapability(Capability.QUERY_AGGREGATES_MIN)) {
return false;
}
- } else if(func.equals(NonReserved.MAX)) {
+ break;
+ case MAX:
if(! caps.supportsCapability(Capability.QUERY_AGGREGATES_MAX)) {
return false;
}
+ break;
+ default:
+ if (aggregate.isEnhancedNumeric()) {
+ if (!caps.supportsCapability(Capability.QUERY_AGGREGATES_ENHANCED_NUMERIC)) {
+ return false;
+ }
+ } else {
+ return false;
+ }
+ break;
}
// Check DISTINCT if necessary
Modified:
trunk/engine/src/main/java/org/teiid/query/optimizer/relational/rules/RuleCleanCriteria.java
===================================================================
---
trunk/engine/src/main/java/org/teiid/query/optimizer/relational/rules/RuleCleanCriteria.java 2010-06-22
17:21:54 UTC (rev 2275)
+++
trunk/engine/src/main/java/org/teiid/query/optimizer/relational/rules/RuleCleanCriteria.java 2010-06-22
18:58:30 UTC (rev 2276)
@@ -22,7 +22,7 @@
package org.teiid.query.optimizer.relational.rules;
-import org.teiid.api.exception.query.CriteriaEvaluationException;
+import org.teiid.api.exception.query.ExpressionEvaluationException;
import org.teiid.api.exception.query.QueryPlannerException;
import org.teiid.common.buffer.BlockedException;
import org.teiid.core.TeiidComponentException;
@@ -83,7 +83,7 @@
//none of the following exceptions should ever occur
} catch(BlockedException e) {
throw new TeiidComponentException(e);
- } catch (CriteriaEvaluationException e) {
+ } catch (ExpressionEvaluationException e) {
throw new TeiidComponentException(e);
}
}
Modified:
trunk/engine/src/main/java/org/teiid/query/optimizer/relational/rules/RulePushAggregates.java
===================================================================
---
trunk/engine/src/main/java/org/teiid/query/optimizer/relational/rules/RulePushAggregates.java 2010-06-22
17:21:54 UTC (rev 2275)
+++
trunk/engine/src/main/java/org/teiid/query/optimizer/relational/rules/RulePushAggregates.java 2010-06-22
18:58:30 UTC (rev 2276)
@@ -76,12 +76,14 @@
import org.teiid.query.sql.symbol.GroupSymbol;
import org.teiid.query.sql.symbol.SearchedCaseExpression;
import org.teiid.query.sql.symbol.SingleElementSymbol;
+import org.teiid.query.sql.symbol.AggregateSymbol.Type;
import org.teiid.query.sql.util.SymbolMap;
import org.teiid.query.sql.visitor.AggregateSymbolCollectorVisitor;
import org.teiid.query.sql.visitor.ElementCollectorVisitor;
import org.teiid.query.sql.visitor.ExpressionMappingVisitor;
import org.teiid.query.sql.visitor.GroupsUsedByElementsVisitor;
import org.teiid.query.util.CommandContext;
+import org.teiid.translator.SourceSystemFunctions;
/**
@@ -191,9 +193,10 @@
SymbolMap parentMap = (SymbolMap)child.getProperty(NodeConstants.Info.SYMBOL_MAP);
List<ElementSymbol> virtualElements = parentMap.getKeys();
+ List<SingleElementSymbol> copy = new
ArrayList<SingleElementSymbol>(aggregates);
+ aggregates.clear();
+ Map<AggregateSymbol, Expression> aggMap = buildAggregateMap(copy, metadata,
aggregates);
- Map<AggregateSymbol, Expression> aggMap = buildAggregateMap(new
ArrayList<SingleElementSymbol>(aggregates), metadata, aggregates);
-
boolean shouldPushdown = false;
List<Boolean> pushdownList = new ArrayList<Boolean>(unionChildren.size());
for (PlanNode planNode : unionChildren) {
@@ -351,11 +354,15 @@
if (pushdown) {
projectedViewSymbols.add(agg);
} else {
- if (agg.getAggregateFunction().equals(NonReserved.COUNT)) {
- SearchedCaseExpression count = new SearchedCaseExpression(Arrays.asList(new
IsNullCriteria(agg.getExpression())), Arrays.asList(new Constant(Integer.valueOf(0))));
- count.setElseExpression(new Constant(Integer.valueOf(1)));
- count.setType(DataTypeManager.DefaultDataClasses.INTEGER);
- projectedViewSymbols.add(new ExpressionSymbol("stagedAgg", count));
//$NON-NLS-1$
+ if (agg.getAggregateFunction() == Type.COUNT) {
+ if (agg.getExpression() == null) {
+ projectedViewSymbols.add(new ExpressionSymbol("stagedAgg", new
Constant(1))); //$NON-NLS-1$
+ } else {
+ SearchedCaseExpression count = new SearchedCaseExpression(Arrays.asList(new
IsNullCriteria(agg.getExpression())), Arrays.asList(new Constant(Integer.valueOf(0))));
+ count.setElseExpression(new Constant(Integer.valueOf(1)));
+ count.setType(DataTypeManager.DefaultDataClasses.INTEGER);
+ projectedViewSymbols.add(new ExpressionSymbol("stagedAgg", count));
//$NON-NLS-1$
+ }
} else { //min, max, sum
Expression ex = agg.getExpression();
ex = ResolverUtil.convertExpression(ex,
DataTypeManager.getDataTypeName(agg.getType()), metadata);
@@ -668,20 +675,18 @@
Expression newExpression = null;
- String aggFunction = partitionAgg.getAggregateFunction();
- if (aggFunction.equals(NonReserved.COUNT)) {
+ Type aggFunction = partitionAgg.getAggregateFunction();
+ if (aggFunction == Type.COUNT) {
//COUNT(x) -> CONVERT(SUM(COUNT(x)), INTEGER)
AggregateSymbol newAgg = new AggregateSymbol("stagedAgg",
NonReserved.SUM, false, partitionAgg); //$NON-NLS-1$
// Build conversion function to convert SUM (which returns LONG) back to
INTEGER
- Constant convertTargetType = new
Constant(DataTypeManager.getDataTypeName(partitionAgg.getType()),
-
DataTypeManager.DefaultDataClasses.STRING);
- Function convertFunc = new Function(FunctionLibrary.CONVERT, new
Expression[] {newAgg, convertTargetType});
+ Function convertFunc = new Function(FunctionLibrary.CONVERT, new
Expression[] {newAgg, new
Constant(DataTypeManager.getDataTypeName(partitionAgg.getType()))});
ResolverVisitor.resolveLanguageObject(convertFunc, metadata);
newExpression = convertFunc;
nestedAggregates.add(partitionAgg);
- } else if (aggFunction.equals(NonReserved.AVG)) {
+ } else if (aggFunction == Type.AVG) {
//AVG(x) -> SUM(SUM(x)) / SUM(COUNT(x))
AggregateSymbol countAgg = new AggregateSymbol("stagedAgg",
NonReserved.COUNT, false, partitionAgg.getExpression()); //$NON-NLS-1$
AggregateSymbol sumAgg = new AggregateSymbol("stagedAgg",
NonReserved.SUM, false, partitionAgg.getExpression()); //$NON-NLS-1$
@@ -689,15 +694,56 @@
AggregateSymbol sumSumAgg = new AggregateSymbol("stagedAgg",
NonReserved.SUM, false, sumAgg); //$NON-NLS-1$
AggregateSymbol sumCountAgg = new AggregateSymbol("stagedAgg",
NonReserved.SUM, false, countAgg); //$NON-NLS-1$
- Function divideFunc = new Function("/", new Expression[]
{sumSumAgg, sumCountAgg}); //$NON-NLS-1$
+ Expression convertedSum = new Function(FunctionLibrary.CONVERT, new
Expression[] {sumSumAgg, new
Constant(DataTypeManager.getDataTypeName(partitionAgg.getType()))});
+ Expression convertCount = new Function(FunctionLibrary.CONVERT, new
Expression[] {sumCountAgg, new
Constant(DataTypeManager.getDataTypeName(partitionAgg.getType()))});
+
+ Function divideFunc = new Function("/", new Expression[]
{convertedSum, convertCount}); //$NON-NLS-1$
ResolverVisitor.resolveLanguageObject(divideFunc, metadata);
newExpression = divideFunc;
nestedAggregates.add(countAgg);
nestedAggregates.add(sumAgg);
+ } else if (partitionAgg.isEnhancedNumeric()) {
+ //e.g. STDDEV_SAMP := CASE WHEN COUNT(X) > 1 THEN SQRT((SUM(X^2) -
SUM(X)^2/COUNT(X))/(COUNT(X) - 1))
+ AggregateSymbol countAgg = new AggregateSymbol("stagedAgg",
NonReserved.COUNT, false, partitionAgg.getExpression()); //$NON-NLS-1$
+ AggregateSymbol sumAgg = new AggregateSymbol("stagedAgg",
NonReserved.SUM, false, partitionAgg.getExpression()); //$NON-NLS-1$
+ AggregateSymbol sumSqAgg = new AggregateSymbol("stagedAgg",
NonReserved.SUM, false, new Function(SourceSystemFunctions.POWER, new Expression[]
{partitionAgg.getExpression(), new Constant(2)})); //$NON-NLS-1$
+
+ AggregateSymbol sumSumAgg = new AggregateSymbol("stagedAgg",
NonReserved.SUM, false, sumAgg); //$NON-NLS-1$
+ AggregateSymbol sumCountAgg = new AggregateSymbol("stagedAgg",
NonReserved.SUM, false, countAgg); //$NON-NLS-1$
+ AggregateSymbol sumSumSqAgg = new AggregateSymbol("stagedAgg",
NonReserved.SUM, false, sumSqAgg); //$NON-NLS-1$
+
+ Expression convertedSum = new Function(FunctionLibrary.CONVERT, new
Expression[] {sumSumAgg, new Constant(DataTypeManager.DefaultDataTypes.DOUBLE)});
+
+ Function divideFunc = new Function(SourceSystemFunctions.DIVIDE_OP, new
Expression[] {new Function(SourceSystemFunctions.POWER, new Expression[] {convertedSum,
new Constant(2)}), sumCountAgg});
+
+ Function minusFunc = new Function(SourceSystemFunctions.SUBTRACT_OP, new
Expression[] {sumSumSqAgg, divideFunc});
+ Expression divisor = null;
+ if (aggFunction == Type.STDDEV_SAMP || aggFunction == Type.VAR_SAMP) {
+ divisor = new Function(SourceSystemFunctions.SUBTRACT_OP, new
Expression[] {sumCountAgg, new Constant(1)});
+ } else {
+ divisor = sumCountAgg;
+ }
+ Expression result = new Function(SourceSystemFunctions.DIVIDE_OP, new
Expression[] {minusFunc, divisor});
+ if (aggFunction == Type.STDDEV_POP || aggFunction == Type.STDDEV_SAMP) {
+ result = new Function(SourceSystemFunctions.SQRT, new Expression[]
{result});
+ } else {
+ result = new Function(FunctionLibrary.CONVERT, new Expression[]
{result, new Constant(DataTypeManager.DefaultDataTypes.DOUBLE)});
+ }
+ Expression n = new Constant(0);
+ if (aggFunction == Type.STDDEV_SAMP || aggFunction == Type.VAR_SAMP) {
+ n = new Constant(1);
+ }
+ result = new SearchedCaseExpression(Arrays.asList(new
CompareCriteria(sumCountAgg, CompareCriteria.GT, n)), Arrays.asList(result));
+ ResolverVisitor.resolveLanguageObject(result, metadata);
+
+ newExpression = result;
+ nestedAggregates.add(countAgg);
+ nestedAggregates.add(sumAgg);
+ nestedAggregates.add(sumSqAgg);
} else {
//AGG(X) -> AGG(AGG(X))
- newExpression = new AggregateSymbol("stagedAgg", aggFunction,
false, partitionAgg); //$NON-NLS-1$
+ newExpression = new AggregateSymbol("stagedAgg",
aggFunction.name(), false, partitionAgg); //$NON-NLS-1$
nestedAggregates.add(partitionAgg);
}
Modified:
trunk/engine/src/main/java/org/teiid/query/optimizer/relational/rules/RuleRemoveOptionalJoins.java
===================================================================
---
trunk/engine/src/main/java/org/teiid/query/optimizer/relational/rules/RuleRemoveOptionalJoins.java 2010-06-22
17:21:54 UTC (rev 2275)
+++
trunk/engine/src/main/java/org/teiid/query/optimizer/relational/rules/RuleRemoveOptionalJoins.java 2010-06-22
18:58:30 UTC (rev 2276)
@@ -33,7 +33,6 @@
import org.teiid.api.exception.query.QueryResolverException;
import org.teiid.core.TeiidComponentException;
import org.teiid.core.util.Assertion;
-import org.teiid.language.SQLConstants.NonReserved;
import org.teiid.query.analysis.AnalysisRecord;
import org.teiid.query.metadata.QueryMetadataInterface;
import org.teiid.query.optimizer.capabilities.CapabilitiesFinder;
@@ -277,8 +276,13 @@
static boolean areAggregatesCardinalityDependent(Set<AggregateSymbol> aggs) {
for (AggregateSymbol aggregateSymbol : aggs) {
- if (aggregateSymbol.getAggregateFunction().equalsIgnoreCase(NonReserved.COUNT) ||
- aggregateSymbol.getAggregateFunction().equalsIgnoreCase(NonReserved.AVG)) {
+ switch (aggregateSymbol.getAggregateFunction()) {
+ case COUNT:
+ case AVG:
+ case STDDEV_POP:
+ case STDDEV_SAMP:
+ case VAR_POP:
+ case VAR_SAMP:
return true;
}
}
Modified: trunk/engine/src/main/java/org/teiid/query/parser/ParseInfo.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/parser/ParseInfo.java 2010-06-22 17:21:54
UTC (rev 2275)
+++ trunk/engine/src/main/java/org/teiid/query/parser/ParseInfo.java 2010-06-22 18:58:30
UTC (rev 2276)
@@ -22,15 +22,14 @@
package org.teiid.query.parser;
+import java.util.HashMap;
+import java.util.Map;
+
public class ParseInfo {
- public int anonExprCount = 0;
- public int anonCountCount = 0;
- public int anonSumCount = 0;
- public int anonAvgCount = 0;
- public int anonMinCount = 0;
- public int anonMaxCount = 0;
+ public Map<String, Integer> nameCounts = new HashMap<String, Integer>();
+
public int referenceCount = 0;
// This gets set according to the current clause
Modified: trunk/engine/src/main/java/org/teiid/query/parser/SQLParserUtil.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/parser/SQLParserUtil.java 2010-06-22
17:21:54 UTC (rev 2275)
+++ trunk/engine/src/main/java/org/teiid/query/parser/SQLParserUtil.java 2010-06-22
18:58:30 UTC (rev 2276)
@@ -28,7 +28,6 @@
import org.teiid.core.util.Assertion;
import org.teiid.core.util.StringUtil;
-import org.teiid.language.SQLConstants.NonReserved;
import org.teiid.language.SQLConstants.Reserved;
import org.teiid.query.QueryPlugin;
import org.teiid.query.sql.lang.Command;
@@ -234,37 +233,18 @@
* @param functionType Null for expression, the function name for aggregates
* @return New unique function name
*/
- String generateFunctionName(ParseInfo info, String functionType) throws
ParseException {
- if(functionType == null) {
- int num = info.anonExprCount++;
- return "expr" + (num == 0 ? "" : ""+num);
//$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
-
- } else if(functionType.equals(NonReserved.COUNT)) {
- int num = info.anonCountCount++;
- return "count" + (num == 0 ? "" :
""+num);//$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
-
- } else if(functionType.equals(NonReserved.SUM)) {
- int num = info.anonSumCount++;
- return "sum" + (num == 0 ? "" :
""+num);//$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
-
- } else if(functionType.equals(NonReserved.AVG)) {
- int num = info.anonAvgCount++;
- return "avg" + (num == 0 ? "" :
""+num);//$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
-
- } else if(functionType.equals(NonReserved.MIN)) {
- int num = info.anonMinCount++;
- return "min" + (num == 0 ? "" :
""+num);//$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
-
- } else if(functionType.equals(NonReserved.MAX)) {
- int num = info.anonMaxCount++;
- return "max" + (num == 0 ? "" :
""+num);//$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- } else if(functionType.equals(Reserved.XMLAGG)) {
- int num = info.anonMaxCount++;
- return "xmlagg" + (num == 0 ? "" :
""+num);//$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- } else {
- Object[] params = new Object[] { functionType };
- throw new
ParseException(QueryPlugin.Util.getString("SQLParser.Unknown_agg_func",
params)); //$NON-NLS-1$
+ String generateFunctionName(ParseInfo info, String functionType) {
+ if (functionType == null) {
+ functionType = "expr"; //$NON-NLS-1$
+ } else {
+ functionType = functionType.toLowerCase();
+ }
+ Integer num = info.nameCounts.get(functionType);
+ if (num == null) {
+ num = 0;
}
+ info.nameCounts.put(functionType, num + 1);
+ return functionType + (num == 0 ? "" : ""+num); //$NON-NLS-1$
//$NON-NLS-2$
}
int getOperator(String opString) {
Modified: trunk/engine/src/main/java/org/teiid/query/processor/relational/AccessNode.java
===================================================================
---
trunk/engine/src/main/java/org/teiid/query/processor/relational/AccessNode.java 2010-06-22
17:21:54 UTC (rev 2275)
+++
trunk/engine/src/main/java/org/teiid/query/processor/relational/AccessNode.java 2010-06-22
18:58:30 UTC (rev 2276)
@@ -27,7 +27,6 @@
import java.util.ArrayList;
import java.util.List;
-import org.teiid.api.exception.query.CriteriaEvaluationException;
import org.teiid.api.exception.query.ExpressionEvaluationException;
import org.teiid.api.exception.query.QueryValidatorException;
import org.teiid.client.plan.PlanNode;
@@ -116,7 +115,7 @@
static boolean prepareCommand(Command atomicCommand, RelationalNode node, CommandContext
context, QueryMetadataInterface metadata)
throws ExpressionEvaluationException, TeiidComponentException,
- TeiidProcessingException, CriteriaEvaluationException {
+ TeiidProcessingException {
try {
// Defect 16059 - Rewrite the command once the references have been replaced
with values.
QueryRewriter.evaluateAndRewrite(atomicCommand, node.getDataManager(),
context, metadata);
Modified:
trunk/engine/src/main/java/org/teiid/query/processor/relational/GroupingNode.java
===================================================================
---
trunk/engine/src/main/java/org/teiid/query/processor/relational/GroupingNode.java 2010-06-22
17:21:54 UTC (rev 2275)
+++
trunk/engine/src/main/java/org/teiid/query/processor/relational/GroupingNode.java 2010-06-22
18:58:30 UTC (rev 2276)
@@ -47,6 +47,7 @@
import org.teiid.query.function.aggregate.Count;
import org.teiid.query.function.aggregate.Max;
import org.teiid.query.function.aggregate.Min;
+import org.teiid.query.function.aggregate.StatsFunction;
import org.teiid.query.function.aggregate.Sum;
import org.teiid.query.function.aggregate.XMLAgg;
import org.teiid.query.processor.ProcessorDataManager;
@@ -57,6 +58,7 @@
import org.teiid.query.sql.symbol.ElementSymbol;
import org.teiid.query.sql.symbol.Expression;
import org.teiid.query.sql.symbol.SingleElementSymbol;
+import org.teiid.query.sql.symbol.AggregateSymbol.Type;
import org.teiid.query.util.CommandContext;
@@ -162,20 +164,30 @@
Expression ex = aggSymbol.getExpression();
inputType = ex.getType();
int index = collectExpression(ex);
- String function = aggSymbol.getAggregateFunction();
- if(function.equals(NonReserved.COUNT)) {
- functions[i] = new Count();
- } else if(function.equals(NonReserved.SUM)) {
- functions[i] = new Sum();
- } else if(function.equals(NonReserved.AVG)) {
- functions[i] = new Avg();
- } else if(function.equals(NonReserved.MIN)) {
- functions[i] = new Min();
- } else if (function.equals(NonReserved.MAX)){
- functions[i] = new Max();
- } else {
- functions[i] = new XMLAgg(context);
- }
+ Type function = aggSymbol.getAggregateFunction();
+ switch (function) {
+ case COUNT:
+ functions[i] = new Count();
+ break;
+ case SUM:
+ functions[i] = new Sum();
+ break;
+ case AVG:
+ functions[i] = new Avg();
+ break;
+ case MIN:
+ functions[i] = new Min();
+ break;
+ case MAX:
+ functions[i] = new Max();
+ break;
+ case XMLAGG:
+ functions[i] = new XMLAgg(context);
+ break;
+ default:
+ functions[i] = new StatsFunction(function);
+
+ }
if(aggSymbol.isDistinct() &&
!function.equals(NonReserved.MIN) && !function.equals(NonReserved.MAX)) {
SortingFilter filter = new SortingFilter(functions[i],
getBufferManager(), getConnectionID(), true);
Modified: trunk/engine/src/main/java/org/teiid/query/processor/relational/JoinNode.java
===================================================================
---
trunk/engine/src/main/java/org/teiid/query/processor/relational/JoinNode.java 2010-06-22
17:21:54 UTC (rev 2275)
+++
trunk/engine/src/main/java/org/teiid/query/processor/relational/JoinNode.java 2010-06-22
18:58:30 UTC (rev 2276)
@@ -28,7 +28,7 @@
import java.util.List;
import java.util.Map;
-import org.teiid.api.exception.query.CriteriaEvaluationException;
+import org.teiid.api.exception.query.ExpressionEvaluationException;
import org.teiid.client.plan.PlanNode;
import org.teiid.common.buffer.BlockedException;
import org.teiid.common.buffer.BufferManager;
@@ -289,7 +289,7 @@
return this.joinCriteria;
}
- boolean matchesCriteria(List outputTuple) throws BlockedException,
TeiidComponentException, CriteriaEvaluationException {
+ boolean matchesCriteria(List outputTuple) throws BlockedException,
TeiidComponentException, ExpressionEvaluationException {
return (this.joinCriteria == null ||
getEvaluator(this.combinedElementMap).evaluate(this.joinCriteria, outputTuple));
}
Modified:
trunk/engine/src/main/java/org/teiid/query/processor/relational/JoinStrategy.java
===================================================================
---
trunk/engine/src/main/java/org/teiid/query/processor/relational/JoinStrategy.java 2010-06-22
17:21:54 UTC (rev 2275)
+++
trunk/engine/src/main/java/org/teiid/query/processor/relational/JoinStrategy.java 2010-06-22
18:58:30 UTC (rev 2276)
@@ -25,7 +25,6 @@
import java.util.ArrayList;
import java.util.List;
-import org.teiid.api.exception.query.CriteriaEvaluationException;
import org.teiid.common.buffer.BufferManager.BufferReserveMode;
import org.teiid.core.TeiidComponentException;
import org.teiid.core.TeiidProcessingException;
@@ -84,7 +83,7 @@
return combinedRow;
}
- protected abstract void process() throws TeiidComponentException,
CriteriaEvaluationException, TeiidProcessingException;
+ protected abstract void process() throws TeiidComponentException,
TeiidProcessingException;
public abstract JoinStrategy clone();
Modified:
trunk/engine/src/main/java/org/teiid/query/processor/relational/MergeJoinStrategy.java
===================================================================
---
trunk/engine/src/main/java/org/teiid/query/processor/relational/MergeJoinStrategy.java 2010-06-22
17:21:54 UTC (rev 2275)
+++
trunk/engine/src/main/java/org/teiid/query/processor/relational/MergeJoinStrategy.java 2010-06-22
18:58:30 UTC (rev 2276)
@@ -24,7 +24,6 @@
import java.util.List;
-import org.teiid.api.exception.query.CriteriaEvaluationException;
import org.teiid.core.TeiidComponentException;
import org.teiid.core.TeiidProcessingException;
import org.teiid.query.processor.relational.SourceState.ImplicitBuffer;
@@ -137,7 +136,7 @@
@Override
protected void process() throws TeiidComponentException,
- CriteriaEvaluationException, TeiidProcessingException {
+ TeiidProcessingException {
while (this.mergeState != MergeState.DONE) {
while (this.mergeState == MergeState.SCAN) {
Modified:
trunk/engine/src/main/java/org/teiid/query/processor/relational/NestedTableJoinStrategy.java
===================================================================
---
trunk/engine/src/main/java/org/teiid/query/processor/relational/NestedTableJoinStrategy.java 2010-06-22
17:21:54 UTC (rev 2275)
+++
trunk/engine/src/main/java/org/teiid/query/processor/relational/NestedTableJoinStrategy.java 2010-06-22
18:58:30 UTC (rev 2276)
@@ -25,7 +25,6 @@
import java.util.List;
import java.util.Map;
-import org.teiid.api.exception.query.CriteriaEvaluationException;
import org.teiid.common.buffer.IndexedTupleSource;
import org.teiid.core.TeiidComponentException;
import org.teiid.core.TeiidProcessingException;
@@ -88,7 +87,7 @@
@Override
protected void process() throws TeiidComponentException,
- CriteriaEvaluationException, TeiidProcessingException {
+ TeiidProcessingException {
if (leftMap != null && !leftSource.open) {
for (Map.Entry<ElementSymbol, Expression> entry : leftMap.asMap().entrySet()) {
Modified:
trunk/engine/src/main/java/org/teiid/query/processor/relational/PartitionedSortJoin.java
===================================================================
---
trunk/engine/src/main/java/org/teiid/query/processor/relational/PartitionedSortJoin.java 2010-06-22
17:21:54 UTC (rev 2275)
+++
trunk/engine/src/main/java/org/teiid/query/processor/relational/PartitionedSortJoin.java 2010-06-22
18:58:30 UTC (rev 2276)
@@ -26,7 +26,6 @@
import java.util.Comparator;
import java.util.List;
-import org.teiid.api.exception.query.CriteriaEvaluationException;
import org.teiid.common.buffer.IndexedTupleSource;
import org.teiid.common.buffer.TupleBatch;
import org.teiid.common.buffer.TupleBuffer;
@@ -222,7 +221,7 @@
@Override
protected void process() throws TeiidComponentException,
- CriteriaEvaluationException, TeiidProcessingException {
+ TeiidProcessingException {
if (this.processingSortLeft != SortOption.PARTITION &&
this.processingSortRight != SortOption.PARTITION) {
super.process();
}
Modified:
trunk/engine/src/main/java/org/teiid/query/processor/relational/RelationalNodeUtil.java
===================================================================
---
trunk/engine/src/main/java/org/teiid/query/processor/relational/RelationalNodeUtil.java 2010-06-22
17:21:54 UTC (rev 2275)
+++
trunk/engine/src/main/java/org/teiid/query/processor/relational/RelationalNodeUtil.java 2010-06-22
18:58:30 UTC (rev 2276)
@@ -22,7 +22,7 @@
package org.teiid.query.processor.relational;
-import org.teiid.api.exception.query.CriteriaEvaluationException;
+import org.teiid.api.exception.query.ExpressionEvaluationException;
import org.teiid.common.buffer.BlockedException;
import org.teiid.core.TeiidComponentException;
import org.teiid.query.eval.Evaluator;
@@ -55,9 +55,10 @@
* @throws TeiidComponentException
* @throws BlockedException
* @throws TeiidComponentException
+ * @throws ExpressionEvaluationException
* @since 4.2
*/
- private static boolean evaluateCriteria(Criteria criteria) throws
CriteriaEvaluationException, TeiidComponentException {
+ private static boolean evaluateCriteria(Criteria criteria) throws
TeiidComponentException, ExpressionEvaluationException {
if(criteria == null) {
return true;
}
@@ -72,9 +73,10 @@
* @param simplifyCriteria wheter to simplify the criteria of the command if they
always evaluate to true
* @return true if this command should be executed by the connector; false
otherwise.
* @throws TeiidComponentException
+ * @throws ExpressionEvaluationException
* @since 4.2
*/
- public static boolean shouldExecute(Command command, boolean simplifyCriteria) throws
CriteriaEvaluationException, TeiidComponentException {
+ public static boolean shouldExecute(Command command, boolean simplifyCriteria) throws
TeiidComponentException, ExpressionEvaluationException {
int cmdType = command.getType();
Criteria criteria = null;
switch(cmdType) {
Modified: trunk/engine/src/main/java/org/teiid/query/processor/xml/CriteriaCondition.java
===================================================================
---
trunk/engine/src/main/java/org/teiid/query/processor/xml/CriteriaCondition.java 2010-06-22
17:21:54 UTC (rev 2275)
+++
trunk/engine/src/main/java/org/teiid/query/processor/xml/CriteriaCondition.java 2010-06-22
18:58:30 UTC (rev 2276)
@@ -28,7 +28,7 @@
import java.util.List;
import java.util.Map;
-import org.teiid.api.exception.query.CriteriaEvaluationException;
+import org.teiid.api.exception.query.ExpressionEvaluationException;
import org.teiid.core.TeiidComponentException;
import org.teiid.core.TeiidProcessingException;
import org.teiid.query.eval.Evaluator;
@@ -80,7 +80,7 @@
try {
return new Evaluator(elementMap, env.getDataManager(),
env.getProcessorContext()).evaluate(this.criteria, data);
- } catch (CriteriaEvaluationException e) {
+ } catch (ExpressionEvaluationException e) {
throw new TeiidComponentException(e);
}
}
Modified: trunk/engine/src/main/java/org/teiid/query/rewriter/QueryRewriter.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/rewriter/QueryRewriter.java 2010-06-22
17:21:54 UTC (rev 2275)
+++ trunk/engine/src/main/java/org/teiid/query/rewriter/QueryRewriter.java 2010-06-22
18:58:30 UTC (rev 2276)
@@ -41,7 +41,7 @@
import java.util.Set;
import java.util.StringTokenizer;
-import org.teiid.api.exception.query.CriteriaEvaluationException;
+import org.teiid.api.exception.query.ExpressionEvaluationException;
import org.teiid.api.exception.query.FunctionExecutionException;
import org.teiid.api.exception.query.QueryMetadataException;
import org.teiid.api.exception.query.QueryResolverException;
@@ -138,6 +138,7 @@
import org.teiid.query.sql.symbol.ScalarSubquery;
import org.teiid.query.sql.symbol.SearchedCaseExpression;
import org.teiid.query.sql.symbol.SingleElementSymbol;
+import org.teiid.query.sql.symbol.AggregateSymbol.Type;
import org.teiid.query.sql.util.SymbolMap;
import org.teiid.query.sql.util.ValueIterator;
import org.teiid.query.sql.visitor.AggregateSymbolCollectorVisitor;
@@ -1131,7 +1132,7 @@
return FALSE_CRITERIA;
- } catch(CriteriaEvaluationException e) {
+ } catch(ExpressionEvaluationException e) {
throw new QueryValidatorException(e, ErrorMessageKeys.REWRITER_0001,
QueryExecPlugin.Util.getString(ErrorMessageKeys.REWRITER_0001, crit));
}
}
@@ -1920,8 +1921,14 @@
}
private Expression rewriteExpression(AggregateSymbol expression) {
- if (!expression.getAggregateFunction().equals(NonReserved.COUNT)
- && !expression.getAggregateFunction().equals(NonReserved.SUM)
+ if (expression.isBoolean()) {
+ if (expression.getAggregateFunction() == Type.EVERY) {
+ expression.setAggregateFunction(Type.MIN);
+ } else {
+ expression.setAggregateFunction(Type.MAX);
+ }
+ }
+ if ((expression.getAggregateFunction() == Type.MAX ||
expression.getAggregateFunction() == Type.MIN)
&& EvaluatableVisitor.willBecomeConstant(expression.getExpression())) {
try {
return new ExpressionSymbol(expression.getName(), ResolverUtil
Modified: trunk/engine/src/main/java/org/teiid/query/sql/lang/MatchCriteria.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/sql/lang/MatchCriteria.java 2010-06-22
17:21:54 UTC (rev 2275)
+++ trunk/engine/src/main/java/org/teiid/query/sql/lang/MatchCriteria.java 2010-06-22
18:58:30 UTC (rev 2276)
@@ -24,7 +24,7 @@
import java.util.Arrays;
-import org.teiid.api.exception.query.CriteriaEvaluationException;
+import org.teiid.api.exception.query.ExpressionEvaluationException;
import org.teiid.core.util.EquivalenceUtil;
import org.teiid.core.util.HashCodeUtil;
import org.teiid.query.QueryPlugin;
@@ -250,7 +250,7 @@
this.newWildCard = newWildCard;
}
- public StringBuffer translate(String pattern, char escape) throws
CriteriaEvaluationException {
+ public StringBuffer translate(String pattern, char escape) throws
ExpressionEvaluationException {
StringBuffer newPattern = new StringBuffer();
@@ -282,14 +282,14 @@
}
} else {
if (escaped) {
- throw new
CriteriaEvaluationException(QueryPlugin.Util.getString("MatchCriteria.invalid_escape",
new Object[] {pattern, new Character(escape)})); //$NON-NLS-1$
+ throw new
ExpressionEvaluationException(QueryPlugin.Util.getString("MatchCriteria.invalid_escape",
new Object[] {pattern, new Character(escape)})); //$NON-NLS-1$
}
appendCharacter(newPattern, character);
}
}
if (escaped) {
- throw new
CriteriaEvaluationException(QueryPlugin.Util.getString("MatchCriteria.invalid_escape",
new Object[] {pattern, new Character(escape)})); //$NON-NLS-1$
+ throw new
ExpressionEvaluationException(QueryPlugin.Util.getString("MatchCriteria.invalid_escape",
new Object[] {pattern, new Character(escape)})); //$NON-NLS-1$
}
return newPattern;
Modified: trunk/engine/src/main/java/org/teiid/query/sql/symbol/AggregateSymbol.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/sql/symbol/AggregateSymbol.java 2010-06-22
17:21:54 UTC (rev 2275)
+++ trunk/engine/src/main/java/org/teiid/query/sql/symbol/AggregateSymbol.java 2010-06-22
18:58:30 UTC (rev 2276)
@@ -23,19 +23,13 @@
package org.teiid.query.sql.symbol;
import java.util.HashMap;
-import java.util.HashSet;
import java.util.Map;
-import java.util.Set;
import org.teiid.core.types.DataTypeManager;
import org.teiid.core.util.EquivalenceUtil;
import org.teiid.core.util.HashCodeUtil;
-import org.teiid.language.SQLConstants.NonReserved;
-import org.teiid.language.SQLConstants.Reserved;
-import org.teiid.query.QueryPlugin;
import org.teiid.query.sql.LanguageVisitor;
import org.teiid.query.sql.lang.OrderBy;
-import org.teiid.query.util.ErrorMessageKeys;
/**
@@ -58,25 +52,32 @@
* bigdecimal.</p>
*/
public class AggregateSymbol extends ExpressionSymbol {
+
+ public enum Type {
+ COUNT,
+ SUM,
+ AVG,
+ MIN,
+ MAX,
+ XMLAGG,
+ ANY,
+ SOME,
+ EVERY,
+ STDDEV_POP,
+ STDDEV_SAMP,
+ VAR_POP,
+ VAR_SAMP;
+ }
- private String aggregate;
+ private Type aggregate;
private boolean distinct;
private OrderBy orderBy;
private static final Class<Integer> COUNT_TYPE =
DataTypeManager.DefaultDataClasses.INTEGER;
- private static final Set<String> AGGREGATE_FUNCTIONS;
private static final Map<Class<?>, Class<?>> SUM_TYPES;
private static final Map<Class<?>, Class<?>> AVG_TYPES;
static {
- AGGREGATE_FUNCTIONS = new HashSet<String>();
- AGGREGATE_FUNCTIONS.add(NonReserved.COUNT);
- AGGREGATE_FUNCTIONS.add(NonReserved.SUM);
- AGGREGATE_FUNCTIONS.add(NonReserved.AVG);
- AGGREGATE_FUNCTIONS.add(NonReserved.MIN);
- AGGREGATE_FUNCTIONS.add(NonReserved.MAX);
- AGGREGATE_FUNCTIONS.add(Reserved.XMLAGG);
-
SUM_TYPES = new HashMap<Class<?>, Class<?>>();
SUM_TYPES.put(DataTypeManager.DefaultDataClasses.BYTE,
DataTypeManager.DefaultDataClasses.LONG);
SUM_TYPES.put(DataTypeManager.DefaultDataClasses.SHORT,
DataTypeManager.DefaultDataClasses.LONG);
@@ -104,10 +105,9 @@
* @param canonicalName
* @since 4.3
*/
- protected AggregateSymbol(String name, String canonicalName, String
aggregateFunction, boolean isDistinct, Expression expression) {
+ protected AggregateSymbol(String name, String canonicalName, Type aggregateFunction,
boolean isDistinct, Expression expression) {
super(name, canonicalName, expression);
-
- setAggregateFunction(aggregateFunction);
+ this.aggregate = aggregateFunction;
this.distinct = isDistinct;
}
@@ -120,8 +120,7 @@
*/
public AggregateSymbol(String name, String aggregateFunction, boolean isDistinct,
Expression expression) {
super(name, expression);
-
- setAggregateFunction(aggregateFunction);
+ this.aggregate = Type.valueOf(aggregateFunction);
this.distinct = isDistinct;
}
@@ -135,11 +134,7 @@
* @see org.teiid.language.SQLConstants.NonReserved#MIN
* @see org.teiid.language.SQLConstants.NonReserved#MAX
*/
- private void setAggregateFunction(String aggregateFunction) {
- // Validate aggregate
- if(! AGGREGATE_FUNCTIONS.contains(aggregateFunction)) {
- throw new
IllegalArgumentException(QueryPlugin.Util.getString(ErrorMessageKeys.SQL_0013, new
Object[] {aggregateFunction, AGGREGATE_FUNCTIONS}));
- }
+ public void setAggregateFunction(Type aggregateFunction) {
this.aggregate = aggregateFunction;
}
@@ -147,13 +142,8 @@
* Get the aggregate function type - this will map to one of the reserved words
* for the aggregate functions.
* @return Aggregate function type
- * @see org.teiid.language.SQLConstants.NonReserved#COUNT
- * @see org.teiid.language.SQLConstants.NonReserved#SUM
- * @see org.teiid.language.SQLConstants.NonReserved#AVG
- * @see org.teiid.language.SQLConstants.NonReserved#MIN
- * @see org.teiid.language.SQLConstants.NonReserved#MAX
*/
- public String getAggregateFunction() {
+ public Type getAggregateFunction() {
return this.aggregate;
}
@@ -172,19 +162,36 @@
* @return Type of the symbol
*/
public Class<?> getType() {
- if(this.aggregate.equals(NonReserved.COUNT)) {
+ if(this.aggregate == Type.COUNT) {
return COUNT_TYPE;
- } else if(this.aggregate.equals(NonReserved.SUM) ) {
+ } else if(this.aggregate == Type.SUM ) {
Class<?> expressionType = this.getExpression().getType();
return SUM_TYPES.get(expressionType);
- } else if (this.aggregate.equals(NonReserved.AVG)) {
+ } else if (this.aggregate == Type.AVG) {
Class<?> expressionType = this.getExpression().getType();
return AVG_TYPES.get(expressionType);
+ } else if (isBoolean()) {
+ return DataTypeManager.DefaultDataClasses.BOOLEAN;
+ } else if (isEnhancedNumeric()) {
+ return DataTypeManager.DefaultDataClasses.DOUBLE;
} else {
return this.getExpression().getType();
}
}
+ public boolean isBoolean() {
+ return this.aggregate == Type.EVERY
+ || this.aggregate == Type.SOME
+ || this.aggregate == Type.ANY;
+ }
+
+ public boolean isEnhancedNumeric() {
+ return this.aggregate == Type.STDDEV_POP
+ || this.aggregate == Type.STDDEV_SAMP
+ || this.aggregate == Type.VAR_SAMP
+ || this.aggregate == Type.VAR_POP;
+ }
+
public void acceptVisitor(LanguageVisitor visitor) {
visitor.visit(this);
}
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 2010-06-22
17:21:54 UTC (rev 2275)
+++
trunk/engine/src/main/java/org/teiid/query/sql/visitor/SQLStringVisitor.java 2010-06-22
18:58:30 UTC (rev 2276)
@@ -1095,7 +1095,7 @@
// ############ Visitor methods for symbol objects ####################
public void visit(AggregateSymbol obj) {
- parts.add(obj.getAggregateFunction());
+ parts.add(obj.getAggregateFunction().name());
parts.add("("); //$NON-NLS-1$
if(obj.isDistinct()) {
Modified:
trunk/engine/src/main/java/org/teiid/query/validator/AggregateValidationVisitor.java
===================================================================
---
trunk/engine/src/main/java/org/teiid/query/validator/AggregateValidationVisitor.java 2010-06-22
17:21:54 UTC (rev 2275)
+++
trunk/engine/src/main/java/org/teiid/query/validator/AggregateValidationVisitor.java 2010-06-22
18:58:30 UTC (rev 2276)
@@ -26,8 +26,6 @@
import java.util.Set;
import org.teiid.core.types.DataTypeManager;
-import org.teiid.language.SQLConstants.NonReserved;
-import org.teiid.language.SQLConstants.Reserved;
import org.teiid.query.QueryPlugin;
import org.teiid.query.sql.LanguageObject;
import org.teiid.query.sql.navigator.PreOrderNavigator;
@@ -38,12 +36,11 @@
import org.teiid.query.sql.symbol.ExpressionSymbol;
import org.teiid.query.sql.symbol.Function;
import org.teiid.query.sql.symbol.SearchedCaseExpression;
+import org.teiid.query.sql.symbol.AggregateSymbol.Type;
import org.teiid.query.sql.visitor.AggregateSymbolCollectorVisitor;
import org.teiid.query.sql.visitor.ElementCollectorVisitor;
import org.teiid.query.util.ErrorMessageKeys;
-
-
/**
* Validate that all ElementSymbol and ExpressionSymbols used in the HAVING
* and SELECT clauses are based on symbols used in the GROUP BY clause.
@@ -72,15 +69,27 @@
}
// Verify data type of aggregate expression
- String aggregateFunction = obj.getAggregateFunction();
- if((aggregateFunction.equals(NonReserved.SUM) ||
aggregateFunction.equals(NonReserved.AVG)) && obj.getType() == null) {
+ Type aggregateFunction = obj.getAggregateFunction();
+ if((aggregateFunction == Type.SUM || aggregateFunction == Type.AVG) &&
obj.getType() == null) {
handleValidationError(QueryPlugin.Util.getString(ErrorMessageKeys.VALIDATOR_0041, new
Object[] {aggregateFunction, obj}), obj);
- } else if (aggregateFunction.equals(Reserved.XMLAGG) && obj.getType() !=
DataTypeManager.DefaultDataClasses.XML) {
-
handleValidationError(QueryPlugin.Util.getString("AggregateValidationVisitor.non_xml",
new Object[] {aggregateFunction, obj}), obj); //$NON-NLS-1$
+ } else if (obj.getType() != DataTypeManager.DefaultDataClasses.NULL) {
+ if (aggregateFunction == Type.XMLAGG && aggExp.getType() !=
DataTypeManager.DefaultDataClasses.XML) {
+
handleValidationError(QueryPlugin.Util.getString("AggregateValidationVisitor.non_xml",
new Object[] {aggregateFunction, obj}), obj); //$NON-NLS-1$
+ } else if (obj.isBoolean() && aggExp.getType() !=
DataTypeManager.DefaultDataClasses.BOOLEAN) {
+
handleValidationError(QueryPlugin.Util.getString("AggregateValidationVisitor.non_boolean",
new Object[] {aggregateFunction, obj}), obj); //$NON-NLS-1$
+ }
}
- if((obj.isDistinct() || aggregateFunction.equals(NonReserved.MIN) ||
aggregateFunction.equals(NonReserved.MAX)) &&
DataTypeManager.isNonComparable(DataTypeManager.getDataTypeName(aggExp.getType()))) {
+ if((obj.isDistinct() || aggregateFunction == Type.MIN || aggregateFunction ==
Type.MAX) &&
DataTypeManager.isNonComparable(DataTypeManager.getDataTypeName(aggExp.getType()))) {
handleValidationError(QueryPlugin.Util.getString("AggregateValidationVisitor.non_comparable",
new Object[] {aggregateFunction, obj}), obj); //$NON-NLS-1$
}
+ if(obj.isEnhancedNumeric()) {
+ if (!Number.class.isAssignableFrom(aggExp.getType())) {
+
handleValidationError(QueryPlugin.Util.getString(ErrorMessageKeys.VALIDATOR_0041, new
Object[] {aggregateFunction, obj}), obj);
+ }
+ if (obj.isDistinct()) {
+
handleValidationError(QueryPlugin.Util.getString("AggregateValidationVisitor.invalid_distinct",
new Object[] {aggregateFunction, obj}), obj); //$NON-NLS-1$
+ }
+ }
validateBelow = false;
}
Modified: trunk/engine/src/main/javacc/org/teiid/query/parser/SQLParser.jj
===================================================================
--- trunk/engine/src/main/javacc/org/teiid/query/parser/SQLParser.jj 2010-06-22 17:21:54
UTC (rev 2275)
+++ trunk/engine/src/main/javacc/org/teiid/query/parser/SQLParser.jj 2010-06-22 18:58:30
UTC (rev 2276)
@@ -1638,7 +1638,7 @@
String func = null;
if(expression instanceof AggregateSymbol) {
es = (AggregateSymbol)expression;
- func = ((AggregateSymbol)expression).getAggregateFunction();
+ func = ((AggregateSymbol)expression).getAggregateFunction().name();
} else {
String functionName = generateFunctionName(info, null);
es = new ExpressionSymbol(functionName, expression);
@@ -1725,9 +1725,14 @@
<RPAREN> ) |
// Remaining aggregates
- ( func = nonReserved("COUNT", "SUM", "AVG",
"MIN", "MAX")
+ ( (func = nonReserved("COUNT", "SUM", "AVG",
"MIN", "MAX", "EVERY", "STDDEV_POP",
"STDDEV_SAMP", "VAR_SAMP", "VAR_POP")
+ |
+ <ANY> { func = "ANY"; }
+ |
+ <SOME> { func = "SOME"; }
+ )
<LPAREN>
- [ <DISTINCT> {isDistinct=true;} ]
+ [ <DISTINCT> {isDistinct=true;} | <ALL>]
expression = expression(info)
<RPAREN>
)
@@ -1799,30 +1804,17 @@
(
(
<LBRACE> nonReserved("OJ")
- result=tableReferenceUnescaped(info)
+ result=joinedTable(info)
<RBRACE>
)
|
- result=tableReferenceUnescaped(info)
+ result=joinedTable(info)
)
{
return result;
}
}
-FromClause tableReferenceUnescaped(ParseInfo info) :
-{
- FromClause result = null;
-}
-{
- ( LOOKAHEAD(tablePrimary(info)
((<UNION><JOIN>)|<CROSS>|<LEFT>|<RIGHT>|<INNER>|<FULL>|<JOIN>))
result = joinedTable(info)
- | result = tablePrimary(info)
- )
- {
- return result;
- }
-}
-
FromClause joinedTable(ParseInfo info) :
{
FromClause result = null;
@@ -1838,7 +1830,7 @@
jp.setLeftClause(result);
result = jp;
}
- ) +
+ ) *
{
return result;
}
@@ -1895,11 +1887,11 @@
|
LOOKAHEAD(subqueryFromClause(info)) clause = subqueryFromClause(info)
|
- ( lparen = <LPAREN> clause = joinedTable(info)
- {
+ (lparen = <LPAREN> clause = joinedTable(info)
+ {
setFromClauseOptions(lparen, clause);
- }
- <RPAREN>
+ }
+ <RPAREN>
)
)
[ (<MAKEDEP> { clause.setMakeDep(true); })
@@ -2341,7 +2333,7 @@
}
{
[<NOT> {isNot=true;}]
- crit=primary(info)
+ crit=booleanPrimary(info)
{
if(isNot) {
@@ -2358,7 +2350,7 @@
* @return Parsed primary criteria
* @throws ParseException if parsing failed
*/
-Criteria primary(ParseInfo info) :
+Criteria booleanPrimary(ParseInfo info) :
{
Criteria crit = null;
}
@@ -2380,46 +2372,63 @@
PredicateCriteria predicate(ParseInfo info) :
{
PredicateCriteria pdCrit = null;
+ Expression ex = null;
}
{
- ( LOOKAHEAD(subqueryCompareCriteria(info)) pdCrit=subqueryCompareCriteria(info) |
- LOOKAHEAD(compareCrit(info)) pdCrit=compareCrit(info) |
- LOOKAHEAD(matchCrit(info)) pdCrit=matchCrit(info) |
- LOOKAHEAD(betweenCrit(info)) pdCrit=betweenCrit(info) |
- LOOKAHEAD(setCrit(info)) pdCrit=setCrit(info) |
- LOOKAHEAD(existsCriteria(info)) pdCrit=existsCriteria(info) |
- pdCrit = hasCriteria() |
- LOOKAHEAD(translateCriteria(info)) pdCrit = translateCriteria(info) |
- pdCrit = isNullCrit(info)
- )
-
+ (
+ LOOKAHEAD(2) pdCrit = translateCriteria(info)
+ |
+ (ex = commonValueExpression(info)
+ (
+ LOOKAHEAD(2) pdCrit=betweenCrit(info, ex) |
+ LOOKAHEAD(2) pdCrit=matchCrit(info, ex) |
+ pdCrit=setCrit(info, ex) |
+ pdCrit = isNullCrit(info, ex) |
+ LOOKAHEAD(operator() expression(info)) pdCrit=compareCrit(info, ex) |
+ pdCrit=subqueryCompareCriteria(info, ex)
+ )
+ )
+ |
+ pdCrit=existsCriteria(info) |
+ pdCrit = hasCriteria()
+ )
{
return pdCrit;
}
}
+Token operator() :
+{
+ Token operator = null;
+}
+{
+ (operator=<EQ> |
+ operator=<NE> |
+ operator=<NE2> |
+ operator=<LT> |
+ operator=<LE> |
+ operator=<GT> |
+ operator=<GE>
+ )
+ {
+ return operator;
+ }
+}
+
+
/**
* <p>Parse a compare criteria.</p>
* @return Parsed compare criteria
* @throws ParseException if parsing failed
*/
-CompareCriteria compareCrit(ParseInfo info) :
+CompareCriteria compareCrit(ParseInfo info, Expression expression) :
{
- Expression expression = null;
Expression value = null;
Token operator = null;
}
{
- expression=expression(info)
- ( operator=<EQ> |
- operator=<NE> |
- operator=<NE2> |
- operator=<LT> |
- operator=<LE> |
- operator=<GT> |
- operator=<GE>
- )
- value=expression(info)
+ operator=operator()
+ value=commonValueExpression(info)
{
CompareCriteria compareCriteria = new CompareCriteria();
@@ -2455,9 +2464,8 @@
* @return Parsed subquery compare criteria
* @throws ParseException if parsing failed
*/
-SubqueryCompareCriteria subqueryCompareCriteria(ParseInfo info) :
+SubqueryCompareCriteria subqueryCompareCriteria(ParseInfo info, Expression expression) :
{
- Expression expression = null;
SubqueryCompareCriteria subqueryCrit = null;
Command subquery = null;
Token operator = null;
@@ -2465,15 +2473,7 @@
}
{
- expression=expression(info)
- ( operator=<EQ> |
- operator=<NE> |
- operator=<NE2> |
- operator=<LT> |
- operator=<LE> |
- operator=<GT> |
- operator=<GE>
- )
+ operator=operator()
( quantifier=<ANY> |
quantifier=<SOME> |
quantifier=<ALL>
@@ -2508,22 +2508,19 @@
* @return Parsed match criteria
* @throws ParseException if parsing failed
*/
-MatchCriteria matchCrit(ParseInfo info) :
+MatchCriteria matchCrit(ParseInfo info, Expression expression) :
{
Character esc = null;
- Expression expression = null;
Expression value = null;
boolean negated = false;
}
{
- ( expression=expression(info)
- [<NOT> {negated = true;}]
- <LIKE>
- value=expression(info)
- [ <ESCAPE> esc = charVal(info, "LIKE ESCAPE") |
- (<LBRACE> <ESCAPE> esc = charVal(info, "LIKE ESCAPE")
<RBRACE>)
- ]
- )
+ [<NOT> {negated = true;}]
+ <LIKE>
+ value=commonValueExpression(info)
+ [ <ESCAPE> esc = charVal(info, "LIKE ESCAPE") |
+ (<LBRACE> <ESCAPE> esc = charVal(info, "LIKE ESCAPE")
<RBRACE>)
+ ]
{
MatchCriteria matchcriteria = new MatchCriteria(expression, value);
matchcriteria.setNegated(negated);
@@ -2553,18 +2550,17 @@
* @return Parsed BETWEEN criteria
* @throws ParseException if parsing failed
*/
-BetweenCriteria betweenCrit(ParseInfo info) :
+BetweenCriteria betweenCrit(ParseInfo info, Expression expression) :
{
- Expression expression = null, lowerExpression = null, upperExpression = null;
+ Expression lowerExpression = null, upperExpression = null;
boolean negated = false;
}
{
- expression = expression(info)
[<NOT> {negated=true;}]
<BETWEEN>
- lowerExpression = expression(info)
+ lowerExpression = commonValueExpression(info)
<AND>
- upperExpression = expression(info)
+ upperExpression = commonValueExpression(info)
{
BetweenCriteria criteria = new BetweenCriteria(expression, lowerExpression,
upperExpression);
@@ -2578,14 +2574,12 @@
* @return Parsed IS NULL criteria
* @throws ParseException if parsing failed
*/
-IsNullCriteria isNullCrit(ParseInfo info) :
+IsNullCriteria isNullCrit(ParseInfo info, Expression expression) :
{
- Expression expression = null;
boolean negated = false;
IsNullCriteria criteria = null;
}
{
- expression=expression(info)
<IS>
[<NOT> {negated = true;}]
<NULL>
@@ -2602,9 +2596,8 @@
* @return Parsed set criteria
* @throws ParseException if parsing failed
*/
-AbstractSetCriteria setCrit(ParseInfo info) :
+AbstractSetCriteria setCrit(ParseInfo info, Expression expression) :
{
- Expression expression = null;
Expression value = null;
List setList = new ArrayList();
Command command = null;
@@ -2612,19 +2605,18 @@
AbstractSetCriteria criteria = null;
}
{
- expression=expression(info)
[<NOT> {negated = true;}]
<IN>
(
LOOKAHEAD(subquery(info)) (command = subquery(info)) |
(
<LPAREN>
- value = expression(info)
+ value = commonValueExpression(info)
{
setList.add(value);
}
( <COMMA>
- value = expression(info)
+ value = commonValueExpression(info)
{
setList.add(value);
}
@@ -2909,18 +2901,13 @@
Expression expression = null;
}
{
- expression = concatExpression(info)
+ expression = commonValueExpression(info)
{
return expression;
}
}
-/**
- * <p>Parse an expression - made up of literals and functions.</p>
- * @return Expression
- * @throws ParseException if parsing failed
- */
-Expression concatExpression(ParseInfo info) :
+Expression commonValueExpression(ParseInfo info) :
{
Expression leftExpression = null;
Expression rightExpression = null;
@@ -3002,10 +2989,10 @@
String operator = null;
}
{
- ( leftExpression=basicExpression(info)
+ ( leftExpression=valueExpressionPrimary(info)
(
operator=timesOperator()
- rightExpression=basicExpression(info)
+ rightExpression=valueExpressionPrimary(info)
{
leftExpression = new Function(operator, new Expression[] {leftExpression,
rightExpression});
rightExpression = null;
@@ -3043,7 +3030,7 @@
* @return Expression
* @throws ParseException if parsing failed
*/
-Expression basicExpression(ParseInfo info) :
+Expression valueExpressionPrimary(ParseInfo info) :
{
Token refToken = null;
Expression expression = null;
@@ -3066,8 +3053,12 @@
)
|
// Aggregate function
- LOOKAHEAD(<ID>, {matchesAny(getToken(1).image, "count",
"min", "max", "sum", "avg") != null})
(expression=aggregateSymbol(info))
+ LOOKAHEAD(<ID>, {matchesAny(getToken(1).image, "count",
"min", "max", "sum", "avg", "every",
"STDDEV_POP", "STDDEV_SAMP", "VAR_SAMP",
"VAR_POP") != null}) (expression=aggregateSymbol(info))
|
+ LOOKAHEAD(<ANY>) (expression=aggregateSymbol(info))
+ |
+ LOOKAHEAD(<SOME>) (expression=aggregateSymbol(info))
+ |
(expression=xmlAgg(info))
|
// Function
@@ -3093,11 +3084,11 @@
|
subquery = subquery(info)
|
- // Non-searched CASE expressions
- LOOKAHEAD(caseExpression(info)) expression = caseExpression(info)
- |
// Searched CASE expressions
- LOOKAHEAD(searchedCaseExpression(info)) expression = searchedCaseExpression(info)
+ LOOKAHEAD(2) expression = searchedCaseExpression(info)
+ |
+ // Non-searched CASE expressions
+ expression = caseExpression(info)
)
{
Modified: trunk/engine/src/main/resources/org/teiid/query/i18n.properties
===================================================================
--- trunk/engine/src/main/resources/org/teiid/query/i18n.properties 2010-06-22 17:21:54
UTC (rev 2275)
+++ trunk/engine/src/main/resources/org/teiid/query/i18n.properties 2010-06-22 18:58:30
UTC (rev 2276)
@@ -301,6 +301,8 @@
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}
AggregateValidationVisitor.non_xml = The XMLAGG aggregate function {0} requires an
expression of type XML: {1}
+AggregateValidationVisitor.non_boolean=The boolean aggregate functions ANY, SOME, EVERY
require a boolean expression.
+AggregateValidationVisitor.invalid_distinct=The enhanced numeric aggregate functions
STDDEV_POP, STDDEV_SAMP, VAR_POP, VAR_SAMP cannot have DISTINCT specified.
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/org/teiid/query/optimizer/TestAggregatePushdown.java
===================================================================
---
trunk/engine/src/test/java/org/teiid/query/optimizer/TestAggregatePushdown.java 2010-06-22
17:21:54 UTC (rev 2275)
+++
trunk/engine/src/test/java/org/teiid/query/optimizer/TestAggregatePushdown.java 2010-06-22
18:58:30 UTC (rev 2276)
@@ -35,6 +35,7 @@
import org.teiid.query.processor.ProcessorPlan;
import org.teiid.query.unittest.FakeMetadataFacade;
import org.teiid.query.unittest.FakeMetadataFactory;
+import org.teiid.translator.SourceSystemFunctions;
public class TestAggregatePushdown {
@@ -287,6 +288,36 @@
});
}
+ @Test public void testStddevAggregate() throws Exception {
+ FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+ BasicSourceCapabilities caps = getAggregateCapabilities();
+ caps.setFunctionSupport(SourceSystemFunctions.POWER, true);
+ caps.setFunctionSupport(SourceSystemFunctions.CONVERT, true);
+ capFinder.addCapabilities("pm1", caps); //$NON-NLS-1$
+ capFinder.addCapabilities("pm2", caps); //$NON-NLS-1$
+
+ String sql = "SELECT stddev_pop(y.e2) from pm1.g1 x, pm2.g1 y where x.e3 =
y.e3 group by x.e2, y.e1"; //$NON-NLS-1$
+ ProcessorPlan plan = TestOptimizer.helpPlan(sql,
FakeMetadataFactory.example1Cached(), null, capFinder,
+ new String[] {"SELECT DISTINCT g_0.e3 AS c_0,
g_0.e1 AS c_1, COUNT(g_0.e2) AS c_2, SUM(power(g_0.e2, 2)) AS c_3, SUM(g_0.e2) AS c_4 FROM
pm2.g1 AS g_0 GROUP BY g_0.e3, g_0.e1 ORDER BY c_0", "SELECT DISTINCT g_0.e3 AS
c_0, g_0.e2 AS c_1 FROM pm1.g1 AS g_0 GROUP BY g_0.e3, g_0.e2 ORDER BY c_0"},
TestOptimizer.ComparisonMode.EXACT_COMMAND_STRING); //$NON-NLS-1$ //$NON-NLS-2$
+
+ TestOptimizer.checkNodeTypes(plan, new int[] {
+ 2, // Access
+ 0, // DependentAccess
+ 0, // DependentSelect
+ 0, // DependentProject
+ 0, // DupRemove
+ 1, // Grouping
+ 0, // NestedLoopJoinStrategy
+ 1, // MergeJoinStrategy
+ 0, // Null
+ 0, // PlanExecution
+ 1, // Project
+ 0, // Select
+ 0, // Sort
+ 0 // UnionAll
+ });
+ }
+
@Test public void testCountAggregate() throws Exception {
FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
BasicSourceCapabilities caps = getAggregateCapabilities();
@@ -816,8 +847,8 @@
capFinder.addCapabilities("pm1", caps); //$NON-NLS-1$
capFinder.addCapabilities("pm2",
TestOptimizer.getTypicalCapabilities()); //$NON-NLS-1$
- ProcessorPlan plan = TestOptimizer.helpPlan("select max(e2) from (select e1,
e2 from pm1.g1 union all select e1, e2 from pm2.g2) z",
FakeMetadataFactory.example1Cached(), null, capFinder, //$NON-NLS-1$
- new String[]{"SELECT MAX(v_0.c_0) FROM (SELECT g_0.e2 AS c_0 FROM pm1.g1
AS g_0) AS v_0 HAVING COUNT(*) > 0", //$NON-NLS-1$
+ ProcessorPlan plan = TestOptimizer.helpPlan("select max(e2), count(*) from
(select e1, e2 from pm1.g1 union all select e1, e2 from pm2.g2) z",
FakeMetadataFactory.example1Cached(), null, capFinder, //$NON-NLS-1$
+ new String[]{"SELECT MAX(v_0.c_0), COUNT(*) FROM (SELECT g_0.e2 AS c_0
FROM pm1.g1 AS g_0) AS v_0 HAVING COUNT(*) > 0", //$NON-NLS-1$
"SELECT g_0.e2 FROM pm2.g2 AS g_0"},
ComparisonMode.EXACT_COMMAND_STRING); //$NON-NLS-1$
TestOptimizer.checkNodeTypes(plan, new int[] {
2, // Access
Modified: trunk/engine/src/test/java/org/teiid/query/processor/FakeDataManager.java
===================================================================
--- trunk/engine/src/test/java/org/teiid/query/processor/FakeDataManager.java 2010-06-22
17:21:54 UTC (rev 2275)
+++ trunk/engine/src/test/java/org/teiid/query/processor/FakeDataManager.java 2010-06-22
18:58:30 UTC (rev 2276)
@@ -29,7 +29,7 @@
import java.util.List;
import java.util.Map;
-import org.teiid.api.exception.query.CriteriaEvaluationException;
+import org.teiid.api.exception.query.ExpressionEvaluationException;
import org.teiid.api.exception.query.QueryResolverException;
import org.teiid.common.buffer.BlockedException;
import org.teiid.common.buffer.TupleSource;
@@ -38,7 +38,6 @@
import org.teiid.query.eval.Evaluator;
import org.teiid.query.metadata.QueryMetadataInterface;
import org.teiid.query.metadata.TempMetadataID;
-import org.teiid.query.processor.ProcessorDataManager;
import org.teiid.query.resolver.util.ResolverUtil;
import org.teiid.query.sql.lang.BatchedUpdateCommand;
import org.teiid.query.sql.lang.Command;
@@ -180,7 +179,7 @@
if(new Evaluator(lookupMap, null, null).evaluate(query.getCriteria(),
tuples[i])) {
filteredTuples.add(tuples[i]);
}
- } catch(CriteriaEvaluationException e) {
+ } catch(ExpressionEvaluationException e) {
throw new TeiidComponentException(e, e.getMessage());
}
}
@@ -221,7 +220,7 @@
if(new Evaluator(lookupMap, null, null).evaluate(update.getCriteria(),
tuples[i])) {
updated++;
}
- } catch(CriteriaEvaluationException e) {
+ } catch(ExpressionEvaluationException e) {
throw new TeiidComponentException(e, e.getMessage());
}
}
Modified:
trunk/engine/src/test/java/org/teiid/query/processor/TestAggregateProcessing.java
===================================================================
---
trunk/engine/src/test/java/org/teiid/query/processor/TestAggregateProcessing.java 2010-06-22
17:21:54 UTC (rev 2275)
+++
trunk/engine/src/test/java/org/teiid/query/processor/TestAggregateProcessing.java 2010-06-22
18:58:30 UTC (rev 2276)
@@ -25,6 +25,7 @@
import static org.teiid.query.processor.TestProcessor.*;
import java.math.BigDecimal;
+import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
@@ -35,11 +36,11 @@
import org.teiid.query.optimizer.TestOptimizer;
import org.teiid.query.optimizer.capabilities.BasicSourceCapabilities;
import org.teiid.query.optimizer.capabilities.FakeCapabilitiesFinder;
-import org.teiid.query.processor.ProcessorPlan;
import org.teiid.query.sql.lang.Command;
import org.teiid.query.unittest.FakeMetadataFactory;
+import org.teiid.translator.SourceSystemFunctions;
-
+@SuppressWarnings("nls")
public class TestAggregateProcessing {
static void sampleDataBQT3(FakeDataManager dataMgr) throws Exception {
@@ -282,5 +283,71 @@
helpProcess(plan, dataManager, expected);
}
+
+ @Test public void testPushDownOverUnionMixed1() throws Exception {
+ FakeCapabilitiesFinder capFinder = new FakeCapabilitiesFinder();
+ BasicSourceCapabilities caps = TestAggregatePushdown.getAggregateCapabilities();
+ caps.setFunctionSupport(SourceSystemFunctions.POWER, true);
+ caps.setFunctionSupport(SourceSystemFunctions.CONVERT, true);
+ capFinder.addCapabilities("pm2", caps); //$NON-NLS-1$
+ capFinder.addCapabilities("pm1",
TestOptimizer.getTypicalCapabilities()); //$NON-NLS-1$
+
+ ProcessorPlan plan = helpGetPlan(helpParse("select max(e2), count(*),
stddev_pop(e2), var_samp(e2) from (select e1, e2 from pm1.g1 union all select e1, e2 from
pm2.g2) z"), FakeMetadataFactory.example1Cached(), capFinder); //$NON-NLS-1$
+
+ HardcodedDataManager dataManager = new HardcodedDataManager();
+ dataManager.addData("SELECT g_0.e2 FROM pm1.g1 AS g_0", new List[]
{Arrays.asList(1), Arrays.asList(2)});
+ dataManager.addData("SELECT MAX(v_0.c_0), COUNT(*), COUNT(v_0.c_0),
SUM(power(v_0.c_0, 2)), SUM(v_0.c_0) FROM (SELECT g_0.e2 AS c_0 FROM pm2.g2 AS g_0) AS v_0
HAVING COUNT(*) > 0", new List[] {Arrays.asList(5, 6, 4, BigInteger.valueOf(50l),
10l)});
+
+ List[] expected = new List[] {
+ Arrays.asList(5, 8, 2.1213203435596424, 5.4),
+ };
+
+ helpProcess(plan, dataManager, expected);
+ }
+ @Test public void testBooleanAgg() {
+ String sql = "select every(e3), any(e3) from pm1.g1"; //$NON-NLS-1$
+
+ List[] expected = new List[] {
+ Arrays.asList(Boolean.FALSE, Boolean.TRUE),
+ };
+
+ FakeDataManager dataManager = new FakeDataManager();
+ sampleData1(dataManager);
+
+ ProcessorPlan plan = helpGetPlan(helpParse(sql),
FakeMetadataFactory.example1Cached());
+
+ helpProcess(plan, dataManager, expected);
+ }
+
+ @Test public void testStatsFunctions() {
+ String sql = "select stddev_pop(e2), var_samp(e2) from pm1.g1";
//$NON-NLS-1$
+
+ List[] expected = new List[] {
+ Arrays.asList(1.0671873729054748, 1.3666666666666667),
+ };
+
+ FakeDataManager dataManager = new FakeDataManager();
+ sampleData1(dataManager);
+
+ ProcessorPlan plan = helpGetPlan(helpParse(sql),
FakeMetadataFactory.example1Cached());
+
+ helpProcess(plan, dataManager, expected);
+ }
+
+ @Test public void testStatsFunctions1() {
+ String sql = "select stddev_samp(e2), var_pop(e2) from (select 2 e2) x";
//$NON-NLS-1$
+
+ List[] expected = new List[] {
+ Arrays.asList(null, 0.0),
+ };
+
+ FakeDataManager dataManager = new FakeDataManager();
+ sampleData1(dataManager);
+
+ ProcessorPlan plan = helpGetPlan(helpParse(sql),
FakeMetadataFactory.example1Cached());
+
+ helpProcess(plan, dataManager, expected);
+ }
+
}
Modified: trunk/engine/src/test/java/org/teiid/query/processor/TestProcessor.java
===================================================================
--- trunk/engine/src/test/java/org/teiid/query/processor/TestProcessor.java 2010-06-22
17:21:54 UTC (rev 2275)
+++ trunk/engine/src/test/java/org/teiid/query/processor/TestProcessor.java 2010-06-22
18:58:30 UTC (rev 2276)
@@ -7570,6 +7570,6 @@
helpProcess(plan, dataManager, expected);
}
-
+
private static final boolean DEBUG = false;
}
Modified: trunk/engine/src/test/java/org/teiid/query/processor/TestVirtualDepJoin.java
===================================================================
---
trunk/engine/src/test/java/org/teiid/query/processor/TestVirtualDepJoin.java 2010-06-22
17:21:54 UTC (rev 2275)
+++
trunk/engine/src/test/java/org/teiid/query/processor/TestVirtualDepJoin.java 2010-06-22
18:58:30 UTC (rev 2276)
@@ -31,7 +31,6 @@
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
-import java.util.Properties;
import org.junit.Test;
import org.teiid.common.buffer.BufferManager;
@@ -46,9 +45,6 @@
import org.teiid.query.optimizer.capabilities.BasicSourceCapabilities;
import org.teiid.query.optimizer.capabilities.FakeCapabilitiesFinder;
import org.teiid.query.optimizer.capabilities.SourceCapabilities.Capability;
-import org.teiid.query.processor.BatchCollector;
-import org.teiid.query.processor.ProcessorPlan;
-import org.teiid.query.processor.QueryProcessor;
import org.teiid.query.sql.lang.Command;
import org.teiid.query.unittest.FakeMetadataFacade;
import org.teiid.query.unittest.FakeMetadataFactory;
Modified:
trunk/engine/src/test/java/org/teiid/query/processor/eval/TestCriteriaEvaluator.java
===================================================================
---
trunk/engine/src/test/java/org/teiid/query/processor/eval/TestCriteriaEvaluator.java 2010-06-22
17:21:54 UTC (rev 2275)
+++
trunk/engine/src/test/java/org/teiid/query/processor/eval/TestCriteriaEvaluator.java 2010-06-22
18:58:30 UTC (rev 2276)
@@ -34,7 +34,7 @@
import java.util.Map;
import org.junit.Test;
-import org.teiid.api.exception.query.CriteriaEvaluationException;
+import org.teiid.api.exception.query.ExpressionEvaluationException;
import org.teiid.common.buffer.BlockedException;
import org.teiid.core.TeiidComponentException;
import org.teiid.core.TeiidProcessingException;
@@ -59,7 +59,7 @@
// ################################## TEST HELPERS ################################
- private void helpTestMatch(String value, String pattern, char escape, boolean
negated, boolean expectedMatch) throws CriteriaEvaluationException, BlockedException,
TeiidComponentException {
+ private void helpTestMatch(String value, String pattern, char escape, boolean
negated, boolean expectedMatch) throws ExpressionEvaluationException, BlockedException,
TeiidComponentException {
MatchCriteria crit = new MatchCriteria(new Constant(value), new
Constant(pattern), escape);
crit.setNegated(negated);
boolean actualMatch = Evaluator.evaluate(crit);
@@ -67,11 +67,11 @@
assertEquals("Match criteria test failed for value=[" + value +
"], pattern=[" + pattern + "], hasEscape=" + (escape !=
MatchCriteria.NULL_ESCAPE_CHAR) + ": ", expectedMatch, actualMatch);
//$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
}
- private void helpTestMatch(String value, String pattern, char escape, boolean
expectedMatch) throws CriteriaEvaluationException, BlockedException,
TeiidComponentException {
+ private void helpTestMatch(String value, String pattern, char escape, boolean
expectedMatch) throws ExpressionEvaluationException, BlockedException,
TeiidComponentException {
helpTestMatch(value, pattern, escape, false, expectedMatch);
}
- private void helpTestIsNull(String value, boolean negated, boolean expectedMatch)
throws CriteriaEvaluationException, BlockedException, TeiidComponentException {
+ private void helpTestIsNull(String value, boolean negated, boolean expectedMatch)
throws ExpressionEvaluationException, BlockedException, TeiidComponentException {
IsNullCriteria criteria = new IsNullCriteria(new Constant(value));
criteria.setNegated(negated);
@@ -79,11 +79,11 @@
assertEquals("Result did not match expected value", expectedMatch,
result); //$NON-NLS-1$
}
- private void helpTestSetCriteria(int value, boolean negated, boolean expectedMatch)
throws CriteriaEvaluationException, BlockedException, TeiidComponentException {
+ private void helpTestSetCriteria(int value, boolean negated, boolean expectedMatch)
throws ExpressionEvaluationException, BlockedException, TeiidComponentException {
helpTestSetCriteria(new Integer(value), negated, expectedMatch);
}
- private void helpTestSetCriteria(Integer value, boolean negated, boolean
expectedMatch) throws CriteriaEvaluationException, BlockedException,
TeiidComponentException {
+ private void helpTestSetCriteria(Integer value, boolean negated, boolean
expectedMatch) throws ExpressionEvaluationException, BlockedException,
TeiidComponentException {
Collection constants = new ArrayList(2);
constants.add(new Constant(new Integer(1000)));
constants.add(new Constant(new Integer(5000)));
@@ -93,7 +93,7 @@
assertEquals("Result did not match expected value", expectedMatch,
result); //$NON-NLS-1$
}
- private void helpTestCompareSubqueryCriteria(Criteria crit, boolean expectedResult,
final Collection values) throws CriteriaEvaluationException, BlockedException,
TeiidComponentException{
+ private void helpTestCompareSubqueryCriteria(Criteria crit, boolean expectedResult,
final Collection values) throws ExpressionEvaluationException, BlockedException,
TeiidComponentException{
Map elementMap = new HashMap();
ElementSymbol e1 = new ElementSymbol("e1"); //$NON-NLS-1$
@@ -334,7 +334,7 @@
@Test public void testMatch49() throws Exception {
try {
helpTestMatch("abc", "a", 'a', true);
//$NON-NLS-1$ //$NON-NLS-2$
- } catch (CriteriaEvaluationException cee) {
+ } catch (ExpressionEvaluationException cee) {
assertEquals("Invalid escape sequence \"a\" with escape
character \"a\"", cee.getMessage()); //$NON-NLS-1$
}
}
@@ -343,7 +343,7 @@
@Test public void testMatch50() throws Exception {
try {
helpTestMatch("abc", "ab", 'a', true);
//$NON-NLS-1$ //$NON-NLS-2$
- } catch (CriteriaEvaluationException cee) {
+ } catch (ExpressionEvaluationException cee) {
assertEquals("Invalid escape sequence \"ab\" with escape
character \"a\"", cee.getMessage()); //$NON-NLS-1$
}
}
@@ -502,7 +502,7 @@
values.add("c"); //$NON-NLS-1$
try {
helpTestCompareSubqueryCriteria(crit, false, values);
- } catch (CriteriaEvaluationException e) {
+ } catch (ExpressionEvaluationException e) {
assertEquals("Error Code:ERR.015.006.0056 Message:The subquery of this
compare criteria has to be scalar, but returned more than one value: e1 =
(<undefined>)", e.getMessage()); //$NON-NLS-1$
}
}
Modified: trunk/engine/src/test/java/org/teiid/query/validator/TestValidator.java
===================================================================
--- trunk/engine/src/test/java/org/teiid/query/validator/TestValidator.java 2010-06-22
17:21:54 UTC (rev 2275)
+++ trunk/engine/src/test/java/org/teiid/query/validator/TestValidator.java 2010-06-22
18:58:30 UTC (rev 2276)
@@ -2038,5 +2038,17 @@
@Test public void testDecode() throws Exception {
helpValidate("select to_bytes(e1, '?') from pm1.g1", new String[]
{"to_bytes(e1, '?')"}, FakeMetadataFactory.example1Cached());
}
+
+ @Test public void testValidateXMLAGG() {
+ helpValidate("SELECT XMLAGG(e1) from pm1.g1", new String[]
{"XMLAGG(e1)"}, FakeMetadataFactory.example1Cached()); //$NON-NLS-1$
//$NON-NLS-2$
+ }
+
+ @Test public void testValidateBooleanAgg() {
+ helpValidate("SELECT EVERY(e1) from pm1.g1", new String[]
{"EVERY(e1)"}, FakeMetadataFactory.example1Cached()); //$NON-NLS-1$
//$NON-NLS-2$
+ }
+
+ @Test public void testValidateStatAgg() {
+ helpValidate("SELECT stddev_pop(distinct e2) from pm1.g1", new String[]
{"STDDEV_POP(DISTINCT e2)"}, FakeMetadataFactory.example1Cached());
//$NON-NLS-1$ //$NON-NLS-2$
+ }
}