teiid SVN: r2181 - in trunk: api/src/main/java/org/teiid/language and 49 other directories.
by teiid-commits@lists.jboss.org
Author: shawkins
Date: 2010-06-04 17:51:29 -0400 (Fri, 04 Jun 2010)
New Revision: 2181
Added:
trunk/engine/src/main/java/org/teiid/query/processor/relational/XMLTableNode.java
trunk/engine/src/main/java/org/teiid/query/sql/lang/TableFunctionReference.java
trunk/engine/src/main/java/org/teiid/query/sql/lang/XMLTable.java
trunk/engine/src/main/java/org/teiid/query/sql/symbol/DerivedColumn.java
trunk/engine/src/main/java/org/teiid/query/sql/symbol/XMLSerialize.java
trunk/engine/src/main/java/org/teiid/query/xquery/saxon/PathMapFilter.java
trunk/engine/src/test/java/org/teiid/dqp/internal/process/SimpleQueryProcessorFactory.java
Removed:
trunk/engine/src/main/java/org/teiid/query/optimizer/xquery/
trunk/engine/src/main/java/org/teiid/query/processor/xquery/
trunk/engine/src/main/java/org/teiid/query/sql/lang/XQuery.java
trunk/engine/src/main/java/org/teiid/query/xquery/XQueryExpression.java
trunk/engine/src/main/java/org/teiid/query/xquery/XQuerySQLEvaluator.java
trunk/engine/src/main/java/org/teiid/query/xquery/saxon/DocFunctionURIResolver.java
trunk/engine/src/test/java/org/teiid/query/parser/TestParserXQuery.java
trunk/engine/src/test/java/org/teiid/query/processor/dynamic/
trunk/engine/src/test/java/org/teiid/query/processor/xquery/
trunk/engine/src/test/java/org/teiid/query/xquery/HardcodedSqlEval.java
trunk/engine/src/test/java/org/teiid/query/xquery/TestXQueryEngine.java
Modified:
trunk/api/src/main/java/org/teiid/language/SQLReservedWords.java
trunk/api/src/main/java/org/teiid/language/visitor/SQLStringVisitor.java
trunk/api/src/main/java/org/teiid/translator/SourceSystemFunctions.java
trunk/client/src/main/java/org/teiid/jdbc/DatabaseMetaDataImpl.java
trunk/common-core/src/main/java/org/teiid/core/types/Streamable.java
trunk/common-core/src/main/java/org/teiid/core/types/basic/StringToSQLXMLTransform.java
trunk/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/hsql/AddDiffModifier.java
trunk/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/postgresql/PostgreSQLExecutionFactory.java
trunk/connectors/translator-jdbc/src/test/java/org/teiid/translator/jdbc/TestEscapeSyntaxModifier.java
trunk/documentation/reference/src/main/docbook/en-US/content/federated_planning.xml
trunk/documentation/reference/src/main/docbook/en-US/content/scalar_functions.xml
trunk/documentation/reference/src/main/docbook/en-US/content/transaction_support.xml
trunk/engine/pom.xml
trunk/engine/src/main/java/org/teiid/dqp/internal/process/MetaDataProcessor.java
trunk/engine/src/main/java/org/teiid/dqp/internal/process/Request.java
trunk/engine/src/main/java/org/teiid/query/eval/Evaluator.java
trunk/engine/src/main/java/org/teiid/query/function/FunctionMethods.java
trunk/engine/src/main/java/org/teiid/query/function/source/SystemSource.java
trunk/engine/src/main/java/org/teiid/query/function/source/XMLSystemFunctions.java
trunk/engine/src/main/java/org/teiid/query/optimizer/QueryOptimizer.java
trunk/engine/src/main/java/org/teiid/query/optimizer/relational/PlanToProcessConverter.java
trunk/engine/src/main/java/org/teiid/query/optimizer/relational/RelationalPlanner.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/NewCalculateCostUtil.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/RuleRaiseAccess.java
trunk/engine/src/main/java/org/teiid/query/optimizer/relational/rules/RuleRemoveOptionalJoins.java
trunk/engine/src/main/java/org/teiid/query/parser/QueryParser.java
trunk/engine/src/main/java/org/teiid/query/parser/SQLParserUtil.java
trunk/engine/src/main/java/org/teiid/query/processor/relational/GroupingNode.java
trunk/engine/src/main/java/org/teiid/query/processor/relational/TextTableNode.java
trunk/engine/src/main/java/org/teiid/query/resolver/QueryResolver.java
trunk/engine/src/main/java/org/teiid/query/resolver/command/ExecResolver.java
trunk/engine/src/main/java/org/teiid/query/resolver/command/SimpleQueryResolver.java
trunk/engine/src/main/java/org/teiid/query/resolver/util/ResolverUtil.java
trunk/engine/src/main/java/org/teiid/query/resolver/util/ResolverVisitor.java
trunk/engine/src/main/java/org/teiid/query/rewriter/QueryRewriter.java
trunk/engine/src/main/java/org/teiid/query/sql/LanguageVisitor.java
trunk/engine/src/main/java/org/teiid/query/sql/lang/Command.java
trunk/engine/src/main/java/org/teiid/query/sql/lang/TextTable.java
trunk/engine/src/main/java/org/teiid/query/sql/navigator/PreOrPostOrderNavigator.java
trunk/engine/src/main/java/org/teiid/query/sql/symbol/AggregateSymbol.java
trunk/engine/src/main/java/org/teiid/query/sql/symbol/XMLAttributes.java
trunk/engine/src/main/java/org/teiid/query/sql/symbol/XMLForest.java
trunk/engine/src/main/java/org/teiid/query/sql/visitor/ExpressionMappingVisitor.java
trunk/engine/src/main/java/org/teiid/query/sql/visitor/SQLStringVisitor.java
trunk/engine/src/main/java/org/teiid/query/validator/AggregateValidationVisitor.java
trunk/engine/src/main/java/org/teiid/query/validator/ValidationVisitor.java
trunk/engine/src/main/java/org/teiid/query/xquery/saxon/SaxonXQueryExpression.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/dqp/internal/datamgr/language/TestAggregateImpl.java
trunk/engine/src/test/java/org/teiid/dqp/internal/process/TestDQPCore.java
trunk/engine/src/test/java/org/teiid/dqp/internal/process/TestDataTierManager.java
trunk/engine/src/test/java/org/teiid/dqp/internal/process/TestPreparedStatement.java
trunk/engine/src/test/java/org/teiid/query/function/TestFunction.java
trunk/engine/src/test/java/org/teiid/query/function/TestFunctionLibrary.java
trunk/engine/src/test/java/org/teiid/query/function/source/TestXMLSystemFunctions.java
trunk/engine/src/test/java/org/teiid/query/optimizer/relational/rules/TestCapabilitiesUtil.java
trunk/engine/src/test/java/org/teiid/query/parser/TestParser.java
trunk/engine/src/test/java/org/teiid/query/processor/TestSQLXMLProcessing.java
trunk/engine/src/test/java/org/teiid/query/resolver/TestFunctionResolving.java
trunk/engine/src/test/java/org/teiid/query/rewriter/TestQueryRewriter.java
trunk/engine/src/test/java/org/teiid/query/sql/proc/TestCreateUpdateProcedureCommand.java
trunk/engine/src/test/java/org/teiid/query/sql/symbol/TestAggregateSymbol.java
trunk/engine/src/test/java/org/teiid/query/sql/visitor/TestExpressionMappingVisitor.java
trunk/engine/src/test/java/org/teiid/query/sql/visitor/TestSQLStringVisitor.java
trunk/engine/src/test/java/org/teiid/query/validator/TestValidator.java
trunk/pom.xml
trunk/test-integration/common/src/test/java/org/teiid/connector/visitor/util/TestSQLStringVisitor.java
Log:
TEIID-1087 TEIID-171 TEIID-1005 initial commit of xquery overhaul. added xquery analysis based upon saxon path maps. memory usage will be nearly as good as xom/nux, but there are far fewer restrictions on the row path expression. also added xmlserialize and cleaned up the parser further to remove more unnecessarily reserved words.
Modified: trunk/api/src/main/java/org/teiid/language/SQLReservedWords.java
===================================================================
--- trunk/api/src/main/java/org/teiid/language/SQLReservedWords.java 2010-06-04 21:35:06 UTC (rev 2180)
+++ trunk/api/src/main/java/org/teiid/language/SQLReservedWords.java 2010-06-04 21:51:29 UTC (rev 2181)
@@ -46,6 +46,39 @@
public static final String LPAREN = "("; //$NON-NLS-1$
public static final String RPAREN = ")"; //$NON-NLS-1$
}
+
+ public interface NonReserved {
+ public static final String SQL_TSI_FRAC_SECOND = "SQL_TSI_FRAC_SECOND"; //$NON-NLS-1$
+ public static final String SQL_TSI_SECOND = "SQL_TSI_SECOND"; //$NON-NLS-1$
+ public static final String SQL_TSI_MINUTE = "SQL_TSI_MINUTE"; //$NON-NLS-1$
+ public static final String SQL_TSI_HOUR = "SQL_TSI_HOUR"; //$NON-NLS-1$
+ public static final String SQL_TSI_DAY = "SQL_TSI_DAY"; //$NON-NLS-1$
+ public static final String SQL_TSI_WEEK = "SQL_TSI_WEEK"; //$NON-NLS-1$
+ public static final String SQL_TSI_MONTH = "SQL_TSI_MONTH"; //$NON-NLS-1$
+ public static final String SQL_TSI_QUARTER = "SQL_TSI_QUARTER"; //$NON-NLS-1$
+ public static final String SQL_TSI_YEAR = "SQL_TSI_YEAR"; //$NON-NLS-1$
+ public static final String TIMESTAMPADD = "TIMESTAMPADD"; //$NON-NLS-1$
+ public static final String TIMESTAMPDIFF = "TIMESTAMPDIFF"; //$NON-NLS-1$
+ //aggregate functions
+ public static final String MAX = "MAX"; //$NON-NLS-1$
+ public static final String MIN = "MIN"; //$NON-NLS-1$
+ public static final String COUNT = "COUNT"; //$NON-NLS-1$
+ public static final String AVG = "AVG"; //$NON-NLS-1$
+ public static final String SUM = "SUM"; //$NON-NLS-1$
+ //texttable
+ public static final String WIDTH = "WIDTH"; //$NON-NLS-1$
+ public static final String DELIMITER = "DELIMITER"; //$NON-NLS-1$
+ public static final String HEADER = "HEADER"; //$NON-NLS-1$
+ public static final String QUOTE = "QUOTE"; //$NON-NLS-1$
+ public static final String COLUMNS = "COLUMNS"; //$NON-NLS-1$
+ //xmltable
+ public static final String ORDINALITY = "ORDINALITY"; //$NON-NLS-1$
+ public static final String PASSING = "PASSING"; //$NON-NLS-1$
+ public static final String PATH = "PATH"; //$NON-NLS-1$
+ //xmlserialize
+ public static final String DOCUMENT = "DOCUMENT"; //$NON-NLS-1$
+ public static final String CONTENT = "CONTENT"; //$NON-NLS-1$
+ }
//Teiid specific
public static final String BIGDECIMAL = "BIGDECIMAL"; //$NON-NLS-1$
@@ -54,26 +87,13 @@
public static final String BYTE = "BYTE"; //$NON-NLS-1$
public static final String CRITERIA = "CRITERIA"; //$NON-NLS-1$
public static final String ERROR = "ERROR"; //$NON-NLS-1$
- public static final String FN = "FN"; //$NON-NLS-1$
public static final String LIMIT = "LIMIT"; //$NON-NLS-1$
public static final String LONG = "LONG"; //$NON-NLS-1$
public static final String LOOP = "LOOP"; //$NON-NLS-1$
public static final String MAKEDEP = "MAKEDEP"; //$NON-NLS-1$
public static final String MAKENOTDEP = "MAKENOTDEP"; //$NON-NLS-1$
public static final String NOCACHE = "NOCACHE"; //$NON-NLS-1$
- public static final String OJ = "OJ"; //$NON-NLS-1$
- public static final String SQL_TSI_FRAC_SECOND = "SQL_TSI_FRAC_SECOND"; //$NON-NLS-1$
- public static final String SQL_TSI_SECOND = "SQL_TSI_SECOND"; //$NON-NLS-1$
- public static final String SQL_TSI_MINUTE = "SQL_TSI_MINUTE"; //$NON-NLS-1$
- public static final String SQL_TSI_HOUR = "SQL_TSI_HOUR"; //$NON-NLS-1$
- public static final String SQL_TSI_DAY = "SQL_TSI_DAY"; //$NON-NLS-1$
- public static final String SQL_TSI_WEEK = "SQL_TSI_WEEK"; //$NON-NLS-1$
- public static final String SQL_TSI_MONTH = "SQL_TSI_MONTH"; //$NON-NLS-1$
- public static final String SQL_TSI_QUARTER = "SQL_TSI_QUARTER"; //$NON-NLS-1$
- public static final String SQL_TSI_YEAR = "SQL_TSI_YEAR"; //$NON-NLS-1$
- public static final String STRING = "STRING"; //$NON-NLS-1$
- public static final String TIMESTAMPADD = "TIMESTAMPADD"; //$NON-NLS-1$
- public static final String TIMESTAMPDIFF = "TIMESTAMPDIFF"; //$NON-NLS-1$
+ public static final String STRING = "STRING"; //$NON-NLS-1$
public static final String VIRTUAL = "VIRTUAL"; //$NON-NLS-1$
public static final String WHILE = "WHILE"; //$NON-NLS-1$
@@ -92,8 +112,7 @@
public static final String ASYMETRIC = "ASYMETRIC"; //$NON-NLS-1$
public static final String ATOMIC = "ATOMIC"; //$NON-NLS-1$
public static final String AUTHORIZATION = "AUTHORIZATION"; //$NON-NLS-1$
- public static final String AVG = "AVG"; //$NON-NLS-1$
- public static final String BEGIN = "BEGIN"; //$NON-NLS-1$
+ public static final String BEGIN = "BEGIN"; //$NON-NLS-1$
public static final String BETWEEN = "BETWEEN"; //$NON-NLS-1$
public static final String BIGINT = "BIGINT"; //$NON-NLS-1$
public static final String BINARY = "BINARY"; //$NON-NLS-1$
@@ -117,7 +136,6 @@
public static final String CONVERT = "CONVERT"; //$NON-NLS-1$
public static final String CONSTRAINT = "CONSTRAINT"; //$NON-NLS-1$
public static final String CONTINUE = "CONTINUE"; //$NON-NLS-1$
- public static final String COUNT = "COUNT"; //$NON-NLS-1$
public static final String CORRESPONDING = "CORRESPONDING"; //$NON-NLS-1$
public static final String CREATE = "CREATE"; //$NON-NLS-1$
public static final String CROSS = "CROSS"; //$NON-NLS-1$
@@ -201,9 +219,7 @@
public static final String LOCALTIME = "LOCALTIME"; //$NON-NLS-1$
public static final String LOCALTIMESTAMP = "LOCALTIMESTAMP"; //$NON-NLS-1$
public static final String MATCH = "MATCH"; //$NON-NLS-1$
- public static final String MAX = "MAX"; //$NON-NLS-1$
- public static final String MIN = "MIN"; //$NON-NLS-1$
- public static final String MEMBER = "MEMBER"; //$NON-NLS-1$
+ public static final String MEMBER = "MEMBER"; //$NON-NLS-1$
public static final String MERGE = "MERGE"; //$NON-NLS-1$
public static final String METHOD = "METHOD"; //$NON-NLS-1$
public static final String MINUTE = "MINUTE"; //$NON-NLS-1$
@@ -280,8 +296,7 @@
public static final String SYMETRIC = "SYMETRIC"; //$NON-NLS-1$
public static final String SYSTEM = "SYSTEM"; //$NON-NLS-1$
public static final String SYSTEM_USER = "SYSTEM_USER"; //$NON-NLS-1$
- public static final String SUM = "SUM"; //$NON-NLS-1$
- public static final String TABLE = "TABLE"; //$NON-NLS-1$
+ public static final String TABLE = "TABLE"; //$NON-NLS-1$
public static final String TEMPORARY = "TEMPORARY"; //$NON-NLS-1$
public static final String THEN = "THEN"; //$NON-NLS-1$
public static final String TIME = "TIME"; //$NON-NLS-1$
Modified: trunk/api/src/main/java/org/teiid/language/visitor/SQLStringVisitor.java
===================================================================
--- trunk/api/src/main/java/org/teiid/language/visitor/SQLStringVisitor.java 2010-06-04 21:35:06 UTC (rev 2180)
+++ trunk/api/src/main/java/org/teiid/language/visitor/SQLStringVisitor.java 2010-06-04 21:51:29 UTC (rev 2181)
@@ -70,6 +70,7 @@
import org.teiid.language.TableReference;
import org.teiid.language.Update;
import org.teiid.language.Argument.Direction;
+import org.teiid.language.SQLReservedWords.NonReserved;
import org.teiid.language.SQLReservedWords.Tokens;
import org.teiid.language.SortSpecification.Ordering;
import org.teiid.metadata.AbstractMetadataRecord;
@@ -393,7 +394,7 @@
}
buffer.append(Tokens.RPAREN);
- } else if(name.equalsIgnoreCase(SQLReservedWords.TIMESTAMPADD) || name.equalsIgnoreCase(SQLReservedWords.TIMESTAMPDIFF)) {
+ } else if(name.equalsIgnoreCase(NonReserved.TIMESTAMPADD) || name.equalsIgnoreCase(NonReserved.TIMESTAMPDIFF)) {
buffer.append(name);
buffer.append(Tokens.LPAREN);
Modified: trunk/api/src/main/java/org/teiid/translator/SourceSystemFunctions.java
===================================================================
--- trunk/api/src/main/java/org/teiid/translator/SourceSystemFunctions.java 2010-06-04 21:35:06 UTC (rev 2180)
+++ trunk/api/src/main/java/org/teiid/translator/SourceSystemFunctions.java 2010-06-04 21:51:29 UTC (rev 2181)
@@ -136,7 +136,6 @@
//xml
public static final String XPATHVALUE = "xpathvalue"; //$NON-NLS-1$
- public static final String XPATHQUERY = "xpathquery"; //$NON-NLS-1$
public static final String XSLTRANSFORM = "xsltransform"; //$NON-NLS-1$
public static final String XMLCONCAT = "xmlconcat"; //$NON-NLS-1$
public static final String XMLCOMMENT = "xmlcomment"; //$NON-NLS-1$
Modified: trunk/client/src/main/java/org/teiid/jdbc/DatabaseMetaDataImpl.java
===================================================================
--- trunk/client/src/main/java/org/teiid/jdbc/DatabaseMetaDataImpl.java 2010-06-04 21:35:06 UTC (rev 2180)
+++ trunk/client/src/main/java/org/teiid/jdbc/DatabaseMetaDataImpl.java 2010-06-04 21:51:29 UTC (rev 2181)
@@ -70,9 +70,8 @@
private final static String EXTRA_CHARS = ".@"; //$NON-NLS-1$
// constant value giving the key words not in SQL-92
final static String KEY_WORDS = "OPTION, BIGDECIMAL"+ //$NON-NLS-1$
- ", BIGDECIMAL, BIGINTEGER, BREAK, BYTE, CRITERIA, ERROR, FN, LIMIT, LONG, LOOP, MAKEDEP, MAKENOTDEP"+ //$NON-NLS-1$
- ", NOCACHE, OJ, SQL_TSI_FRAC_SECOND, SQL_TSI_SECOND, SQL_TSI_MINUTE, SQL_TSI_HOUR, SQL_TSI_DAY, SQL_TSI_WEEK, SQL_TSI_MONTH"+ //$NON-NLS-1$
- ", SQL_TSI_QUARTER, SQL_TSI_YEAR, STRING, TIMESTAMPADD, TIMESTAMPDIFF, VIRTUAL, WHILE"; //$NON-NLS-1$
+ ", BIGDECIMAL, BIGINTEGER, BREAK, BYTE, CRITERIA, ERROR, LIMIT, LONG, LOOP, MAKEDEP, MAKENOTDEP"+ //$NON-NLS-1$
+ ", NOCACHE, STRING, VIRTUAL, WHILE"; //$NON-NLS-1$
// constant value giving preferred name for a procedure
private final static String PROCEDURE_TERM = "StoredProcedure"; //$NON-NLS-1$
// constant value giving the names of numeric functions supported
Modified: trunk/common-core/src/main/java/org/teiid/core/types/Streamable.java
===================================================================
--- trunk/common-core/src/main/java/org/teiid/core/types/Streamable.java 2010-06-04 21:35:06 UTC (rev 2180)
+++ trunk/common-core/src/main/java/org/teiid/core/types/Streamable.java 2010-06-04 21:51:29 UTC (rev 2181)
@@ -84,6 +84,9 @@
@Override
public String toString() {
+ if (reference == null) {
+ return super.toString();
+ }
return reference.toString();
}
Modified: trunk/common-core/src/main/java/org/teiid/core/types/basic/StringToSQLXMLTransform.java
===================================================================
--- trunk/common-core/src/main/java/org/teiid/core/types/basic/StringToSQLXMLTransform.java 2010-06-04 21:35:06 UTC (rev 2180)
+++ trunk/common-core/src/main/java/org/teiid/core/types/basic/StringToSQLXMLTransform.java 2010-06-04 21:51:29 UTC (rev 2181)
@@ -58,7 +58,7 @@
return result;
}
- static Type isXml(Reader reader) throws TransformationException {
+ public static Type isXml(Reader reader) throws TransformationException {
Type type = Type.FRAGMENT;
XMLInputFactory inputFactory = XMLInputFactory.newInstance();
try{
Modified: trunk/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/hsql/AddDiffModifier.java
===================================================================
--- trunk/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/hsql/AddDiffModifier.java 2010-06-04 21:35:06 UTC (rev 2180)
+++ trunk/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/hsql/AddDiffModifier.java 2010-06-04 21:51:29 UTC (rev 2181)
@@ -31,7 +31,7 @@
import org.teiid.language.Function;
import org.teiid.language.LanguageFactory;
import org.teiid.language.Literal;
-import org.teiid.language.SQLReservedWords;
+import org.teiid.language.SQLReservedWords.NonReserved;
import org.teiid.translator.TypeFacility;
import org.teiid.translator.jdbc.ExtractFunctionModifier;
import org.teiid.translator.jdbc.FunctionModifier;
@@ -41,12 +41,12 @@
private static Map<String, String> INTERVAL_MAP = new HashMap<String, String>();
static {
- INTERVAL_MAP.put(SQLReservedWords.SQL_TSI_DAY, ExtractFunctionModifier.DAY);
- INTERVAL_MAP.put(SQLReservedWords.SQL_TSI_HOUR, ExtractFunctionModifier.HOUR);
- INTERVAL_MAP.put(SQLReservedWords.SQL_TSI_MINUTE, ExtractFunctionModifier.MINUTE);
- INTERVAL_MAP.put(SQLReservedWords.SQL_TSI_MONTH, ExtractFunctionModifier.MONTH);
- INTERVAL_MAP.put(SQLReservedWords.SQL_TSI_SECOND, ExtractFunctionModifier.SECOND);
- INTERVAL_MAP.put(SQLReservedWords.SQL_TSI_YEAR, ExtractFunctionModifier.YEAR);
+ INTERVAL_MAP.put(NonReserved.SQL_TSI_DAY, ExtractFunctionModifier.DAY);
+ INTERVAL_MAP.put(NonReserved.SQL_TSI_HOUR, ExtractFunctionModifier.HOUR);
+ INTERVAL_MAP.put(NonReserved.SQL_TSI_MINUTE, ExtractFunctionModifier.MINUTE);
+ INTERVAL_MAP.put(NonReserved.SQL_TSI_MONTH, ExtractFunctionModifier.MONTH);
+ INTERVAL_MAP.put(NonReserved.SQL_TSI_SECOND, ExtractFunctionModifier.SECOND);
+ INTERVAL_MAP.put(NonReserved.SQL_TSI_YEAR, ExtractFunctionModifier.YEAR);
}
private boolean add;
@@ -72,11 +72,11 @@
return null;
}
if (add) {
- if (interval.equals(SQLReservedWords.SQL_TSI_FRAC_SECOND)) {
+ if (interval.equals(NonReserved.SQL_TSI_FRAC_SECOND)) {
intervalType.setValue("MILLISECOND"); //$NON-NLS-1$
Expression[] args = new Expression[] {function.getParameters().get(1), factory.createLiteral(1000000, TypeFacility.RUNTIME_TYPES.INTEGER)};
function.getParameters().set(1, factory.createFunction("/", args, TypeFacility.RUNTIME_TYPES.INTEGER)); //$NON-NLS-1$
- } else if (interval.equals(SQLReservedWords.SQL_TSI_QUARTER)) {
+ } else if (interval.equals(NonReserved.SQL_TSI_QUARTER)) {
intervalType.setValue(ExtractFunctionModifier.DAY);
Expression[] args = new Expression[] {function.getParameters().get(1), factory.createLiteral(91, TypeFacility.RUNTIME_TYPES.INTEGER)};
function.getParameters().set(1, factory.createFunction("*", args, TypeFacility.RUNTIME_TYPES.INTEGER)); //$NON-NLS-1$
@@ -87,10 +87,10 @@
}
return null;
}
- if (interval.equals(SQLReservedWords.SQL_TSI_FRAC_SECOND)) {
+ if (interval.equals(NonReserved.SQL_TSI_FRAC_SECOND)) {
intervalType.setValue("MILLISECOND"); //$NON-NLS-1$
return Arrays.asList(function, " * 1000000"); //$NON-NLS-1$
- } else if (interval.equals(SQLReservedWords.SQL_TSI_QUARTER)) {
+ } else if (interval.equals(NonReserved.SQL_TSI_QUARTER)) {
intervalType.setValue(ExtractFunctionModifier.DAY);
return Arrays.asList(function, " / 91"); //$NON-NLS-1$
}
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-04 21:35:06 UTC (rev 2180)
+++ trunk/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/postgresql/PostgreSQLExecutionFactory.java 2010-06-04 21:51:29 UTC (rev 2181)
@@ -35,7 +35,7 @@
import org.teiid.language.LanguageObject;
import org.teiid.language.Limit;
import org.teiid.language.Literal;
-import org.teiid.language.SQLReservedWords;
+import org.teiid.language.SQLReservedWords.NonReserved;
import org.teiid.translator.Translator;
import org.teiid.translator.TranslatorException;
import org.teiid.translator.ExecutionContext;
@@ -205,9 +205,9 @@
if (obj instanceof AggregateFunction) {
AggregateFunction agg = (AggregateFunction)obj;
if (agg.getExpression() != null && TypeFacility.RUNTIME_TYPES.BOOLEAN.equals(agg.getExpression().getType())) {
- if (agg.getName().equalsIgnoreCase(SQLReservedWords.MIN)) {
+ if (agg.getName().equalsIgnoreCase(NonReserved.MIN)) {
agg.setName("bool_and"); //$NON-NLS-1$
- } else if (agg.getName().equalsIgnoreCase(SQLReservedWords.MAX)) {
+ } else if (agg.getName().equalsIgnoreCase(NonReserved.MAX)) {
agg.setName("bool_or"); //$NON-NLS-1$
}
}
Modified: trunk/connectors/translator-jdbc/src/test/java/org/teiid/translator/jdbc/TestEscapeSyntaxModifier.java
===================================================================
--- trunk/connectors/translator-jdbc/src/test/java/org/teiid/translator/jdbc/TestEscapeSyntaxModifier.java 2010-06-04 21:35:06 UTC (rev 2180)
+++ trunk/connectors/translator-jdbc/src/test/java/org/teiid/translator/jdbc/TestEscapeSyntaxModifier.java 2010-06-04 21:51:29 UTC (rev 2181)
@@ -29,7 +29,7 @@
import org.teiid.cdk.CommandBuilder;
import org.teiid.language.Function;
import org.teiid.language.Literal;
-import org.teiid.language.SQLReservedWords;
+import org.teiid.language.SQLReservedWords.NonReserved;
import org.teiid.query.unittest.TimestampUtil;
import org.teiid.translator.jdbc.EscapeSyntaxModifier;
@@ -57,7 +57,7 @@
}
public void testTimestampAdd() {
- Literal arg1 = CommandBuilder.getLanuageFactory().createLiteral(SQLReservedWords.SQL_TSI_HOUR, String.class);
+ Literal arg1 = CommandBuilder.getLanuageFactory().createLiteral(NonReserved.SQL_TSI_HOUR, String.class);
Literal arg2 = CommandBuilder.getLanuageFactory().createLiteral(Integer.valueOf(1), Integer.class);
Literal arg3 = CommandBuilder.getLanuageFactory().createLiteral(TimestampUtil.createTimestamp(0, 0, 0, 0, 0, 0, 0), Timestamp.class);
Function func = CommandBuilder.getLanuageFactory().createFunction("timestampadd", Arrays.asList( arg1, arg2, arg3), Timestamp.class); //$NON-NLS-1$
Modified: trunk/documentation/reference/src/main/docbook/en-US/content/federated_planning.xml
===================================================================
--- trunk/documentation/reference/src/main/docbook/en-US/content/federated_planning.xml 2010-06-04 21:35:06 UTC (rev 2180)
+++ trunk/documentation/reference/src/main/docbook/en-US/content/federated_planning.xml 2010-06-04 21:51:29 UTC (rev 2181)
@@ -654,7 +654,7 @@
<sect1 id="query_planner">
<title>Query Planner</title>
<para>For each sub-command in the user command an appropriate kind
- of sub-planner is used (relational, XML, XQuery, procedure,
+ of sub-planner is used (relational, XML, procedure,
etc).</para>
<para>Each planner has three primary phases:</para>
<orderedlist>
@@ -1045,10 +1045,5 @@
of repeated fragments (each a new query) until some termination
criteria or limit is met.</para>
</sect2>
- <sect2>
- <title>XQuery Planner</title>
- <para>XQuery planning uses the embedded Saxon XQuery
- engine to compile the query. There is no direct optimization by Teiid.</para>
- </sect2>
</sect1>
</chapter>
\ No newline at end of file
Modified: trunk/documentation/reference/src/main/docbook/en-US/content/scalar_functions.xml
===================================================================
--- trunk/documentation/reference/src/main/docbook/en-US/content/scalar_functions.xml 2010-06-04 21:35:06 UTC (rev 2180)
+++ trunk/documentation/reference/src/main/docbook/en-US/content/scalar_functions.xml 2010-06-04 21:51:29 UTC (rev 2181)
@@ -1932,34 +1932,20 @@
<tbody>
<row>
<entry>
- <para><code>XPATHVALUE(doc, xpath [, namepaces])</code></para>
+ <para><code>XPATHVALUE(doc, xpath)</code></para>
</entry>
<entry>
<para>Applies the XPATH query to the document and returns a
string value for the first matching result. An attempt is made to provide a
meaningful result for non-text nodes.</para>
- <para>The optional namespaces string is used to provide default and prefix to uri mappings for the given xpath. The format is the same as namespace declarations in an xml element: xmlns:foo="uri"</para>
</entry>
<entry>
- <para>Doc in {string, xml} and xpath, namespaces in {string}. Return value is a string.
+ <para>Doc in {string, xml} and xpath. Return value is a string.
</para>
</entry>
</row>
<row>
<entry>
- <para><code>XPATHQUERY(doc, xpath [, namepaces])</code></para>
- </entry>
- <entry>
- <para>Takes a document and an XPATH query and returns a SQL/XML of the result.</para>
- <para>The optional namespaces string is used to provide default and prefix to uri mappings for the given xpath. The format is the same as namespace declarations in an xml element: xmlns:foo="uri"</para>
- </entry>
- <entry>
- <para>Doc in {string, xml} and xpath, namespaces in {string}. Return value is a string.
- </para>
- </entry>
- </row>
- <row>
- <entry>
<para><code>XSLTRANSFORM(doc, xsl)</code></para>
</entry>
<entry>
@@ -2043,6 +2029,21 @@
</para>
</entry>
</row>
+ <row>
+ <entry>
+ <para><code>XMLSERIALIZE((DOCUMENT|CONTENT) exp [AS datatype])</code></para>
+ </entry>
+ <entry>
+ <para>Returns a character type representation of the exp.
+ Only a character type (string, varchar, clob) may be specified as the datatype.
+ If DOCUMENT is specified and the xml is not a valid document or fragment, then an exception is raised.
+ </para>
+ </entry>
+ <entry>
+ <para>Exp is xml. Return value mathces datatype.
+ </para>
+ </entry>
+ </row>
</tbody>
</tgroup>
</informaltable>
Modified: trunk/documentation/reference/src/main/docbook/en-US/content/transaction_support.xml
===================================================================
--- trunk/documentation/reference/src/main/docbook/en-US/content/transaction_support.xml 2010-06-04 21:35:06 UTC (rev 2180)
+++ trunk/documentation/reference/src/main/docbook/en-US/content/transaction_support.xml 2010-06-04 21:51:29 UTC (rev 2181)
@@ -93,7 +93,7 @@
</para>
</listitem>
<listitem>
- <para>If the user command is a SELECT (including XML) or an XQuery and the transaction isolation is not REPEATABLE_READ nor SERIALIABLE.
+ <para>If the user command is a SELECT (including XML) and the transaction isolation is not REPEATABLE_READ nor SERIALIABLE.
</para>
</listitem>
<listitem>
Modified: trunk/engine/pom.xml
===================================================================
--- trunk/engine/pom.xml 2010-06-04 21:35:06 UTC (rev 2180)
+++ trunk/engine/pom.xml 2010-06-04 21:51:29 UTC (rev 2181)
@@ -83,13 +83,14 @@
</dependency>
<dependency>
- <groupId>net.sf.saxon</groupId>
+ <groupId>net.sourceforge.saxon</groupId>
<artifactId>saxon</artifactId>
</dependency>
<dependency>
- <groupId>net.sf.saxon</groupId>
- <artifactId>saxon-dom</artifactId>
+ <groupId>net.sourceforge.saxon</groupId>
+ <classifier>dom</classifier>
+ <artifactId>saxon</artifactId>
</dependency>
<dependency>
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-04 21:35:06 UTC (rev 2180)
+++ trunk/engine/src/main/java/org/teiid/dqp/internal/process/MetaDataProcessor.java 2010-06-04 21:51:29 UTC (rev 2181)
@@ -29,6 +29,8 @@
import java.util.Map;
import java.util.Set;
+import nux.xom.xquery.XQuery;
+
import org.teiid.api.exception.query.QueryMetadataException;
import org.teiid.api.exception.query.QueryParserException;
import org.teiid.api.exception.query.QueryResolverException;
@@ -43,7 +45,7 @@
import org.teiid.dqp.internal.process.SessionAwareCache.CacheID;
import org.teiid.dqp.internal.process.multisource.MultiSourceMetadataWrapper;
import org.teiid.dqp.message.RequestID;
-import org.teiid.language.SQLReservedWords;
+import org.teiid.language.SQLReservedWords.NonReserved;
import org.teiid.query.analysis.AnalysisRecord;
import org.teiid.query.metadata.QueryMetadataInterface;
import org.teiid.query.metadata.SupportConstants;
@@ -54,7 +56,6 @@
import org.teiid.query.resolver.QueryResolver;
import org.teiid.query.sql.lang.Command;
import org.teiid.query.sql.lang.Query;
-import org.teiid.query.sql.lang.XQuery;
import org.teiid.query.sql.symbol.AggregateSymbol;
import org.teiid.query.sql.symbol.AliasSymbol;
import org.teiid.query.sql.symbol.ElementSymbol;
@@ -161,10 +162,6 @@
case Command.TYPE_CREATE:
case Command.TYPE_DROP:
break;
- case Command.TYPE_XQUERY:
- columnMetadata = new Map[1];
- columnMetadata[0] = createXQueryColumnMetadata((XQuery)originalCommand);
- break;
default:
columnMetadata = createProjectedSymbolMetadata(originalCommand);
}
@@ -322,7 +319,7 @@
Expression expression = symbol.getExpression();
String function = symbol.getAggregateFunction();
- if(function.equals(SQLReservedWords.MIN) || function.equals(SQLReservedWords.MAX)){
+ if(function.equals(NonReserved.MIN) || function.equals(NonReserved.MAX)){
if(expression instanceof ElementSymbol) {
return createColumnMetadata(shortColumnName, (ElementSymbol)expression);
}
Modified: trunk/engine/src/main/java/org/teiid/dqp/internal/process/Request.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/dqp/internal/process/Request.java 2010-06-04 21:35:06 UTC (rev 2180)
+++ trunk/engine/src/main/java/org/teiid/dqp/internal/process/Request.java 2010-06-04 21:51:29 UTC (rev 2181)
@@ -71,7 +71,6 @@
import org.teiid.query.processor.QueryProcessor;
import org.teiid.query.processor.TempTableDataManager;
import org.teiid.query.processor.xml.XMLPlan;
-import org.teiid.query.processor.xquery.XQueryPlan;
import org.teiid.query.resolver.QueryResolver;
import org.teiid.query.rewriter.QueryRewriter;
import org.teiid.query.sql.lang.BatchedUpdateCommand;
@@ -81,7 +80,6 @@
import org.teiid.query.sql.lang.QueryCommand;
import org.teiid.query.sql.lang.SetQuery;
import org.teiid.query.sql.lang.StoredProcedure;
-import org.teiid.query.sql.lang.XQuery;
import org.teiid.query.sql.symbol.Constant;
import org.teiid.query.sql.symbol.Reference;
import org.teiid.query.sql.visitor.ReferenceCollectorVisitor;
@@ -206,9 +204,6 @@
} else if (userCommand instanceof SetQuery) {
returnsResultSet = true;
returnsUpdateCount = false;
- } else if (userCommand instanceof XQuery) {
- returnsResultSet = true;
- returnsUpdateCount = false;
} else if (userCommand instanceof StoredProcedure) {
returnsUpdateCount = false;
StoredProcedure proc = (StoredProcedure)userCommand;
@@ -462,23 +457,14 @@
}
private void postProcessXML() {
- if (requestMsg.getXMLFormat() != null) {
- if(processPlan instanceof XQueryPlan) {
- ((XQueryPlan)processPlan).setXMLFormat(requestMsg.getXMLFormat());
- } else if (processPlan instanceof XMLPlan) {
- ((XMLPlan)processPlan).setXMLFormat(requestMsg.getXMLFormat());
- }
+ if (requestMsg.getXMLFormat() != null && processPlan instanceof XMLPlan) {
+ ((XMLPlan)processPlan).setXMLFormat(requestMsg.getXMLFormat());
}
this.context.setValidateXML(requestMsg.getValidationMode());
}
public QueryProcessor createQueryProcessor(String query, String recursionGroup, CommandContext commandContext) throws TeiidProcessingException, TeiidComponentException {
- boolean isRootXQuery = recursionGroup == null && commandContext.getCallStackDepth() == 0 && userCommand instanceof XQuery;
-
ParseInfo parseInfo = new ParseInfo();
- if (isRootXQuery) {
- parseInfo.ansiQuotedIdentifiers = requestMsg.isAnsiQuotedIdentifiers();
- }
Command newCommand = QueryParser.getQueryParser().parseCommand(query, parseInfo);
QueryResolver.resolveCommand(newCommand, metadata);
@@ -488,10 +474,6 @@
validateQuery(newCommand);
- if (isRootXQuery) {
- validateAccess(newCommand);
- }
-
CommandContext copy = (CommandContext) commandContext.clone();
if (recursionGroup != null) {
copy.pushCall(recursionGroup);
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-04 21:35:06 UTC (rev 2180)
+++ trunk/engine/src/main/java/org/teiid/query/eval/Evaluator.java 2010-06-04 21:51:29 UTC (rev 2181)
@@ -40,7 +40,12 @@
import org.teiid.core.ComponentNotFoundException;
import org.teiid.core.TeiidComponentException;
import org.teiid.core.TeiidProcessingException;
+import org.teiid.core.types.DataTypeManager;
import org.teiid.core.types.Sequencable;
+import org.teiid.core.types.TransformationException;
+import org.teiid.core.types.XMLType;
+import org.teiid.core.types.XMLType.Type;
+import org.teiid.core.types.basic.StringToSQLXMLTransform;
import org.teiid.core.util.Assertion;
import org.teiid.core.util.EquivalenceUtil;
import org.teiid.query.QueryPlugin;
@@ -66,10 +71,11 @@
import org.teiid.query.sql.lang.SubqueryContainer;
import org.teiid.query.sql.lang.SubquerySetCriteria;
import org.teiid.query.sql.symbol.AggregateSymbol;
-import org.teiid.query.sql.symbol.AliasSymbol;
import org.teiid.query.sql.symbol.CaseExpression;
import org.teiid.query.sql.symbol.Constant;
import org.teiid.query.sql.symbol.ContextReference;
+import org.teiid.query.sql.symbol.DerivedColumn;
+import org.teiid.query.sql.symbol.ElementSymbol;
import org.teiid.query.sql.symbol.Expression;
import org.teiid.query.sql.symbol.ExpressionSymbol;
import org.teiid.query.sql.symbol.Function;
@@ -80,6 +86,7 @@
import org.teiid.query.sql.symbol.XMLElement;
import org.teiid.query.sql.symbol.XMLForest;
import org.teiid.query.sql.symbol.XMLNamespaces;
+import org.teiid.query.sql.symbol.XMLSerialize;
import org.teiid.query.sql.symbol.XMLNamespaces.NamespaceItem;
import org.teiid.query.sql.util.ValueIterator;
import org.teiid.query.sql.util.ValueIteratorSource;
@@ -584,7 +591,7 @@
}
} else if (expression instanceof XMLForest){
XMLForest function = (XMLForest)expression;
- List<SingleElementSymbol> args = function.getArgs();
+ List<DerivedColumn> args = function.getArgs();
NameValuePair<Object>[] nameValuePairs = getNameValuePairs(tuple, args);
try {
@@ -592,20 +599,43 @@
} catch (TeiidProcessingException e) {
throw new FunctionExecutionException(e, e.getMessage());
}
+ } else if (expression instanceof XMLSerialize){
+ XMLSerialize xs = (XMLSerialize)expression;
+ XMLType value = (XMLType) internalEvaluate(xs.getExpression(), tuple);
+ if (value == null) {
+ return null;
+ }
+ try {
+ if (!xs.isDocument()) {
+ return DataTypeManager.transformValue(value, xs.getType());
+ }
+ if (value.getType() == Type.UNKNOWN) {
+ Type type = StringToSQLXMLTransform.isXml(value.getCharacterStream());
+ value.setType(type);
+ }
+ if (value.getType() == Type.DOCUMENT || value.getType() == Type.FRAGMENT) {
+ return DataTypeManager.transformValue(value, xs.getType());
+ }
+ } catch (SQLException e) {
+ throw new FunctionExecutionException(e, e.getMessage());
+ } catch (TransformationException e) {
+ throw new FunctionExecutionException(e, e.getMessage());
+ }
+ throw new FunctionExecutionException(QueryPlugin.Util.getString("Evaluator.xmlserialize")); //$NON-NLS-1$
} else {
throw new TeiidComponentException(ErrorMessageKeys.PROCESSOR_0016, QueryPlugin.Util.getString(ErrorMessageKeys.PROCESSOR_0016, expression.getClass().getName()));
}
}
- private NameValuePair<Object>[] getNameValuePairs(List tuple, List<SingleElementSymbol> args)
+ private NameValuePair<Object>[] getNameValuePairs(List tuple, List<DerivedColumn> args)
throws ExpressionEvaluationException, BlockedException, TeiidComponentException {
NameValuePair<Object>[] nameValuePairs = new NameValuePair[args.size()];
for (int i = 0; i < args.size(); i++) {
- SingleElementSymbol symbol = args.get(i);
- String name = symbol.getShortName();
- Expression ex = symbol;
- if (symbol instanceof AliasSymbol) {
- ex = ((AliasSymbol) symbol).getSymbol();
+ DerivedColumn symbol = args.get(i);
+ String name = symbol.getAlias();
+ Expression ex = symbol.getExpression();
+ if (name == null && ex instanceof ElementSymbol) {
+ name = ((ElementSymbol)ex).getShortName();
}
nameValuePairs[i] = new NameValuePair<Object>(name, internalEvaluate(ex, tuple));
}
Modified: trunk/engine/src/main/java/org/teiid/query/function/FunctionMethods.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/function/FunctionMethods.java 2010-06-04 21:35:06 UTC (rev 2180)
+++ trunk/engine/src/main/java/org/teiid/query/function/FunctionMethods.java 2010-06-04 21:51:29 UTC (rev 2181)
@@ -41,7 +41,7 @@
import org.teiid.core.types.DataTypeManager;
import org.teiid.core.types.TransformationException;
import org.teiid.core.util.TimestampWithTimezone;
-import org.teiid.language.SQLReservedWords;
+import org.teiid.language.SQLReservedWords.NonReserved;
import org.teiid.query.QueryPlugin;
import org.teiid.query.util.CommandContext;
import org.teiid.query.util.ErrorMessageKeys;
@@ -450,7 +450,7 @@
cal.setTime(timestamp);
// case of interval = 1, fractional seconds (nanos), don't go to branches of addField()
- if (intervalType.equalsIgnoreCase(SQLReservedWords.SQL_TSI_FRAC_SECOND)) {
+ if (intervalType.equalsIgnoreCase(NonReserved.SQL_TSI_FRAC_SECOND)) {
int countValue = count.intValue();
nanos += countValue;
@@ -488,23 +488,23 @@
private static void addField(String interval, Integer count, Calendar cal) {
int countValue = count.intValue();
- if(interval.equalsIgnoreCase(SQLReservedWords.SQL_TSI_FRAC_SECOND)) {
+ if(interval.equalsIgnoreCase(NonReserved.SQL_TSI_FRAC_SECOND)) {
//nano seconds - should never get into this branch
- } else if(interval.equalsIgnoreCase(SQLReservedWords.SQL_TSI_SECOND)) {
+ } else if(interval.equalsIgnoreCase(NonReserved.SQL_TSI_SECOND)) {
cal.add(Calendar.SECOND, countValue);
- } else if(interval.equalsIgnoreCase(SQLReservedWords.SQL_TSI_MINUTE)) {
+ } else if(interval.equalsIgnoreCase(NonReserved.SQL_TSI_MINUTE)) {
cal.add(Calendar.MINUTE, countValue);
- } else if(interval.equalsIgnoreCase(SQLReservedWords.SQL_TSI_HOUR)) {
+ } else if(interval.equalsIgnoreCase(NonReserved.SQL_TSI_HOUR)) {
cal.add(Calendar.HOUR_OF_DAY, countValue);
- } else if(interval.equalsIgnoreCase(SQLReservedWords.SQL_TSI_DAY)) {
+ } else if(interval.equalsIgnoreCase(NonReserved.SQL_TSI_DAY)) {
cal.add(Calendar.DAY_OF_YEAR, countValue);
- } else if(interval.equalsIgnoreCase(SQLReservedWords.SQL_TSI_WEEK)) {
+ } else if(interval.equalsIgnoreCase(NonReserved.SQL_TSI_WEEK)) {
cal.add(Calendar.WEEK_OF_YEAR, countValue);
- } else if(interval.equalsIgnoreCase(SQLReservedWords.SQL_TSI_MONTH)) {
+ } else if(interval.equalsIgnoreCase(NonReserved.SQL_TSI_MONTH)) {
cal.add(Calendar.MONTH, countValue);
- } else if(interval.equalsIgnoreCase(SQLReservedWords.SQL_TSI_QUARTER)) {
+ } else if(interval.equalsIgnoreCase(NonReserved.SQL_TSI_QUARTER)) {
cal.add(Calendar.MONTH, countValue*3);
- } else if(interval.equalsIgnoreCase(SQLReservedWords.SQL_TSI_YEAR)) {
+ } else if(interval.equalsIgnoreCase(NonReserved.SQL_TSI_YEAR)) {
cal.add(Calendar.YEAR, countValue);
}
}
@@ -526,25 +526,25 @@
long tsDiff = ts2 - ts1;
long count = 0;
- if(intervalType.equalsIgnoreCase(SQLReservedWords.SQL_TSI_FRAC_SECOND)) {
+ if(intervalType.equalsIgnoreCase(NonReserved.SQL_TSI_FRAC_SECOND)) {
count = tsDiff;
} else {
tsDiff = tsDiff / 1000000; //convert to milliseconds
- if(intervalType.equalsIgnoreCase(SQLReservedWords.SQL_TSI_SECOND)) {
+ if(intervalType.equalsIgnoreCase(NonReserved.SQL_TSI_SECOND)) {
count = tsDiff / 1000;
- } else if(intervalType.equalsIgnoreCase(SQLReservedWords.SQL_TSI_MINUTE)) {
+ } else if(intervalType.equalsIgnoreCase(NonReserved.SQL_TSI_MINUTE)) {
count = (tsDiff / 1000) / 60;
- } else if(intervalType.equalsIgnoreCase(SQLReservedWords.SQL_TSI_HOUR)) {
+ } else if(intervalType.equalsIgnoreCase(NonReserved.SQL_TSI_HOUR)) {
count = (tsDiff / 1000) / (60*60);
- } else if(intervalType.equalsIgnoreCase(SQLReservedWords.SQL_TSI_DAY)) {
+ } else if(intervalType.equalsIgnoreCase(NonReserved.SQL_TSI_DAY)) {
count = (tsDiff / 1000) / (60*60*24);
- } else if(intervalType.equalsIgnoreCase(SQLReservedWords.SQL_TSI_WEEK)) {
+ } else if(intervalType.equalsIgnoreCase(NonReserved.SQL_TSI_WEEK)) {
count = (tsDiff / 1000) / (60*60*24*7);
- } else if(intervalType.equalsIgnoreCase(SQLReservedWords.SQL_TSI_MONTH)) {
+ } else if(intervalType.equalsIgnoreCase(NonReserved.SQL_TSI_MONTH)) {
count = (tsDiff / 1000) / (60*60*24*30);
- } else if(intervalType.equalsIgnoreCase(SQLReservedWords.SQL_TSI_QUARTER)) {
+ } else if(intervalType.equalsIgnoreCase(NonReserved.SQL_TSI_QUARTER)) {
count = (tsDiff / 1000) / (60*60*24*91);
- } else if(intervalType.equalsIgnoreCase(SQLReservedWords.SQL_TSI_YEAR)) {
+ } else if(intervalType.equalsIgnoreCase(NonReserved.SQL_TSI_YEAR)) {
count = (tsDiff / 1000) / (60*60*24*365);
}
}
Modified: trunk/engine/src/main/java/org/teiid/query/function/source/SystemSource.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/function/source/SystemSource.java 2010-06-04 21:35:06 UTC (rev 2180)
+++ trunk/engine/src/main/java/org/teiid/query/function/source/SystemSource.java 2010-06-04 21:51:29 UTC (rev 2181)
@@ -166,7 +166,6 @@
addParseNumberFunctions();
// xml functions
- addXpathQueryFunction();
addXpathValueFunction();
addXslTransformFunction();
addXmlConcat();
@@ -893,52 +892,8 @@
new FunctionParameter("document", DataTypeManager.DefaultDataTypes.XML, QueryPlugin.Util.getString("SystemSource.xpath_param1")), //$NON-NLS-1$ //$NON-NLS-2$
new FunctionParameter("xpath", DataTypeManager.DefaultDataTypes.STRING, QueryPlugin.Util.getString("SystemSource.xpath_param2"))}, //$NON-NLS-1$ //$NON-NLS-2$
new FunctionParameter("result", DataTypeManager.DefaultDataTypes.STRING, QueryPlugin.Util.getString("SystemSource.xpathvalue_result")) ) ); //$NON-NLS-1$ //$NON-NLS-2$
-
- functions.add(new FunctionMethod(SourceSystemFunctions.XPATHVALUE, QueryPlugin.Util.getString("SystemSource.xpathvalue_description"), XML, XML_FUNCTION_CLASS, "xpathValue", //$NON-NLS-1$ //$NON-NLS-2$
- new FunctionParameter[] {
- new FunctionParameter("document", DataTypeManager.DefaultDataTypes.STRING, QueryPlugin.Util.getString("SystemSource.xpath_param1")), //$NON-NLS-1$ //$NON-NLS-2$
- new FunctionParameter("xpath", DataTypeManager.DefaultDataTypes.STRING, QueryPlugin.Util.getString("SystemSource.xpath_param2")), //$NON-NLS-1$ //$NON-NLS-2$
- new FunctionParameter("namespace", DataTypeManager.DefaultDataTypes.STRING, QueryPlugin.Util.getString("SystemSource.xpath_param3"))}, //$NON-NLS-1$ //$NON-NLS-2$
- new FunctionParameter("result", DataTypeManager.DefaultDataTypes.STRING, QueryPlugin.Util.getString("SystemSource.xpathvalue_result")) ) ); //$NON-NLS-1$ //$NON-NLS-2$
-
- functions.add(new FunctionMethod(SourceSystemFunctions.XPATHVALUE, QueryPlugin.Util.getString("SystemSource.xpathvalue_description"), XML, XML_FUNCTION_CLASS, "xpathValue", //$NON-NLS-1$ //$NON-NLS-2$
- new FunctionParameter[] {
- new FunctionParameter("document", DataTypeManager.DefaultDataTypes.XML, QueryPlugin.Util.getString("SystemSource.xpath_param1")), //$NON-NLS-1$ //$NON-NLS-2$
- new FunctionParameter("xpath", DataTypeManager.DefaultDataTypes.STRING, QueryPlugin.Util.getString("SystemSource.xpath_param2")), //$NON-NLS-1$ //$NON-NLS-2$
- new FunctionParameter("namespace", DataTypeManager.DefaultDataTypes.STRING, QueryPlugin.Util.getString("SystemSource.xpath_param3"))}, //$NON-NLS-1$ //$NON-NLS-2$
- new FunctionParameter("result", DataTypeManager.DefaultDataTypes.STRING, QueryPlugin.Util.getString("SystemSource.xpathvalue_result")) ) ); //$NON-NLS-1$ //$NON-NLS-2$
-
}
- private void addXpathQueryFunction() {
- functions.add(new FunctionMethod(SourceSystemFunctions.XPATHQUERY, QueryPlugin.Util.getString("SystemSource.xpath_description"), XML, XML_FUNCTION_CLASS, "xpathQuery", //$NON-NLS-1$ //$NON-NLS-2$
- new FunctionParameter[] {
- new FunctionParameter("document", DataTypeManager.DefaultDataTypes.STRING, QueryPlugin.Util.getString("SystemSource.xpath_param1")), //$NON-NLS-1$ //$NON-NLS-2$
- new FunctionParameter("xpath", DataTypeManager.DefaultDataTypes.STRING, QueryPlugin.Util.getString("SystemSource.xpath_param2"))}, //$NON-NLS-1$ //$NON-NLS-2$
- new FunctionParameter("result", DataTypeManager.DefaultDataTypes.XML, QueryPlugin.Util.getString("SystemSource.xpath_result")) ) ); //$NON-NLS-1$ //$NON-NLS-2$
-
- functions.add(new FunctionMethod(SourceSystemFunctions.XPATHQUERY, QueryPlugin.Util.getString("SystemSource.xpath_description"), XML, XML_FUNCTION_CLASS, "xpathQuery", //$NON-NLS-1$ //$NON-NLS-2$
- new FunctionParameter[] {
- new FunctionParameter("document", DataTypeManager.DefaultDataTypes.XML, QueryPlugin.Util.getString("SystemSource.xpath_param1")), //$NON-NLS-1$ //$NON-NLS-2$
- new FunctionParameter("xpath", DataTypeManager.DefaultDataTypes.STRING, QueryPlugin.Util.getString("SystemSource.xpath_param2"))}, //$NON-NLS-1$ //$NON-NLS-2$
- new FunctionParameter("result", DataTypeManager.DefaultDataTypes.XML, QueryPlugin.Util.getString("SystemSource.xpath_result")) ) ); //$NON-NLS-1$ //$NON-NLS-2$
-
- functions.add(new FunctionMethod(SourceSystemFunctions.XPATHQUERY, QueryPlugin.Util.getString("SystemSource.xpath_description"), XML, XML_FUNCTION_CLASS, "xpathQuery", //$NON-NLS-1$ //$NON-NLS-2$
- new FunctionParameter[] {
- new FunctionParameter("document", DataTypeManager.DefaultDataTypes.STRING, QueryPlugin.Util.getString("SystemSource.xpath_param1")), //$NON-NLS-1$ //$NON-NLS-2$
- new FunctionParameter("xpath", DataTypeManager.DefaultDataTypes.STRING, QueryPlugin.Util.getString("SystemSource.xpath_param2")), //$NON-NLS-1$ //$NON-NLS-2$
- new FunctionParameter("namespaces", DataTypeManager.DefaultDataTypes.STRING, QueryPlugin.Util.getString("SystemSource.xpath_param3"))}, //$NON-NLS-1$ //$NON-NLS-2$
- new FunctionParameter("result", DataTypeManager.DefaultDataTypes.XML, QueryPlugin.Util.getString("SystemSource.xpath_result")) ) ); //$NON-NLS-1$ //$NON-NLS-2$
-
- functions.add(new FunctionMethod(SourceSystemFunctions.XPATHQUERY, QueryPlugin.Util.getString("SystemSource.xpath_description"), XML, XML_FUNCTION_CLASS, "xpathQuery", //$NON-NLS-1$ //$NON-NLS-2$
- new FunctionParameter[] {
- new FunctionParameter("document", DataTypeManager.DefaultDataTypes.XML, QueryPlugin.Util.getString("SystemSource.xpath_param1")), //$NON-NLS-1$ //$NON-NLS-2$
- new FunctionParameter("xpath", DataTypeManager.DefaultDataTypes.STRING, QueryPlugin.Util.getString("SystemSource.xpath_param2")), //$NON-NLS-1$ //$NON-NLS-2$
- new FunctionParameter("namespaces", DataTypeManager.DefaultDataTypes.STRING, QueryPlugin.Util.getString("SystemSource.xpath_param3"))}, //$NON-NLS-1$ //$NON-NLS-2$
- new FunctionParameter("result", DataTypeManager.DefaultDataTypes.XML, QueryPlugin.Util.getString("SystemSource.xpath_result")) ) ); //$NON-NLS-1$ //$NON-NLS-2$
-
- }
-
private void addXslTransformFunction() {
functions.add(new FunctionMethod(SourceSystemFunctions.XSLTRANSFORM, QueryPlugin.Util.getString("SystemSource.xsltransform_description"), XML, XML_FUNCTION_CLASS, "xslTransform", //$NON-NLS-1$ //$NON-NLS-2$
new FunctionParameter[] {
Modified: trunk/engine/src/main/java/org/teiid/query/function/source/XMLSystemFunctions.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/function/source/XMLSystemFunctions.java 2010-06-04 21:35:06 UTC (rev 2180)
+++ trunk/engine/src/main/java/org/teiid/query/function/source/XMLSystemFunctions.java 2010-06-04 21:51:29 UTC (rev 2181)
@@ -37,7 +37,6 @@
import java.util.List;
import javax.xml.XMLConstants;
-import javax.xml.namespace.NamespaceContext;
import javax.xml.namespace.QName;
import javax.xml.stream.EventFilter;
import javax.xml.stream.FactoryConfigurationError;
@@ -47,21 +46,20 @@
import javax.xml.stream.XMLInputFactory;
import javax.xml.stream.XMLOutputFactory;
import javax.xml.stream.XMLStreamException;
-import javax.xml.stream.XMLStreamReader;
import javax.xml.stream.events.XMLEvent;
-import javax.xml.transform.OutputKeys;
import javax.xml.transform.Source;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerException;
import javax.xml.transform.TransformerFactory;
-import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;
import javax.xml.transform.stream.StreamSource;
-import javax.xml.xpath.XPath;
-import javax.xml.xpath.XPathConstants;
import javax.xml.xpath.XPathExpressionException;
-import javax.xml.xpath.XPathFactory;
+import net.sf.saxon.om.Item;
+import net.sf.saxon.sxpath.XPathEvaluator;
+import net.sf.saxon.sxpath.XPathExpression;
+import net.sf.saxon.trans.XPathException;
+
import org.teiid.api.exception.query.FunctionExecutionException;
import org.teiid.core.TeiidComponentException;
import org.teiid.core.TeiidProcessingException;
@@ -73,13 +71,9 @@
import org.teiid.core.types.XMLTranslator;
import org.teiid.core.types.XMLType;
import org.teiid.core.types.XMLType.Type;
-import org.teiid.query.QueryPlugin;
import org.teiid.query.function.FunctionMethods;
import org.teiid.query.processor.xml.XMLUtil;
import org.teiid.query.util.CommandContext;
-import org.w3c.dom.Node;
-import org.w3c.dom.NodeList;
-import org.xml.sax.InputSource;
/**
@@ -421,130 +415,52 @@
}
- public static String xpathValue(XMLType document, String xpathStr, String namespaces) throws IOException, XPathExpressionException, SQLException, FunctionExecutionException {
- Reader stream = document.getCharacterStream();
- return xpathValue(stream, xpathStr, namespaces);
+ public static String xpathValue(String document, String xpathStr) throws IOException, XPathException {
+ return xpathValue(new StringReader(document), xpathStr);
}
-
- public static String xpathValue(String document, String xpathStr, String namespaces) throws IOException, XPathExpressionException, FunctionExecutionException {
- return xpathValue(new StringReader(document), xpathStr, namespaces);
- }
- public static String xpathValue(String document, String xpathStr) throws IOException, XPathExpressionException, FunctionExecutionException {
- return xpathValue(document, xpathStr, null);
+ public static String xpathValue(XMLType document, String xpathStr) throws IOException, SQLException, XPathException {
+ return xpathValue(document.getCharacterStream(), xpathStr);
}
-
- public static String xpathValue(XMLType document, String xpathStr) throws IOException, SQLException, XPathExpressionException, FunctionExecutionException {
- return xpathValue(document, xpathStr, null);
- }
- public static XMLType xpathQuery(CommandContext context, String document, String xpathStr) throws IOException, TeiidComponentException, TeiidProcessingException, XPathExpressionException {
- return xpathQuery(context, document, xpathStr, null);
- }
-
- public static XMLType xpathQuery(CommandContext context, XMLType document, String xpathStr) throws IOException, SQLException, XPathExpressionException, TeiidComponentException, TeiidProcessingException {
- return xpathQuery(context, document, xpathStr, null);
- }
-
- public static XMLType xpathQuery(CommandContext context, String document, String xpathStr, String namespaces) throws IOException, TeiidComponentException, TeiidProcessingException, XPathExpressionException {
- Reader stream = new StringReader(document);
- return xpathQuery(context, xpathStr, stream, namespaces);
- }
-
- public static XMLType xpathQuery(CommandContext context, XMLType document, String xpathStr, String namespaces) throws IOException, SQLException, XPathExpressionException, TeiidComponentException, TeiidProcessingException {
- Reader stream = ((SQLXML)document).getCharacterStream();
- return xpathQuery(context, xpathStr, stream, namespaces);
- }
-
- private static XMLType xpathQuery(CommandContext context, String xpathStr,
- Reader stream, String namespaces) throws XPathExpressionException,
- TeiidComponentException, TeiidProcessingException,
- IOException {
- try {
- XPathFactory xpathFactory = XPathFactory.newInstance();
- XPath xp = xpathFactory.newXPath();
- NamespaceContext nc = getNamespaces(namespaces);
- if (nc != null) {
- xp.setNamespaceContext(nc);
- }
- final NodeList nodes = (NodeList)xp.evaluate(xpathStr, new InputSource(stream), XPathConstants.NODESET);
- if (nodes.getLength() == 0) {
- return null;
- }
- Type type = nodes.getLength() > 1 ? Type.SIBLINGS : Type.FRAGMENT;
- for (int i = 0; i < nodes.getLength(); i++) {
- Node node = nodes.item(i);
- if (node.getNodeType() == Node.TEXT_NODE) {
- type = Type.TEXT;
- }
- }
- SQLXML sqlXml = XMLUtil.saveToBufferManager(context.getBufferManager(), new XMLTranslator() {
-
- @Override
- public void translate(Writer writer) throws TransformerException {
- TransformerFactory factory = TransformerFactory.newInstance();
- Transformer transformer = factory.newTransformer();
- transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes"); //$NON-NLS-1$
- for (int i = 0; i < nodes.getLength(); i++) {
- Node node = nodes.item(i);
- transformer.transform(new DOMSource(node), new StreamResult(writer));
- }
- }
- }, Streamable.STREAMING_BATCH_SIZE_IN_BYTES);
- XMLType result = new XMLType(sqlXml);
- result.setType(type);
- return result;
- } finally {
- stream.close();
- }
- }
-
- public static String xpathValue(Reader documentReader, String xpath, String namespaces) throws IOException, XPathExpressionException, FunctionExecutionException {
+ public static String xpathValue(Reader documentReader, String xpath) throws IOException, XPathException {
try {
- XPathFactory xpathFactory = XPathFactory.newInstance();
- XPath xp = xpathFactory.newXPath();
- NamespaceContext nc = getNamespaces(namespaces);
- if (nc != null) {
- xp.setNamespaceContext(nc);
- }
- Node node = (Node)xp.evaluate(xpath, new InputSource(documentReader), XPathConstants.NODE);
- if (node == null) {
- return null;
- }
- return node.getTextContent();
+ Source s = new StreamSource(documentReader);
+ XPathEvaluator eval = new XPathEvaluator();
+ // Wrap the string() function to force a string return
+ XPathExpression expr = eval.createExpression(xpath);
+ Object o = expr.evaluateSingle(s);
+
+ if(o == null) {
+ return null;
+ }
+
+ // Return string value of node type
+ if(o instanceof Item) {
+ return ((Item)o).getStringValue();
+ }
+
+ // Return string representation of non-node value
+ return o.toString();
} finally {
// Always close the reader
documentReader.close();
}
}
- public static NamespaceContext getNamespaces(String namespaces) throws FunctionExecutionException {
- if (namespaces == null) {
- return null;
- }
- XMLInputFactory inputFactory = XMLInputFactory.newInstance();
- try {
- XMLStreamReader eventReader = inputFactory.createXMLStreamReader(new StringReader("<x " + namespaces + " />")); //$NON-NLS-1$ //$NON-NLS-2$
- eventReader.next();
- return eventReader.getNamespaceContext();
- } catch (XMLStreamException e) {
- throw new FunctionExecutionException(e, QueryPlugin.Util.getString("XMLSystemFunctions.invalid_namespaces", namespaces)); //$NON-NLS-1$
- }
- }
-
/**
* Validate whether the XPath is a valid XPath. If not valid, an XPathExpressionException will be thrown.
* @param xpath An xpath expression, for example: a/b/c/getText()
* @throws XPathExpressionException
+ * @throws XPathException
*/
- public static void validateXpath(String xpath) throws XPathExpressionException {
+ public static void validateXpath(String xpath) throws XPathException {
if(xpath == null) {
return;
}
- XPathFactory factory = XPathFactory.newInstance();
- XPath xp = factory.newXPath();
- xp.compile(xpath);
+ XPathEvaluator eval = new XPathEvaluator();
+ eval.createExpression(xpath);
}
-
+
}
Modified: trunk/engine/src/main/java/org/teiid/query/optimizer/QueryOptimizer.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/optimizer/QueryOptimizer.java 2010-06-04 21:35:06 UTC (rev 2180)
+++ trunk/engine/src/main/java/org/teiid/query/optimizer/QueryOptimizer.java 2010-06-04 21:51:29 UTC (rev 2181)
@@ -40,7 +40,6 @@
import org.teiid.query.optimizer.proc.ProcedurePlanner;
import org.teiid.query.optimizer.relational.RelationalPlanner;
import org.teiid.query.optimizer.xml.XMLPlanner;
-import org.teiid.query.optimizer.xquery.XQueryPlanner;
import org.teiid.query.processor.ProcessorPlan;
import org.teiid.query.resolver.QueryResolver;
import org.teiid.query.sql.lang.Command;
@@ -61,7 +60,6 @@
private static final CommandPlanner XML_PLANNER = new XMLPlanner();
private static final CommandPlanner PROCEDURE_PLANNER = new ProcedurePlanner();
- private static final CommandPlanner XQUERY_PLANNER = new XQueryPlanner();
private static final CommandPlanner BATCHED_UPDATE_PLANNER = new BatchedUpdatePlanner();
// Can't construct
@@ -98,8 +96,6 @@
if (command.getType() == Command.TYPE_UPDATE_PROCEDURE){
result = PROCEDURE_PLANNER.optimize(command, idGenerator, metadata, capFinder, analysisRecord, context);
- } else if (command.getType() == Command.TYPE_XQUERY){
- result = XQUERY_PLANNER.optimize(command, idGenerator, metadata, capFinder, analysisRecord, context);
} else if (command.getType() == Command.TYPE_BATCHED_UPDATE){
result = BATCHED_UPDATE_PLANNER.optimize(command, idGenerator, metadata, capFinder, analysisRecord, context);
} else {
Modified: trunk/engine/src/main/java/org/teiid/query/optimizer/relational/PlanToProcessConverter.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/optimizer/relational/PlanToProcessConverter.java 2010-06-04 21:35:06 UTC (rev 2180)
+++ trunk/engine/src/main/java/org/teiid/query/optimizer/relational/PlanToProcessConverter.java 2010-06-04 21:51:29 UTC (rev 2181)
@@ -81,6 +81,7 @@
import org.teiid.query.sql.lang.Query;
import org.teiid.query.sql.lang.StoredProcedure;
import org.teiid.query.sql.lang.TextTable;
+import org.teiid.query.sql.lang.XMLTable;
import org.teiid.query.sql.lang.SetQuery.Operation;
import org.teiid.query.sql.symbol.ElementSymbol;
import org.teiid.query.sql.symbol.Expression;
@@ -367,6 +368,9 @@
}
}
Object source = node.getProperty(NodeConstants.Info.TABLE_FUNCTION);
+ if (source instanceof XMLTable) {
+ return null;
+ }
if (!(source instanceof TextTable)) {
return null;
}
Modified: trunk/engine/src/main/java/org/teiid/query/optimizer/relational/RelationalPlanner.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/optimizer/relational/RelationalPlanner.java 2010-06-04 21:35:06 UTC (rev 2180)
+++ trunk/engine/src/main/java/org/teiid/query/optimizer/relational/RelationalPlanner.java 2010-06-04 21:51:29 UTC (rev 2181)
@@ -87,6 +87,7 @@
import org.teiid.query.sql.lang.StoredProcedure;
import org.teiid.query.sql.lang.SubqueryContainer;
import org.teiid.query.sql.lang.SubqueryFromClause;
+import org.teiid.query.sql.lang.TableFunctionReference;
import org.teiid.query.sql.lang.TextTable;
import org.teiid.query.sql.lang.UnaryFromClause;
import org.teiid.query.sql.proc.CreateUpdateProcedureCommand;
@@ -680,8 +681,8 @@
addNestedCommand(node, group, nestedCommand, nestedCommand, true);
hints.hasVirtualGroups = true;
parent.addLastChild(node);
- } else if (clause instanceof TextTable) {
- TextTable tt = (TextTable)clause;
+ } else if (clause instanceof TableFunctionReference) {
+ TableFunctionReference tt = (TableFunctionReference)clause;
GroupSymbol group = tt.getGroupSymbol();
node = NodeFactory.getNewNode(NodeConstants.Types.SOURCE);
node.setProperty(NodeConstants.Info.TABLE_FUNCTION, tt);
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-04 21:35:06 UTC (rev 2180)
+++ trunk/engine/src/main/java/org/teiid/query/optimizer/relational/rules/CapabilitiesUtil.java 2010-06-04 21:51:29 UTC (rev 2181)
@@ -30,7 +30,7 @@
import org.teiid.api.exception.query.QueryMetadataException;
import org.teiid.core.TeiidComponentException;
import org.teiid.core.types.DataTypeManager;
-import org.teiid.language.SQLReservedWords;
+import org.teiid.language.SQLReservedWords.NonReserved;
import org.teiid.query.function.FunctionLibrary;
import org.teiid.query.metadata.QueryMetadataInterface;
import org.teiid.query.optimizer.capabilities.CapabilitiesFinder;
@@ -145,7 +145,7 @@
// Check particular function
String func = aggregate.getAggregateFunction();
- if(func.equals(SQLReservedWords.COUNT)) {
+ if(func.equals(NonReserved.COUNT)) {
if(aggregate.getExpression() == null) {
if(! caps.supportsCapability(Capability.QUERY_AGGREGATES_COUNT_STAR)) {
return false;
@@ -155,19 +155,19 @@
return false;
}
}
- } else if(func.equals(SQLReservedWords.SUM)) {
+ } else if(func.equals(NonReserved.SUM)) {
if(! caps.supportsCapability(Capability.QUERY_AGGREGATES_SUM)) {
return false;
}
- } else if(func.equals(SQLReservedWords.AVG)) {
+ } else if(func.equals(NonReserved.AVG)) {
if(! caps.supportsCapability(Capability.QUERY_AGGREGATES_AVG)) {
return false;
}
- } else if(func.equals(SQLReservedWords.MIN)) {
+ } else if(func.equals(NonReserved.MIN)) {
if(! caps.supportsCapability(Capability.QUERY_AGGREGATES_MIN)) {
return false;
}
- } else if(func.equals(SQLReservedWords.MAX)) {
+ } else if(func.equals(NonReserved.MAX)) {
if(! caps.supportsCapability(Capability.QUERY_AGGREGATES_MAX)) {
return false;
}
Modified: trunk/engine/src/main/java/org/teiid/query/optimizer/relational/rules/NewCalculateCostUtil.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/optimizer/relational/rules/NewCalculateCostUtil.java 2010-06-04 21:35:06 UTC (rev 2180)
+++ trunk/engine/src/main/java/org/teiid/query/optimizer/relational/rules/NewCalculateCostUtil.java 2010-06-04 21:51:29 UTC (rev 2181)
@@ -49,7 +49,6 @@
import org.teiid.query.optimizer.relational.plantree.PlanNode;
import org.teiid.query.processor.relational.JoinNode.JoinStrategyType;
import org.teiid.query.sql.lang.AbstractSetCriteria;
-import org.teiid.query.sql.lang.Command;
import org.teiid.query.sql.lang.CompareCriteria;
import org.teiid.query.sql.lang.CompoundCriteria;
import org.teiid.query.sql.lang.Criteria;
@@ -72,8 +71,6 @@
import org.teiid.query.sql.visitor.GroupsUsedByElementsVisitor;
import org.teiid.query.util.CommandContext;
-
-
/**
* @since 4.3
*/
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-04 21:35:06 UTC (rev 2180)
+++ trunk/engine/src/main/java/org/teiid/query/optimizer/relational/rules/RulePushAggregates.java 2010-06-04 21:51:29 UTC (rev 2181)
@@ -40,7 +40,7 @@
import org.teiid.api.exception.query.QueryResolverException;
import org.teiid.core.TeiidComponentException;
import org.teiid.core.types.DataTypeManager;
-import org.teiid.language.SQLReservedWords;
+import org.teiid.language.SQLReservedWords.NonReserved;
import org.teiid.query.analysis.AnalysisRecord;
import org.teiid.query.function.FunctionLibrary;
import org.teiid.query.metadata.QueryMetadataInterface;
@@ -351,7 +351,7 @@
if (pushdown) {
projectedViewSymbols.add(agg);
} else {
- if (agg.getAggregateFunction().equals(SQLReservedWords.COUNT)) {
+ 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);
@@ -501,7 +501,7 @@
} else {
// if the source has no rows we need to insert a select node with criteria count(*)>0
PlanNode selectNode = NodeFactory.getNewNode(NodeConstants.Types.SELECT);
- AggregateSymbol count = new AggregateSymbol("stagedAgg", SQLReservedWords.COUNT, false, null); //$NON-NLS-1$
+ AggregateSymbol count = new AggregateSymbol("stagedAgg", NonReserved.COUNT, false, null); //$NON-NLS-1$
aggregates.add(count); //consider the count aggregate for the push down call below
selectNode.setProperty(NodeConstants.Info.SELECT_CRITERIA, new CompareCriteria(count, CompareCriteria.GT,
new Constant(new Integer(0))));
@@ -669,9 +669,9 @@
Expression newExpression = null;
String aggFunction = partitionAgg.getAggregateFunction();
- if (aggFunction.equals(SQLReservedWords.COUNT)) {
+ if (aggFunction.equals(NonReserved.COUNT)) {
//COUNT(x) -> CONVERT(SUM(COUNT(x)), INTEGER)
- AggregateSymbol newAgg = new AggregateSymbol("stagedAgg", SQLReservedWords.SUM, false, partitionAgg); //$NON-NLS-1$
+ 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()),
@@ -681,13 +681,13 @@
newExpression = convertFunc;
nestedAggregates.add(partitionAgg);
- } else if (aggFunction.equals(SQLReservedWords.AVG)) {
+ } else if (aggFunction.equals(NonReserved.AVG)) {
//AVG(x) -> SUM(SUM(x)) / SUM(COUNT(x))
- AggregateSymbol countAgg = new AggregateSymbol("stagedAgg", SQLReservedWords.COUNT, false, partitionAgg.getExpression()); //$NON-NLS-1$
- AggregateSymbol sumAgg = new AggregateSymbol("stagedAgg", SQLReservedWords.SUM, false, partitionAgg.getExpression()); //$NON-NLS-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 sumSumAgg = new AggregateSymbol("stagedAgg", SQLReservedWords.SUM, false, sumAgg); //$NON-NLS-1$
- AggregateSymbol sumCountAgg = new AggregateSymbol("stagedAgg", SQLReservedWords.SUM, false, countAgg); //$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$
Function divideFunc = new Function("/", new Expression[] {sumSumAgg, sumCountAgg}); //$NON-NLS-1$
ResolverVisitor.resolveLanguageObject(divideFunc, metadata);
Modified: trunk/engine/src/main/java/org/teiid/query/optimizer/relational/rules/RuleRaiseAccess.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/optimizer/relational/rules/RuleRaiseAccess.java 2010-06-04 21:35:06 UTC (rev 2180)
+++ trunk/engine/src/main/java/org/teiid/query/optimizer/relational/rules/RuleRaiseAccess.java 2010-06-04 21:51:29 UTC (rev 2181)
@@ -42,7 +42,6 @@
import org.teiid.query.optimizer.relational.plantree.NodeEditor;
import org.teiid.query.optimizer.relational.plantree.NodeFactory;
import org.teiid.query.optimizer.relational.plantree.PlanNode;
-import org.teiid.query.sql.lang.Command;
import org.teiid.query.sql.lang.CompareCriteria;
import org.teiid.query.sql.lang.Criteria;
import org.teiid.query.sql.lang.JoinType;
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-04 21:35:06 UTC (rev 2180)
+++ trunk/engine/src/main/java/org/teiid/query/optimizer/relational/rules/RuleRemoveOptionalJoins.java 2010-06-04 21:51:29 UTC (rev 2181)
@@ -33,7 +33,7 @@
import org.teiid.api.exception.query.QueryResolverException;
import org.teiid.core.TeiidComponentException;
import org.teiid.core.util.Assertion;
-import org.teiid.language.SQLReservedWords;
+import org.teiid.language.SQLReservedWords.NonReserved;
import org.teiid.query.analysis.AnalysisRecord;
import org.teiid.query.metadata.QueryMetadataInterface;
import org.teiid.query.optimizer.capabilities.CapabilitiesFinder;
@@ -277,8 +277,8 @@
static boolean areAggregatesCardinalityDependent(Set<AggregateSymbol> aggs) {
for (AggregateSymbol aggregateSymbol : aggs) {
- if (aggregateSymbol.getAggregateFunction().equalsIgnoreCase(SQLReservedWords.COUNT) ||
- aggregateSymbol.getAggregateFunction().equalsIgnoreCase(SQLReservedWords.AVG)) {
+ if (aggregateSymbol.getAggregateFunction().equalsIgnoreCase(NonReserved.COUNT) ||
+ aggregateSymbol.getAggregateFunction().equalsIgnoreCase(NonReserved.AVG)) {
return true;
}
}
Modified: trunk/engine/src/main/java/org/teiid/query/parser/QueryParser.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/parser/QueryParser.java 2010-06-04 21:35:06 UTC (rev 2180)
+++ trunk/engine/src/main/java/org/teiid/query/parser/QueryParser.java 2010-06-04 21:51:29 UTC (rev 2181)
@@ -25,16 +25,10 @@
import java.io.StringReader;
import org.teiid.api.exception.query.QueryParserException;
-import org.teiid.core.TeiidProcessingException;
-import org.teiid.language.SQLReservedWords;
import org.teiid.query.QueryPlugin;
import org.teiid.query.sql.lang.Command;
import org.teiid.query.sql.lang.Criteria;
-import org.teiid.query.sql.lang.Option;
-import org.teiid.query.sql.lang.XQuery;
import org.teiid.query.sql.symbol.Expression;
-import org.teiid.query.xquery.XQueryExpression;
-import org.teiid.query.xquery.saxon.SaxonXQueryExpression;
/**
* <p>Converts a SQL-string to an object version of a query. This
@@ -60,7 +54,6 @@
private static final String XQUERY_DECLARE = "declare"; //$NON-NLS-1$
private static final String XML_OPEN_BRACKET = "<"; //$NON-NLS-1$
- private static final String XML_CLOSE_BRACKET = ">"; //$NON-NLS-1$
private SQLParser parser;
@@ -113,62 +106,19 @@
throw new QueryParserException(QueryPlugin.Util.getString("QueryParser.emptysql")); //$NON-NLS-1$
}
- QueryParserException qpe = null;
try {
Command result = parseCommandWithParser(sql, parseInfo);
result.setCache(parseInfo.cache);
return result;
} catch (QueryParserException e) {
- qpe = e;
- }
-
- try {
- // Check for OPTION
- Option option = null;
- int closeBracket = sql.lastIndexOf(XML_CLOSE_BRACKET);
- int optionIndex = sql.toUpperCase().lastIndexOf(SQLReservedWords.OPTION);
- if (optionIndex != -1 && optionIndex > closeBracket){
- String optionSQL = sql.substring(optionIndex);
- option = getOption(optionSQL, parseInfo);
- sql = sql.substring(0, optionIndex-1);
- }
-
- XQueryExpression expr = new SaxonXQueryExpression();
- expr.compileXQuery(sql);
- XQuery xquery = new XQuery(sql, expr);
- if (option != null){
- xquery.setOption(option);
- }
- return xquery;
- } catch (TeiidProcessingException e) {
if(sql.startsWith(XML_OPEN_BRACKET) || sql.startsWith(XQUERY_DECLARE)) {
- throw new QueryParserException(e, QueryPlugin.Util.getString("QueryParser.xqueryCompilation")); //$NON-NLS-1$
+ throw new QueryParserException(e, QueryPlugin.Util.getString("QueryParser.xqueryCompilation", sql)); //$NON-NLS-1$
}
+ throw e;
}
-
- throw qpe;
}
/**
- * Parses Option object given option SQL fragment.
- * @param optionSQL option SQL
- * @return Option object
- */
- private Option getOption(String optionSQL, ParseInfo parseInfo) throws QueryParserException {
- Option result = null;
- try{
- result = getSqlParser(optionSQL).option(parseInfo);
-
- } catch(ParseException pe) {
- throw convertParserException(pe);
-
- } catch(TokenMgrError tme) {
- handleTokenMgrError(tme);
- }
- return result;
- }
-
- /**
* Parse the String sql into a Command using the MetaMatrix parser.
* @param sql to parse
* @return parsed Command
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-04 21:35:06 UTC (rev 2180)
+++ trunk/engine/src/main/java/org/teiid/query/parser/SQLParserUtil.java 2010-06-04 21:51:29 UTC (rev 2181)
@@ -29,6 +29,7 @@
import org.teiid.core.util.Assertion;
import org.teiid.core.util.StringUtil;
import org.teiid.language.SQLReservedWords;
+import org.teiid.language.SQLReservedWords.NonReserved;
import org.teiid.query.QueryPlugin;
import org.teiid.query.sql.lang.Command;
import org.teiid.query.sql.lang.FromClause;
@@ -40,6 +41,15 @@
public class SQLParserUtil {
+ String matchesAny(String arg, String ... expected) {
+ for (String string : expected) {
+ if (string.equalsIgnoreCase(arg)) {
+ return arg;
+ }
+ }
+ return null;
+ }
+
String normalizeStringLiteral(String s) {
int start = 1;
if (s.charAt(0) == 'N') {
@@ -229,23 +239,23 @@
int num = info.anonExprCount++;
return "expr" + (num == 0 ? "" : ""+num); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- } else if(functionType.equals(SQLReservedWords.COUNT)) {
+ } 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(SQLReservedWords.SUM)) {
+ } 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(SQLReservedWords.AVG)) {
+ } 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(SQLReservedWords.MIN)) {
+ } 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(SQLReservedWords.MAX)) {
+ } 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(SQLReservedWords.XMLAGG)) {
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-04 21:35:06 UTC (rev 2180)
+++ trunk/engine/src/main/java/org/teiid/query/processor/relational/GroupingNode.java 2010-06-04 21:51:29 UTC (rev 2181)
@@ -39,7 +39,7 @@
import org.teiid.common.buffer.TupleSource;
import org.teiid.core.TeiidComponentException;
import org.teiid.core.TeiidProcessingException;
-import org.teiid.language.SQLReservedWords;
+import org.teiid.language.SQLReservedWords.NonReserved;
import org.teiid.query.eval.Evaluator;
import org.teiid.query.function.aggregate.AggregateFunction;
import org.teiid.query.function.aggregate.Avg;
@@ -163,21 +163,21 @@
inputType = ex.getType();
int index = collectExpression(ex);
String function = aggSymbol.getAggregateFunction();
- if(function.equals(SQLReservedWords.COUNT)) {
+ if(function.equals(NonReserved.COUNT)) {
functions[i] = new Count();
- } else if(function.equals(SQLReservedWords.SUM)) {
+ } else if(function.equals(NonReserved.SUM)) {
functions[i] = new Sum();
- } else if(function.equals(SQLReservedWords.AVG)) {
+ } else if(function.equals(NonReserved.AVG)) {
functions[i] = new Avg();
- } else if(function.equals(SQLReservedWords.MIN)) {
+ } else if(function.equals(NonReserved.MIN)) {
functions[i] = new Min();
- } else if (function.equals(SQLReservedWords.MAX)){
+ } else if (function.equals(NonReserved.MAX)){
functions[i] = new Max();
} else {
functions[i] = new XMLAgg(context);
}
- if(aggSymbol.isDistinct() && !function.equals(SQLReservedWords.MIN) && !function.equals(SQLReservedWords.MAX)) {
+ if(aggSymbol.isDistinct() && !function.equals(NonReserved.MIN) && !function.equals(NonReserved.MAX)) {
SortingFilter filter = new SortingFilter(functions[i], getBufferManager(), getConnectionID(), true);
ElementSymbol element = new ElementSymbol("val"); //$NON-NLS-1$
element.setType(inputType);
Modified: trunk/engine/src/main/java/org/teiid/query/processor/relational/TextTableNode.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/processor/relational/TextTableNode.java 2010-06-04 21:35:06 UTC (rev 2180)
+++ trunk/engine/src/main/java/org/teiid/query/processor/relational/TextTableNode.java 2010-06-04 21:51:29 UTC (rev 2181)
@@ -69,7 +69,6 @@
private char quote;
private char delimiter;
private int lineWidth;
- private List<Class<?>> types;
private Map elementMap;
private int[] projectionIndexes;
@@ -86,7 +85,7 @@
public void initialize(CommandContext context, BufferManager bufferManager,
ProcessorDataManager dataMgr) {
super.initialize(context, bufferManager, dataMgr);
- if (types != null) {
+ if (elementMap != null) {
return;
}
if (table.getSkip() != null) {
@@ -113,11 +112,6 @@
quote = table.getQuote();
}
}
- types = new ArrayList<Class<?>>();
- //TODO: if all string types, then we can skip this step
- for (TextColumn col : table.getColumns()) {
- types.add(DataTypeManager.getDataTypeClass(col.getType()));
- }
this.elementMap = createLookupMap(table.getProjectedSymbols());
this.projectionIndexes = getProjectionIndexes(elementMap, getElements());
}
@@ -190,7 +184,7 @@
}
val = vals.get(index);
try {
- tuple.add(DataTypeManager.transformValue(val, types.get(output)));
+ tuple.add(DataTypeManager.transformValue(val, table.getColumns().get(output).getSymbol().getType()));
} catch (TransformationException e) {
throw new TeiidProcessingException(e, QueryExecPlugin.Util.getString("TextTableNode.conversion_error", col.getName(), textLine)); //$NON-NLS-1$
}
Added: trunk/engine/src/main/java/org/teiid/query/processor/relational/XMLTableNode.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/processor/relational/XMLTableNode.java (rev 0)
+++ trunk/engine/src/main/java/org/teiid/query/processor/relational/XMLTableNode.java 2010-06-04 21:51:29 UTC (rev 2181)
@@ -0,0 +1,103 @@
+/*
+ * 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.processor.relational;
+
+import java.util.Map;
+
+import net.sf.saxon.query.XQueryExpression;
+import nu.xom.Element;
+import nu.xom.Node;
+import nu.xom.NodeFactory;
+import nu.xom.Nodes;
+import nux.xom.pool.XQueryPool;
+import nux.xom.xquery.StreamingPathFilter;
+import nux.xom.xquery.StreamingTransform;
+import nux.xom.xquery.XQueryUtil;
+
+import org.teiid.common.buffer.BlockedException;
+import org.teiid.common.buffer.BufferManager;
+import org.teiid.common.buffer.TupleBatch;
+import org.teiid.core.TeiidComponentException;
+import org.teiid.core.TeiidProcessingException;
+import org.teiid.query.processor.ProcessorDataManager;
+import org.teiid.query.sql.lang.XMLTable;
+import org.teiid.query.util.CommandContext;
+
+/**
+ * Handles xml processing.
+ */
+public class XMLTableNode extends SubqueryAwareRelationalNode {
+
+ private XMLTable table;
+
+ //initialized state
+ private Map elementMap;
+ private int[] projectionIndexes;
+
+ //per file state
+
+ public XMLTableNode(int nodeID) {
+ super(nodeID);
+ }
+
+ @Override
+ public void initialize(CommandContext context, BufferManager bufferManager,
+ ProcessorDataManager dataMgr) {
+ super.initialize(context, bufferManager, dataMgr);
+ if (elementMap != null) {
+ return;
+ }
+ this.elementMap = createLookupMap(table.getProjectedSymbols());
+ this.projectionIndexes = getProjectionIndexes(elementMap, getElements());
+ }
+
+ @Override
+ public void closeDirect() {
+ super.closeDirect();
+ reset();
+ }
+
+ public void setTable(XMLTable table) {
+ this.table = table;
+ }
+
+ @Override
+ public XMLTableNode clone() {
+ XMLTableNode clone = new XMLTableNode(getID());
+ this.copy(this, clone);
+ clone.setTable(table);
+ return clone;
+ }
+
+ @Override
+ protected TupleBatch nextBatchDirect() throws BlockedException,
+ TeiidComponentException, TeiidProcessingException {
+ return null;
+ }
+
+ public static void main(String[] args) {
+
+
+ }
+
+}
\ No newline at end of file
Property changes on: trunk/engine/src/main/java/org/teiid/query/processor/relational/XMLTableNode.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified: trunk/engine/src/main/java/org/teiid/query/resolver/QueryResolver.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/resolver/QueryResolver.java 2010-06-04 21:35:06 UTC (rev 2180)
+++ trunk/engine/src/main/java/org/teiid/query/resolver/QueryResolver.java 2010-06-04 21:51:29 UTC (rev 2181)
@@ -49,7 +49,6 @@
import org.teiid.query.resolver.command.UpdateProcedureResolver;
import org.teiid.query.resolver.command.UpdateResolver;
import org.teiid.query.resolver.command.XMLQueryResolver;
-import org.teiid.query.resolver.command.XQueryResolver;
import org.teiid.query.resolver.util.ResolverUtil;
import org.teiid.query.resolver.util.ResolverVisitor;
import org.teiid.query.sql.lang.Command;
@@ -80,7 +79,6 @@
private static final CommandResolver UPDATE_RESOLVER = new UpdateResolver();
private static final CommandResolver DELETE_RESOLVER = new DeleteResolver();
private static final CommandResolver UPDATE_PROCEDURE_RESOLVER = new UpdateProcedureResolver();
- private static final CommandResolver X_QUERY_RESOLVER = new XQueryResolver();
private static final CommandResolver BATCHED_UPDATE_RESOLVER = new BatchedUpdateResolver();
private static final CommandResolver DYNAMIC_COMMAND_RESOLVER = new DynamicCommandResolver();
private static final CommandResolver TEMP_TABLE_RESOLVER = new TempTableResolver();
@@ -207,7 +205,6 @@
case Command.TYPE_DELETE: return DELETE_RESOLVER;
case Command.TYPE_STORED_PROCEDURE: return EXEC_RESOLVER;
case Command.TYPE_UPDATE_PROCEDURE: return UPDATE_PROCEDURE_RESOLVER;
- case Command.TYPE_XQUERY: return X_QUERY_RESOLVER;
case Command.TYPE_BATCHED_UPDATE: return BATCHED_UPDATE_RESOLVER;
case Command.TYPE_DYNAMIC: return DYNAMIC_COMMAND_RESOLVER;
case Command.TYPE_CREATE: return TEMP_TABLE_RESOLVER;
Modified: trunk/engine/src/main/java/org/teiid/query/resolver/command/ExecResolver.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/resolver/command/ExecResolver.java 2010-06-04 21:35:06 UTC (rev 2180)
+++ trunk/engine/src/main/java/org/teiid/query/resolver/command/ExecResolver.java 2010-06-04 21:51:29 UTC (rev 2181)
@@ -54,7 +54,6 @@
import org.teiid.query.sql.lang.SPParameter;
import org.teiid.query.sql.lang.StoredProcedure;
import org.teiid.query.sql.lang.SubqueryContainer;
-import org.teiid.query.sql.lang.XQuery;
import org.teiid.query.sql.symbol.ElementSymbol;
import org.teiid.query.sql.symbol.Expression;
import org.teiid.query.sql.symbol.GroupSymbol;
@@ -66,20 +65,6 @@
*/
public class ExecResolver extends ProcedureContainerResolver implements VariableResolver {
- @Override
- public Command expandCommand(ProcedureContainer procCommand,
- QueryMetadataInterface metadata, AnalysisRecord analysis)
- throws QueryMetadataException, QueryResolverException,
- TeiidComponentException {
- Command command = super.expandCommand(procCommand, metadata, analysis);
- if (command instanceof XQuery) {
- XQuery query = (XQuery)command;
- query.setProcedureGroup(procCommand.getGroup().getCanonicalName());
- query.setVariables(getVariableValues(procCommand, metadata));
- }
- return command;
- }
-
/**
* @see org.teiid.query.resolver.CommandResolver#findCommandMetadata(org.teiid.query.sql.lang.Command,
* org.teiid.query.metadata.QueryMetadataInterface)
Modified: trunk/engine/src/main/java/org/teiid/query/resolver/command/SimpleQueryResolver.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/resolver/command/SimpleQueryResolver.java 2010-06-04 21:35:06 UTC (rev 2180)
+++ trunk/engine/src/main/java/org/teiid/query/resolver/command/SimpleQueryResolver.java 2010-06-04 21:51:29 UTC (rev 2181)
@@ -68,13 +68,16 @@
import org.teiid.query.sql.lang.SubqueryContainer;
import org.teiid.query.sql.lang.SubqueryFromClause;
import org.teiid.query.sql.lang.SubquerySetCriteria;
+import org.teiid.query.sql.lang.TableFunctionReference;
import org.teiid.query.sql.lang.TextTable;
import org.teiid.query.sql.lang.UnaryFromClause;
+import org.teiid.query.sql.lang.XMLTable;
import org.teiid.query.sql.navigator.PostOrderNavigator;
import org.teiid.query.sql.symbol.AliasSymbol;
import org.teiid.query.sql.symbol.AllInGroupSymbol;
import org.teiid.query.sql.symbol.AllSymbol;
import org.teiid.query.sql.symbol.ElementSymbol;
+import org.teiid.query.sql.symbol.Expression;
import org.teiid.query.sql.symbol.ExpressionSymbol;
import org.teiid.query.sql.symbol.GroupSymbol;
import org.teiid.query.sql.symbol.Reference;
@@ -83,7 +86,6 @@
import org.teiid.query.sql.visitor.ElementCollectorVisitor;
import org.teiid.query.util.ErrorMessageKeys;
-
public class SimpleQueryResolver implements CommandResolver {
private static final String ALL_IN_GROUP_SUFFIX = ".*"; //$NON-NLS-1$
@@ -280,21 +282,54 @@
postVisitVisitor(obj);
}
- /**
- * TextTables have similar resolving semantics to a nested table.
- */
@Override
public void visit(TextTable obj) {
- LinkedHashSet<GroupSymbol> saved = new LinkedHashSet<GroupSymbol>(this.currentGroups);
- if (allowImplicit) {
- currentGroups.addAll(this.implicitGroups);
- }
+ LinkedHashSet<GroupSymbol> saved = preTableFunctionReference(obj);
this.visitNode(obj.getFile());
try {
obj.setFile(ResolverUtil.convertExpression(obj.getFile(), DataTypeManager.DefaultDataTypes.CLOB, metadata));
} catch (QueryResolverException e) {
throw new TeiidRuntimeException(e);
}
+ postTableFunctionReference(obj, saved);
+ //set to fixed width if any column has width specified
+ for (TextTable.TextColumn col : obj.getColumns()) {
+ if (col.getWidth() != null) {
+ obj.setFixedWidth(true);
+ break;
+ }
+ }
+ }
+
+ @Override
+ public void visit(XMLTable obj) {
+ LinkedHashSet<GroupSymbol> saved = preTableFunctionReference(obj);
+ visitNodes(obj.getPassing());
+ postTableFunctionReference(obj, saved);
+ try {
+ obj.compileXqueryExpression();
+ for (XMLTable.XMLColumn column : obj.getColumns()) {
+ if (column.getDefaultExpression() == null) {
+ continue;
+ }
+ ResolverVisitor.resolveLanguageObject(column.getDefaultExpression(), metadata);
+ Expression ex = ResolverUtil.convertExpression(column.getDefaultExpression(), DataTypeManager.getDataTypeName(column.getSymbol().getType()), metadata);
+ column.setDefaultExpression(ex);
+ }
+ } catch (TeiidException e) {
+ throw new TeiidRuntimeException(e);
+ }
+ }
+
+ public LinkedHashSet<GroupSymbol> preTableFunctionReference(TableFunctionReference tfr) {
+ LinkedHashSet<GroupSymbol> saved = new LinkedHashSet<GroupSymbol>(this.currentGroups);
+ if (allowImplicit) {
+ currentGroups.addAll(this.implicitGroups);
+ }
+ return saved;
+ }
+
+ public void postTableFunctionReference(TableFunctionReference obj, LinkedHashSet<GroupSymbol> saved) {
//we didn't create a true external context, so we manually mark external
for (ElementSymbol symbol : ElementCollectorVisitor.getElements(obj, false)) {
if (symbol.isExternalReference()) {
@@ -325,13 +360,6 @@
throw new TeiidRuntimeException(e);
}
}
- //set to fixed width if any column has width specified
- for (TextTable.TextColumn col : obj.getColumns()) {
- if (col.getWidth() != null) {
- obj.setFixedWidth(true);
- break;
- }
- }
}
public void visit(SubqueryFromClause obj) {
Modified: trunk/engine/src/main/java/org/teiid/query/resolver/util/ResolverUtil.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/resolver/util/ResolverUtil.java 2010-06-04 21:35:06 UTC (rev 2180)
+++ trunk/engine/src/main/java/org/teiid/query/resolver/util/ResolverUtil.java 2010-06-04 21:51:29 UTC (rev 2181)
@@ -612,7 +612,7 @@
public static TempMetadataID addTempGroup(TempMetadataAdapter metadata,
GroupSymbol symbol,
List symbols, boolean tempTable) throws QueryResolverException {
- HashSet names = new HashSet();
+ HashSet<String> names = new HashSet<String>();
for (Iterator i = symbols.iterator(); i.hasNext();) {
SingleElementSymbol ses = (SingleElementSymbol)i.next();
if (!names.add(ses.getShortCanonicalName())) {
Modified: trunk/engine/src/main/java/org/teiid/query/resolver/util/ResolverVisitor.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/resolver/util/ResolverVisitor.java 2010-06-04 21:35:06 UTC (rev 2180)
+++ trunk/engine/src/main/java/org/teiid/query/resolver/util/ResolverVisitor.java 2010-06-04 21:51:29 UTC (rev 2181)
@@ -64,6 +64,7 @@
import org.teiid.query.sql.symbol.GroupSymbol;
import org.teiid.query.sql.symbol.Reference;
import org.teiid.query.sql.symbol.SearchedCaseExpression;
+import org.teiid.query.sql.symbol.XMLSerialize;
import org.teiid.query.util.ErrorMessageKeys;
@@ -274,7 +275,6 @@
}
}
-
public void visit(SubquerySetCriteria obj) {
try {
obj.setExpression(ResolverUtil.resolveSubqueryPredicateCriteria(obj.getExpression(), obj, metadata));
@@ -329,6 +329,15 @@
handleException(new QueryResolverException(e, QueryPlugin.Util.getString("SetClause.resolvingError", new Object[] {obj.getValue(), obj.getSymbol(), type}))); //$NON-NLS-1$
}
}
+
+ @Override
+ public void visit(XMLSerialize obj) {
+ try {
+ obj.setExpression(ResolverUtil.convertExpression(obj.getExpression(), DataTypeManager.DefaultDataTypes.XML, metadata));
+ } catch (QueryResolverException e) {
+ handleException(new QueryResolverException(e, QueryPlugin.Util.getString("XMLSerialize.resolvingError", obj))); //$NON-NLS-1$
+ }
+ }
public TeiidComponentException getComponentException() {
return this.componentException;
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-04 21:35:06 UTC (rev 2180)
+++ trunk/engine/src/main/java/org/teiid/query/rewriter/QueryRewriter.java 2010-06-04 21:51:29 UTC (rev 2181)
@@ -53,7 +53,7 @@
import org.teiid.core.types.DataTypeManager;
import org.teiid.core.util.Assertion;
import org.teiid.core.util.TimestampWithTimezone;
-import org.teiid.language.SQLReservedWords;
+import org.teiid.language.SQLReservedWords.NonReserved;
import org.teiid.query.eval.Evaluator;
import org.teiid.query.execution.QueryExecPlugin;
import org.teiid.query.function.FunctionDescriptor;
@@ -110,6 +110,7 @@
import org.teiid.query.sql.lang.TranslatableProcedureContainer;
import org.teiid.query.sql.lang.UnaryFromClause;
import org.teiid.query.sql.lang.Update;
+import org.teiid.query.sql.lang.XMLTable;
import org.teiid.query.sql.lang.PredicateCriteria.Negatable;
import org.teiid.query.sql.navigator.PostOrderNavigator;
import org.teiid.query.sql.navigator.PreOrderNavigator;
@@ -137,6 +138,9 @@
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.XMLElement;
+import org.teiid.query.sql.symbol.XMLForest;
+import org.teiid.query.sql.symbol.XMLSerialize;
import org.teiid.query.sql.util.SymbolMap;
import org.teiid.query.sql.util.ValueIterator;
import org.teiid.query.sql.visitor.AggregateSymbolCollectorVisitor;
@@ -921,6 +925,8 @@
} else if (clause instanceof TextTable) {
TextTable tt = (TextTable)clause;
tt.setFile(rewriteExpressionDirect(tt.getFile()));
+ } else if (clause instanceof XMLTable) {
+ rewriteExpressions(clause);
}
return clause;
}
@@ -1895,6 +1901,12 @@
} else {
expression = rewriteExpressionDirect(((ExpressionSymbol)expression).getExpression());
}
+ } else if (expression instanceof XMLElement) {
+ rewriteExpressions(expression);
+ } else if (expression instanceof XMLForest) {
+ rewriteExpressions(expression);
+ } else if (expression instanceof XMLSerialize) {
+ rewriteExpressions(expression);
}
if(dataMgr == null) {
@@ -1913,8 +1925,8 @@
}
private Expression rewriteExpression(AggregateSymbol expression) {
- if (!expression.getAggregateFunction().equals(SQLReservedWords.COUNT)
- && !expression.getAggregateFunction().equals(SQLReservedWords.SUM)
+ if (!expression.getAggregateFunction().equals(NonReserved.COUNT)
+ && !expression.getAggregateFunction().equals(NonReserved.SUM)
&& EvaluatableVisitor.willBecomeConstant(expression.getExpression())) {
try {
return new ExpressionSymbol(expression.getName(), ResolverUtil
@@ -1967,7 +1979,7 @@
}
case 1: {//from_unixtime(a) => timestampadd(SQL_TSI_SECOND, a, new Timestamp(0))
Function result = new Function(FunctionLibrary.TIMESTAMPADD,
- new Expression[] {new Constant(SQLReservedWords.SQL_TSI_SECOND), function.getArg(0), new Constant(new Timestamp(0)) });
+ new Expression[] {new Constant(NonReserved.SQL_TSI_SECOND), function.getArg(0), new Constant(new Timestamp(0)) });
//resolve the function
FunctionDescriptor descriptor =
funcLibrary.findFunction(FunctionLibrary.TIMESTAMPADD, new Class[] { DataTypeManager.DefaultDataClasses.STRING, DataTypeManager.DefaultDataClasses.INTEGER, DataTypeManager.DefaultDataClasses.TIMESTAMP });
Modified: trunk/engine/src/main/java/org/teiid/query/sql/LanguageVisitor.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/sql/LanguageVisitor.java 2010-06-04 21:35:06 UTC (rev 2180)
+++ trunk/engine/src/main/java/org/teiid/query/sql/LanguageVisitor.java 2010-06-04 21:51:29 UTC (rev 2181)
@@ -84,7 +84,6 @@
visit((ProcedureContainer)obj);
}
public void visit(Into obj) {}
- public void visit(XQuery obj) {}
public void visit(DependentSetCriteria obj) {}
public void visit(Create obj) {}
public void visit(Drop obj) {}
@@ -131,4 +130,7 @@
public void visit(XMLForest obj) {}
public void visit(XMLNamespaces obj) {}
public void visit(TextTable obj) {}
+ public void visit(XMLTable obj) {}
+ public void visit(DerivedColumn obj) {}
+ public void visit(XMLSerialize obj) {}
}
Modified: trunk/engine/src/main/java/org/teiid/query/sql/lang/Command.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/sql/lang/Command.java 2010-06-04 21:35:06 UTC (rev 2180)
+++ trunk/engine/src/main/java/org/teiid/query/sql/lang/Command.java 2010-06-04 21:51:29 UTC (rev 2181)
@@ -93,11 +93,6 @@
public static final int TYPE_UPDATE_PROCEDURE = 7;
/**
- * Represents an XQuery
- */
- public static final int TYPE_XQUERY = 8;
-
- /**
* Represents a batched sequence of UPDATE statements
*/
public static final int TYPE_BATCHED_UPDATE = 9;
Added: trunk/engine/src/main/java/org/teiid/query/sql/lang/TableFunctionReference.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/sql/lang/TableFunctionReference.java (rev 0)
+++ trunk/engine/src/main/java/org/teiid/query/sql/lang/TableFunctionReference.java 2010-06-04 21:51:29 UTC (rev 2181)
@@ -0,0 +1,172 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA.
+ */
+
+package org.teiid.query.sql.lang;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+
+import org.teiid.core.types.DataTypeManager;
+import org.teiid.core.util.EquivalenceUtil;
+import org.teiid.query.sql.symbol.ElementSymbol;
+import org.teiid.query.sql.symbol.GroupSymbol;
+import org.teiid.query.sql.util.SymbolMap;
+
+public abstract class TableFunctionReference extends FromClause {
+
+ public static class ProjectedColumn {
+ private String name;
+ private String type;
+ private ElementSymbol symbol;
+
+ public ProjectedColumn(String name, String type) {
+ this.name = name;
+ this.type = type;
+ this.symbol = new ElementSymbol(name);
+ symbol.setType(DataTypeManager.getDataTypeClass(type));
+ }
+
+ protected ProjectedColumn() {
+
+ }
+
+ public ElementSymbol getSymbol() {
+ return symbol;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public String getType() {
+ return type;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (obj == this) {
+ return true;
+ }
+ if (!(obj instanceof ProjectedColumn)) {
+ return false;
+ }
+ ProjectedColumn other = (ProjectedColumn)obj;
+ return this.symbol.equals(other.symbol)
+ && this.name.equals(other.name)
+ && this.type.equals(other.type);
+ }
+
+ public int hashCode() {
+ return symbol.hashCode();
+ }
+
+ public void copy(ProjectedColumn copy) {
+ copy.name = this.name;
+ copy.type = this.type;
+ copy.symbol = (ElementSymbol)this.symbol.clone();
+ }
+
+ }
+
+ private GroupSymbol symbol;
+ private SymbolMap correlatedReferences;
+
+ public SymbolMap getCorrelatedReferences() {
+ return correlatedReferences;
+ }
+
+ public void setCorrelatedReferences(SymbolMap correlatedReferences) {
+ this.correlatedReferences = correlatedReferences;
+ }
+
+ public void copy(TableFunctionReference copy) {
+ copy.symbol = (GroupSymbol)this.symbol.clone();
+ if (correlatedReferences != null) {
+ copy.correlatedReferences = correlatedReferences.clone();
+ }
+ }
+
+ @Override
+ public void collectGroups(Collection groups) {
+ groups.add(getGroupSymbol());
+ }
+
+ /**
+ * Get name of this clause.
+ * @return Name of clause
+ */
+ public String getName() {
+ return this.symbol.getName();
+ }
+
+ public String getOutputName() {
+ return this.symbol.getOutputName();
+ }
+
+ /**
+ * Get GroupSymbol representing the named subquery
+ * @return GroupSymbol representing the subquery
+ */
+ public GroupSymbol getGroupSymbol() {
+ return this.symbol;
+ }
+
+ /**
+ * Reset the alias for this subquery from clause and it's pseudo-GroupSymbol.
+ * WARNING: this will modify the hashCode and equals semantics and will cause this object
+ * to be lost if currently in a HashMap or HashSet.
+ * @param name New name
+ * @since 4.3
+ */
+ public void setName(String name) {
+ this.symbol = new GroupSymbol(name);
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (obj == this) {
+ return true;
+ }
+ if (!(obj instanceof TableFunctionReference)) {
+ return false;
+ }
+ TableFunctionReference other = (TableFunctionReference)obj;
+ return EquivalenceUtil.areEqual(symbol, other.symbol);
+ }
+
+ @Override
+ public int hashCode() {
+ return this.symbol.hashCode();
+ }
+
+ public abstract List<? extends ProjectedColumn> getColumns();
+
+ public List<ElementSymbol> getProjectedSymbols() {
+ ArrayList<ElementSymbol> symbols = new ArrayList<ElementSymbol>(getColumns().size());
+ for (ProjectedColumn col : getColumns()) {
+ symbols.add(col.getSymbol());
+ }
+ return symbols;
+ }
+
+}
Property changes on: trunk/engine/src/main/java/org/teiid/query/sql/lang/TableFunctionReference.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified: trunk/engine/src/main/java/org/teiid/query/sql/lang/TextTable.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/sql/lang/TextTable.java 2010-06-04 21:35:06 UTC (rev 2180)
+++ trunk/engine/src/main/java/org/teiid/query/sql/lang/TextTable.java 2010-06-04 21:51:29 UTC (rev 2181)
@@ -1,47 +1,51 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA.
+ */
+
package org.teiid.query.sql.lang;
import java.util.ArrayList;
-import java.util.Collection;
import java.util.List;
-import org.teiid.core.types.DataTypeManager;
import org.teiid.core.util.EquivalenceUtil;
-import org.teiid.query.sql.LanguageObject;
import org.teiid.query.sql.LanguageVisitor;
-import org.teiid.query.sql.symbol.ElementSymbol;
import org.teiid.query.sql.symbol.Expression;
-import org.teiid.query.sql.symbol.GroupSymbol;
-import org.teiid.query.sql.util.SymbolMap;
-public class TextTable extends FromClause {
+/**
+ * Represents the TEXTTABLE table function.
+ */
+public class TextTable extends TableFunctionReference {
- public static class TextColumn {
- private String name;
- private String type;
+ public static class TextColumn extends ProjectedColumn {
private Integer width;
public TextColumn(String name, String type, Integer width) {
- this.name = name;
- this.type = type;
+ super(name, type);
this.width = width;
}
- public void setName(String name) {
- this.name = name;
+ protected TextColumn() {
+
}
- public String getName() {
- return name;
- }
-
- public String getType() {
- return type;
- }
-
- public void setType(String type) {
- this.type = type;
- }
-
public Integer getWidth() {
return width;
}
@@ -55,28 +59,22 @@
if (obj == this) {
return true;
}
- if (!(obj instanceof TextColumn)) {
+ if (!super.equals(obj) || !(obj instanceof TextColumn)) {
return false;
}
TextColumn other = (TextColumn)obj;
- return this.name.equalsIgnoreCase(other.name) && this.type.equalsIgnoreCase(other.type)
- && EquivalenceUtil.areEqual(width, other.width);
+ return EquivalenceUtil.areEqual(width, other.width);
}
- public int hashCode() {
- return name.hashCode();
- }
-
@Override
public TextColumn clone() {
- return new TextColumn(name, type, width);
+ TextColumn clone = new TextColumn();
+ clone.width = this.width;
+ this.copy(clone);
+ return clone;
}
}
- private GroupSymbol symbol;
- private List<ElementSymbol> projectedSymbols;
- private SymbolMap correlatedReferences;
-
private Expression file;
private List<TextColumn> columns = new ArrayList<TextColumn>();
private Character delimiter;
@@ -95,14 +93,6 @@
this.quote = quote;
}
- public SymbolMap getCorrelatedReferences() {
- return correlatedReferences;
- }
-
- public void setCorrelatedReferences(SymbolMap correlatedReferences) {
- this.correlatedReferences = correlatedReferences;
- }
-
public boolean isEscape() {
return escape;
}
@@ -167,97 +157,36 @@
@Override
public TextTable clone() {
TextTable clone = new TextTable();
+ this.copy(clone);
clone.setDelimiter(this.delimiter);
clone.setFile((Expression)this.file.clone());
clone.setHeader(this.header);
clone.setSkip(this.skip);
clone.setQuote(this.quote);
clone.escape = this.escape;
- clone.symbol = (GroupSymbol)this.symbol.clone();
for (TextColumn column : columns) {
clone.getColumns().add(column.clone());
}
- if (projectedSymbols != null) {
- clone.projectedSymbols = LanguageObject.Util.deepClone(this.projectedSymbols, ElementSymbol.class);
- }
- if (correlatedReferences != null) {
- clone.correlatedReferences = correlatedReferences.clone();
- }
clone.fixedWidth = this.fixedWidth;
return clone;
}
@Override
- public void collectGroups(Collection groups) {
- groups.add(getGroupSymbol());
- }
-
- /**
- * Get name of this clause.
- * @return Name of clause
- */
- public String getName() {
- return this.symbol.getName();
- }
-
- public String getOutputName() {
- return this.symbol.getOutputName();
- }
-
- /**
- * Get GroupSymbol representing the named subquery
- * @return GroupSymbol representing the subquery
- */
- public GroupSymbol getGroupSymbol() {
- return this.symbol;
- }
-
- /**
- * Reset the alias for this subquery from clause and it's pseudo-GroupSymbol.
- * WARNING: this will modify the hashCode and equals semantics and will cause this object
- * to be lost if currently in a HashMap or HashSet.
- * @param name New name
- * @since 4.3
- */
- public void setName(String name) {
- this.symbol = new GroupSymbol(name);
- }
-
- @Override
public boolean equals(Object obj) {
if (obj == this) {
return true;
}
- if (!(obj instanceof TextTable)) {
+ if (!super.equals(obj) || !(obj instanceof TextTable)) {
return false;
}
TextTable other = (TextTable)obj;
return this.columns.equals(other.columns)
&& EquivalenceUtil.areEqual(file, other.file)
- && EquivalenceUtil.areEqual(symbol, other.symbol)
&& EquivalenceUtil.areEqual(delimiter, other.delimiter)
&& EquivalenceUtil.areEqual(escape, other.escape)
&& EquivalenceUtil.areEqual(quote, other.quote)
&& EquivalenceUtil.areEqual(header, other.header)
&& EquivalenceUtil.areEqual(skip, other.skip);
-
}
- @Override
- public int hashCode() {
- return this.symbol.hashCode();
- }
-
- public List<ElementSymbol> getProjectedSymbols() {
- if (projectedSymbols == null) {
- projectedSymbols = new ArrayList<ElementSymbol>(columns.size());
- for (TextColumn column : columns) {
- ElementSymbol elementSymbol = new ElementSymbol(column.getName());
- elementSymbol.setType(DataTypeManager.getDataTypeClass(column.getType()));
- projectedSymbols.add(elementSymbol);
- }
- }
- return projectedSymbols;
- }
-
}
Added: trunk/engine/src/main/java/org/teiid/query/sql/lang/XMLTable.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/sql/lang/XMLTable.java (rev 0)
+++ trunk/engine/src/main/java/org/teiid/query/sql/lang/XMLTable.java 2010-06-04 21:51:29 UTC (rev 2181)
@@ -0,0 +1,198 @@
+package org.teiid.query.sql.lang;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.List;
+
+import net.sf.saxon.sxpath.XPathExpression;
+
+import org.teiid.core.TeiidProcessingException;
+import org.teiid.core.types.DataTypeManager;
+import org.teiid.core.util.EquivalenceUtil;
+import org.teiid.query.sql.LanguageVisitor;
+import org.teiid.query.sql.symbol.DerivedColumn;
+import org.teiid.query.sql.symbol.ElementSymbol;
+import org.teiid.query.sql.symbol.Expression;
+import org.teiid.query.sql.symbol.XMLNamespaces;
+import org.teiid.query.xquery.saxon.SaxonXQueryExpression;
+
+public class XMLTable extends TableFunctionReference {
+
+ public static class XMLColumn extends ProjectedColumn {
+ private boolean ordinal;
+ private String path;
+ private Expression defaultExpression;
+
+ private XPathExpression pathExpression;
+
+ public XMLColumn(String name) {
+ super(name, DataTypeManager.DefaultDataTypes.STRING);
+ this.ordinal = true;
+ }
+
+ public XMLColumn(String name, String type, String path, Expression defaultExpression) {
+ super(name, type);
+ this.path = path;
+ this.defaultExpression = defaultExpression;
+ }
+
+ protected XMLColumn() {
+
+ }
+
+ public Expression getDefaultExpression() {
+ return defaultExpression;
+ }
+
+ public void setDefaultExpression(Expression defaultExpression) {
+ this.defaultExpression = defaultExpression;
+ }
+
+ public String getPath() {
+ return path;
+ }
+
+ public void setPath(String path) {
+ this.path = path;
+ }
+
+ public boolean isOrdinal() {
+ return ordinal;
+ }
+
+ public void setOrdinal(boolean ordinal) {
+ this.ordinal = ordinal;
+ }
+
+ public void setPathExpression(XPathExpression pathExpression) {
+ this.pathExpression = pathExpression;
+ }
+
+ public XPathExpression getPathExpression() {
+ return pathExpression;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (obj == this) {
+ return true;
+ }
+ if (!super.equals(obj) || !(obj instanceof XMLColumn)) {
+ return false;
+ }
+ XMLColumn other = (XMLColumn)obj;
+ return this.ordinal == other.ordinal
+ && EquivalenceUtil.areEqual(this.path, other.path)
+ && EquivalenceUtil.areEqual(this.defaultExpression, other.defaultExpression);
+ }
+
+ @Override
+ public XMLColumn clone() {
+ XMLColumn clone = new XMLColumn();
+ super.copy(clone);
+ clone.ordinal = this.ordinal;
+ clone.path = this.path;
+ if (this.defaultExpression != null) {
+ clone.defaultExpression = (Expression)this.defaultExpression.clone();
+ }
+ clone.pathExpression = this.pathExpression;
+ return clone;
+ }
+ }
+
+ private List<XMLColumn> columns = new ArrayList<XMLColumn>();
+ private XMLNamespaces namespaces;
+ private String xquery;
+ private List<DerivedColumn> passing = new ArrayList<DerivedColumn>();
+ private ElementSymbol defaultColumn;
+
+ private SaxonXQueryExpression xqueryExpression;
+
+ public List<DerivedColumn> getPassing() {
+ return passing;
+ }
+
+ public void compileXqueryExpression() throws TeiidProcessingException {
+ this.xqueryExpression = new SaxonXQueryExpression(xquery, namespaces, passing, columns);
+ }
+
+ public SaxonXQueryExpression getXqueryExpression() {
+ return xqueryExpression;
+ }
+
+ public void setPassing(List<DerivedColumn> passing) {
+ this.passing = passing;
+ }
+
+ public String getXquery() {
+ return xquery;
+ }
+
+ public void setXquery(String xquery) {
+ this.xquery = xquery;
+ }
+
+ public List<XMLColumn> getColumns() {
+ return columns;
+ }
+
+ public void setColumns(List<XMLColumn> columns) {
+ this.columns = columns;
+ }
+
+ public XMLNamespaces getNamespaces() {
+ return namespaces;
+ }
+
+ public void setNamespaces(XMLNamespaces namespaces) {
+ this.namespaces = namespaces;
+ }
+
+ @Override
+ public List<ElementSymbol> getProjectedSymbols() {
+ if (!columns.isEmpty()) {
+ return super.getProjectedSymbols();
+ }
+ if (defaultColumn == null) {
+ defaultColumn = new ElementSymbol("COLUMN_VALUE"); //$NON-NLS-1$
+ defaultColumn.setType(DataTypeManager.DefaultDataClasses.XML);
+ }
+ return Arrays.asList(defaultColumn);
+ }
+
+ @Override
+ public void acceptVisitor(LanguageVisitor visitor) {
+ visitor.visit(this);
+ }
+
+ @Override
+ public XMLTable clone() {
+ XMLTable clone = new XMLTable();
+ for (XMLColumn column : columns) {
+ clone.getColumns().add(column.clone());
+ }
+ if (defaultColumn != null) {
+ clone.defaultColumn = this.defaultColumn;
+ }
+ return clone;
+ }
+
+ @Override
+ public void collectGroups(Collection groups) {
+ groups.add(getGroupSymbol());
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (obj == this) {
+ return true;
+ }
+ if (!super.equals(obj) || !(obj instanceof XMLTable)) {
+ return false;
+ }
+ XMLTable other = (XMLTable)obj;
+ return this.columns.equals(other.columns);
+ }
+
+}
Property changes on: trunk/engine/src/main/java/org/teiid/query/sql/lang/XMLTable.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Deleted: trunk/engine/src/main/java/org/teiid/query/sql/lang/XQuery.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/sql/lang/XQuery.java 2010-06-04 21:35:06 UTC (rev 2180)
+++ trunk/engine/src/main/java/org/teiid/query/sql/lang/XQuery.java 2010-06-04 21:51:29 UTC (rev 2181)
@@ -1,155 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * See the COPYRIGHT.txt file distributed with this work for information
- * regarding copyright ownership. Some portions may be licensed
- * to Red Hat, Inc. under one or more contributor license agreements.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
- * 02110-1301 USA.
- */
-
-package org.teiid.query.sql.lang;
-
-import java.util.ArrayList;
-import java.util.List;
-import java.util.Map;
-
-import org.teiid.core.types.DataTypeManager;
-import org.teiid.core.util.EquivalenceUtil;
-import org.teiid.query.sql.LanguageVisitor;
-import org.teiid.query.sql.symbol.ElementSymbol;
-import org.teiid.query.sql.visitor.SQLStringVisitor;
-import org.teiid.query.xquery.XQueryExpression;
-
-
-/**
- * An XQuery command object
- */
-public class XQuery extends Command {
-
- private String xQuery;
- private XQueryExpression compiledXQuery;
- private Map variables;
- private String procedureGroup;
-
- public XQuery(){
- }
-
- public XQuery(String xQuery, XQueryExpression compiledXQuery){
- this.xQuery = xQuery;
- this.compiledXQuery = compiledXQuery;
- }
-
- public void setProcedureGroup(String procedureGroup) {
- this.procedureGroup = procedureGroup;
- }
-
- public void setVariables(Map variables) {
- this.variables = variables;
- }
-
- public Map getVariables() {
- return variables;
- }
-
- public String getXQuery(){
- return xQuery;
- }
-
- public XQueryExpression getCompiledXQuery(){
- return this.compiledXQuery;
- }
-
- /**
- * @see org.teiid.query.sql.lang.Command#getType()
- */
- public int getType() {
- return Command.TYPE_XQUERY;
- }
-
- /**
- * @see org.teiid.query.sql.lang.Command#getProjectedSymbols()
- */
- public List getProjectedSymbols() {
- List selectList = new ArrayList(1);
- ElementSymbol xmlElement = new ElementSymbol("xml"); //$NON-NLS-1$
- xmlElement.setType(DataTypeManager.DefaultDataClasses.XML);
- selectList.add(xmlElement);
- return selectList;
- }
-
- /**
- * Compare two queries for equality. Queries will only evaluate to equal if
- * they are IDENTICAL.
- * @param obj Other object
- * @return True if equal
- */
- public boolean equals(Object obj) {
- // Quick same object test
- if(this == obj) {
- return true;
- }
-
- // Quick fail tests
- if(!(obj instanceof XQuery)) {
- return false;
- }
-
- return EquivalenceUtil.areEqual(getXQuery(), ((XQuery)obj).getXQuery());
- }
-
- /**
- * Get hashcode for query.
- * @return Hash code
- */
- public int hashCode() {
- return xQuery.hashCode();
- }
-
- /**
- * Return a copy of this SQLQuery.
- * @return Deep or safe clone
- */
- public Object clone() {
- XQuery copy = new XQuery(getXQuery(), this.compiledXQuery);
- copy.variables = variables;
- copy.procedureGroup = procedureGroup;
- copyMetadataState(copy);
- return copy;
- }
-
- public void acceptVisitor(LanguageVisitor visitor) {
- visitor.visit(this);
- }
-
- /**
- * Returns a string representation of an instance of this class.
- * @return String representation of object
- */
- public String toString() {
- return SQLStringVisitor.getSQLString(this);
- }
-
- /**
- * @see org.teiid.query.sql.lang.Command#areResultsCachable()
- */
- public boolean areResultsCachable() {
- return true;
- }
-
- public String getProcedureGroup() {
- return procedureGroup;
- }
-}
Modified: trunk/engine/src/main/java/org/teiid/query/sql/navigator/PreOrPostOrderNavigator.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/sql/navigator/PreOrPostOrderNavigator.java 2010-06-04 21:35:06 UTC (rev 2180)
+++ trunk/engine/src/main/java/org/teiid/query/sql/navigator/PreOrPostOrderNavigator.java 2010-06-04 21:51:29 UTC (rev 2181)
@@ -64,7 +64,7 @@
import org.teiid.query.sql.lang.TextTable;
import org.teiid.query.sql.lang.UnaryFromClause;
import org.teiid.query.sql.lang.Update;
-import org.teiid.query.sql.lang.XQuery;
+import org.teiid.query.sql.lang.XMLTable;
import org.teiid.query.sql.proc.AssignmentStatement;
import org.teiid.query.sql.proc.Block;
import org.teiid.query.sql.proc.BreakStatement;
@@ -85,6 +85,7 @@
import org.teiid.query.sql.symbol.AllSymbol;
import org.teiid.query.sql.symbol.CaseExpression;
import org.teiid.query.sql.symbol.Constant;
+import org.teiid.query.sql.symbol.DerivedColumn;
import org.teiid.query.sql.symbol.ElementSymbol;
import org.teiid.query.sql.symbol.Expression;
import org.teiid.query.sql.symbol.ExpressionSymbol;
@@ -93,12 +94,11 @@
import org.teiid.query.sql.symbol.Reference;
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.XMLAttributes;
import org.teiid.query.sql.symbol.XMLElement;
import org.teiid.query.sql.symbol.XMLForest;
import org.teiid.query.sql.symbol.XMLNamespaces;
-import org.teiid.query.sql.util.SymbolMap;
+import org.teiid.query.sql.symbol.XMLSerialize;
@@ -479,11 +479,6 @@
visitNode(obj.getBlock());
postVisitVisitor(obj);
}
- public void visit(XQuery obj) {
- preVisitVisitor(obj);
- visitNode(obj.getOption());
- postVisitVisitor(obj);
- }
/**
* NOTE: we specifically don't need to visit the as columns or the using identifiers.
@@ -520,20 +515,14 @@
public void visit(XMLForest obj) {
preVisitVisitor(obj);
visitNode(obj.getNamespaces());
- //we just want the underlying expressions, not the wrapping alias/expression symbols
- for (SingleElementSymbol symbol : obj.getArgs()) {
- visitNode(SymbolMap.getExpression(symbol));
- }
+ visitNodes(obj.getArgs());
postVisitVisitor(obj);
}
@Override
public void visit(XMLAttributes obj) {
preVisitVisitor(obj);
- //we just want the underlying expressions, not the wrapping alias/expression symbols
- for (SingleElementSymbol symbol : obj.getArgs()) {
- visitNode(SymbolMap.getExpression(symbol));
- }
+ visitNodes(obj.getArgs());
postVisitVisitor(obj);
}
@@ -560,6 +549,32 @@
postVisitVisitor(obj);
}
+ @Override
+ public void visit(XMLTable obj) {
+ preVisitVisitor(obj);
+ visitNode(obj.getNamespaces());
+ visitNodes(obj.getPassing());
+ for (XMLTable.XMLColumn column : obj.getColumns()) {
+ visitNode(column.getDefaultExpression());
+ }
+ visitNode(obj.getGroupSymbol());
+ postVisitVisitor(obj);
+ }
+
+ @Override
+ public void visit(DerivedColumn obj) {
+ preVisitVisitor(obj);
+ visitNode(obj.getExpression());
+ postVisitVisitor(obj);
+ }
+
+ @Override
+ public void visit(XMLSerialize obj) {
+ preVisitVisitor(obj);
+ visitNode(obj.getExpression());
+ postVisitVisitor(obj);
+ }
+
public static void doVisit(LanguageObject object, LanguageVisitor visitor, boolean order) {
PreOrPostOrderNavigator nav = new PreOrPostOrderNavigator(visitor, order);
object.acceptVisitor(nav);
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-04 21:35:06 UTC (rev 2180)
+++ trunk/engine/src/main/java/org/teiid/query/sql/symbol/AggregateSymbol.java 2010-06-04 21:51:29 UTC (rev 2181)
@@ -31,6 +31,7 @@
import org.teiid.core.util.EquivalenceUtil;
import org.teiid.core.util.HashCodeUtil;
import org.teiid.language.SQLReservedWords;
+import org.teiid.language.SQLReservedWords.NonReserved;
import org.teiid.query.QueryPlugin;
import org.teiid.query.sql.LanguageVisitor;
import org.teiid.query.sql.lang.OrderBy;
@@ -69,11 +70,11 @@
static {
AGGREGATE_FUNCTIONS = new HashSet<String>();
- AGGREGATE_FUNCTIONS.add(SQLReservedWords.COUNT);
- AGGREGATE_FUNCTIONS.add(SQLReservedWords.SUM);
- AGGREGATE_FUNCTIONS.add(SQLReservedWords.AVG);
- AGGREGATE_FUNCTIONS.add(SQLReservedWords.MIN);
- AGGREGATE_FUNCTIONS.add(SQLReservedWords.MAX);
+ 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(SQLReservedWords.XMLAGG);
SUM_TYPES = new HashMap<Class<?>, Class<?>>();
@@ -113,7 +114,7 @@
/**
* Construct an aggregate symbol with all given data.
* @param name Name of the function
- * @param aggregateFunction Aggregate function type ({@link org.teiid.language.SQLReservedWords#COUNT}, etc)
+ * @param aggregateFunction Aggregate function type ({@link org.teiid.language.SQLReservedWords.NonReserved#COUNT}, etc)
* @param isDistinct True if DISTINCT flag is set
* @param expression Contained expression
*/
@@ -128,11 +129,11 @@
* Set the aggregate function. If the aggregate function is an invalid value, an
* IllegalArgumentException is thrown.
* @param aggregateFunction Aggregate function type
- * @see org.teiid.language.SQLReservedWords#COUNT
- * @see org.teiid.language.SQLReservedWords#SUM
- * @see org.teiid.language.SQLReservedWords#AVG
- * @see org.teiid.language.SQLReservedWords#MIN
- * @see org.teiid.language.SQLReservedWords#MAX
+ * @see org.teiid.language.SQLReservedWords.NonReserved#COUNT
+ * @see org.teiid.language.SQLReservedWords.NonReserved#SUM
+ * @see org.teiid.language.SQLReservedWords.NonReserved#AVG
+ * @see org.teiid.language.SQLReservedWords.NonReserved#MIN
+ * @see org.teiid.language.SQLReservedWords.NonReserved#MAX
*/
private void setAggregateFunction(String aggregateFunction) {
// Validate aggregate
@@ -146,11 +147,11 @@
* 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.SQLReservedWords#COUNT
- * @see org.teiid.language.SQLReservedWords#SUM
- * @see org.teiid.language.SQLReservedWords#AVG
- * @see org.teiid.language.SQLReservedWords#MIN
- * @see org.teiid.language.SQLReservedWords#MAX
+ * @see org.teiid.language.SQLReservedWords.NonReserved#COUNT
+ * @see org.teiid.language.SQLReservedWords.NonReserved#SUM
+ * @see org.teiid.language.SQLReservedWords.NonReserved#AVG
+ * @see org.teiid.language.SQLReservedWords.NonReserved#MIN
+ * @see org.teiid.language.SQLReservedWords.NonReserved#MAX
*/
public String getAggregateFunction() {
return this.aggregate;
@@ -171,12 +172,12 @@
* @return Type of the symbol
*/
public Class<?> getType() {
- if(this.aggregate.equals(SQLReservedWords.COUNT)) {
+ if(this.aggregate.equals(NonReserved.COUNT)) {
return COUNT_TYPE;
- } else if(this.aggregate.equals(SQLReservedWords.SUM) ) {
+ } else if(this.aggregate.equals(NonReserved.SUM) ) {
Class<?> expressionType = this.getExpression().getType();
return SUM_TYPES.get(expressionType);
- } else if (this.aggregate.equals(SQLReservedWords.AVG)) {
+ } else if (this.aggregate.equals(NonReserved.AVG)) {
Class<?> expressionType = this.getExpression().getType();
return AVG_TYPES.get(expressionType);
} else {
Added: trunk/engine/src/main/java/org/teiid/query/sql/symbol/DerivedColumn.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/sql/symbol/DerivedColumn.java (rev 0)
+++ trunk/engine/src/main/java/org/teiid/query/sql/symbol/DerivedColumn.java 2010-06-04 21:51:29 UTC (rev 2181)
@@ -0,0 +1,100 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA.
+ */
+
+package org.teiid.query.sql.symbol;
+
+import org.teiid.core.util.EquivalenceUtil;
+import org.teiid.core.util.HashCodeUtil;
+import org.teiid.query.sql.LanguageObject;
+import org.teiid.query.sql.LanguageVisitor;
+import org.teiid.query.sql.visitor.SQLStringVisitor;
+
+public class DerivedColumn implements LanguageObject {
+
+ private String alias;
+ private Expression expression;
+ private boolean propagateName = true;
+
+ public DerivedColumn(String name, Expression expression) {
+ this.alias = name;
+ this.expression = expression;
+ }
+
+ public boolean isPropagateName() {
+ return propagateName;
+ }
+
+ public void setPropagateName(boolean propagateName) {
+ this.propagateName = propagateName;
+ }
+
+ public String getAlias() {
+ return alias;
+ }
+
+ public Expression getExpression() {
+ return expression;
+ }
+
+ public void setAlias(String name) {
+ this.alias = name;
+ }
+
+ public void setExpression(Expression expression) {
+ this.expression = expression;
+ }
+
+ @Override
+ public void acceptVisitor(LanguageVisitor visitor) {
+ visitor.visit(this);
+ }
+
+ @Override
+ public int hashCode() {
+ return HashCodeUtil.hashCode(0, alias, expression);
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (obj == this) {
+ return true;
+ }
+ if (!(obj instanceof DerivedColumn)) {
+ return false;
+ }
+ DerivedColumn other = (DerivedColumn)obj;
+ return EquivalenceUtil.areEqual(alias, other.alias) && this.expression.equals(other.expression);
+ }
+
+ @Override
+ public DerivedColumn clone() {
+ DerivedColumn clone = new DerivedColumn(alias, (Expression)this.expression.clone());
+ clone.propagateName = propagateName;
+ return clone;
+ }
+
+ @Override
+ public String toString() {
+ return SQLStringVisitor.getSQLString(this);
+ }
+
+}
Property changes on: trunk/engine/src/main/java/org/teiid/query/sql/symbol/DerivedColumn.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified: trunk/engine/src/main/java/org/teiid/query/sql/symbol/XMLAttributes.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/sql/symbol/XMLAttributes.java 2010-06-04 21:35:06 UTC (rev 2180)
+++ trunk/engine/src/main/java/org/teiid/query/sql/symbol/XMLAttributes.java 2010-06-04 21:51:29 UTC (rev 2181)
@@ -36,19 +36,19 @@
public class XMLAttributes implements LanguageObject {
private static final long serialVersionUID = -3348922701950966494L;
- private List<SingleElementSymbol> args;
+ private List<DerivedColumn> args;
- public XMLAttributes(List<SingleElementSymbol> args) {
+ public XMLAttributes(List<DerivedColumn> args) {
this.args = args;
}
- public List<SingleElementSymbol> getArgs() {
+ public List<DerivedColumn> getArgs() {
return args;
}
@Override
public XMLAttributes clone() {
- XMLAttributes clone = new XMLAttributes(LanguageObject.Util.deepClone(args, SingleElementSymbol.class));
+ XMLAttributes clone = new XMLAttributes(LanguageObject.Util.deepClone(args, DerivedColumn.class));
return clone;
}
Modified: trunk/engine/src/main/java/org/teiid/query/sql/symbol/XMLForest.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/sql/symbol/XMLForest.java 2010-06-04 21:35:06 UTC (rev 2180)
+++ trunk/engine/src/main/java/org/teiid/query/sql/symbol/XMLForest.java 2010-06-04 21:51:29 UTC (rev 2181)
@@ -25,20 +25,18 @@
import java.util.List;
import org.teiid.core.types.DataTypeManager;
-import org.teiid.core.util.EquivalenceUtil;
import org.teiid.core.util.HashCodeUtil;
import org.teiid.query.sql.LanguageObject;
import org.teiid.query.sql.LanguageVisitor;
import org.teiid.query.sql.visitor.SQLStringVisitor;
-
public class XMLForest implements Expression {
private static final long serialVersionUID = -3348922701950966494L;
- private List<SingleElementSymbol> args;
+ private List<DerivedColumn> args;
private XMLNamespaces namespaces;
- public XMLForest(List<SingleElementSymbol> args) {
+ public XMLForest(List<DerivedColumn> args) {
this.args = args;
}
@@ -50,7 +48,7 @@
this.namespaces = namespaces;
}
- public List<SingleElementSymbol> getArgs() {
+ public List<DerivedColumn> getArgs() {
return args;
}
@@ -61,8 +59,8 @@
@Override
public boolean isResolved() {
- for (SingleElementSymbol arg : args) {
- if (!arg.isResolved()) {
+ for (DerivedColumn arg : args) {
+ if (!arg.getExpression().isResolved()) {
return false;
}
}
@@ -76,7 +74,7 @@
@Override
public XMLForest clone() {
- XMLForest clone = new XMLForest(LanguageObject.Util.deepClone(args, SingleElementSymbol.class));
+ XMLForest clone = new XMLForest(LanguageObject.Util.deepClone(args, DerivedColumn.class));
return clone;
}
Added: trunk/engine/src/main/java/org/teiid/query/sql/symbol/XMLSerialize.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/sql/symbol/XMLSerialize.java (rev 0)
+++ trunk/engine/src/main/java/org/teiid/query/sql/symbol/XMLSerialize.java 2010-06-04 21:51:29 UTC (rev 2181)
@@ -0,0 +1,113 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA.
+ */
+
+package org.teiid.query.sql.symbol;
+
+import org.teiid.core.types.DataTypeManager;
+import org.teiid.query.sql.LanguageVisitor;
+import org.teiid.query.sql.visitor.SQLStringVisitor;
+
+public class XMLSerialize implements Expression {
+
+ private static final long serialVersionUID = -6574662238317329252L;
+
+ private boolean document;
+ private Expression expression;
+ private String typeString;
+ private Class<?> type;
+
+ @Override
+ public Class<?> getType() {
+ if (type == null) {
+ if (typeString == null) {
+ type = DataTypeManager.DefaultDataClasses.CLOB;
+ } else {
+ type = DataTypeManager.getDataTypeClass(typeString);
+ }
+ }
+ return type;
+ }
+
+ public Expression getExpression() {
+ return expression;
+ }
+
+ public boolean isDocument() {
+ return document;
+ }
+
+ public void setDocument(boolean document) {
+ this.document = document;
+ }
+
+ public void setExpression(Expression expression) {
+ this.expression = expression;
+ }
+
+ public void setTypeString(String typeString) {
+ this.typeString = typeString;
+ }
+
+ public String getTypeString() {
+ return typeString;
+ }
+
+ @Override
+ public boolean isResolved() {
+ return expression.isResolved();
+ }
+
+ @Override
+ public void acceptVisitor(LanguageVisitor visitor) {
+ visitor.visit(this);
+ }
+
+ @Override
+ public XMLSerialize clone() {
+ XMLSerialize clone = new XMLSerialize();
+ return clone;
+ }
+
+ @Override
+ public int hashCode() {
+ return expression.hashCode();
+ }
+
+ public boolean equals(Object obj) {
+ if (obj == this) {
+ return true;
+ }
+ if (!(obj instanceof XMLSerialize)) {
+ return false;
+ }
+ XMLSerialize other = (XMLSerialize)obj;
+ return document == other.document
+ && this.expression.equals(other.expression)
+ && this.getType() == other.getType();
+ }
+
+ @Override
+ public String toString() {
+ return SQLStringVisitor.getSQLString(this);
+ }
+
+}
Property changes on: trunk/engine/src/main/java/org/teiid/query/sql/symbol/XMLSerialize.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified: trunk/engine/src/main/java/org/teiid/query/sql/visitor/ExpressionMappingVisitor.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/sql/visitor/ExpressionMappingVisitor.java 2010-06-04 21:35:06 UTC (rev 2180)
+++ trunk/engine/src/main/java/org/teiid/query/sql/visitor/ExpressionMappingVisitor.java 2010-06-04 21:51:29 UTC (rev 2181)
@@ -49,18 +49,22 @@
import org.teiid.query.sql.lang.StoredProcedure;
import org.teiid.query.sql.lang.SubqueryCompareCriteria;
import org.teiid.query.sql.lang.SubquerySetCriteria;
+import org.teiid.query.sql.lang.XMLTable;
+import org.teiid.query.sql.lang.XMLTable.XMLColumn;
import org.teiid.query.sql.navigator.PreOrderNavigator;
import org.teiid.query.sql.proc.AssignmentStatement;
import org.teiid.query.sql.symbol.AggregateSymbol;
import org.teiid.query.sql.symbol.AliasSymbol;
import org.teiid.query.sql.symbol.CaseExpression;
+import org.teiid.query.sql.symbol.DerivedColumn;
+import org.teiid.query.sql.symbol.ElementSymbol;
import org.teiid.query.sql.symbol.Expression;
import org.teiid.query.sql.symbol.ExpressionSymbol;
import org.teiid.query.sql.symbol.Function;
import org.teiid.query.sql.symbol.SearchedCaseExpression;
import org.teiid.query.sql.symbol.SingleElementSymbol;
-import org.teiid.query.sql.symbol.XMLAttributes;
-import org.teiid.query.sql.symbol.XMLForest;
+import org.teiid.query.sql.symbol.XMLElement;
+import org.teiid.query.sql.symbol.XMLSerialize;
/**
@@ -88,15 +92,29 @@
}
@Override
- public void visit(XMLForest obj) {
- replaceSymbols(obj.getArgs(), true);
+ public void visit(DerivedColumn obj) {
+ Expression original = obj.getExpression();
+ obj.setExpression(replaceExpression(original));
+ if (obj.isPropagateName() && obj.getAlias() == null && !(obj.getExpression() instanceof ElementSymbol) && original instanceof ElementSymbol) {
+ obj.setAlias(((ElementSymbol)original).getShortName());
+ }
}
@Override
- public void visit(XMLAttributes obj) {
- replaceSymbols(obj.getArgs(), true);
+ public void visit(XMLTable obj) {
+ for (XMLColumn col : obj.getColumns()) {
+ Expression exp = col.getDefaultExpression();
+ if (exp != null) {
+ col.setDefaultExpression(replaceExpression(exp));
+ }
+ }
}
-
+
+ @Override
+ public void visit(XMLSerialize obj) {
+ obj.setExpression(replaceExpression(obj.getExpression()));
+ }
+
private void replaceSymbols(List symbols, boolean alias) {
for (int i = 0; i < symbols.size(); i++) {
Object symbol = symbols.get(i);
@@ -359,4 +377,11 @@
}
}
+ @Override
+ public void visit(XMLElement obj) {
+ for (int i = 0; i < obj.getContent().size(); i++) {
+ obj.getContent().set(i, replaceExpression(obj.getContent().get(i)));
+ }
+ }
+
}
Modified: trunk/engine/src/main/java/org/teiid/query/sql/visitor/SQLStringVisitor.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/sql/visitor/SQLStringVisitor.java 2010-06-04 21:35:06 UTC (rev 2180)
+++ trunk/engine/src/main/java/org/teiid/query/sql/visitor/SQLStringVisitor.java 2010-06-04 21:51:29 UTC (rev 2181)
@@ -32,6 +32,7 @@
import org.teiid.core.types.DataTypeManager;
import org.teiid.core.util.StringUtil;
import org.teiid.language.SQLReservedWords;
+import org.teiid.language.SQLReservedWords.NonReserved;
import org.teiid.language.SQLReservedWords.Tokens;
import org.teiid.query.function.FunctionLibrary;
import org.teiid.query.sql.LanguageObject;
@@ -78,8 +79,9 @@
import org.teiid.query.sql.lang.TextTable;
import org.teiid.query.sql.lang.UnaryFromClause;
import org.teiid.query.sql.lang.Update;
-import org.teiid.query.sql.lang.XQuery;
+import org.teiid.query.sql.lang.XMLTable;
import org.teiid.query.sql.lang.TextTable.TextColumn;
+import org.teiid.query.sql.lang.XMLTable.XMLColumn;
import org.teiid.query.sql.proc.AssignmentStatement;
import org.teiid.query.sql.proc.Block;
import org.teiid.query.sql.proc.BreakStatement;
@@ -101,6 +103,7 @@
import org.teiid.query.sql.symbol.AllSymbol;
import org.teiid.query.sql.symbol.CaseExpression;
import org.teiid.query.sql.symbol.Constant;
+import org.teiid.query.sql.symbol.DerivedColumn;
import org.teiid.query.sql.symbol.ElementSymbol;
import org.teiid.query.sql.symbol.Expression;
import org.teiid.query.sql.symbol.ExpressionSymbol;
@@ -115,6 +118,7 @@
import org.teiid.query.sql.symbol.XMLElement;
import org.teiid.query.sql.symbol.XMLForest;
import org.teiid.query.sql.symbol.XMLNamespaces;
+import org.teiid.query.sql.symbol.XMLSerialize;
import org.teiid.query.sql.symbol.XMLNamespaces.NamespaceItem;
import org.teiid.translator.SourceSystemFunctions;
@@ -961,17 +965,6 @@
}
}
- public void visit(XQuery obj) {
- // XQuery string
- parts.add(obj.getXQuery());
-
- // Option clause
- if(obj.getOption() != null) {
- parts.add(SPACE);
- parts.add(registerNode(obj.getOption()));
- }
- }
-
public void visit(StoredProcedure obj) {
addCacheHint(obj);
//exec clause
@@ -1249,7 +1242,7 @@
}
parts.add(")"); //$NON-NLS-1$
- } else if(name.equalsIgnoreCase(SQLReservedWords.TIMESTAMPADD) || name.equalsIgnoreCase(SQLReservedWords.TIMESTAMPDIFF)) {
+ } else if(name.equalsIgnoreCase(NonReserved.TIMESTAMPADD) || name.equalsIgnoreCase(NonReserved.TIMESTAMPDIFF)) {
parts.add(name);
parts.add("("); //$NON-NLS-1$
@@ -1274,11 +1267,15 @@
}
private void registerNodes(LanguageObject[] objects, int begin) {
- for (int i = begin; i < objects.length; i++) {
+ registerNodes(Arrays.asList(objects), begin);
+ }
+
+ private void registerNodes(List<? extends LanguageObject> objects, int begin) {
+ for (int i = begin; i < objects.size(); i++) {
if (i > 0) {
parts.add(", "); //$NON-NLS-1$
}
- parts.add(registerNode(objects[i]));
+ parts.add(registerNode(objects.get(i)));
}
}
@@ -1559,7 +1556,7 @@
public void visit(XMLAttributes obj) {
parts.add(FunctionLibrary.XMLATTRIBUTES);
parts.add("("); //$NON-NLS-1$
- registerNodes(obj.getArgs().toArray(new LanguageObject[obj.getArgs().size()]), 0);
+ registerNodes(obj.getArgs(), 0);
parts.add(")"); //$NON-NLS-1$
}
@@ -1579,7 +1576,7 @@
if (!obj.getContent().isEmpty()) {
parts.add(", "); //$NON-NLS-1$
}
- registerNodes(obj.getContent().toArray(new LanguageObject[obj.getContent().size()]), 0);
+ registerNodes(obj.getContent(), 0);
parts.add(")"); //$NON-NLS-1$
}
@@ -1591,7 +1588,7 @@
parts.add(registerNode(obj.getNamespaces()));
parts.add(", "); //$NON-NLS-1$
}
- registerNodes(obj.getArgs().toArray(new LanguageObject[obj.getArgs().size()]), 0);
+ registerNodes(obj.getArgs(), 0);
parts.add(")"); //$NON-NLS-1$
}
@@ -1605,9 +1602,8 @@
if (item.getUri() == null) {
parts.add("NO DEFAULT"); //$NON-NLS-1$
} else {
- parts.add("DEFAULT '"); //$NON-NLS-1$
+ parts.add("DEFAULT "); //$NON-NLS-1$
parts.add(registerNode(new Constant(item.getUri())));
- parts.add("'"); //$NON-NLS-1$
}
} else {
parts.add(registerNode(new Constant(item.getUri())));
@@ -1637,7 +1633,7 @@
parts.add("TEXTTABLE("); //$NON-NLS-1$
parts.add(registerNode(obj.getFile()));
parts.add(SPACE);
- parts.add("COLUMNS"); //$NON-NLS-1$
+ parts.add(NonReserved.COLUMNS);
for (Iterator<TextColumn> cols = obj.getColumns().iterator(); cols.hasNext();) {
TextColumn col = cols.next();
@@ -1647,7 +1643,7 @@
parts.add(col.getType());
if (col.getWidth() != null) {
parts.add(SPACE);
- parts.add("WIDTH"); //$NON-NLS-1$
+ parts.add(NonReserved.WIDTH);
parts.add(SPACE);
parts.add(col.getWidth());
}
@@ -1657,7 +1653,7 @@
}
if (obj.getDelimiter() != null) {
parts.add(SPACE);
- parts.add("DELIMITER"); //$NON-NLS-1$
+ parts.add(NonReserved.DELIMITER);
parts.add(SPACE);
parts.add(registerNode(new Constant(obj.getDelimiter())));
}
@@ -1666,14 +1662,14 @@
if (obj.isEscape()) {
parts.add(SQLReservedWords.ESCAPE);
} else {
- parts.add("QUOTE"); //$NON-NLS-1$
+ parts.add(NonReserved.QUOTE);
}
parts.add(SPACE);
parts.add(registerNode(new Constant(obj.getQuote())));
}
if (obj.getHeader() != null) {
parts.add(SPACE);
- parts.add("HEADER"); //$NON-NLS-1$
+ parts.add(NonReserved.HEADER);
if (1 != obj.getHeader()) {
parts.add(SPACE);
parts.add(obj.getHeader());
@@ -1692,6 +1688,91 @@
outputDisplayName(obj.getName());
}
+ @Override
+ public void visit(XMLTable obj) {
+ parts.add("XMLTABLE("); //$NON-NLS-1$
+ if (obj.getNamespaces() != null) {
+ parts.add(registerNode(obj.getNamespaces()));
+ parts.add(","); //$NON-NLS-1$
+ parts.add(SPACE);
+ }
+ parts.add(new Constant(obj.getXquery()));
+ if (!obj.getPassing().isEmpty()) {
+ parts.add(SPACE);
+ parts.add(NonReserved.PASSING);
+ parts.add(SPACE);
+ registerNodes(obj.getPassing(), 0);
+ }
+ if (!obj.getColumns().isEmpty()) {
+ parts.add(SPACE);
+ parts.add(NonReserved.COLUMNS);
+ for (Iterator<XMLColumn> cols = obj.getColumns().iterator(); cols.hasNext();) {
+ XMLColumn col = cols.next();
+ parts.add(SPACE);
+ outputDisplayName(col.getName());
+ parts.add(SPACE);
+ if (col.isOrdinal()) {
+ parts.add(SQLReservedWords.FOR);
+ parts.add(SPACE);
+ parts.add(NonReserved.ORDINALITY);
+ } else {
+ parts.add(col.getType());
+ if (col.getPath() != null) {
+ parts.add(SPACE);
+ parts.add(NonReserved.PATH);
+ parts.add(SPACE);
+ parts.add(new Constant(col.getPath()));
+ }
+ if (col.getDefaultExpression() != null) {
+ parts.add(SPACE);
+ parts.add(SQLReservedWords.DEFAULT);
+ parts.add(SPACE);
+ parts.add(registerNode(col.getDefaultExpression()));
+ }
+ }
+ if (cols.hasNext()) {
+ parts.add(","); //$NON-NLS-1$
+ }
+ }
+ }
+ parts.add(")");//$NON-NLS-1$
+ parts.add(SPACE);
+ parts.add(SQLReservedWords.AS);
+ parts.add(SPACE);
+ outputDisplayName(obj.getName());
+ }
+
+ @Override
+ public void visit(DerivedColumn obj) {
+ parts.add(registerNode(obj.getExpression()));
+ if (obj.getAlias() != null) {
+ parts.add(SPACE);
+ parts.add(SQLReservedWords.AS);
+ parts.add(SPACE);
+ outputDisplayName(obj.getAlias());
+ }
+ }
+
+ @Override
+ public void visit(XMLSerialize obj) {
+ parts.add(SQLReservedWords.XMLSERIALIZE);
+ parts.add(SQLReservedWords.Tokens.LPAREN);
+ if (obj.isDocument()) {
+ parts.add(SQLReservedWords.NonReserved.DOCUMENT);
+ } else {
+ parts.add(SQLReservedWords.NonReserved.CONTENT);
+ }
+ parts.add(SPACE);
+ parts.add(registerNode(obj.getExpression()));
+ if (obj.getTypeString() != null) {
+ parts.add(SPACE);
+ parts.add(SQLReservedWords.AS);
+ parts.add(SPACE);
+ parts.add(obj.getTypeString());
+ }
+ parts.add(SQLReservedWords.Tokens.RPAREN);
+ }
+
public static String escapeSinglePart(String part) {
if(isReservedWord(part)) {
return ID_ESCAPE_CHAR + part + ID_ESCAPE_CHAR;
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-04 21:35:06 UTC (rev 2180)
+++ trunk/engine/src/main/java/org/teiid/query/validator/AggregateValidationVisitor.java 2010-06-04 21:51:29 UTC (rev 2181)
@@ -27,6 +27,7 @@
import org.teiid.core.types.DataTypeManager;
import org.teiid.language.SQLReservedWords;
+import org.teiid.language.SQLReservedWords.NonReserved;
import org.teiid.query.QueryPlugin;
import org.teiid.query.sql.LanguageObject;
import org.teiid.query.sql.navigator.PreOrderNavigator;
@@ -72,12 +73,12 @@
// Verify data type of aggregate expression
String aggregateFunction = obj.getAggregateFunction();
- if((aggregateFunction.equals(SQLReservedWords.SUM) || aggregateFunction.equals(SQLReservedWords.AVG)) && obj.getType() == null) {
+ if((aggregateFunction.equals(NonReserved.SUM) || aggregateFunction.equals(NonReserved.AVG)) && obj.getType() == null) {
handleValidationError(QueryPlugin.Util.getString(ErrorMessageKeys.VALIDATOR_0041, new Object[] {aggregateFunction, obj}), obj);
} else if (aggregateFunction.equals(SQLReservedWords.XMLAGG) && obj.getType() != DataTypeManager.DefaultDataClasses.XML) {
- handleValidationError(QueryPlugin.Util.getString("AggregateValidationVisitor.non_xml", new Object[] {aggregateFunction, obj}), obj);
+ handleValidationError(QueryPlugin.Util.getString("AggregateValidationVisitor.non_xml", new Object[] {aggregateFunction, obj}), obj); //$NON-NLS-1$
}
- if((obj.isDistinct() || aggregateFunction.equals(SQLReservedWords.MIN) || aggregateFunction.equals(SQLReservedWords.MAX)) && DataTypeManager.isNonComparable(DataTypeManager.getDataTypeName(aggExp.getType()))) {
+ if((obj.isDistinct() || aggregateFunction.equals(NonReserved.MIN) || aggregateFunction.equals(NonReserved.MAX)) && DataTypeManager.isNonComparable(DataTypeManager.getDataTypeName(aggExp.getType()))) {
handleValidationError(QueryPlugin.Util.getString("AggregateValidationVisitor.non_comparable", new Object[] {aggregateFunction, obj}), obj); //$NON-NLS-1$
}
validateBelow = false;
Modified: trunk/engine/src/main/java/org/teiid/query/validator/ValidationVisitor.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/validator/ValidationVisitor.java 2010-06-04 21:35:06 UTC (rev 2180)
+++ trunk/engine/src/main/java/org/teiid/query/validator/ValidationVisitor.java 2010-06-04 21:51:29 UTC (rev 2181)
@@ -31,10 +31,9 @@
import java.util.Map;
import java.util.Set;
-import javax.xml.xpath.XPathExpressionException;
+import net.sf.saxon.trans.XPathException;
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.QueryValidatorException;
import org.teiid.core.TeiidComponentException;
@@ -81,7 +80,9 @@
import org.teiid.query.sql.lang.SubquerySetCriteria;
import org.teiid.query.sql.lang.TextTable;
import org.teiid.query.sql.lang.Update;
+import org.teiid.query.sql.lang.XMLTable;
import org.teiid.query.sql.lang.SetQuery.Operation;
+import org.teiid.query.sql.lang.XMLTable.XMLColumn;
import org.teiid.query.sql.navigator.PreOrderNavigator;
import org.teiid.query.sql.proc.AssignmentStatement;
import org.teiid.query.sql.proc.CreateUpdateProcedureCommand;
@@ -94,6 +95,7 @@
import org.teiid.query.sql.symbol.AbstractCaseExpression;
import org.teiid.query.sql.symbol.AggregateSymbol;
import org.teiid.query.sql.symbol.Constant;
+import org.teiid.query.sql.symbol.DerivedColumn;
import org.teiid.query.sql.symbol.ElementSymbol;
import org.teiid.query.sql.symbol.Expression;
import org.teiid.query.sql.symbol.ExpressionSymbol;
@@ -103,6 +105,7 @@
import org.teiid.query.sql.symbol.SingleElementSymbol;
import org.teiid.query.sql.symbol.XMLAttributes;
import org.teiid.query.sql.symbol.XMLForest;
+import org.teiid.query.sql.symbol.XMLNamespaces;
import org.teiid.query.sql.util.SymbolMap;
import org.teiid.query.sql.visitor.AggregateSymbolCollectorVisitor;
import org.teiid.query.sql.visitor.CommandCollectorVisitor;
@@ -327,24 +330,16 @@
// can't use this pseudo-function in non-XML queries
handleValidationError(QueryPlugin.Util.getString("ValidationVisitor.The_rowlimit_function_cannot_be_used_in_a_non-XML_command"), obj); //$NON-NLS-1$
}
- } else if(obj.getFunctionDescriptor().getName().equalsIgnoreCase(SourceSystemFunctions.XPATHVALUE) || obj.getFunctionDescriptor().getName().equalsIgnoreCase(SourceSystemFunctions.XPATHQUERY)) {
+ } else if(obj.getFunctionDescriptor().getName().equalsIgnoreCase(SourceSystemFunctions.XPATHVALUE)) {
// Validate the xpath value is valid
if(obj.getArgs()[1] instanceof Constant) {
Constant xpathConst = (Constant) obj.getArgs()[1];
try {
XMLSystemFunctions.validateXpath((String)xpathConst.getValue());
- } catch(XPathExpressionException e) {
+ } catch(XPathException e) {
handleValidationError(QueryPlugin.Util.getString("QueryResolver.invalid_xpath", e.getMessage()), obj); //$NON-NLS-1$
}
}
- if (obj.getArgs().length > 2 && obj.getArgs()[2] instanceof Constant) {
- Constant xpathConst = (Constant) obj.getArgs()[2];
- try {
- XMLSystemFunctions.getNamespaces((String)xpathConst.getValue());
- } catch(FunctionExecutionException e) {
- handleValidationError(e.getMessage(), obj);
- }
- }
}
}
@@ -1071,7 +1066,7 @@
// Validate use of 'rowlimit' and 'rowlimitexception' pseudo-functions - they cannot be nested within another
// function, and their operands must be a nonnegative integers
- // Collect all occurrances of rowlimit function
+ // Collect all occurrences of rowlimit function
List rowLimitFunctions = new ArrayList();
FunctionCollectorVisitor visitor = new FunctionCollectorVisitor(rowLimitFunctions, FunctionLibrary.ROWLIMIT);
PreOrderNavigator.doVisit(obj, visitor);
@@ -1142,24 +1137,85 @@
}
@Override
+ public void visit(XMLForest obj) {
+ for (DerivedColumn dc : obj.getArgs()) {
+ if (dc.getAlias() == null && !(dc.getExpression() instanceof ElementSymbol)) {
+ handleValidationError(QueryPlugin.Util.getString("ValidationVisitor.expression_requires_name"), obj); //$NON-NLS-1$
+ }
+ }
+ }
+
+ @Override
public void visit(XMLAttributes obj) {
- for (SingleElementSymbol arg : obj.getArgs()) {
- if (arg instanceof ExpressionSymbol) {
- handleValidationError("ValidationVisitor.expression_requires_name", arg); //$NON-NLS-1$
- }
+ for (DerivedColumn dc : obj.getArgs()) {
+ if (dc.getAlias() == null && !(dc.getExpression() instanceof ElementSymbol)) {
+ handleValidationError(QueryPlugin.Util.getString("ValidationVisitor.expression_requires_name"), obj); //$NON-NLS-1$
+ }
}
}
@Override
- public void visit(XMLForest obj) {
- for (SingleElementSymbol arg : obj.getArgs()) {
- if (arg instanceof ExpressionSymbol) {
- handleValidationError("ValidationVisitor.expression_requires_name", arg); //$NON-NLS-1$
- }
+ public void visit(XMLTable obj) {
+ boolean context = false;
+ boolean hadError = false;
+ HashSet<String> names = new HashSet<String>();
+ for (DerivedColumn dc : obj.getPassing()) {
+ if (dc.getAlias() == null) {
+ Class<?> type = dc.getExpression().getType();
+ if (type != DataTypeManager.DefaultDataClasses.STRING &&
+ type != DataTypeManager.DefaultDataClasses.XML &&
+ type != DataTypeManager.DefaultDataClasses.CLOB) {
+ handleValidationError(QueryPlugin.Util.getString("ValidationVisitor.context_item_type"), obj); //$NON-NLS-1$
+ }
+ if (context && !hadError) {
+ handleValidationError(QueryPlugin.Util.getString("ValidationVisitor.passing_requires_name"), obj); //$NON-NLS-1$
+ hadError = true;
+ }
+ context = true;
+ } else if (!names.add(dc.getAlias().toUpperCase())) {
+ handleValidationError(QueryPlugin.Util.getString("ValidationVisitor.duplicate_passing", dc.getAlias()), obj); //$NON-NLS-1$
+ }
}
+ boolean hasOrdinal = false;
+ for (XMLColumn xc : obj.getColumns()) {
+ if (!xc.isOrdinal()) {
+ if (xc.getDefaultExpression() != null && !EvaluatableVisitor.isFullyEvaluatable(obj, false)) {
+ handleValidationError(QueryPlugin.Util.getString("ValidationVisitor.invalid_default", xc.getDefaultExpression()), obj); //$NON-NLS-1$
+ }
+ continue;
+ }
+ if (hasOrdinal) {
+ handleValidationError(QueryPlugin.Util.getString("ValidationVisitor.one_ordinal"), obj); //$NON-NLS-1$
+ break;
+ }
+ hasOrdinal = true;
+ }
}
@Override
+ public void visit(XMLNamespaces obj) {
+ boolean hasDefault = false;
+ boolean noDefault = false;
+ for (XMLNamespaces.NamespaceItem item : obj.getNamespaceItems()) {
+ if (item.getPrefix() != null) {
+ if (item.getPrefix().equals("xml") || item.getPrefix().equals("xmlns")) { //$NON-NLS-1$ //$NON-NLS-2$
+ handleValidationError(QueryPlugin.Util.getString("ValidationVisitor.xml_namespaces_reserved"), obj); //$NON-NLS-1$
+ }
+ continue;
+ }
+ if (hasDefault || noDefault) {
+ handleValidationError(QueryPlugin.Util.getString("ValidationVisitor.xml_namespaces"), obj); //$NON-NLS-1$
+ break;
+ }
+ if (item.getUri() == null) {
+ noDefault = true;
+ } else {
+ hasDefault = true;
+ }
+ }
+ }
+
+ @Override
public void visit(TextTable obj) {
boolean widthSet = false;
Character delimiter = null;
Deleted: trunk/engine/src/main/java/org/teiid/query/xquery/XQueryExpression.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/xquery/XQueryExpression.java 2010-06-04 21:35:06 UTC (rev 2180)
+++ trunk/engine/src/main/java/org/teiid/query/xquery/XQueryExpression.java 2010-06-04 21:51:29 UTC (rev 2181)
@@ -1,70 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * See the COPYRIGHT.txt file distributed with this work for information
- * regarding copyright ownership. Some portions may be licensed
- * to Red Hat, Inc. under one or more contributor license agreements.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
- * 02110-1301 USA.
- */
-
-package org.teiid.query.xquery;
-
-import org.teiid.core.TeiidComponentException;
-import org.teiid.core.TeiidProcessingException;
-import org.teiid.core.types.XMLTranslator;
-
-/**
- * An XQueryExpression - the object representation of
- * a compiled XQuery. Must be thread-safe and immutable.
- */
-public interface XQueryExpression {
-
- /**
- * Return the compiled XQueryExpression - the result of this
- * call should be used as a parameter to the
- * {@link #getDocumentNames getDocumentNames} and
- * {@link #evaluateXQuery evaluateXQuery} methods.
- * A null return value is interpreted to mean that XQueries
- * are not supported by this engine at all.
- * @param xQueryString the original XQuery String
- * @throws TeiidProcessingException if xQueryString is
- * invalid and fails to compile
- */
- public void compileXQuery(String xQueryString)
- throws TeiidProcessingException;
-
-
- /**
- * Evaluate the XQuery and return results. A null return
- * value is interpreted to mean that XQueries are not supported
- * by this engine.
- * @param compiledXQuery compiled XQueryExpression
- * @throws TeiidProcessingException if xQueryString is
- * invalid and fails to compile
- */
- public XMLTranslator evaluateXQuery(XQuerySQLEvaluator sqlEval)
- throws TeiidProcessingException, TeiidComponentException;
-
-
- /**
- * This method sets whether the documents should be returned in compact
- * format (no extraneous whitespace). Non-compact format is more human-readable
- * (and bigger). Additional formats may be possible in future.
- * @param xmlFormat A string giving the format in which xml results need to be returned
- */
- public void setXMLFormat(String xmlFormat);
-
-}
Deleted: trunk/engine/src/main/java/org/teiid/query/xquery/XQuerySQLEvaluator.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/xquery/XQuerySQLEvaluator.java 2010-06-04 21:35:06 UTC (rev 2180)
+++ trunk/engine/src/main/java/org/teiid/query/xquery/XQuerySQLEvaluator.java 2010-06-04 21:51:29 UTC (rev 2181)
@@ -1,55 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * See the COPYRIGHT.txt file distributed with this work for information
- * regarding copyright ownership. Some portions may be licensed
- * to Red Hat, Inc. under one or more contributor license agreements.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
- * 02110-1301 USA.
- */
-
-package org.teiid.query.xquery;
-
-import javax.xml.transform.Source;
-
-import org.teiid.api.exception.query.ExpressionEvaluationException;
-import org.teiid.api.exception.query.QueryParserException;
-import org.teiid.common.buffer.BlockedException;
-import org.teiid.core.TeiidComponentException;
-import org.teiid.core.TeiidProcessingException;
-
-
-
-/**
- * @since 4.3
- */
-public interface XQuerySQLEvaluator {
-
- /**
- * Execute a SQL string that returns an XML result
- * @param sql SQL string, typically an EXEC against an xml service or virtual document
- * @throws QueryParserException If sql parameter is not sql
- * @throws TeiidProcessingException If execution of the sql fails due to a bad query
- * @throws TeiidComponentException If execution of the sql fails due to an internal failure
- */
- Source executeSQL(String sql) throws QueryParserException, TeiidProcessingException, TeiidComponentException;
-
- /**
- * Closes any resources opened during the evaluation
- */
- void close() throws TeiidComponentException ;
-
- Object getParameterValue(String key) throws ExpressionEvaluationException, BlockedException, TeiidComponentException;
-}
Deleted: trunk/engine/src/main/java/org/teiid/query/xquery/saxon/DocFunctionURIResolver.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/xquery/saxon/DocFunctionURIResolver.java 2010-06-04 21:35:06 UTC (rev 2180)
+++ trunk/engine/src/main/java/org/teiid/query/xquery/saxon/DocFunctionURIResolver.java 2010-06-04 21:51:29 UTC (rev 2181)
@@ -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.query.xquery.saxon;
-
-import java.util.Map;
-
-import javax.xml.transform.Source;
-import javax.xml.transform.TransformerException;
-import javax.xml.transform.URIResolver;
-import javax.xml.transform.stream.StreamSource;
-
-import org.teiid.api.exception.query.QueryParserException;
-import org.teiid.query.xquery.XQuerySQLEvaluator;
-
-
-
-/**
- * A URI resolver for XQuery 'doc' function. This resolver is knows
- * how to handle SQL calls from this URI, such that it can execute the
- * SQL and return the results in the form of XML which 'doc' understands.
- */
-public class DocFunctionURIResolver implements URIResolver {
-
- private Map virtualDocuments;
- private XQuerySQLEvaluator sqlEval;
-
- public DocFunctionURIResolver(Map virtualDocuments, XQuerySQLEvaluator sqlEval) {
- this.virtualDocuments = virtualDocuments;
- this.sqlEval = sqlEval;
- }
-
- public Source resolve(String href, String base) throws TransformerException {
- Source doc = null;
-
- if (this.virtualDocuments != null){
- doc = new StreamSource((String)this.virtualDocuments.get(href.toUpperCase()));
- }
-
- if(doc == null) {
- // Attempt to parse dynamic sql string
- try {
- doc = sqlEval.executeSQL(href);
-
- } catch(QueryParserException e) {
- // ignore - fall through and try as URI
- } catch(Exception e) {
- throw new TransformerException(e.getMessage(), e);
- }
- }
-
- if(doc != null) {
- return doc;
- }
-
- //Will cause standard URI resolver to kick in
- return null;
- }
-
-}
Added: trunk/engine/src/main/java/org/teiid/query/xquery/saxon/PathMapFilter.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/xquery/saxon/PathMapFilter.java (rev 0)
+++ trunk/engine/src/main/java/org/teiid/query/xquery/saxon/PathMapFilter.java 2010-06-04 21:51:29 UTC (rev 2181)
@@ -0,0 +1,194 @@
+package org.teiid.query.xquery.saxon;
+
+import java.util.LinkedList;
+import java.util.List;
+
+import net.sf.saxon.event.ProxyReceiver;
+import net.sf.saxon.expr.AxisExpression;
+import net.sf.saxon.expr.PathMap.PathMapArc;
+import net.sf.saxon.expr.PathMap.PathMapNode;
+import net.sf.saxon.expr.PathMap.PathMapRoot;
+import net.sf.saxon.om.Axis;
+import net.sf.saxon.om.Item;
+import net.sf.saxon.pattern.NodeTest;
+import net.sf.saxon.trans.XPathException;
+import net.sf.saxon.type.Type;
+
+/**
+ * A filter that uses the PathMap to determine what should be included in the document
+ *
+ * TODO: optimize filtering by not reconstructing the matchcontexts
+ * TODO: we may still need to do xom/nux style handling of large results, but
+ * that requires more analysis to determine subtree independence
+ */
+class PathMapFilter extends ProxyReceiver {
+
+ static class MatchContext {
+ List<PathMapArc> elementArcs;
+ List<PathMapArc> attributeArcs;
+ boolean matchedElement;
+ boolean matchesText;
+ boolean matchesComment;
+
+ void bulidContext(PathMapNode node) {
+ for (PathMapArc arc : node.getArcs()) {
+ processArc(arc);
+ }
+ }
+
+ void processArc(PathMapArc arc) {
+ AxisExpression ae = arc.getStep();
+ NodeTest test = ae.getNodeTest();
+ if (test == null) {
+ addAnyNodeArc(arc);
+ } else {
+ switch (test.getPrimitiveType()) {
+ case Type.TEXT:
+ matchesText = true;
+ case Type.NODE:
+ addAnyNodeArc(arc);
+ break;
+ case Type.COMMENT:
+ matchesComment = true;
+ break;
+ case Type.ELEMENT:
+ addElementArc(arc);
+ break;
+ case Type.ATTRIBUTE:
+ addAttributeArc(arc);
+ break;
+ }
+ }
+ }
+
+ private void addAnyNodeArc(PathMapArc arc) {
+ if (arc.getStep().getAxis() == Axis.ATTRIBUTE) {
+ addAttributeArc(arc);
+ return;
+ }
+ addElementArc(arc);
+ addAttributeArc(arc);
+ matchesText = true;
+ matchesComment = true;
+ }
+
+ private void addAttributeArc(PathMapArc arc) {
+ if (attributeArcs == null) {
+ attributeArcs = new LinkedList<PathMapArc>();
+ }
+ attributeArcs.add(arc);
+ }
+
+ private void addElementArc(PathMapArc arc) {
+ if (elementArcs == null) {
+ elementArcs = new LinkedList<PathMapArc>();
+ }
+ elementArcs.add(arc);
+ }
+ }
+
+
+ private LinkedList<MatchContext> matchContext = new LinkedList<MatchContext>();
+
+ public PathMapFilter(PathMapRoot root) {
+ MatchContext mc = new MatchContext();
+ mc.bulidContext(root);
+ matchContext.add(mc);
+ }
+
+ @Override
+ public void startElement(int nameCode, int typeCode,
+ int locationId, int properties)
+ throws XPathException {
+ MatchContext mc = matchContext.getLast();
+ MatchContext newContext = new MatchContext();
+ if (mc.elementArcs != null) {
+ for (PathMapArc arc : mc.elementArcs) {
+ AxisExpression ae = arc.getStep();
+ NodeTest test = ae.getNodeTest();
+ if (test == null || test.matches(Type.ELEMENT, nameCode, typeCode)) {
+ newContext.bulidContext(arc.getTarget());
+ newContext.matchedElement = true;
+ }
+ if (ae.getAxis() == Axis.DESCENDANT || ae.getAxis() == Axis.DESCENDANT_OR_SELF) {
+ newContext.processArc(arc);
+ }
+ }
+ }
+ matchContext.add(newContext);
+ if (newContext.matchedElement) {
+ super.startElement(nameCode, typeCode, locationId, properties);
+ }
+ }
+
+ @Override
+ public void attribute(int nameCode, int typeCode,
+ CharSequence value, int locationId, int properties)
+ throws XPathException {
+ MatchContext mc = matchContext.getLast();
+ if (!mc.matchedElement) {
+ return;
+ }
+ if (mc.attributeArcs != null) {
+ for (PathMapArc arc : mc.attributeArcs) {
+ AxisExpression ae = arc.getStep();
+ NodeTest test = ae.getNodeTest();
+ if (test == null || test.matches(Type.ATTRIBUTE, nameCode, typeCode)) {
+ super.attribute(nameCode, typeCode, value, locationId, properties);
+ return;
+ }
+ }
+ }
+ }
+
+ @Override
+ public void characters(CharSequence chars, int locationId,
+ int properties) throws XPathException {
+ MatchContext context = matchContext.getLast();
+ if (context.matchedElement && context.matchesText) {
+ super.characters(chars, locationId, properties);
+ }
+ }
+
+ @Override
+ public void comment(CharSequence chars, int locationId,
+ int properties) throws XPathException {
+ MatchContext context = matchContext.getLast();
+ if (context.matchedElement && context.matchesComment) {
+ super.comment(chars, locationId, properties);
+ }
+ }
+
+ @Override
+ public void processingInstruction(String target,
+ CharSequence data, int locationId, int properties)
+ throws XPathException {
+ MatchContext context = matchContext.getLast();
+ if (context.matchedElement) {
+ super.processingInstruction(target, data, locationId, properties);
+ }
+ }
+
+ @Override
+ public void namespace(int namespaceCode, int properties)
+ throws XPathException {
+ MatchContext context = matchContext.getLast();
+ if (context.matchedElement) {
+ super.namespace(namespaceCode, properties);
+ }
+ }
+
+ @Override
+ public void endElement() throws XPathException {
+ MatchContext context = matchContext.removeLast();
+ if (context.matchedElement) {
+ super.endElement();
+ }
+ }
+
+ @Override
+ public void append(Item item, int locationId,
+ int copyNamespaces) throws XPathException {
+ super.append(item, locationId, copyNamespaces);
+ }
+}
\ No newline at end of file
Property changes on: trunk/engine/src/main/java/org/teiid/query/xquery/saxon/PathMapFilter.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified: trunk/engine/src/main/java/org/teiid/query/xquery/saxon/SaxonXQueryExpression.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/xquery/saxon/SaxonXQueryExpression.java 2010-06-04 21:35:06 UTC (rev 2180)
+++ trunk/engine/src/main/java/org/teiid/query/xquery/saxon/SaxonXQueryExpression.java 2010-06-04 21:51:29 UTC (rev 2181)
@@ -22,54 +22,96 @@
package org.teiid.query.xquery.saxon;
-import java.io.Writer;
+import java.io.StringReader;
+import java.sql.Clob;
import java.sql.SQLException;
import java.sql.SQLXML;
-import java.util.HashMap;
+import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Properties;
-import java.util.regex.Matcher;
-import java.util.regex.Pattern;
import javax.xml.transform.ErrorListener;
+import javax.xml.transform.Source;
import javax.xml.transform.TransformerException;
-import javax.xml.transform.stream.StreamResult;
+import javax.xml.transform.stream.StreamSource;
-import org.teiid.core.TeiidComponentException;
-import org.teiid.core.TeiidProcessingException;
-import org.teiid.core.types.XMLTranslator;
-import org.teiid.query.QueryPlugin;
-import org.teiid.query.util.XMLFormatConstants;
-import org.teiid.query.xquery.XQueryExpression;
-import org.teiid.query.xquery.XQuerySQLEvaluator;
-
+import net.sf.saxon.AugmentedSource;
import net.sf.saxon.Configuration;
-import net.sf.saxon.om.NodeInfo;
+import net.sf.saxon.event.ProxyReceiver;
+import net.sf.saxon.expr.AxisExpression;
+import net.sf.saxon.expr.Expression;
+import net.sf.saxon.expr.PathMap;
+import net.sf.saxon.expr.PathMap.PathMapArc;
+import net.sf.saxon.expr.PathMap.PathMapNode;
+import net.sf.saxon.expr.PathMap.PathMapNodeSet;
+import net.sf.saxon.expr.PathMap.PathMapRoot;
+import net.sf.saxon.om.Axis;
+import net.sf.saxon.om.DocumentInfo;
+import net.sf.saxon.om.SequenceIterator;
+import net.sf.saxon.om.StructuredQName;
+import net.sf.saxon.pattern.AnyNodeTest;
+import net.sf.saxon.pattern.NodeKindTest;
import net.sf.saxon.query.DynamicQueryContext;
import net.sf.saxon.query.QueryResult;
import net.sf.saxon.query.StaticQueryContext;
+import net.sf.saxon.query.XQueryExpression;
+import net.sf.saxon.sxpath.IndependentContext;
+import net.sf.saxon.sxpath.XPathEvaluator;
+import net.sf.saxon.sxpath.XPathExpression;
+import net.sf.saxon.trace.ExpressionPresenter;
import net.sf.saxon.trans.XPathException;
+import net.sf.saxon.type.ItemType;
+import net.sf.saxon.type.TypeHierarchy;
+import net.sf.saxon.value.SequenceType;
+import org.teiid.api.exception.query.QueryResolverException;
+import org.teiid.core.TeiidProcessingException;
+import org.teiid.core.TeiidRuntimeException;
+import org.teiid.core.types.ClobType;
+import org.teiid.core.types.DataTypeManager;
+import org.teiid.core.types.XMLType;
+import org.teiid.logging.LogConstants;
+import org.teiid.logging.LogManager;
+import org.teiid.logging.MessageLevel;
+import org.teiid.query.QueryPlugin;
+import org.teiid.query.sql.lang.XMLTable;
+import org.teiid.query.sql.lang.XMLTable.XMLColumn;
+import org.teiid.query.sql.symbol.DerivedColumn;
+import org.teiid.query.sql.symbol.XMLNamespaces;
+import org.teiid.query.sql.symbol.XMLNamespaces.NamespaceItem;
-/**
- * Saxon implementation of MetaMatrix XQueryExpression
- */
-public class SaxonXQueryExpression implements XQueryExpression {
+public class SaxonXQueryExpression {
+
+ private static final Expression DUMMY_EXPRESSION = new Expression() {
+ @Override
+ public ItemType getItemType(TypeHierarchy th) {
+ return null;
+ }
- /**
- * Regex used to match the external parameter declarations and return parameter names and types (if defined).
- */
- private static final Pattern EXTERNAL_VARIABLE_PATTERN = Pattern.compile("declare\\s+variable\\s+\\$(\\S+)(?:\\s+as\\s+(\\S+))?\\s+external(?:\\s+)?;"); //$NON-NLS-1$
-
- private String xQueryString;
- private net.sf.saxon.query.XQueryExpression xQuery;
- private Map virtualDocuments;
- private String xmlFormat;
- private Map<String, String> paramDeclarations;
+ @Override
+ public void explain(ExpressionPresenter out) {
+ }
- // Create a default error listener to use when compiling - this prevents
+ @Override
+ public Expression copy() {
+ return null;
+ }
+
+ @Override
+ protected int computeCardinality() {
+ return 0;
+ }
+
+ @Override
+ public PathMapNodeSet addToPathMap(PathMap pathMap,
+ PathMapNodeSet pathMapNodeSet) {
+ return pathMapNodeSet;
+ }
+ };
+
+ // Create a default error listener to use when compiling - this prevents
// errors from being printed to System.err.
private static final ErrorListener ERROR_LISTENER = new ErrorListener() {
public void warning(TransformerException arg0) throws TransformerException {
@@ -79,63 +121,178 @@
public void fatalError(TransformerException arg0) throws TransformerException {
}
};
-
- /**
- * @see com.metamatrix.query.xquery.XQueryEngine#compileXQuery(java.lang.String)
- */
- public void compileXQuery(String xQueryString)
- throws TeiidProcessingException{
-
- this.xQueryString = xQueryString;
-
- Configuration config = new Configuration();
+
+ private net.sf.saxon.query.XQueryExpression xQuery;
+ private PathMap.PathMapRoot contextRoot;
+ private Configuration config = new Configuration();
+
+ public SaxonXQueryExpression(String xQueryString, XMLNamespaces namespaces, List<DerivedColumn> passing, List<XMLTable.XMLColumn> columns)
+ throws TeiidProcessingException {
config.setErrorListener(ERROR_LISTENER);
+ StaticQueryContext context = new StaticQueryContext(config);
+ IndependentContext ic = new IndependentContext(config);
- StaticQueryContext context = new StaticQueryContext(config);
-
- try {
- this.xQuery = context.compileQuery(xQueryString);
- }catch(XPathException e) {
- throw new TeiidProcessingException(e);
+ if (namespaces != null) {
+ for (NamespaceItem item : namespaces.getNamespaceItems()) {
+ if (item.getPrefix() == null) {
+ if (item.getUri() == null) {
+ context.setDefaultElementNamespace(""); //$NON-NLS-1$
+ ic.setDefaultElementNamespace(""); //$NON-NLS-1$
+ } else {
+ context.setDefaultElementNamespace(item.getUri());
+ ic.setDefaultElementNamespace(item.getUri());
+ }
+ } else {
+ context.declareNamespace(item.getPrefix(), item.getUri());
+ ic.declareNamespace(item.getPrefix(), item.getUri());
+ }
+ }
}
+ boolean hasContext = false;
+ for (DerivedColumn derivedColumn : passing) {
+ if (derivedColumn.getAlias() == null) {
+ hasContext = true; //skip the context item
+ continue;
+ }
+ try {
+ context.declareGlobalVariable(StructuredQName.fromClarkName(derivedColumn.getAlias()), SequenceType.ANY_SEQUENCE, null, true);
+ } catch (XPathException e) {
+ throw new TeiidRuntimeException(e, "Could not define global variable"); //$NON-NLS-1$
+ }
+ ic.declareVariable("", derivedColumn.getAlias()); //$NON-NLS-1$
+ }
- // Scrape parameter names from xquery prolog
- parseParameters();
- }
+ XPathEvaluator eval = new XPathEvaluator(config);
+ eval.setStaticContext(ic);
+
+ processColumns(columns, eval);
- /**
- * declare variable $IN1 as xs:string external;
- *
- */
- private void parseParameters() {
- this.paramDeclarations = new HashMap<String, String>();
-
- Matcher matcher = EXTERNAL_VARIABLE_PATTERN.matcher(xQueryString);
- while(matcher.find()) {
- String var = matcher.group(1);
- String type = matcher.group(2);
- paramDeclarations.put(var, type);
+ try {
+ this.xQuery = context.compileQuery(xQueryString);
+ } catch (XPathException e) {
+ throw new QueryResolverException(e, QueryPlugin.Util.getString("SaxonXQueryExpression.compile_failed")); //$NON-NLS-1$
+ }
+ if (hasContext) {
+ useDocumentProjection(columns);
+ } else {
+ LogManager.logDetail(LogConstants.CTX_QUERY_PLANNER, "Document projection will not be used, since no context item exists or there are unknown dependencies"); //$NON-NLS-1$
}
}
+
+ private void useDocumentProjection(List<XMLTable.XMLColumn> columns) {
+ XQueryExpression toAnalyze = this.xQuery;
+
+ PathMap map = new PathMap(DUMMY_EXPRESSION);
+ PathMapNodeSet set = toAnalyze.getExpression().addToPathMap(map, null);
+
+ boolean complexEndState = false;
+ if (set != null) {
+ if (columns != null && !columns.isEmpty()) {
+ if (set.size() != 1) {
+ complexEndState = true;
+ } else {
+ for (XMLColumn xmlColumn : columns) {
+ if (xmlColumn.isOrdinal()) {
+ continue;
+ }
+ Expression internalExpression = xmlColumn.getPathExpression().getInternalExpression();
+ PathMap subMap = new PathMap(internalExpression);
+ PathMapRoot root = subMap.getContextRoot();
+ if (root == null) {
+ continue;
+ }
+ PathMapNodeSet finalNodes = internalExpression.addToPathMap(map, set);
+ if (finalNodes != null) {
+ for (Iterator iter = finalNodes.iterator(); iter.hasNext(); ) {
+ PathMapNode subNode = (PathMapNode)iter.next();
+ if (xmlColumn.getSymbol().getType() == DataTypeManager.DefaultDataClasses.XML) {
+ subNode.createArc(new AxisExpression(Axis.DESCENDANT_OR_SELF, AnyNodeTest.getInstance()));
+ subNode.setReturnable(true);
+ } else {
+ //this may not always be needed, but it doesn't harm anything
+ subNode.createArc(new AxisExpression(Axis.CHILD, NodeKindTest.TEXT));
+ subNode.setAtomized();
+ }
+ }
+ }
+ }
+ }
+ } else {
+ for (Iterator iter = set.iterator(); iter.hasNext(); ) {
+ PathMapNode subNode = (PathMapNode)iter.next();
+ subNode.createArc(new AxisExpression(Axis.DESCENDANT_OR_SELF, AnyNodeTest.getInstance()));
+ subNode.setReturnable(true);
+ }
+ }
+ }
+ //PathMap map = toAnalyze.getPathMap();
+ contextRoot = map.getContextRoot();
+ if (contextRoot == null || complexEndState || contextRoot.hasUnknownDependencies()) {
+ LogManager.logDetail(LogConstants.CTX_QUERY_PLANNER, "Document projection will not be used, since no context item exists or there are unknown dependencies"); //$NON-NLS-1$
+ contextRoot = null;
+ } else if (LogManager.isMessageToBeRecorded(LogConstants.CTX_QUERY_PLANNER, MessageLevel.DETAIL)) {
+ StringBuilder sb = new StringBuilder();
+ showArcs(sb, contextRoot, 0);
+ LogManager.logDetail(LogConstants.CTX_QUERY_PLANNER, "Using path filtering for XQuery context item: \n" + sb.toString()); //$NON-NLS-1$
+ }
+/* StringBuilder sb = new StringBuilder();
+ showArcs(sb, contextRoot, 0);
+ System.out.println(sb);
+*/ }
+
+ private void processColumns(List<XMLTable.XMLColumn> columns, XPathEvaluator eval)
+ throws TeiidProcessingException {
+ if (columns == null) {
+ return;
+ }
+ for (XMLColumn xmlColumn : columns) {
+ if (xmlColumn.isOrdinal()) {
+ continue;
+ }
+ String path = xmlColumn.getPath();
+ if (path == null) {
+ path = xmlColumn.getName();
+ }
+ path = path.trim();
+ if (path.startsWith("/") && !path.startsWith("//")) {
+ path = path.substring(1);
+ }
+ XPathExpression exp;
+ try {
+ exp = eval.createExpression(path);
+ } catch (XPathException e) {
+ throw new TeiidProcessingException(e, "Invalid path expression");
+ }
+ xmlColumn.setPathExpression(exp);
+ }
+ }
- /**
- * @see com.metamatrix.query.xquery.XQueryEngine#evaluateXQuery(org.teiid.query.xquery.XQueryExpression)
- */
- public XMLTranslator evaluateXQuery(XQuerySQLEvaluator sqlEval)
- throws TeiidProcessingException, TeiidComponentException {
-
- Configuration config = new Configuration();
+ public static Source convertToSource(Object value) throws TeiidProcessingException {
+ if (value == null) {
+ return null;
+ }
+ try {
+ if (value instanceof XMLType) {
+ return ((SQLXML)value).getSource(null);
+ }
+ if (value instanceof String) {
+ return new StreamSource(new StringReader((String)value));
+ }
+ if (value instanceof ClobType) {
+ return new StreamSource(((Clob)value).getCharacterStream());
+ }
+ } catch (SQLException e) {
+ throw new TeiidProcessingException(e);
+ }
+ throw new AssertionError("Unknown type"); //$NON-NLS-1$
+ }
+
+ public SequenceIterator evaluateXQuery(Object context, Map<String, Object> parameterValues) throws TeiidProcessingException {
DynamicQueryContext dynamicContext = new DynamicQueryContext(config);
- // Set URIResolver to handle virtual doc and sql in doc() function
- dynamicContext.setURIResolver(new DocFunctionURIResolver(this.virtualDocuments, sqlEval));
-
- // Set external parameter values (if used in a view with params)
- for (Map.Entry<String, String> entry : this.paramDeclarations.entrySet()) {
- Object value = sqlEval.getParameterValue(entry.getKey());
- // Check for xml and serialize
- String type = entry.getValue();
- if(type != null && type.equals("node()") && value != null) { //$NON-NLS-1$
+ for (Map.Entry<String, Object> entry : parameterValues.entrySet()) {
+ Object value = entry.getValue();
+ if(value instanceof SQLXML) {
try {
value = ((SQLXML)value).getSource(null);
} catch (SQLException e) {
@@ -145,62 +302,46 @@
dynamicContext.setParameter(entry.getKey(), value);
}
- // Evaluate
- List rawResults = null;
+ if (context != null) {
+ Source source = convertToSource(context);
+ if (contextRoot != null) {
+ //create our own filter as this logic is not provided in the free saxon
+ ProxyReceiver filter = new PathMapFilter(contextRoot);
+ AugmentedSource sourceInput = AugmentedSource.makeAugmentedSource(source);
+ sourceInput.addFilter(filter);
+ source = sourceInput;
+ }
+ DocumentInfo doc;
+ try {
+ doc = config.buildDocument(source);
+ } catch (XPathException e) {
+ throw new TeiidProcessingException(e);
+ }
+ dynamicContext.setContextItem(doc);
+ }
try {
- rawResults = this.xQuery.evaluate(dynamicContext);
+ //return this.xQuery.iterator(dynamicContext);
+ QueryResult.serializeSequence(xQuery.iterator(dynamicContext), config, System.out, new Properties());
+ return null;
} catch (TransformerException e) {
- Throwable cause = e.getCause();
- while (cause instanceof TransformerException) {
- Throwable nestedCause = ((TransformerException)cause).getCause();
- if (nestedCause == cause) {
- break;
- }
- cause = nestedCause;
- }
- if(cause instanceof TeiidProcessingException) {
- throw (TeiidProcessingException) cause;
- } else if(cause instanceof TeiidComponentException) {
- throw (TeiidComponentException) cause;
- }
- if (cause instanceof RuntimeException) {
- throw new TeiidComponentException(e, QueryPlugin.Util.getString("SaxonXQueryExpression.bad_xquery")); //$NON-NLS-1$
- }
throw new TeiidProcessingException(e, QueryPlugin.Util.getString("SaxonXQueryExpression.bad_xquery")); //$NON-NLS-1$
}
-
- // Read results
- Iterator i = rawResults.iterator();
- while (i.hasNext()) {
- Object obj = i.next();
-
- // output
- if (obj instanceof NodeInfo){
- final NodeInfo nodeInfo = (NodeInfo)obj;
- final Properties props = new Properties();
- if (XMLFormatConstants.XML_TREE_FORMAT.equals(this.xmlFormat)) {
- props.setProperty("indent", "yes");//$NON-NLS-1$//$NON-NLS-2$
- }
- return new XMLTranslator() {
-
- @Override
- public void translate(Writer writer) throws TransformerException {
- QueryResult.serialize(nodeInfo, new StreamResult(writer), props, new Configuration());
- }
- };
- }
- }
- throw new TeiidProcessingException(QueryPlugin.Util.getString("wrong_result_type")); //$NON-NLS-1$
}
+
+ public Configuration getConfig() {
+ return config;
+ }
- /**
- * This method sets whether the documents should be returned in compact
- * format (no extraneous whitespace). Non-compact format is more human-readable
- * (and bigger). Additional formats may be possible in future.
- * @param xmlFormat A string giving the format in which xml results need to be returned
- */
- public void setXMLFormat(String xmlFormat) {
- this.xmlFormat = xmlFormat;
- }
-
+ public static void showArcs(StringBuilder sb, PathMapNode node, int level) {
+ for (PathMapArc pathMapArc : node.getArcs()) {
+ char[] pad = new char[level*2];
+ Arrays.fill(pad, ' ');
+ sb.append(new String(pad));
+ sb.append(pathMapArc.getStep());
+ sb.append('\n');
+ node = pathMapArc.getTarget();
+ showArcs(sb, node, level + 1);
+ }
+ }
+
}
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-04 21:35:06 UTC (rev 2180)
+++ trunk/engine/src/main/javacc/org/teiid/query/parser/SQLParser.jj 2010-06-04 21:51:29 UTC (rev 2181)
@@ -28,6 +28,7 @@
* file. <B>WARNING:</B> DO NOT MODIFY the SQLParser.java file as it will be
* regenerated from the .jj file and your changes will be lost!</p>
*/
+@SuppressWarnings("nls")
public class SQLParser extends SQLParserUtil {
} // end class
@@ -89,15 +90,6 @@
{
<CAST: "cast">
| <CONVERT: "convert">
-| <TIMESTAMPADD: "timestampadd">
-| <TIMESTAMPDIFF: "timestampdiff">
-
-/* aggregate */
-| <COUNT: "count">
-| <SUM: "sum">
-| <AVG: "avg">
-| <MIN: "min">
-| <MAX: "max">
}
TOKEN : /* Reserved words */
@@ -163,7 +155,6 @@
| <FALSE: "false">
| <FETCH: "fetch">
| <FILTER: "filter">
-| <FN: "fn">
| <FOR: "for">
| <FORIEGN: "foriegn">
| <FROM: "from">
@@ -221,7 +212,6 @@
| <OLD: "old">
| <ON: "on">
| <ONLY: "only">
-| <OJ: "oj">
| <OPEN: "open">
| <OPTION: "option">
| <OR: "or">
@@ -359,19 +349,6 @@
| <IMPORT: "import">
}
-TOKEN : /* Special function words */
-{
- <SQL_TSI_FRAC_SECOND: "SQL_TSI_FRAC_SECOND">
-| <SQL_TSI_SECOND: "SQL_TSI_SECOND">
-| <SQL_TSI_MINUTE: "SQL_TSI_MINUTE">
-| <SQL_TSI_HOUR: "SQL_TSI_HOUR">
-| <SQL_TSI_DAY: "SQL_TSI_DAY">
-| <SQL_TSI_WEEK: "SQL_TSI_WEEK">
-| <SQL_TSI_MONTH: "SQL_TSI_MONTH">
-| <SQL_TSI_QUARTER: "SQL_TSI_QUARTER">
-| <SQL_TSI_YEAR: "SQL_TSI_YEAR">
-}
-
TOKEN : /* User variables and literals */
{
< ALL_IN_GROUP: <ID> <PERIOD> <STAR> >
@@ -456,7 +433,7 @@
Command command = null;
}
{
- (LOOKAHEAD(2) (command = createUpdateProcedure(info)) |
+ (LOOKAHEAD(2) command = createUpdateProcedure(info) |
command = userCommand(info) |
command = callableStatement(info)
)
@@ -1644,8 +1621,7 @@
(
// Expression
expression=expression(info)
- [[<AS>] ( alias=id() )
- ]
+ [[<AS>] alias=id() ]
)
{
SingleElementSymbol es = null;
@@ -1669,6 +1645,25 @@
}
}
+DerivedColumn derivedColumn(ParseInfo info) :
+{
+ Expression expression = null;
+ String alias = null;
+}
+{
+ (
+ // Expression
+ expression=expression(info)
+ [<AS> alias=id() ]
+ )
+ {
+ if(alias != null) {
+ alias = validateAlias(alias);
+ }
+ return new DerivedColumn(alias, expression);
+ }
+}
+
AllInGroupSymbol allInGroupSymbol() :
{
Token allInGroupToken = null;
@@ -1681,54 +1676,60 @@
}
}
+AggregateSymbol xmlAgg(ParseInfo info) :
+{
+ Expression expression = null;
+ OrderBy orderBy = null;
+}
+{
+ <XMLAGG> <LPAREN>
+ expression = expression(info)
+ [
+ orderBy = orderby(info)
+ ]
+ <RPAREN>
+ {
+ if(! info.aggregatesAllowed) {
+ throw new ParseException(QueryPlugin.Util.getString("SQLParser.Aggregate_only_top_level")); //$NON-NLS-1$
+ }
+
+ String name = generateFunctionName(info, "XMLAGG");
+ AggregateSymbol agg = new AggregateSymbol(name, "XMLAGG", false, expression);
+ agg.setOrderBy(orderBy);
+ return agg;
+ }
+}
+
AggregateSymbol aggregateSymbol(ParseInfo info) :
{
- Token functionToken = null;
+ String func = null;
Token starToken = null;
AggregateSymbol agg = null;
boolean isDistinct = false;
Expression expression = null;
- OrderBy orderBy = null;
}
{
- // Things that can be aliased
(
// COUNT(*)
LOOKAHEAD(3) (
- functionToken = <COUNT>
+ func = nonReserved("COUNT")
<LPAREN>
starToken = <STAR>
<RPAREN> ) |
// Remaining aggregates
- ( ( functionToken = <COUNT> |
- functionToken = <SUM> |
- functionToken = <AVG> |
- functionToken = <MIN> |
- functionToken = <MAX>
- )
+ ( func = nonReserved("COUNT", "SUM", "AVG", "MIN", "MAX")
<LPAREN>
[ <DISTINCT> {isDistinct=true;} ]
expression = expression(info)
<RPAREN>
)
- |
- (
- functionToken = <XMLAGG>
- <LPAREN>
- expression = expression(info)
- [
- orderBy = orderby(info)
- ]
- <RPAREN>
- )
)
{
if(! info.aggregatesAllowed) {
throw new ParseException(QueryPlugin.Util.getString("SQLParser.Aggregate_only_top_level")); //$NON-NLS-1$
}
-
- String func = functionToken.image.toUpperCase();
+ func = func.toUpperCase();
String name = generateFunctionName(info, func);
if(starToken == null) {
// Aggregate
@@ -1737,7 +1738,6 @@
// COUNT(*)
agg = new AggregateSymbol(name, func, false, null);
}
- agg.setOrderBy(orderBy);
return agg;
}
}
@@ -1791,7 +1791,7 @@
{
(
(
- <LBRACE> <OJ>
+ <LBRACE> nonReserved("OJ")
result=tableReferenceUnescaped(info)
<RBRACE>
)
@@ -1882,6 +1882,8 @@
{
( LOOKAHEAD(<ID> <LPAREN>, { "texttable".equalsIgnoreCase(getToken(1).image) }) clause = textTable(info)
|
+ LOOKAHEAD(<ID> <LPAREN>, { "xmltable".equalsIgnoreCase(getToken(1).image) }) clause = xmlTable(info)
+ |
clause = unaryFromClause(info)
|
LOOKAHEAD(subqueryFromClause(info)) clause = subqueryFromClause(info)
@@ -1901,44 +1903,69 @@
}
}
+XMLSerialize xmlSerialize(ParseInfo info) :
+{
+ Expression expr = null;
+ String doc = null;
+ Token t = null;
+}
+{
+ <XMLSERIALIZE> <LPAREN>
+ doc = nonReserved("DOCUMENT", "CONTENT")
+ expr = expression(info)
+ [
+ <AS> (t = <STRING> | t = <VARCHAR> | t = <CLOB>)
+ ]
+ <RPAREN>
+ {
+ XMLSerialize result = new XMLSerialize();
+ result.setExpression(expr);
+ result.setDocument("document".equalsIgnoreCase(doc));
+ if (t != null) {
+ result.setTypeString(t.image);
+ }
+ return result;
+ }
+}
+
+String nonReserved(String... expected) :
+{
+ Token t = null;
+}
+{
+ t = <ID>
+ {
+ String result = matchesAny(t.image, expected);
+ if (result != null) {
+ return result;
+ }
+ throw new ParseException(QueryPlugin.Util.getString("SQLParser.expected_non_reserved", Arrays.toString(expected), t.image));
+ }
+}
+
TextTable textTable(ParseInfo info) :
{
Expression file = null;
- String name = null;
- Constant datatype = null;
+ TextTable.TextColumn column = null;
List<TextTable.TextColumn> columns = new ArrayList<TextTable.TextColumn>();
- Integer width = null;
Character delimiter = null;
boolean escape = false;
Character quote = null;
Integer header = null;
Integer skip = null;
- Token columnsToken = null;
String aliasID = null;
}
{
<ID> <LPAREN> file = expression(info)
- columnsToken = <ID> { if (!"columns".equalsIgnoreCase(columnsToken.image)) throw new ParseException(QueryPlugin.Util.getString("SQLParser.expected_columns")); }
- name = id()
- datatype = dataType()
- [
- LOOKAHEAD(<ID>, { "width".equalsIgnoreCase(getToken(1).image) }) <ID>
- width = intVal()
- ]
+ nonReserved("COLUMNS")
+ column = textColumn(info)
{
- columns.add(new TextTable.TextColumn(validateElementName(name), (String)datatype.getValue(), width));
- width = null;
+ columns.add(column);
}
(<COMMA>
- name = id()
- datatype = dataType()
- [
- LOOKAHEAD(<ID>, { "width".equalsIgnoreCase(getToken(1).image) }) <ID>
- width = intVal()
- ]
+ column = textColumn(info)
{
- columns.add(new TextTable.TextColumn(validateElementName(name), (String)datatype.getValue(), width));
- width = null;
+ columns.add(column);
}
)*
[
@@ -1982,6 +2009,109 @@
}
}
+TextTable.TextColumn textColumn(ParseInfo info):
+{
+ String name = null;
+ Constant datatype = null;
+ Integer width = null;
+}
+{
+ name = id()
+ datatype = dataType()
+ [
+ LOOKAHEAD(<ID>, { "width".equalsIgnoreCase(getToken(1).image) }) <ID>
+ width = intVal()
+ ]
+ {
+ return new TextTable.TextColumn(validateElementName(name), (String)datatype.getValue(), width);
+ }
+}
+
+XMLTable xmlTable(ParseInfo info) :
+{
+ String xquery = null;
+ XMLNamespaces xmlNamespaces = null;
+ DerivedColumn passing = null;
+ ArrayList<DerivedColumn> passingValues = new ArrayList<DerivedColumn>();
+ XMLTable.XMLColumn column = null;
+ ArrayList<XMLTable.XMLColumn> columns = new ArrayList<XMLTable.XMLColumn>();
+ String aliasID = null;
+}
+{
+ <ID> <LPAREN>
+ [ xmlNamespaces = xmlNamespaces(info) <COMMA> ]
+ xquery = stringVal()
+ [
+ LOOKAHEAD(<ID>, { "passing".equalsIgnoreCase(getToken(1).image) }) <ID>
+ passing = derivedColumn(info)
+ {
+ passingValues.add(passing);
+ passing.setPropagateName(false);
+ }
+ (<COMMA>
+ passing = derivedColumn(info)
+ {
+ passingValues.add(passing);
+ passing.setPropagateName(false);
+ }
+ )*
+ ]
+
+ [
+ LOOKAHEAD(<ID>, { "columns".equalsIgnoreCase(getToken(1).image) }) <ID>
+ column = xmlColumn(info)
+ {
+ columns.add(column);
+ }
+ (<COMMA>
+ column = xmlColumn(info)
+ {
+ columns.add(column);
+ }
+ )*
+ ]
+ <RPAREN>
+ [<AS>] aliasID=id()
+ {
+ XMLTable result = new XMLTable();
+ result.setXquery(xquery);
+ result.setNamespaces(xmlNamespaces);
+ result.setPassing(passingValues);
+ result.setColumns(columns);
+ result.setName(validateAlias(aliasID));
+ return result;
+ }
+}
+
+XMLTable.XMLColumn xmlColumn(ParseInfo info):
+{
+ String name = null;
+ Constant datatype = null;
+ String path = null;
+ Expression defaultExpr = null;
+}
+{
+ name = id()
+
+ ((
+ <FOR> nonReserved("ORDINALITY")
+ {
+ return new XMLTable.XMLColumn(name);
+ }
+ ) | (
+ datatype = dataType()
+ [
+ nonReserved("PATH") path = stringVal()
+ ]
+ [
+ <DEFAULT_KEYWORD> defaultExpr = expression(info)
+ ]
+ {
+ return new XMLTable.XMLColumn(name, (String)datatype.getValue(), path, defaultExpr);
+ }
+ ))
+}
+
int intVal() :
{
Token t;
@@ -2867,14 +2997,16 @@
literal=literal()
|
// Escaped function
- ( <LBRACE> <FN>
+ ( <LBRACE> nonReserved("FN")
expression=function(info)
<RBRACE>
)
|
// Aggregate function
- (expression=aggregateSymbol(info))
+ LOOKAHEAD(<ID>, {matchesAny(getToken(1).image, "count", "min", "max", "sum", "avg") != null}) (expression=aggregateSymbol(info))
|
+ (expression=xmlAgg(info))
+ |
// Function
LOOKAHEAD(2) (expression=function(info))
|
@@ -3034,8 +3166,8 @@
<RPAREN>
)
|
- (
- (funcToken = <TIMESTAMPADD> | funcToken = <TIMESTAMPDIFF>)
+ LOOKAHEAD(<ID>, {matchesAny(getToken(1).image, "timestampadd", "timestampdiff") != null}) (
+ funcName = nonReserved("TIMESTAMPADD", "TIMESTAMPDIFF")
<LPAREN>
expression = intervalType()
{
@@ -3147,6 +3279,10 @@
{
return expression;
}
+ | expression = xmlSerialize(info)
+ {
+ return expression;
+ }
|
( funcName = id()
{
@@ -3216,17 +3352,17 @@
XMLAttributes xmlAttributes(ParseInfo info) :
{
- Expression expression = null;
- ArrayList args = new ArrayList();
+ DerivedColumn expression = null;
+ ArrayList<DerivedColumn> args = new ArrayList<DerivedColumn>();
}
{
<XMLATTRIBUTES> <LPAREN>
- expression = selectExpression(info)
+ expression = derivedColumn(info)
{
args.add(expression);
expression = null;
}
- (<COMMA> expression=selectExpression(info)
+ (<COMMA> expression=derivedColumn(info)
{
args.add(expression);
expression = null;
@@ -3240,21 +3376,21 @@
XMLForest xmlForest(ParseInfo info) :
{
- Expression expression = null;
+ DerivedColumn expression = null;
XMLNamespaces xmlNamespaces = null;
- ArrayList args = new ArrayList();
+ ArrayList<DerivedColumn> args = new ArrayList<DerivedColumn>();
}
{
<XMLFOREST> <LPAREN>
[
xmlNamespaces = xmlNamespaces(info) <COMMA>
]
- expression = selectExpression(info)
+ expression = derivedColumn(info)
{
args.add(expression);
expression = null;
}
- (<COMMA> expression=selectExpression(info)
+ (<COMMA> expression=derivedColumn(info)
{
args.add(expression);
expression = null;
@@ -3376,23 +3512,14 @@
*/
Constant intervalType() :
{
- Token typeToken = null;
+ String type = null;
}
{
(
- typeToken = <SQL_TSI_FRAC_SECOND> |
- typeToken = <SQL_TSI_SECOND> |
- typeToken = <SQL_TSI_MINUTE> |
- typeToken = <SQL_TSI_HOUR> |
- typeToken = <SQL_TSI_DAY> |
- typeToken = <SQL_TSI_WEEK> |
- typeToken = <SQL_TSI_MONTH> |
- typeToken = <SQL_TSI_QUARTER> |
- typeToken = <SQL_TSI_YEAR>
+ type = nonReserved("SQL_TSI_FRAC_SECOND", "SQL_TSI_SECOND", "SQL_TSI_MINUTE", "SQL_TSI_HOUR", "SQL_TSI_DAY", "SQL_TSI_WEEK", "SQL_TSI_MONTH", "SQL_TSI_QUARTER", "SQL_TSI_YEAR")
)
-
{
- return new Constant(typeToken.image);
+ return new Constant(type);
}
}
/**
Modified: trunk/engine/src/main/resources/org/teiid/query/i18n.properties
===================================================================
--- trunk/engine/src/main/resources/org/teiid/query/i18n.properties 2010-06-04 21:35:06 UTC (rev 2180)
+++ trunk/engine/src/main/resources/org/teiid/query/i18n.properties 2010-06-04 21:51:29 UTC (rev 2181)
@@ -121,7 +121,7 @@
QueryParser.nullBlock= Parser cannot parse a null block.
QueryParser.lexicalError= Lexical error: {0}
QueryParser.nullSqlExpr= Parser cannot parse a null sql expression.
-QueryParser.xqueryCompilation= XQuery compilation error: {0}
+QueryParser.xqueryCompilation= Direct usage of XQuery is no longer supported, use XMLQUERY instead.
# processor (006)
ERR.015.006.0010= Unknown criteria type: {0}
@@ -279,7 +279,7 @@
ERR.015.012.0025 = Command must project at least one symbol
ERR.015.012.0026 = Expressions of type OBJECT, CLOB, BLOB, or XML cannot be used in SELECT DISTINCT, ORDER BY, GROUP BY, or non-all set queries: [{0}]
ERR.015.012.0027 = Expressions of type OBJECT, CLOB, BLOB, or XML cannot be used in comparison: {0}.
-ValidationVisitor.expression_requires_name = Non-column expressions require a name in XMLATTRIBUTES or XMLFOREST
+ValidationVisitor.expression_requires_name = Non-column expressions require a name in XMLATTRIBUTES, XMLFOREST, or XMLTABLE
ValidationVisitor.invalid_lookup_key=Expressions of type OBJECT, CLOB, BLOB, or XML cannot be used as LOOKUP key columns: {0}.
ValidationVisitor.limit_not_valid_for_xml=The limit clause cannot be used on an XML document query.
ValidationVisitor.translated_or=Translated user criteria must not contain OR criteria
@@ -423,7 +423,7 @@
SQLParser.Invalid_alias=Invalid alias format: [{0}]
SQLParser.Invalid_short_name=Invalid simple identifier format: [{0}]
SQLParser.Invalid_char={0} value must be a single character: [{1}].
-SQLParser.expected_columns=Columns non-reserved word expected in TEXTTABLE.
+SQLParser.expected_non_reserved=Expected non-reserved word {0}, but was {1}.
SystemSource.Add_desc=Add two numbers
SystemSource.Add_result_desc=Left operand + right operand
SystemSource.Subtract_desc=Subtract two numbers
@@ -769,7 +769,6 @@
SystemSource.xpath_description=Evaluate the XPath expression against a document
SystemSource.xpath_param1=Source document
SystemSource.xpath_param2=XPath expression
-SystemSource.xpath_param3=Namespaces
SystemSource.xpathvalue_result=Single result
SystemSource.xpath_result=XPath result
SystemSource.xsltransform_description=Transform the document with the given stylesheet.
@@ -816,6 +815,8 @@
TempMetadataAdapter.Group_____{0}_____not_found._1=Group ''{0}'' not found.
ExpressionEvaluator.Must_push=Function {0} is marked in the function metadata as a function that must be evaluated at the source.
ExpressionEvaluator.Eval_failed=Unable to evaluate {0}: {1}
+XMLSerialize.data_exception=XMLSerialize: data exception - not an xml document
+XMLSerialize.resolvingError=XMLSerialize is valid only for XML expressions: {0}
FunctionDefinitionsReader.Read_error=Error reading FunctionDefinitions.xmi: {0}
FunctionDefinitionsSource.Read_error=Error reading {0}
ExecResolver.Param_convert_fail=Unable to convert procedural parameter of type {0} to expected type {1}
@@ -889,6 +890,13 @@
ValidationVisitor.text_table_negative=Text table WIDTH, HEADER, or SKIP values must not be negative.
ValidationVisitor.text_table_delimiter=Text table DELIMITER cannot be the same as the QUOTE or ESCAPE characters.
ValidationVisitor.text_table_newline=Text table DELIMITER, QUOTE, and ESCAPE characters cannot be the new line character.
+ValidationVisitor.xml_namespaces=At most only one NO DEFAULT or DEFAULT namespace may be specified.
+ValidationVisitor.xml_namespaces_reserved=At most only one NO DEFAULT or DEFAULT namespace may be specified.
+ValidationVisitor.context_item_type=XMLTABLE or XMLQUERY PASSING context item must be a character type (XML, STRING, CLOB).
+ValidationVisitor.passing_requires_name=XMLTABLE or XMLQUERY PASSING clause can only contain at most 1 unnamed item.
+ValidationVisitor.duplicate_passing=XMLTABLE or XMLQUERY PASSING clause duplicate item name "{0}".
+ValidationVisitor.one_ordinal=Only one FOR ORDINALITY column is allowed for an XMLTABLE.
+ValidationVisitor.invalid_default=XMLTABLE DEFAULT expression is invalid: "{0}"
UpdateProcedureResolver.only_variables=Element symbol "{0}" cannot be assigned a value. Only declared VARIABLES can be assigned values.
wrong_result_type=No results found; or non-XML result object has been produced as a result of the execution of XQuery expression. Please note that only XML type results are supported.
MappingLoader.unknown_node_type=Unknown Node Type "{0}" being loaded by the XML mapping document.
@@ -900,6 +908,7 @@
invalid_recurive_node= Found recursive node {0} without recursive root node.
criteria_node_not_allowed=Criteria Nodes can be only added on the Choice nodes; Wrong type of parent found.
SaxonXQueryExpression.bad_xquery=Failed to evaluate XQuery expression; Please check the query and correct errors in syntax or usage.
+SaxonXQueryExpression.compile_failed=Could not compile XQuery; Please check the query for syntax or usage errors.
SimpleQueryResolver.unknown_group_in_nocache=Unknown group "{0}" found in the Option NOCACHE hint.
MappingLoader.invalidName=Null or blank name found in the Mapping Document, Must have valid name. Re-build the VDB
MatchCriteria.invalid_escape=Invalid escape sequence "{0}" with escape character "{1}"
Modified: trunk/engine/src/test/java/org/teiid/dqp/internal/datamgr/language/TestAggregateImpl.java
===================================================================
--- trunk/engine/src/test/java/org/teiid/dqp/internal/datamgr/language/TestAggregateImpl.java 2010-06-04 21:35:06 UTC (rev 2180)
+++ trunk/engine/src/test/java/org/teiid/dqp/internal/datamgr/language/TestAggregateImpl.java 2010-06-04 21:51:29 UTC (rev 2181)
@@ -27,7 +27,7 @@
import org.teiid.core.types.DataTypeManager;
import org.teiid.language.AggregateFunction;
import org.teiid.language.Literal;
-import org.teiid.language.SQLReservedWords;
+import org.teiid.language.SQLReservedWords.NonReserved;
import org.teiid.query.sql.symbol.AggregateSymbol;
import org.teiid.query.sql.symbol.Constant;
@@ -52,23 +52,23 @@
}
public void testGetName() throws Exception {
- assertEquals(AggregateFunction.COUNT, example("testName", SQLReservedWords.COUNT, true, 42).getName()); //$NON-NLS-1$
+ assertEquals(AggregateFunction.COUNT, example("testName", NonReserved.COUNT, true, 42).getName()); //$NON-NLS-1$
}
public void testIsDistinct() throws Exception {
- assertTrue(example("testName", SQLReservedWords.COUNT, true, 42).isDistinct()); //$NON-NLS-1$
- assertFalse(example("testName", SQLReservedWords.COUNT, false, 42).isDistinct()); //$NON-NLS-1$
+ assertTrue(example("testName", NonReserved.COUNT, true, 42).isDistinct()); //$NON-NLS-1$
+ assertFalse(example("testName", NonReserved.COUNT, false, 42).isDistinct()); //$NON-NLS-1$
}
public void testGetExpression() throws Exception {
- AggregateFunction agg = example("testName", SQLReservedWords.COUNT, true, 42); //$NON-NLS-1$
+ AggregateFunction agg = example("testName", NonReserved.COUNT, true, 42); //$NON-NLS-1$
assertNotNull(agg.getExpression());
assertTrue(agg.getExpression() instanceof Literal);
assertEquals(new Integer(42), ((Literal)agg.getExpression()).getValue());
}
public void testGetType() throws Exception {
- assertEquals(DataTypeManager.DefaultDataClasses.INTEGER, example("x", SQLReservedWords.COUNT, true, 42).getType()); //$NON-NLS-1$
+ assertEquals(DataTypeManager.DefaultDataClasses.INTEGER, example("x", NonReserved.COUNT, true, 42).getType()); //$NON-NLS-1$
}
}
Copied: trunk/engine/src/test/java/org/teiid/dqp/internal/process/SimpleQueryProcessorFactory.java (from rev 2171, trunk/engine/src/test/java/org/teiid/query/processor/dynamic/SimpleQueryProcessorFactory.java)
===================================================================
--- trunk/engine/src/test/java/org/teiid/dqp/internal/process/SimpleQueryProcessorFactory.java (rev 0)
+++ trunk/engine/src/test/java/org/teiid/dqp/internal/process/SimpleQueryProcessorFactory.java 2010-06-04 21:51:29 UTC (rev 2181)
@@ -0,0 +1,75 @@
+/*
+ * 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.dqp.internal.process;
+
+import org.teiid.common.buffer.BufferManager;
+import org.teiid.core.TeiidComponentException;
+import org.teiid.core.TeiidProcessingException;
+import org.teiid.core.id.IDGenerator;
+import org.teiid.query.analysis.AnalysisRecord;
+import org.teiid.query.metadata.QueryMetadataInterface;
+import org.teiid.query.optimizer.QueryOptimizer;
+import org.teiid.query.optimizer.capabilities.CapabilitiesFinder;
+import org.teiid.query.parser.QueryParser;
+import org.teiid.query.processor.ProcessorDataManager;
+import org.teiid.query.processor.ProcessorPlan;
+import org.teiid.query.processor.QueryProcessor;
+import org.teiid.query.resolver.QueryResolver;
+import org.teiid.query.rewriter.QueryRewriter;
+import org.teiid.query.sql.lang.Command;
+import org.teiid.query.util.CommandContext;
+
+
+
+public class SimpleQueryProcessorFactory implements QueryProcessor.ProcessorFactory {
+
+ private QueryMetadataInterface metadata;
+ private CapabilitiesFinder finder;
+ private IDGenerator idGenerator;
+ private BufferManager bufferMgr;
+ private ProcessorDataManager dataMgr;
+
+ public SimpleQueryProcessorFactory(BufferManager bufferMgr,
+ ProcessorDataManager dataMgr, CapabilitiesFinder finder,
+ IDGenerator idGenerator, QueryMetadataInterface metadata) {
+ this.bufferMgr = bufferMgr;
+ this.dataMgr = dataMgr;
+ this.finder = finder;
+ this.idGenerator = idGenerator;
+ this.metadata = metadata;
+ }
+
+ @Override
+ public QueryProcessor createQueryProcessor(String sql, String recursionGroup, CommandContext commandContext)
+ throws TeiidProcessingException, TeiidComponentException {
+ Command command = QueryParser.getQueryParser().parseCommand(sql);
+ QueryResolver.resolveCommand(command, metadata);
+ command = QueryRewriter.rewrite(command, metadata, commandContext);
+ ProcessorPlan plan = QueryOptimizer.optimizePlan(command, metadata,
+ idGenerator, finder, AnalysisRecord.createNonRecordingRecord(),
+ commandContext);
+
+ CommandContext copy = (CommandContext) commandContext.clone();
+ return new QueryProcessor(plan, copy, bufferMgr, dataMgr);
+ }
+}
Property changes on: trunk/engine/src/test/java/org/teiid/dqp/internal/process/SimpleQueryProcessorFactory.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified: trunk/engine/src/test/java/org/teiid/dqp/internal/process/TestDQPCore.java
===================================================================
--- trunk/engine/src/test/java/org/teiid/dqp/internal/process/TestDQPCore.java 2010-06-04 21:35:06 UTC (rev 2180)
+++ trunk/engine/src/test/java/org/teiid/dqp/internal/process/TestDQPCore.java 2010-06-04 21:51:29 UTC (rev 2181)
@@ -188,17 +188,6 @@
assertEquals("[QueryValidatorException]Group does not exist: BQT3.SmallA", results.getException().toString()); //$NON-NLS-1$
}
- @Test public void testXQueryVisibility() throws Exception {
- String xquery = "<Items>\r\n" + //$NON-NLS-1$
- "{\r\n" + //$NON-NLS-1$
- "for $x in doc(\"select * from bqt3.smalla\")//Item\r\n" + //$NON-NLS-1$
- "return <Item>{$x/intkey/text()}</Item>\r\n" + //$NON-NLS-1$
- "}\r\n" + //$NON-NLS-1$
- "</Items>\r\n"; //$NON-NLS-1$
-
- helpTestVisibilityFails(xquery);
- }
-
///////////////////////////Helper method///////////////////////////////////
private ResultsMessage helpExecute(String sql, String userName) throws Exception {
return helpExecute(sql, userName, 1, false);
Modified: trunk/engine/src/test/java/org/teiid/dqp/internal/process/TestDataTierManager.java
===================================================================
--- trunk/engine/src/test/java/org/teiid/dqp/internal/process/TestDataTierManager.java 2010-06-04 21:35:06 UTC (rev 2180)
+++ trunk/engine/src/test/java/org/teiid/dqp/internal/process/TestDataTierManager.java 2010-06-04 21:51:29 UTC (rev 2181)
@@ -36,7 +36,6 @@
import org.teiid.query.metadata.QueryMetadataInterface;
import org.teiid.query.optimizer.capabilities.DefaultCapabilitiesFinder;
import org.teiid.query.parser.QueryParser;
-import org.teiid.query.processor.dynamic.SimpleQueryProcessorFactory;
import org.teiid.query.resolver.QueryResolver;
import org.teiid.query.sql.lang.Command;
import org.teiid.query.unittest.FakeMetadataFactory;
Modified: trunk/engine/src/test/java/org/teiid/dqp/internal/process/TestPreparedStatement.java
===================================================================
--- trunk/engine/src/test/java/org/teiid/dqp/internal/process/TestPreparedStatement.java 2010-06-04 21:35:06 UTC (rev 2180)
+++ trunk/engine/src/test/java/org/teiid/dqp/internal/process/TestPreparedStatement.java 2010-06-04 21:51:29 UTC (rev 2181)
@@ -31,8 +31,6 @@
import org.junit.Test;
import org.mockito.Mockito;
import org.teiid.adminapi.impl.VDBMetaData;
-import org.teiid.api.exception.query.QueryParserException;
-import org.teiid.api.exception.query.QueryPlannerException;
import org.teiid.api.exception.query.QueryResolverException;
import org.teiid.api.exception.query.QueryValidatorException;
import org.teiid.client.RequestMessage;
@@ -419,17 +417,4 @@
helpTestProcessing(preparedSql, values, expected, dataManager, FakeMetadataFactory.example1Cached(), false, false,FakeMetadataFactory.example1VDB());
}
- @Test public void testXQueryParam() throws Exception {
- String preparedSql = "exec m.xproc3(?)"; //$NON-NLS-1$
-
- List<String> values = Arrays.asList("<test1/>"); //$NON-NLS-1$
- List[] expected = new List[] {
- Arrays.asList("<?xml version=\"1.0\" encoding=\"UTF-8\"?><wrap><test1/></wrap>"), //$NON-NLS-1$
- };
-
- FakeDataManager dataManager = new FakeDataManager();
- TestProcessor.sampleData1(dataManager);
- helpTestProcessing(preparedSql, values, expected, dataManager, FakeMetadataFactory.exampleXQueryTransformations(), false, false, FakeMetadataFactory.exampleXQueryTransformationsVDB());
- }
-
}
Modified: trunk/engine/src/test/java/org/teiid/query/function/TestFunction.java
===================================================================
--- trunk/engine/src/test/java/org/teiid/query/function/TestFunction.java 2010-06-04 21:35:06 UTC (rev 2180)
+++ trunk/engine/src/test/java/org/teiid/query/function/TestFunction.java 2010-06-04 21:51:29 UTC (rev 2181)
@@ -34,7 +34,7 @@
import org.junit.Test;
import org.teiid.api.exception.query.FunctionExecutionException;
-import org.teiid.language.SQLReservedWords;
+import org.teiid.language.SQLReservedWords.NonReserved;
import org.teiid.query.function.FunctionMethods;
import org.teiid.query.sql.symbol.Constant;
import org.teiid.query.unittest.TimestampUtil;
@@ -846,18 +846,18 @@
}
@Test public void testTimestampAdd2() throws Exception {
- assertEquals(TimestampUtil.createTimestamp(103, 11, 1, 18, 20, 30, 0), FunctionMethods.timestampAdd(SQLReservedWords.SQL_TSI_HOUR, 3, TimestampUtil.createTimestamp(103, 11, 1, 15, 20, 30, 0)));
+ assertEquals(TimestampUtil.createTimestamp(103, 11, 1, 18, 20, 30, 0), FunctionMethods.timestampAdd(NonReserved.SQL_TSI_HOUR, 3, TimestampUtil.createTimestamp(103, 11, 1, 15, 20, 30, 0)));
}
@Test public void testTimestampDiffTimeStamp_FracSec_1() throws Exception {
- helpTestTimestampDiff(SQLReservedWords.SQL_TSI_FRAC_SECOND,
+ helpTestTimestampDiff(NonReserved.SQL_TSI_FRAC_SECOND,
TimestampUtil.createTimestamp((2001-1900), 5, 21, 3, 9, 35, 1),
TimestampUtil.createTimestamp((2001-1900), 5, 21, 3, 9, 35, 100000000),
new Long(99999999));
}
@Test public void testTimestampDiffTimeStamp_FracSec_2() throws Exception {
- helpTestTimestampDiff(SQLReservedWords.SQL_TSI_FRAC_SECOND,
+ helpTestTimestampDiff(NonReserved.SQL_TSI_FRAC_SECOND,
// 1 day (8.64 x 10^10 nanos) and 1 nano
TimestampUtil.createTimestamp((2001-1900), 5, 21, 3, 9, 35, 2),
TimestampUtil.createTimestamp((2001-1900), 5, 22, 3, 9, 35, 3),
@@ -865,7 +865,7 @@
}
@Test public void testTimestampDiffTimeStamp_FracSec_3() throws Exception {
- helpTestTimestampDiff(SQLReservedWords.SQL_TSI_FRAC_SECOND,
+ helpTestTimestampDiff(NonReserved.SQL_TSI_FRAC_SECOND,
// 1 day (8.64 x 10^10 nanos) less 1 nano
TimestampUtil.createTimestamp((2001-1900), 5, 22, 3, 9, 35, 2),
TimestampUtil.createTimestamp((2001-1900), 5, 21, 3, 9, 35, 3),
@@ -873,28 +873,28 @@
}
@Test public void testTimestampDiffTimeStamp_FracSec_4() throws Exception {
- helpTestTimestampDiff(SQLReservedWords.SQL_TSI_FRAC_SECOND,
+ helpTestTimestampDiff(NonReserved.SQL_TSI_FRAC_SECOND,
TimestampUtil.createTimestamp((2001-1900), 5, 21, 0, 0, 0, 1),
TimestampUtil.createTimestamp((2001-1900), 5, 21, 0, 0, 0, 3),
new Long(00000002));
}
@Test public void testTimestampDiffTimeStamp_FracSec_5() throws Exception {
- helpTestTimestampDiff(SQLReservedWords.SQL_TSI_FRAC_SECOND,
+ helpTestTimestampDiff(NonReserved.SQL_TSI_FRAC_SECOND,
TimestampUtil.createTimestamp((2004-1900), 5, 22, 0, 0, 0, 1),
TimestampUtil.createTimestamp((2004-1900), 5, 22, 0, 0, 0, 10),
new Long(9));
}
@Test public void testTimestampDiffTimeStamp_FracSec_6() throws Exception {
- helpTestTimestampDiff(SQLReservedWords.SQL_TSI_FRAC_SECOND,
+ helpTestTimestampDiff(NonReserved.SQL_TSI_FRAC_SECOND,
TimestampUtil.createTimestamp((2001-1900), 5, 22, 0, 0, 0, 2),
TimestampUtil.createTimestamp((2001-1900), 5, 22, 0, 0, 0, 3),
new Long(1));
}
@Test public void testTimestampDiffTimeStamp_FracSec_7() throws Exception {
- helpTestTimestampDiff(SQLReservedWords.SQL_TSI_FRAC_SECOND,
+ helpTestTimestampDiff(NonReserved.SQL_TSI_FRAC_SECOND,
// 1 nano diff
TimestampUtil.createTimestamp((2004-1900), 5, 22, 3, 9, 35, 2),
TimestampUtil.createTimestamp((2004-1900), 5, 22, 3, 9, 35, 3),
@@ -902,7 +902,7 @@
}
@Test public void testTimestampDiffTimeStamp_FracSec_8() throws Exception {
- helpTestTimestampDiff(SQLReservedWords.SQL_TSI_FRAC_SECOND,
+ helpTestTimestampDiff(NonReserved.SQL_TSI_FRAC_SECOND,
// 1 nano diff
TimestampUtil.createTimestamp((2004-1900), 5, 22, 3, 9, 35, 3),
TimestampUtil.createTimestamp((2004-1900), 5, 22, 3, 9, 35, 2),
@@ -910,98 +910,98 @@
}
@Test public void testTimestampDiffTimeStamp_Min_1() throws Exception {
- helpTestTimestampDiff(SQLReservedWords.SQL_TSI_MINUTE,
+ helpTestTimestampDiff(NonReserved.SQL_TSI_MINUTE,
TimestampUtil.createTimestamp(0, 0, 0, 2, 34, 12, 0),
TimestampUtil.createTimestamp(0, 0, 0, 12, 0, 0, 0),
new Long(565));
}
@Test public void testTimestampDiffTimeStamp_Min_2() throws Exception {
- helpTestTimestampDiff(SQLReservedWords.SQL_TSI_MINUTE,
+ helpTestTimestampDiff(NonReserved.SQL_TSI_MINUTE,
TimestampUtil.createTimestamp((2001-1900), 0, 0, 2, 0, 0, 0),
TimestampUtil.createTimestamp((2001-1900), 0, 0, 0, 33, 12, 0),
new Long(-86));
}
@Test public void testTimestampDiffTimeStamp_Min_3() throws Exception {
- helpTestTimestampDiff(SQLReservedWords.SQL_TSI_MINUTE,
+ helpTestTimestampDiff(NonReserved.SQL_TSI_MINUTE,
TimestampUtil.createTimestamp((2001-1900), 8, 26, 12, 07, 58, 65497),
TimestampUtil.createTimestamp((2001-1900), 8, 29, 11, 25, 42, 483219),
new Long(4277));
}
@Test public void testTimestampDiffTimeStamp_Min_4() throws Exception {
- helpTestTimestampDiff(SQLReservedWords.SQL_TSI_MINUTE,
+ helpTestTimestampDiff(NonReserved.SQL_TSI_MINUTE,
TimestampUtil.createTimestamp((2001-1900), 8, 26, 12, 07, 58, 0),
TimestampUtil.createTimestamp((2001-1900), 8, 29, 11, 25, 42, 0),
new Long(4277));
}
@Test public void testTimestampDiffTimeStamp_Min_5() throws Exception {
- helpTestTimestampDiff(SQLReservedWords.SQL_TSI_MINUTE,
+ helpTestTimestampDiff(NonReserved.SQL_TSI_MINUTE,
TimestampUtil.createTimestamp((2001-1900), 8, 26, 12, 0, 0, 1),
TimestampUtil.createTimestamp((2001-1900), 8, 26, 12, 0, 0, 0),
new Long(0));
}
@Test public void testTimestampDiffTimeStamp_Hour_1() throws Exception {
- helpTestTimestampDiff(SQLReservedWords.SQL_TSI_HOUR,
+ helpTestTimestampDiff(NonReserved.SQL_TSI_HOUR,
TimestampUtil.createTimestamp((2004-1900), 8, 26, 12, 0, 0, 0),
TimestampUtil.createTimestamp((2004-1900), 8, 26, 12, 59, 59, 999999999),
new Long(0));
}
@Test public void testTimestampDiffTimeStamp_Week_1() throws Exception {
- helpTestTimestampDiff(SQLReservedWords.SQL_TSI_WEEK,
+ helpTestTimestampDiff(NonReserved.SQL_TSI_WEEK,
TimestampUtil.createTimestamp((2001-1900), 5, 21, 3, 9, 35, 100),
TimestampUtil.createTimestamp((2001-1900), 4, 2, 5, 19, 35, 500),
new Long(-7));
}
@Test public void testTimestampDiffTimeStamp_Month_1() throws Exception {
- helpTestTimestampDiff(SQLReservedWords.SQL_TSI_MONTH,
+ helpTestTimestampDiff(NonReserved.SQL_TSI_MONTH,
TimestampUtil.createTimestamp((2004-1900), 4, 19, 0, 0, 0, 0),
TimestampUtil.createTimestamp((2004-1900), 11, 20, 12, 0, 0, 0),
new Long(7));
}
@Test public void testTimestampDiffTimeStamp_Month_2() throws Exception {
- helpTestTimestampDiff(SQLReservedWords.SQL_TSI_MONTH,
+ helpTestTimestampDiff(NonReserved.SQL_TSI_MONTH,
TimestampUtil.createTimestamp((2004-1900), 5, 1, 0, 0, 0, 1000000),
TimestampUtil.createTimestamp((2004-1900), 11, 1, 12, 0, 0, 1),
new Long(6));
}
@Test public void testTimestampDiffTimeStamp_Month_3() throws Exception {
- helpTestTimestampDiff(SQLReservedWords.SQL_TSI_MONTH,
+ helpTestTimestampDiff(NonReserved.SQL_TSI_MONTH,
TimestampUtil.createTimestamp((2004-1900), 4, 19, 0, 0, 0, 1),
TimestampUtil.createTimestamp((2004-1900), 11, 18, 12, 0, 0, 1000000),
new Long(7));
}
@Test public void testTimestampDiffTimeStamp_Month_4() throws Exception {
- helpTestTimestampDiff(SQLReservedWords.SQL_TSI_MONTH,
+ helpTestTimestampDiff(NonReserved.SQL_TSI_MONTH,
TimestampUtil.createTimestamp((2004-1900), 4, 1, 0, 0, 0, 1000000),
TimestampUtil.createTimestamp((2004-1900), 11, 1, 0, 0, 0, 0),
new Long(7));
}
@Test public void testTimestampDiffTimeStamp_Month_5() throws Exception {
- helpTestTimestampDiff(SQLReservedWords.SQL_TSI_MONTH,
+ helpTestTimestampDiff(NonReserved.SQL_TSI_MONTH,
TimestampUtil.createTimestamp((2004-1900), 4, 1, 0, 0, 1, 0),
TimestampUtil.createTimestamp((2004-1900), 11, 1, 0, 0, 0, 0),
new Long(7));
}
@Test public void testTimestampDiffTimeStamp_Month_6() throws Exception {
- helpTestTimestampDiff(SQLReservedWords.SQL_TSI_MONTH,
+ helpTestTimestampDiff(NonReserved.SQL_TSI_MONTH,
TimestampUtil.createTimestamp((2004-1900), 4, 1, 0, 0, 1, 0),
TimestampUtil.createTimestamp((2004-1900), 11, 1, 0, 0, 2, 0),
new Long(7));
}
@Test public void testTimestampDiffTimeStamp_Day_1() throws Exception {
- helpTestTimestampDiff(SQLReservedWords.SQL_TSI_DAY,
+ helpTestTimestampDiff(NonReserved.SQL_TSI_DAY,
TimestampUtil.createTimestamp((2004-1900), 2, 1, 0, 0, 0, 0),
TimestampUtil.createTimestamp((2004-1900), 3, 1, 0, 0, 0, 0),
new Long(31));
@@ -1009,20 +1009,20 @@
@Test public void testTimestampDiffTimeStamp_Day_2() throws Exception {
// Leap year
- helpTestTimestampDiff(SQLReservedWords.SQL_TSI_DAY,
+ helpTestTimestampDiff(NonReserved.SQL_TSI_DAY,
TimestampUtil.createTimestamp((2004-1900), 1, 1, 0, 0, 0, 0),
TimestampUtil.createTimestamp((2004-1900), 2, 1, 0, 0, 0, 0),
new Long(29));
}
@Test public void testTimestampDiffTime_Hour_1() throws Exception {
- helpTestTimestampDiff(SQLReservedWords.SQL_TSI_HOUR, new Timestamp(
+ helpTestTimestampDiff(NonReserved.SQL_TSI_HOUR, new Timestamp(
TimestampUtil.createTime(3, 4, 45).getTime()), new Timestamp(
TimestampUtil.createTime(5, 5, 36).getTime()), new Long(2));
}
@Test public void testTimestampDiffTime_Hour_2() throws Exception {
- helpTestTimestampDiff(SQLReservedWords.SQL_TSI_HOUR, new Timestamp(
+ helpTestTimestampDiff(NonReserved.SQL_TSI_HOUR, new Timestamp(
TimestampUtil.createTime(5, 0, 30).getTime()), new Timestamp(
TimestampUtil.createTime(3, 0, 31).getTime()), new Long(-1));
}
Modified: trunk/engine/src/test/java/org/teiid/query/function/TestFunctionLibrary.java
===================================================================
--- trunk/engine/src/test/java/org/teiid/query/function/TestFunctionLibrary.java 2010-06-04 21:35:06 UTC (rev 2180)
+++ trunk/engine/src/test/java/org/teiid/query/function/TestFunctionLibrary.java 2010-06-04 21:51:29 UTC (rev 2181)
@@ -47,14 +47,7 @@
import org.teiid.core.types.XMLType;
import org.teiid.core.util.ObjectConverterUtil;
import org.teiid.core.util.TimestampWithTimezone;
-import org.teiid.language.SQLReservedWords;
-import org.teiid.query.function.FunctionDescriptor;
-import org.teiid.query.function.FunctionForm;
-import org.teiid.query.function.FunctionLibrary;
-import org.teiid.query.function.FunctionMethods;
-import org.teiid.query.function.FunctionTree;
-import org.teiid.query.function.SystemFunctionManager;
-import org.teiid.query.function.UDFSource;
+import org.teiid.language.SQLReservedWords.NonReserved;
import org.teiid.query.function.metadata.FunctionMethod;
import org.teiid.query.unittest.TimestampUtil;
import org.teiid.query.util.CommandContext;
@@ -996,68 +989,68 @@
/** date + month --> count=18, inteval=month, result should be 2004-11-15 */
@Test public void testInvokeTimestampAddDate2() {
- helpInvokeMethod("timestampAdd", new Object[] {SQLReservedWords.SQL_TSI_MONTH, //$NON-NLS-1$
+ helpInvokeMethod("timestampAdd", new Object[] {NonReserved.SQL_TSI_MONTH, //$NON-NLS-1$
new Integer(18), new Timestamp(TimestampUtil.createDate(103, 4, 15).getTime())}, new Timestamp(TimestampUtil.createDate(104, 10, 15).getTime()));
}
/** date + month --> count=-18, inteval=month, result should be 2001-11-15 */
@Test public void testInvokeTimestampAddDate2a() {
- helpInvokeMethod("timestampAdd", new Object[] {SQLReservedWords.SQL_TSI_MONTH, //$NON-NLS-1$
+ helpInvokeMethod("timestampAdd", new Object[] {NonReserved.SQL_TSI_MONTH, //$NON-NLS-1$
new Integer(-18), new Timestamp(TimestampUtil.createDate(103, 4, 15).getTime())}, new Timestamp(TimestampUtil.createDate(101, 10, 15).getTime()));
}
/** date + week --> count=6, inteval=week, result should be 2003-04-03 */
@Test public void testInvokeTimestampAddDate3() {
- helpInvokeMethod("timestampAdd", new Object[] {SQLReservedWords.SQL_TSI_WEEK, //$NON-NLS-1$
+ helpInvokeMethod("timestampAdd", new Object[] {NonReserved.SQL_TSI_WEEK, //$NON-NLS-1$
new Integer(-6), new Timestamp(TimestampUtil.createDate(103, 4, 15).getTime())}, new Timestamp(TimestampUtil.createDate(103, 3, 3).getTime()));
}
/** date + quarter --> count=3, inteval=quarter, result should be 2004-2-15 */
@Test public void testInvokeTimestampAddDate4() {
- helpInvokeMethod("timestampAdd", new Object[] {SQLReservedWords.SQL_TSI_QUARTER, //$NON-NLS-1$
+ helpInvokeMethod("timestampAdd", new Object[] {NonReserved.SQL_TSI_QUARTER, //$NON-NLS-1$
new Integer(3), new Timestamp(TimestampUtil.createDate(103, 4, 15).getTime())}, new Timestamp(TimestampUtil.createDate(104, 1, 15).getTime()));
}
/** date + year --> count=-1, inteval=year, result should be 2002-5-15 */
@Test public void testInvokeTimestampAddDate5() {
- helpInvokeMethod("timestampAdd", new Object[] {SQLReservedWords.SQL_TSI_YEAR, //$NON-NLS-1$
+ helpInvokeMethod("timestampAdd", new Object[] {NonReserved.SQL_TSI_YEAR, //$NON-NLS-1$
new Integer(-1), new Timestamp(TimestampUtil.createDate(103, 4, 15).getTime())}, new Timestamp(TimestampUtil.createDate(102, 4, 15).getTime()));
}
/** time + minute --> count=23, inteval=3, result should be 03:32:12 */
@Test public void testInvokeTimestampAddTime1() {
- helpInvokeMethod("timestampAdd", new Object[] {SQLReservedWords.SQL_TSI_MINUTE, //$NON-NLS-1$
+ helpInvokeMethod("timestampAdd", new Object[] {NonReserved.SQL_TSI_MINUTE, //$NON-NLS-1$
new Integer(23), new Timestamp(TimestampUtil.createTime(3, 9, 12).getTime())}, new Timestamp(TimestampUtil.createTime(3, 32, 12).getTime()));
}
/** time + hour --> count=21, inteval=4, result should be 00:09:12 and overflow */
@Test public void testInvokeTimestampAddTime2() {
- helpInvokeMethod("timestampAdd", new Object[] {SQLReservedWords.SQL_TSI_HOUR, //$NON-NLS-1$
+ helpInvokeMethod("timestampAdd", new Object[] {NonReserved.SQL_TSI_HOUR, //$NON-NLS-1$
new Integer(21), new Timestamp(TimestampUtil.createTime(3, 9, 12).getTime())}, TimestampUtil.createTimestamp(70, 0, 2, 0, 9, 12, 0));
}
/** time + hour --> count=2, inteval=4, result should be 01:12:12*/
@Test public void testInvokeTimestampAddTime3() {
- helpInvokeMethod("timestampAdd", new Object[] {SQLReservedWords.SQL_TSI_HOUR, //$NON-NLS-1$
+ helpInvokeMethod("timestampAdd", new Object[] {NonReserved.SQL_TSI_HOUR, //$NON-NLS-1$
new Integer(2), new Timestamp(TimestampUtil.createTime(23, 12, 12).getTime())}, TimestampUtil.createTimestamp(70, 0, 2, 1, 12, 12, 0));
}
/** time + second --> count=23, inteval=2, result should be 03:10:01 */
@Test public void testInvokeTimestampAddTime4() {
- helpInvokeMethod("timestampAdd", new Object[] {SQLReservedWords.SQL_TSI_SECOND, //$NON-NLS-1$
+ helpInvokeMethod("timestampAdd", new Object[] {NonReserved.SQL_TSI_SECOND, //$NON-NLS-1$
new Integer(49), new Timestamp(TimestampUtil.createTime(3, 9, 12).getTime())}, new Timestamp(TimestampUtil.createTime(3, 10, 1).getTime()));
}
/** timestamp + second --> count=23, inteval=2, result should be 2003-05-15 03:09:35.100 */
@Test public void testInvokeTimestampAddTimestamp1() {
- helpInvokeMethod("timestampAdd", new Object[] {SQLReservedWords.SQL_TSI_SECOND, //$NON-NLS-1$
+ helpInvokeMethod("timestampAdd", new Object[] {NonReserved.SQL_TSI_SECOND, //$NON-NLS-1$
new Integer(23), TimestampUtil.createTimestamp(103, 4, 15, 3, 9, 12, 100)},
TimestampUtil.createTimestamp(103, 4, 15, 3, 9, 35, 100));
}
/** timestamp + nanos --> count=1, inteval=1, result should be 2003-05-15 03:09:12.000000101 */
@Test public void testInvokeTimestampAddTimestamp2() {
- helpInvokeMethod("timestampAdd", new Object[] {SQLReservedWords.SQL_TSI_FRAC_SECOND, //$NON-NLS-1$
+ helpInvokeMethod("timestampAdd", new Object[] {NonReserved.SQL_TSI_FRAC_SECOND, //$NON-NLS-1$
new Integer(1), TimestampUtil.createTimestamp(103, 4, 15, 3, 9, 12, 100)},
TimestampUtil.createTimestamp(103, 4, 15, 3, 9, 12, 101));
}
@@ -1066,14 +1059,14 @@
* with increase in second and minutes, because second already at 59 sec originally
*/
@Test public void testInvokeTimestampAddTimestamp3() {
- helpInvokeMethod("timestampAdd", new Object[] {SQLReservedWords.SQL_TSI_FRAC_SECOND, //$NON-NLS-1$
+ helpInvokeMethod("timestampAdd", new Object[] {NonReserved.SQL_TSI_FRAC_SECOND, //$NON-NLS-1$
new Integer(2100000000), TimestampUtil.createTimestamp(103, 4, 15, 3, 9, 59, 1)},
TimestampUtil.createTimestamp(103, 4, 15, 3, 10, 1, 100000003));
}
/** time --> interval=hour, time1 = 03:04:45, time2= 05:05:36 return = 2 */
@Test public void testInvokeTimestampDiffTime1() {
- helpInvokeMethod("timestampDiff", new Object[] {SQLReservedWords.SQL_TSI_HOUR, //$NON-NLS-1$
+ helpInvokeMethod("timestampDiff", new Object[] {NonReserved.SQL_TSI_HOUR, //$NON-NLS-1$
new Timestamp(TimestampUtil.createTime(3, 4, 45).getTime()), new Timestamp(TimestampUtil.createTime(5, 5, 36).getTime()) },
new Long(2));
}
@@ -1089,7 +1082,7 @@
* time2= 2003-05-02 05:19:35.500 return = 45
*/
@Test public void testInvokeTimestampDiffTimestamp1() {
- helpInvokeMethod("timestampDiff", new Object[] {SQLReservedWords.SQL_TSI_WEEK, //$NON-NLS-1$
+ helpInvokeMethod("timestampDiff", new Object[] {NonReserved.SQL_TSI_WEEK, //$NON-NLS-1$
TimestampUtil.createTimestamp(102, 5, 21, 3, 9, 35, 100), TimestampUtil.createTimestamp(103, 4, 2, 5, 19, 35, 500) },
new Long(45));
}
@@ -1099,7 +1092,7 @@
* time2= 2002-06-21 03:09:35.100000000 return = 999999999
*/
@Test public void testInvokeTimestampDiffTimestamp2() {
- helpInvokeMethod("timestampDiff", new Object[] {SQLReservedWords.SQL_TSI_FRAC_SECOND, //$NON-NLS-1$
+ helpInvokeMethod("timestampDiff", new Object[] {NonReserved.SQL_TSI_FRAC_SECOND, //$NON-NLS-1$
TimestampUtil.createTimestamp(102, 5, 21, 3, 9, 35, 1), TimestampUtil.createTimestamp(102, 5, 21, 3, 9, 35, 100000000) },
new Long(99999999));
}
@@ -1109,7 +1102,7 @@
* time2= 2002-06-22 03:09:35.000000001 return =
*/
@Test public void testInvokeTimestampDiffTimestamp3() {
- helpInvokeMethod("timestampDiff", new Object[] {SQLReservedWords.SQL_TSI_FRAC_SECOND, //$NON-NLS-1$
+ helpInvokeMethod("timestampDiff", new Object[] {NonReserved.SQL_TSI_FRAC_SECOND, //$NON-NLS-1$
TimestampUtil.createTimestamp(102, 5, 21, 3, 9, 35, 2), TimestampUtil.createTimestamp(102, 5, 22, 3, 9, 35, 1) },
new Long(86399999999999L));
}
@@ -1368,14 +1361,4 @@
assertEquals("<!--comment-->", xml);
}
- @Test public void testInvokeXpathQuery() throws Exception {
- CommandContext c = new CommandContext();
- c.setBufferManager(BufferManagerFactory.getStandaloneBufferManager());
- XMLType result = (XMLType)helpInvokeMethod("xpathquery", new Class[] {DataTypeManager.DefaultDataClasses.STRING, DataTypeManager.DefaultDataClasses.STRING},
- new Object[] {"<foo><bar>1</bar><bar>2</bar></foo>", "/foo/bar"}, c);
-
- String xml = ObjectConverterUtil.convertToString(result.getCharacterStream());
- assertEquals("<bar>1</bar><bar>2</bar>", xml);
- }
-
}
Modified: trunk/engine/src/test/java/org/teiid/query/function/source/TestXMLSystemFunctions.java
===================================================================
--- trunk/engine/src/test/java/org/teiid/query/function/source/TestXMLSystemFunctions.java 2010-06-04 21:35:06 UTC (rev 2180)
+++ trunk/engine/src/test/java/org/teiid/query/function/source/TestXMLSystemFunctions.java 2010-06-04 21:51:29 UTC (rev 2181)
@@ -31,19 +31,17 @@
import java.sql.Timestamp;
import java.util.TimeZone;
-import javax.xml.xpath.XPathExpressionException;
+import net.sf.saxon.trans.XPathException;
import org.jdom.Attribute;
import org.jdom.Element;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
-import org.teiid.api.exception.query.FunctionExecutionException;
import org.teiid.core.types.SQLXMLImpl;
import org.teiid.core.types.XMLType;
import org.teiid.core.util.FileUtil;
import org.teiid.core.util.UnitTestUtil;
-import org.teiid.query.function.source.XMLSystemFunctions;
@SuppressWarnings("nls")
@@ -55,17 +53,16 @@
return util.read();
}
- public String helpTestXpathValue(final String xmlFilePath, final String xpath,
- String namespaces, final String expected) throws IOException, XPathExpressionException, FunctionExecutionException {
- final String actual = helpGetNode(xmlFilePath,xpath, namespaces);
+ public String helpTestXpathValue(final String xmlFilePath, final String xpath, final String expected) throws IOException, XPathException {
+ final String actual = helpGetNode(xmlFilePath,xpath);
assertEquals(expected,actual);
return actual;
}
- public String helpGetNode(final String xmlFilePath, final String xpath, String namespaces ) throws IOException, XPathExpressionException, FunctionExecutionException {
+ public String helpGetNode(final String xmlFilePath, final String xpath ) throws IOException, XPathException {
final String xmlContent = getContentOfTestFile(xmlFilePath);
final Reader docReader = new StringReader(xmlContent);
- return XMLSystemFunctions.xpathValue(docReader,xpath, namespaces);
+ return XMLSystemFunctions.xpathValue(docReader,xpath);
}
public void helpCheckElement(final Object jdomNode, final String name, final String prefix, final String namespaceUri,
@@ -148,13 +145,13 @@
assertNull(value);
}
- @Test(expected=XPathExpressionException.class) public void testBadXPath() throws Exception {
+ @Test(expected=XPathException.class) public void testBadXPath() throws Exception {
String doc = "<?xml version=\"1.0\" encoding=\"utf-8\" ?><a><b><c>test</c></b></a>"; //$NON-NLS-1$
String xpath = ":BOGUS:"; //$NON-NLS-1$
XMLSystemFunctions.xpathValue(doc, xpath);
}
- @Test(expected=XPathExpressionException.class) public void testValidateXpath_Defect15088() throws Exception {
+ @Test(expected=XPathException.class) public void testValidateXpath_Defect15088() throws Exception {
// Mismatched tick and quote
final String xpath = "//*[local-name()='bookName\"]"; //$NON-NLS-1$
XMLSystemFunctions.validateXpath(xpath);
@@ -172,43 +169,36 @@
final String xmlFilePath = "testdoc.xml"; //$NON-NLS-1$
final String xpath = "//shipTo/@country"; //$NON-NLS-1$
final String expectedValue = "US"; //$NON-NLS-1$
- helpTestXpathValue(xmlFilePath,xpath,null, expectedValue);
+ helpTestXpathValue(xmlFilePath,xpath, expectedValue);
}
@Test public void testGetSingleMatch_01_002() throws Exception {
final String xmlFilePath = "testdoc.xml"; //$NON-NLS-1$
final String xpath = "//@partNum"; //$NON-NLS-1$
final String expectedValue = "872-AA"; //$NON-NLS-1$
- helpTestXpathValue(xmlFilePath,xpath,null, expectedValue);
+ helpTestXpathValue(xmlFilePath,xpath, expectedValue);
}
@Test public void testGetSingleMatch_01_003() throws Exception {
final String xmlFilePath = "testdoc.xml"; //$NON-NLS-1$
final String xpath = "//productName"; //$NON-NLS-1$
final String expectedValue = "Lawnmower"; //$NON-NLS-1$
- helpTestXpathValue(xmlFilePath,xpath,null, expectedValue);
+ helpTestXpathValue(xmlFilePath,xpath, expectedValue);
}
- @Test public void testGetSingleMatch_01_004() throws Exception {
- final String xmlFilePath = "testdoc.xml"; //$NON-NLS-1$
- final String xpath = "/SOAP-ENV:Envelope/billTo/zip"; //$NON-NLS-1$
- final String expectedValue = "95819"; //$NON-NLS-1$
- helpTestXpathValue(xmlFilePath,xpath,"xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\"", expectedValue);
- }
-
@Test public void testGetSingleMatch_03() throws Exception {
final String xmlFilePath = "testdoc.xml"; //$NON-NLS-1$
final String xpath = "//*[local-name()=\"ReadOnly\"]"; //$NON-NLS-1$
- helpTestXpathValue(xmlFilePath,xpath,null, "false"); //$NON-NLS-1$
+ helpTestXpathValue(xmlFilePath,xpath, "false"); //$NON-NLS-1$
}
/**
* * is no longer valid to match the namespace
*/
- @Test(expected=XPathExpressionException.class) public void testGetSingleMatch_04() throws Exception {
+ @Test public void testGetSingleMatch_04() throws Exception {
final String xmlFilePath = "testdoc.xml"; //$NON-NLS-1$
final String xpath = "//*:ReadOnly"; //$NON-NLS-1$
- helpTestXpathValue(xmlFilePath,xpath,null, "false"); //$NON-NLS-1$
+ helpTestXpathValue(xmlFilePath,xpath, "false"); //$NON-NLS-1$
}
@Test public void testInvokeXmlElement2() throws Exception {
Modified: trunk/engine/src/test/java/org/teiid/query/optimizer/relational/rules/TestCapabilitiesUtil.java
===================================================================
--- trunk/engine/src/test/java/org/teiid/query/optimizer/relational/rules/TestCapabilitiesUtil.java 2010-06-04 21:35:06 UTC (rev 2180)
+++ trunk/engine/src/test/java/org/teiid/query/optimizer/relational/rules/TestCapabilitiesUtil.java 2010-06-04 21:51:29 UTC (rev 2181)
@@ -27,7 +27,7 @@
import org.teiid.api.exception.query.QueryMetadataException;
import org.teiid.core.TeiidComponentException;
-import org.teiid.language.SQLReservedWords;
+import org.teiid.language.SQLReservedWords.NonReserved;
import org.teiid.query.optimizer.capabilities.BasicSourceCapabilities;
import org.teiid.query.optimizer.capabilities.DefaultCapabilitiesFinder;
import org.teiid.query.optimizer.capabilities.FakeCapabilitiesFinder;
@@ -192,7 +192,7 @@
BasicSourceCapabilities caps = new BasicSourceCapabilities();
caps.setCapabilitySupport(Capability.QUERY_AGGREGATES, false);
- AggregateSymbol aggregate = new AggregateSymbol("expr", SQLReservedWords.COUNT, false, null); //$NON-NLS-1$
+ AggregateSymbol aggregate = new AggregateSymbol("expr", NonReserved.COUNT, false, null); //$NON-NLS-1$
helpTestSupportsAggregateFunction(caps, aggregate, false);
}
@@ -204,7 +204,7 @@
caps.setCapabilitySupport(Capability.QUERY_AGGREGATES_COUNT, false);
caps.setCapabilitySupport(Capability.QUERY_AGGREGATES_COUNT_STAR, false);
- AggregateSymbol aggregate = new AggregateSymbol("expr", SQLReservedWords.COUNT, false, null); //$NON-NLS-1$
+ AggregateSymbol aggregate = new AggregateSymbol("expr", NonReserved.COUNT, false, null); //$NON-NLS-1$
helpTestSupportsAggregateFunction(caps, aggregate, false);
}
@@ -216,7 +216,7 @@
caps.setCapabilitySupport(Capability.QUERY_AGGREGATES_COUNT, false);
caps.setCapabilitySupport(Capability.QUERY_AGGREGATES_COUNT_STAR, true);
- AggregateSymbol aggregate = new AggregateSymbol("expr", SQLReservedWords.COUNT, false, null); //$NON-NLS-1$
+ AggregateSymbol aggregate = new AggregateSymbol("expr", NonReserved.COUNT, false, null); //$NON-NLS-1$
helpTestSupportsAggregateFunction(caps, aggregate, true);
}
@@ -228,7 +228,7 @@
caps.setCapabilitySupport(Capability.QUERY_AGGREGATES_COUNT, false);
caps.setCapabilitySupport(Capability.QUERY_AGGREGATES_COUNT_STAR, true);
- AggregateSymbol aggregate = new AggregateSymbol("expr", SQLReservedWords.COUNT, false, new ElementSymbol("x")); //$NON-NLS-1$ //$NON-NLS-2$
+ AggregateSymbol aggregate = new AggregateSymbol("expr", NonReserved.COUNT, false, new ElementSymbol("x")); //$NON-NLS-1$ //$NON-NLS-2$
helpTestSupportsAggregateFunction(caps, aggregate, false);
}
@@ -240,7 +240,7 @@
caps.setCapabilitySupport(Capability.QUERY_AGGREGATES_COUNT, true);
caps.setCapabilitySupport(Capability.QUERY_AGGREGATES_COUNT_STAR, false);
- AggregateSymbol aggregate = new AggregateSymbol("expr", SQLReservedWords.COUNT, false, null); //$NON-NLS-1$
+ AggregateSymbol aggregate = new AggregateSymbol("expr", NonReserved.COUNT, false, null); //$NON-NLS-1$
helpTestSupportsAggregateFunction(caps, aggregate, false);
}
@@ -252,7 +252,7 @@
caps.setCapabilitySupport(Capability.QUERY_AGGREGATES_COUNT, true);
caps.setCapabilitySupport(Capability.QUERY_AGGREGATES_COUNT_STAR, false);
- AggregateSymbol aggregate = new AggregateSymbol("expr", SQLReservedWords.COUNT, false, new ElementSymbol("x")); //$NON-NLS-1$ //$NON-NLS-2$
+ AggregateSymbol aggregate = new AggregateSymbol("expr", NonReserved.COUNT, false, new ElementSymbol("x")); //$NON-NLS-1$ //$NON-NLS-2$
helpTestSupportsAggregateFunction(caps, aggregate, true);
}
@@ -263,7 +263,7 @@
caps.setCapabilitySupport(Capability.QUERY_AGGREGATES, true);
caps.setCapabilitySupport(Capability.QUERY_AGGREGATES_SUM, false);
- AggregateSymbol aggregate = new AggregateSymbol("expr", SQLReservedWords.SUM, false, new ElementSymbol("x")); //$NON-NLS-1$ //$NON-NLS-2$
+ AggregateSymbol aggregate = new AggregateSymbol("expr", NonReserved.SUM, false, new ElementSymbol("x")); //$NON-NLS-1$ //$NON-NLS-2$
helpTestSupportsAggregateFunction(caps, aggregate, false);
}
@@ -274,7 +274,7 @@
caps.setCapabilitySupport(Capability.QUERY_AGGREGATES, true);
caps.setCapabilitySupport(Capability.QUERY_AGGREGATES_SUM, true);
- AggregateSymbol aggregate = new AggregateSymbol("expr", SQLReservedWords.SUM, false, new ElementSymbol("x")); //$NON-NLS-1$ //$NON-NLS-2$
+ AggregateSymbol aggregate = new AggregateSymbol("expr", NonReserved.SUM, false, new ElementSymbol("x")); //$NON-NLS-1$ //$NON-NLS-2$
helpTestSupportsAggregateFunction(caps, aggregate, true);
}
@@ -285,7 +285,7 @@
caps.setCapabilitySupport(Capability.QUERY_AGGREGATES, true);
caps.setCapabilitySupport(Capability.QUERY_AGGREGATES_AVG, false);
- AggregateSymbol aggregate = new AggregateSymbol("expr", SQLReservedWords.AVG, false, new ElementSymbol("x")); //$NON-NLS-1$ //$NON-NLS-2$
+ AggregateSymbol aggregate = new AggregateSymbol("expr", NonReserved.AVG, false, new ElementSymbol("x")); //$NON-NLS-1$ //$NON-NLS-2$
helpTestSupportsAggregateFunction(caps, aggregate, false);
}
@@ -296,7 +296,7 @@
caps.setCapabilitySupport(Capability.QUERY_AGGREGATES, true);
caps.setCapabilitySupport(Capability.QUERY_AGGREGATES_AVG, true);
- AggregateSymbol aggregate = new AggregateSymbol("expr", SQLReservedWords.AVG, false, new ElementSymbol("x")); //$NON-NLS-1$ //$NON-NLS-2$
+ AggregateSymbol aggregate = new AggregateSymbol("expr", NonReserved.AVG, false, new ElementSymbol("x")); //$NON-NLS-1$ //$NON-NLS-2$
helpTestSupportsAggregateFunction(caps, aggregate, true);
}
@@ -307,7 +307,7 @@
caps.setCapabilitySupport(Capability.QUERY_AGGREGATES, true);
caps.setCapabilitySupport(Capability.QUERY_AGGREGATES_MIN, false);
- AggregateSymbol aggregate = new AggregateSymbol("expr", SQLReservedWords.MIN, false, new ElementSymbol("x")); //$NON-NLS-1$ //$NON-NLS-2$
+ AggregateSymbol aggregate = new AggregateSymbol("expr", NonReserved.MIN, false, new ElementSymbol("x")); //$NON-NLS-1$ //$NON-NLS-2$
helpTestSupportsAggregateFunction(caps, aggregate, false);
}
@@ -318,7 +318,7 @@
caps.setCapabilitySupport(Capability.QUERY_AGGREGATES, true);
caps.setCapabilitySupport(Capability.QUERY_AGGREGATES_MIN, true);
- AggregateSymbol aggregate = new AggregateSymbol("expr", SQLReservedWords.MIN, false, new ElementSymbol("x")); //$NON-NLS-1$ //$NON-NLS-2$
+ AggregateSymbol aggregate = new AggregateSymbol("expr", NonReserved.MIN, false, new ElementSymbol("x")); //$NON-NLS-1$ //$NON-NLS-2$
helpTestSupportsAggregateFunction(caps, aggregate, true);
}
@@ -329,7 +329,7 @@
caps.setCapabilitySupport(Capability.QUERY_AGGREGATES, true);
caps.setCapabilitySupport(Capability.QUERY_AGGREGATES_MAX, false);
- AggregateSymbol aggregate = new AggregateSymbol("expr", SQLReservedWords.MAX, false, new ElementSymbol("x")); //$NON-NLS-1$ //$NON-NLS-2$
+ AggregateSymbol aggregate = new AggregateSymbol("expr", NonReserved.MAX, false, new ElementSymbol("x")); //$NON-NLS-1$ //$NON-NLS-2$
helpTestSupportsAggregateFunction(caps, aggregate, false);
}
@@ -340,7 +340,7 @@
caps.setCapabilitySupport(Capability.QUERY_AGGREGATES, true);
caps.setCapabilitySupport(Capability.QUERY_AGGREGATES_MAX, true);
- AggregateSymbol aggregate = new AggregateSymbol("expr", SQLReservedWords.MAX, false, new ElementSymbol("x")); //$NON-NLS-1$ //$NON-NLS-2$
+ AggregateSymbol aggregate = new AggregateSymbol("expr", NonReserved.MAX, false, new ElementSymbol("x")); //$NON-NLS-1$ //$NON-NLS-2$
helpTestSupportsAggregateFunction(caps, aggregate, true);
}
@@ -352,7 +352,7 @@
caps.setCapabilitySupport(Capability.QUERY_AGGREGATES_MAX, true);
caps.setCapabilitySupport(Capability.QUERY_AGGREGATES_DISTINCT, false);
- AggregateSymbol aggregate = new AggregateSymbol("expr", SQLReservedWords.MAX, true, new ElementSymbol("x")); //$NON-NLS-1$ //$NON-NLS-2$
+ AggregateSymbol aggregate = new AggregateSymbol("expr", NonReserved.MAX, true, new ElementSymbol("x")); //$NON-NLS-1$ //$NON-NLS-2$
helpTestSupportsAggregateFunction(caps, aggregate, false);
}
@@ -364,7 +364,7 @@
caps.setCapabilitySupport(Capability.QUERY_AGGREGATES_MAX, true);
caps.setCapabilitySupport(Capability.QUERY_AGGREGATES_DISTINCT, true);
- AggregateSymbol aggregate = new AggregateSymbol("expr", SQLReservedWords.MAX, true, new ElementSymbol("x")); //$NON-NLS-1$ //$NON-NLS-2$
+ AggregateSymbol aggregate = new AggregateSymbol("expr", NonReserved.MAX, true, new ElementSymbol("x")); //$NON-NLS-1$ //$NON-NLS-2$
helpTestSupportsAggregateFunction(caps, aggregate, true);
}
Modified: trunk/engine/src/test/java/org/teiid/query/parser/TestParser.java
===================================================================
--- trunk/engine/src/test/java/org/teiid/query/parser/TestParser.java 2010-06-04 21:35:06 UTC (rev 2180)
+++ trunk/engine/src/test/java/org/teiid/query/parser/TestParser.java 2010-06-04 21:51:29 UTC (rev 2181)
@@ -27,6 +27,7 @@
import java.io.StringReader;
import java.io.UnsupportedEncodingException;
import java.math.BigInteger;
+import java.sql.Date;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
@@ -74,6 +75,7 @@
import org.teiid.query.sql.lang.TextTable;
import org.teiid.query.sql.lang.UnaryFromClause;
import org.teiid.query.sql.lang.Update;
+import org.teiid.query.sql.lang.XMLTable;
import org.teiid.query.sql.lang.SetQuery.Operation;
import org.teiid.query.sql.lang.TextTable.TextColumn;
import org.teiid.query.sql.proc.AssignmentStatement;
@@ -97,6 +99,7 @@
import org.teiid.query.sql.symbol.AllSymbol;
import org.teiid.query.sql.symbol.CaseExpression;
import org.teiid.query.sql.symbol.Constant;
+import org.teiid.query.sql.symbol.DerivedColumn;
import org.teiid.query.sql.symbol.ElementSymbol;
import org.teiid.query.sql.symbol.Expression;
import org.teiid.query.sql.symbol.ExpressionSymbol;
@@ -105,13 +108,13 @@
import org.teiid.query.sql.symbol.Reference;
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.TestCaseExpression;
import org.teiid.query.sql.symbol.TestSearchedCaseExpression;
import org.teiid.query.sql.symbol.XMLAttributes;
import org.teiid.query.sql.symbol.XMLElement;
import org.teiid.query.sql.symbol.XMLForest;
import org.teiid.query.sql.symbol.XMLNamespaces;
+import org.teiid.query.sql.symbol.XMLSerialize;
@SuppressWarnings("nls")
public class TestParser {
@@ -6716,12 +6719,12 @@
@Test public void testXmlElementWithAttributes() throws Exception {
XMLElement f = new XMLElement("y", new ArrayList<Expression>());
- f.setAttributes(new XMLAttributes(Arrays.asList((SingleElementSymbol)new AliasSymbol("val", new ExpressionSymbol("", new Constant("a"))))));
+ f.setAttributes(new XMLAttributes(Arrays.asList(new DerivedColumn("val", new Constant("a")))));
helpTestExpression("xmlelement(y, xmlattributes('a' as val))", "XMLELEMENT(NAME y, XMLATTRIBUTES('a' AS val))", f);
}
@Test public void testXmlForest() throws Exception {
- XMLForest f = new XMLForest(Arrays.asList((SingleElementSymbol)new AliasSymbol("table", new ElementSymbol("a"))));
+ XMLForest f = new XMLForest(Arrays.asList(new DerivedColumn("table", new ElementSymbol("a"))));
helpTestExpression("xmlforest(a as \"table\")", "XMLFOREST(a AS \"table\")", f);
}
@@ -6731,7 +6734,7 @@
}
@Test public void testXmlNamespaces() throws Exception {
- XMLForest f = new XMLForest(Arrays.asList((SingleElementSymbol)new AliasSymbol("table", new ElementSymbol("a"))));
+ XMLForest f = new XMLForest(Arrays.asList(new DerivedColumn("table", new ElementSymbol("a"))));
f.setNamespaces(new XMLNamespaces(Arrays.asList(new XMLNamespaces.NamespaceItem(), new XMLNamespaces.NamespaceItem("x", "http://foo"))));
helpTestExpression("xmlforest(xmlnamespaces(no default, 'http://foo' as x), a as \"table\")", "XMLFOREST(XMLNAMESPACES(NO DEFAULT, 'http://foo' AS x), a AS \"table\")", f);
}
@@ -6784,7 +6787,31 @@
}
@Test public void testTextTableColumns() throws Exception {
- helpException("SELECT * from texttable(foo x string)", "Parsing error: Columns non-reserved word expected in TEXTTABLE.");
+ helpException("SELECT * from texttable(foo x string)", "Parsing error: Expected non-reserved word [COLUMNS], but was x.");
}
+
+ @Test public void testXMLTable() throws Exception {
+ String sql = "SELECT * from xmltable(xmlnamespaces(no default), '/' columns x for ordinality, y date path '@date' default {d'2000-01-01'}) as x"; //$NON-NLS-1$
+ Query query = new Query();
+ query.setSelect(new Select(Arrays.asList(new AllSymbol())));
+ XMLTable xt = new XMLTable();
+ xt.setName("x");
+ xt.setNamespaces(new XMLNamespaces(Arrays.asList(new XMLNamespaces.NamespaceItem())));
+ xt.setXquery("/");
+ List<XMLTable.XMLColumn> columns = new ArrayList<XMLTable.XMLColumn>();
+ columns.add(new XMLTable.XMLColumn("x"));
+ columns.add(new XMLTable.XMLColumn("y", "date", "@date", new Constant(Date.valueOf("2000-01-01"))));
+ xt.setColumns(columns);
+ query.setFrom(new From(Arrays.asList(xt)));
+ helpTest(sql, "SELECT * FROM XMLTABLE(XMLNAMESPACES(NO DEFAULT), '/' COLUMNS x FOR ORDINALITY, y date PATH '@date' DEFAULT {d'2000-01-01'}) AS x", query);
+ }
+
+ @Test public void testXmlSerialize() throws Exception {
+ XMLSerialize f = new XMLSerialize();
+ f.setDocument(true);
+ f.setExpression(new ElementSymbol("x"));
+ f.setTypeString("CLOB");
+ helpTestExpression("xmlserialize(document x as CLOB)", "XMLSERIALIZE(DOCUMENT x AS CLOB)", f);
+ }
}
Deleted: trunk/engine/src/test/java/org/teiid/query/parser/TestParserXQuery.java
===================================================================
--- trunk/engine/src/test/java/org/teiid/query/parser/TestParserXQuery.java 2010-06-04 21:35:06 UTC (rev 2180)
+++ trunk/engine/src/test/java/org/teiid/query/parser/TestParserXQuery.java 2010-06-04 21:51:29 UTC (rev 2181)
@@ -1,125 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * See the COPYRIGHT.txt file distributed with this work for information
- * regarding copyright ownership. Some portions may be licensed
- * to Red Hat, Inc. under one or more contributor license agreements.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
- * 02110-1301 USA.
- */
-
-package org.teiid.query.parser;
-
-import org.teiid.query.sql.lang.XQuery;
-
-import junit.framework.TestCase;
-
-
-public class TestParserXQuery extends TestCase {
-
- /** test a typical XQuery */
- public void testXQuery() {
- String xQueryString = "<Items>\r\n" + //$NON-NLS-1$
- "{\r\n" + //$NON-NLS-1$
- "for $x in doc(\"xmltest.doc9893\")//ItemName\r\n" + //$NON-NLS-1$
- "return <Item>{$x/text()}</Item>\r\n" + //$NON-NLS-1$
- "}\r\n" + //$NON-NLS-1$
- "</Items>\r\n"; //$NON-NLS-1$
-
- XQuery xQuery = new XQuery(xQueryString, null);
-
- TestParser.helpTest(
- xQueryString,
- xQueryString,
- xQuery);
- }
-
- /** test a typical XQuery with multiple docs*/
- public void testXQueryWithMultipleDocs() {
- String xQueryString = "<Items><x>\r\n" + //$NON-NLS-1$
- "{\r\n" + //$NON-NLS-1$
- "for $x in doc(\"xmltest.doc9893\")//ItemName\r\n" + //$NON-NLS-1$
- "return <Item>{$x/text()}</Item>\r\n" + //$NON-NLS-1$
- "}\r\n" + //$NON-NLS-1$
- "</x><y>\r\n" + //$NON-NLS-1$
- "{\r\n" + //$NON-NLS-1$
- "for $x in doc(\"xmltest.doc9893\")//ItemName\r\n" + //$NON-NLS-1$
- "return <Item>{$x/text()}</Item>\r\n" + //$NON-NLS-1$
- "}\r\n" + //$NON-NLS-1$
- "</y></Items>\r\n"; //$NON-NLS-1$
-
- XQuery xQuery = new XQuery(xQueryString, null);
-
- TestParser.helpTest(
- xQueryString,
- xQueryString,
- xQuery);
- }
-
- /** test an XQuery that doesn't begin with the open bracket < */
- public void testXQuery2() {
-
- String xQueryString =
- "for $x in doc(\"xmltest.doc9893\")//ItemName\r\n" + //$NON-NLS-1$
- "return <Item>{$x/text()}</Item>\r\n"; //$NON-NLS-1$
-
-
- XQuery xQuery = new XQuery(xQueryString, null);
-
- TestParser.helpTest(
- xQueryString,
- xQueryString,
- xQuery);
- }
-
- /** test a typical XQuery with OPTION */
- public void testXQueryWithOptionUppercase() {
- String xQueryString = "<Items>\r\n" + //$NON-NLS-1$
- "{\r\n" + //$NON-NLS-1$
- "for $x in doc(\"xmltest.doc9893\")//ItemName\r\n" + //$NON-NLS-1$
- "return <Item>{$x/text()}</Item>\r\n" + //$NON-NLS-1$
- "}\r\n" + //$NON-NLS-1$
- "</Items>"; //$NON-NLS-1$
-
- String expectedString = xQueryString + " OPTION NOCACHE"; //$NON-NLS-1$
-
- XQuery xQuery = new XQuery(xQueryString, null);
-
- TestParser.helpTest(
- expectedString,
- expectedString,
- xQuery);
- }
-
- /** test a typical XQuery with OPTION */
- public void testXQueryWithOptionLowercase() {
- String xQueryString = "<Items>\r\n" + //$NON-NLS-1$
- "{\r\n" + //$NON-NLS-1$
- "for $x in doc(\"xmltest.doc9893\")//ItemName\r\n" + //$NON-NLS-1$
- "return <Item>{$x/text()}</Item>\r\n" + //$NON-NLS-1$
- "}\r\n" + //$NON-NLS-1$
- "</Items>"; //$NON-NLS-1$
-
- String xQueryStringWithOption = xQueryString + " option nocache"; //$NON-NLS-1$
- String expectedString = xQueryString + " OPTION NOCACHE"; //$NON-NLS-1$
-
- XQuery xQuery = new XQuery(xQueryString, null);
-
- TestParser.helpTest(
- xQueryStringWithOption,
- expectedString,
- xQuery);
- }
-}
Modified: trunk/engine/src/test/java/org/teiid/query/processor/TestSQLXMLProcessing.java
===================================================================
--- trunk/engine/src/test/java/org/teiid/query/processor/TestSQLXMLProcessing.java 2010-06-04 21:35:06 UTC (rev 2180)
+++ trunk/engine/src/test/java/org/teiid/query/processor/TestSQLXMLProcessing.java 2010-06-04 21:51:29 UTC (rev 2181)
@@ -27,11 +27,11 @@
import java.util.Arrays;
import java.util.List;
+import org.junit.Ignore;
import org.junit.Test;
import org.teiid.query.processor.ProcessorPlan;
import org.teiid.query.unittest.FakeMetadataFactory;
-
@SuppressWarnings("nls")
public class TestSQLXMLProcessing {
@@ -201,5 +201,36 @@
helpProcess(plan, dataManager, expected);
}
+
+ @Test public void testXmlSerialize() {
+ String sql = "SELECT xmlserialize(document xmlelement(parent) as string)"; //$NON-NLS-1$
+
+ List[] expected = new List[] {
+ Arrays.asList("<parent></parent>"),
+ };
+
+ FakeDataManager dataManager = new FakeDataManager();
+ sampleData1(dataManager);
+
+ ProcessorPlan plan = helpGetPlan(helpParse(sql), FakeMetadataFactory.example1Cached());
+
+ helpProcess(plan, dataManager, expected);
+ }
+
+ @Ignore
+ @Test public void testXmlTable() {
+ String sql = "select * from xmltable('/a/b' passing '<a><b>first</b><b x='attr'>second</b>' columns x string, val string path '/b')"; //$NON-NLS-1$
+
+ List[] expected = new List[] {
+ Arrays.asList("<parent><x e1=\"a\" e2=\"0\"></x><x e1=\"a\" e2=\"0\"></x><x e2=\"1\"></x><x e1=\"c\" e2=\"1\"></x><x e1=\"b\" e2=\"2\"></x><x e1=\"a\" e2=\"3\"></x></parent>"),
+ };
+
+ 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/resolver/TestFunctionResolving.java
===================================================================
--- trunk/engine/src/test/java/org/teiid/query/resolver/TestFunctionResolving.java 2010-06-04 21:35:06 UTC (rev 2180)
+++ trunk/engine/src/test/java/org/teiid/query/resolver/TestFunctionResolving.java 2010-06-04 21:51:29 UTC (rev 2181)
@@ -35,6 +35,7 @@
import org.teiid.query.sql.symbol.Expression;
import org.teiid.query.sql.symbol.Function;
import org.teiid.query.sql.symbol.Reference;
+import org.teiid.query.sql.symbol.XMLSerialize;
import org.teiid.query.unittest.FakeMetadataFactory;
@@ -121,14 +122,14 @@
private Function helpResolveFunction(String sql) throws QueryParserException,
QueryResolverException, TeiidComponentException {
- Function func = getFunction(sql);
+ Function func = (Function)getExpression(sql);
assertEquals(DataTypeManager.DefaultDataClasses.STRING, func.getType());
return func;
}
- private Function getFunction(String sql) throws QueryParserException,
+ private Expression getExpression(String sql) throws QueryParserException,
TeiidComponentException, QueryResolverException {
- Function func = (Function)QueryParser.getQueryParser().parseExpression(sql);
+ Expression func = QueryParser.getQueryParser().parseExpression(sql);
ResolverVisitor.resolveLanguageObject(func, FakeMetadataFactory.example1Cached());
return func;
}
@@ -139,8 +140,20 @@
*/
@Test public void testLookupTypeConversion() throws Exception {
String sql = "lookup('pm1.g1', 'e2', 'e1', 1)"; //$NON-NLS-1$
- Function f = getFunction(sql);
+ Function f = (Function)getExpression(sql);
assertEquals(DataTypeManager.DefaultDataClasses.STRING, f.getArg(3).getType());
}
-
+
+ @Test public void testXMLSerialize() throws Exception {
+ String sql = "xmlserialize(DOCUMENT '<a/>' as clob)"; //$NON-NLS-1$
+ XMLSerialize xs = (XMLSerialize)getExpression(sql);
+ assertEquals(DataTypeManager.DefaultDataClasses.CLOB, xs.getType());
+ }
+
+ @Test(expected=QueryResolverException.class) public void testXMLSerialize_1() throws Exception {
+ String sql = "xmlserialize(DOCUMENT 1 as clob)"; //$NON-NLS-1$
+ XMLSerialize xs = (XMLSerialize)getExpression(sql);
+ assertEquals(DataTypeManager.DefaultDataClasses.CLOB, xs.getType());
+ }
+
}
Modified: trunk/engine/src/test/java/org/teiid/query/rewriter/TestQueryRewriter.java
===================================================================
--- trunk/engine/src/test/java/org/teiid/query/rewriter/TestQueryRewriter.java 2010-06-04 21:35:06 UTC (rev 2180)
+++ trunk/engine/src/test/java/org/teiid/query/rewriter/TestQueryRewriter.java 2010-06-04 21:51:29 UTC (rev 2181)
@@ -2273,4 +2273,22 @@
helpTestRewriteExpression(original, "'<a c=\"b\"></a>'", metadata);
}
+ @Test public void testRewriteXmlElement1() throws Exception {
+ String original = "xmlelement(name a, xmlattributes(1+1 as c), BQT1.SmallA.timevalue)"; //$NON-NLS-1$
+ QueryMetadataInterface metadata = FakeMetadataFactory.exampleBQTCached();
+ helpTestRewriteExpression(original, "XMLELEMENT(NAME a, XMLATTRIBUTES(2 AS c), BQT1.SmallA.timevalue)", metadata);
+ }
+
+ @Test public void testRewriteXmlSerialize() throws Exception {
+ String original = "xmlserialize(document xmlelement(name a, xmlattributes('b' as c)) as string)"; //$NON-NLS-1$
+ QueryMetadataInterface metadata = FakeMetadataFactory.exampleBQTCached();
+ helpTestRewriteExpression(original, "'<a c=\"b\"></a>'", metadata);
+ }
+
+ @Test public void testRewriteXmlTable() throws Exception {
+ String original = "select * from xmltable('/' passing 1 + 1 as a columns x string default curdate()) as x"; //$NON-NLS-1$
+ QueryMetadataInterface metadata = FakeMetadataFactory.exampleBQTCached();
+ helpTestRewriteCommand(original, "SELECT * FROM XMLTABLE('/' PASSING 2 AS a COLUMNS x string DEFAULT curdate()) AS x", metadata);
+ }
+
}
Modified: trunk/engine/src/test/java/org/teiid/query/sql/proc/TestCreateUpdateProcedureCommand.java
===================================================================
--- trunk/engine/src/test/java/org/teiid/query/sql/proc/TestCreateUpdateProcedureCommand.java 2010-06-04 21:35:06 UTC (rev 2180)
+++ trunk/engine/src/test/java/org/teiid/query/sql/proc/TestCreateUpdateProcedureCommand.java 2010-06-04 21:51:29 UTC (rev 2181)
@@ -31,7 +31,6 @@
import org.teiid.query.sql.lang.Command;
import org.teiid.query.sql.lang.Option;
import org.teiid.query.sql.lang.Query;
-import org.teiid.query.sql.lang.XQuery;
import org.teiid.query.sql.proc.CreateUpdateProcedureCommand;
import org.teiid.query.sql.symbol.GroupSymbol;
@@ -195,10 +194,4 @@
UnitTestUtil.helpTestEquivalence(0, s1, s2);
}
- public void testCloneMethod4() {
- CreateUpdateProcedureCommand s1 = new CreateUpdateProcedureCommand();
- s1.getSubCommands().add(new XQuery());
- CreateUpdateProcedureCommand s2 = (CreateUpdateProcedureCommand)s1.clone();
- UnitTestUtil.helpTestEquivalence(0, s1, s2);
- }
}
Modified: trunk/engine/src/test/java/org/teiid/query/sql/symbol/TestAggregateSymbol.java
===================================================================
--- trunk/engine/src/test/java/org/teiid/query/sql/symbol/TestAggregateSymbol.java 2010-06-04 21:35:06 UTC (rev 2180)
+++ trunk/engine/src/test/java/org/teiid/query/sql/symbol/TestAggregateSymbol.java 2010-06-04 21:51:29 UTC (rev 2181)
@@ -25,7 +25,7 @@
import junit.framework.TestCase;
import org.teiid.core.util.UnitTestUtil;
-import org.teiid.language.SQLReservedWords;
+import org.teiid.language.SQLReservedWords.NonReserved;
import org.teiid.query.sql.symbol.AggregateSymbol;
import org.teiid.query.sql.symbol.Constant;
import org.teiid.query.sql.symbol.ElementSymbol;
@@ -76,105 +76,105 @@
// ################################## ACTUAL TESTS ################################
public void testParser1() {
- AggregateSymbol as = new AggregateSymbol("count", SQLReservedWords.COUNT, false, sampleElement()); //$NON-NLS-1$
+ AggregateSymbol as = new AggregateSymbol("count", NonReserved.COUNT, false, sampleElement()); //$NON-NLS-1$
helpParser(as, "COUNT(m.g.c)"); //$NON-NLS-1$
}
public void testParser2() {
- AggregateSymbol as = new AggregateSymbol("count", SQLReservedWords.COUNT, true, sampleElement()); //$NON-NLS-1$
+ AggregateSymbol as = new AggregateSymbol("count", NonReserved.COUNT, true, sampleElement()); //$NON-NLS-1$
helpParser(as, "COUNT(DISTINCT m.g.c)"); //$NON-NLS-1$
}
public void testParser3() {
- AggregateSymbol as = new AggregateSymbol("x", SQLReservedWords.MIN, false, sampleConstant()); //$NON-NLS-1$
+ AggregateSymbol as = new AggregateSymbol("x", NonReserved.MIN, false, sampleConstant()); //$NON-NLS-1$
helpParser(as, "MIN(5)"); //$NON-NLS-1$
}
public void testParser4() {
- AggregateSymbol as = new AggregateSymbol("x", SQLReservedWords.MAX, false, sampleFunction()); //$NON-NLS-1$
+ AggregateSymbol as = new AggregateSymbol("x", NonReserved.MAX, false, sampleFunction()); //$NON-NLS-1$
helpParser(as, "MAX((m.g.c + 5))"); //$NON-NLS-1$
}
public void testParser5() {
- AggregateSymbol as = new AggregateSymbol("x", SQLReservedWords.COUNT, false, null); //$NON-NLS-1$
+ AggregateSymbol as = new AggregateSymbol("x", NonReserved.COUNT, false, null); //$NON-NLS-1$
helpParser(as, "COUNT(*)"); //$NON-NLS-1$
}
public void testEquals1() {
- AggregateSymbol as = new AggregateSymbol("x", SQLReservedWords.COUNT, true, sampleElement()); //$NON-NLS-1$
+ AggregateSymbol as = new AggregateSymbol("x", NonReserved.COUNT, true, sampleElement()); //$NON-NLS-1$
helpEquals(as, as, true);
}
public void testEquals2() {
- AggregateSymbol as1 = new AggregateSymbol("x", SQLReservedWords.COUNT, true, sampleElement()); //$NON-NLS-1$
+ AggregateSymbol as1 = new AggregateSymbol("x", NonReserved.COUNT, true, sampleElement()); //$NON-NLS-1$
AggregateSymbol as2 = (AggregateSymbol) as1.clone();
helpEquals(as1, as2, true);
}
//just changing the name of an aggregatesymbol doesn't matter
public void testEquals3() {
- AggregateSymbol as1 = new AggregateSymbol("x", SQLReservedWords.COUNT, true, sampleElement()); //$NON-NLS-1$
- AggregateSymbol as2 = new AggregateSymbol("y", SQLReservedWords.COUNT, true, sampleElement()); //$NON-NLS-1$
+ AggregateSymbol as1 = new AggregateSymbol("x", NonReserved.COUNT, true, sampleElement()); //$NON-NLS-1$
+ AggregateSymbol as2 = new AggregateSymbol("y", NonReserved.COUNT, true, sampleElement()); //$NON-NLS-1$
helpEquals(as1, as2, true);
}
public void testEquals4() {
- AggregateSymbol as1 = new AggregateSymbol("count", SQLReservedWords.COUNT, false, null); //$NON-NLS-1$
+ AggregateSymbol as1 = new AggregateSymbol("count", NonReserved.COUNT, false, null); //$NON-NLS-1$
AggregateSymbol as2 = (AggregateSymbol) as1.clone();
helpEquals(as1, as2, true);
}
public void testSelfEquivalence(){
- AggregateSymbol test = new AggregateSymbol("x", SQLReservedWords.COUNT, true, sampleElement()); //$NON-NLS-1$
+ AggregateSymbol test = new AggregateSymbol("x", NonReserved.COUNT, true, sampleElement()); //$NON-NLS-1$
int equals = 0;
UnitTestUtil.helpTestEquivalence(equals, test, test);
}
public void testEquivalence(){
- AggregateSymbol test1 = new AggregateSymbol("x", SQLReservedWords.COUNT, true, sampleElement()); //$NON-NLS-1$
- AggregateSymbol test2 = new AggregateSymbol("x", SQLReservedWords.COUNT, true, sampleElement()); //$NON-NLS-1$
+ AggregateSymbol test1 = new AggregateSymbol("x", NonReserved.COUNT, true, sampleElement()); //$NON-NLS-1$
+ AggregateSymbol test2 = new AggregateSymbol("x", NonReserved.COUNT, true, sampleElement()); //$NON-NLS-1$
int equals = 0;
UnitTestUtil.helpTestEquivalence(equals, test1, test2);
}
public void testEquivalenceCountStar(){
- AggregateSymbol test1 = new AggregateSymbol("x", SQLReservedWords.COUNT, false, null); //$NON-NLS-1$
- AggregateSymbol test2 = new AggregateSymbol("x", SQLReservedWords.COUNT, false, null); //$NON-NLS-1$
+ AggregateSymbol test1 = new AggregateSymbol("x", NonReserved.COUNT, false, null); //$NON-NLS-1$
+ AggregateSymbol test2 = new AggregateSymbol("x", NonReserved.COUNT, false, null); //$NON-NLS-1$
int equals = 0;
UnitTestUtil.helpTestEquivalence(equals, test1, test2);
}
public void testEquivalenceCaseInsens(){
- AggregateSymbol test1 = new AggregateSymbol("x", SQLReservedWords.COUNT, true, sampleElement()); //$NON-NLS-1$
- AggregateSymbol test2 = new AggregateSymbol("X", SQLReservedWords.COUNT, true, sampleElement()); //$NON-NLS-1$
+ AggregateSymbol test1 = new AggregateSymbol("x", NonReserved.COUNT, true, sampleElement()); //$NON-NLS-1$
+ AggregateSymbol test2 = new AggregateSymbol("X", NonReserved.COUNT, true, sampleElement()); //$NON-NLS-1$
int equals = 0;
UnitTestUtil.helpTestEquivalence(equals, test1, test2);
}
public void testNonEquivalenceUsingDiffElements(){
- AggregateSymbol test1 = new AggregateSymbol("x", SQLReservedWords.COUNT, true, sampleElement()); //$NON-NLS-1$
- AggregateSymbol test2 = new AggregateSymbol("X", SQLReservedWords.COUNT, true, sampleElement2()); //$NON-NLS-1$
+ AggregateSymbol test1 = new AggregateSymbol("x", NonReserved.COUNT, true, sampleElement()); //$NON-NLS-1$
+ AggregateSymbol test2 = new AggregateSymbol("X", NonReserved.COUNT, true, sampleElement2()); //$NON-NLS-1$
int equals = -1;
UnitTestUtil.helpTestEquivalence(equals, test1, test2);
}
public void testNonEquivalence(){
- AggregateSymbol test1 = new AggregateSymbol("x", SQLReservedWords.COUNT, true, sampleElement()); //$NON-NLS-1$
- AggregateSymbol test2 = new AggregateSymbol("y", SQLReservedWords.COUNT, true, sampleElement2()); //$NON-NLS-1$
+ AggregateSymbol test1 = new AggregateSymbol("x", NonReserved.COUNT, true, sampleElement()); //$NON-NLS-1$
+ AggregateSymbol test2 = new AggregateSymbol("y", NonReserved.COUNT, true, sampleElement2()); //$NON-NLS-1$
int equals = -1;
UnitTestUtil.helpTestEquivalence(equals, test1, test2);
}
public void testNonEquivalence1(){
- AggregateSymbol test1 = new AggregateSymbol("x", SQLReservedWords.COUNT, true, sampleElement()); //$NON-NLS-1$
- AggregateSymbol test2 = new AggregateSymbol("x", SQLReservedWords.COUNT, true, sampleElement2()); //$NON-NLS-1$
+ AggregateSymbol test1 = new AggregateSymbol("x", NonReserved.COUNT, true, sampleElement()); //$NON-NLS-1$
+ AggregateSymbol test2 = new AggregateSymbol("x", NonReserved.COUNT, true, sampleElement2()); //$NON-NLS-1$
int equals = -1;
UnitTestUtil.helpTestEquivalence(equals, test1, test2);
}
public void testNonEquivalence2(){
- AggregateSymbol test1 = new AggregateSymbol("x", SQLReservedWords.MAX, true, sampleElement()); //$NON-NLS-1$
- AggregateSymbol test2 = new AggregateSymbol("x", SQLReservedWords.COUNT, true, sampleElement2()); //$NON-NLS-1$
+ AggregateSymbol test1 = new AggregateSymbol("x", NonReserved.MAX, true, sampleElement()); //$NON-NLS-1$
+ AggregateSymbol test2 = new AggregateSymbol("x", NonReserved.COUNT, true, sampleElement2()); //$NON-NLS-1$
int equals = -1;
UnitTestUtil.helpTestEquivalence(equals, test1, test2);
}
Modified: trunk/engine/src/test/java/org/teiid/query/sql/visitor/TestExpressionMappingVisitor.java
===================================================================
--- trunk/engine/src/test/java/org/teiid/query/sql/visitor/TestExpressionMappingVisitor.java 2010-06-04 21:35:06 UTC (rev 2180)
+++ trunk/engine/src/test/java/org/teiid/query/sql/visitor/TestExpressionMappingVisitor.java 2010-06-04 21:51:29 UTC (rev 2181)
@@ -31,7 +31,7 @@
import java.util.Map;
import org.junit.Test;
-import org.teiid.language.SQLReservedWords;
+import org.teiid.language.SQLReservedWords.NonReserved;
import org.teiid.query.sql.LanguageObject;
import org.teiid.query.sql.lang.CompareCriteria;
import org.teiid.query.sql.lang.Select;
@@ -197,10 +197,10 @@
*/
@Test public void testRecursionDetection() {
ElementSymbol e1 = new ElementSymbol("e1"); //$NON-NLS-1$
- AggregateSymbol a1 = new AggregateSymbol("x", SQLReservedWords.SUM, false, e1); //$NON-NLS-1$
+ AggregateSymbol a1 = new AggregateSymbol("x", NonReserved.SUM, false, e1); //$NON-NLS-1$
Function f = new Function(SourceSystemFunctions.ADD_OP, new Expression[] {a1, a1});
HashMap<AggregateSymbol, AggregateSymbol> map = new HashMap<AggregateSymbol, AggregateSymbol>();
- map.put(a1, new AggregateSymbol("x", SQLReservedWords.SUM, false, a1)); //$NON-NLS-1$
+ map.put(a1, new AggregateSymbol("x", NonReserved.SUM, false, a1)); //$NON-NLS-1$
ExpressionMappingVisitor.mapExpressions(f, map);
assertEquals("(SUM(SUM(e1)) + SUM(SUM(e1)))", f.toString()); //$NON-NLS-1$
}
Modified: trunk/engine/src/test/java/org/teiid/query/sql/visitor/TestSQLStringVisitor.java
===================================================================
--- trunk/engine/src/test/java/org/teiid/query/sql/visitor/TestSQLStringVisitor.java 2010-06-04 21:35:06 UTC (rev 2180)
+++ trunk/engine/src/test/java/org/teiid/query/sql/visitor/TestSQLStringVisitor.java 2010-06-04 21:51:29 UTC (rev 2181)
@@ -27,9 +27,11 @@
import java.util.Arrays;
import java.util.List;
+import junit.framework.TestCase;
+
import org.teiid.client.metadata.ParameterInfo;
import org.teiid.core.types.DataTypeManager;
-import org.teiid.language.SQLReservedWords;
+import org.teiid.language.SQLReservedWords.NonReserved;
import org.teiid.query.parser.QueryParser;
import org.teiid.query.resolver.QueryResolver;
import org.teiid.query.sql.LanguageObject;
@@ -63,7 +65,6 @@
import org.teiid.query.sql.lang.SubquerySetCriteria;
import org.teiid.query.sql.lang.UnaryFromClause;
import org.teiid.query.sql.lang.Update;
-import org.teiid.query.sql.lang.XQuery;
import org.teiid.query.sql.lang.SetQuery.Operation;
import org.teiid.query.sql.proc.AssignmentStatement;
import org.teiid.query.sql.proc.Block;
@@ -90,12 +91,9 @@
import org.teiid.query.sql.symbol.SearchedCaseExpression;
import org.teiid.query.sql.symbol.TestCaseExpression;
import org.teiid.query.sql.symbol.TestSearchedCaseExpression;
-import org.teiid.query.sql.visitor.SQLStringVisitor;
import org.teiid.query.unittest.FakeMetadataFactory;
-import junit.framework.TestCase;
-
public class TestSQLStringVisitor extends TestCase {
// ################################## FRAMEWORK ################################
@@ -998,37 +996,37 @@
}
public void testAggregateSymbol1() {
- AggregateSymbol agg = new AggregateSymbol("abc", SQLReservedWords.COUNT, false, new Constant("abc")); //$NON-NLS-1$ //$NON-NLS-2$
+ AggregateSymbol agg = new AggregateSymbol("abc", NonReserved.COUNT, false, new Constant("abc")); //$NON-NLS-1$ //$NON-NLS-2$
helpTest(agg, "COUNT('abc')"); //$NON-NLS-1$
}
public void testAggregateSymbol2() {
- AggregateSymbol agg = new AggregateSymbol("abc", SQLReservedWords.COUNT, true, new Constant("abc")); //$NON-NLS-1$ //$NON-NLS-2$
+ AggregateSymbol agg = new AggregateSymbol("abc", NonReserved.COUNT, true, new Constant("abc")); //$NON-NLS-1$ //$NON-NLS-2$
helpTest(agg, "COUNT(DISTINCT 'abc')"); //$NON-NLS-1$
}
public void testAggregateSymbol3() {
- AggregateSymbol agg = new AggregateSymbol("abc", SQLReservedWords.COUNT, false, null); //$NON-NLS-1$
+ AggregateSymbol agg = new AggregateSymbol("abc", NonReserved.COUNT, false, null); //$NON-NLS-1$
helpTest(agg, "COUNT(*)"); //$NON-NLS-1$
}
public void testAggregateSymbol4() {
- AggregateSymbol agg = new AggregateSymbol("abc", SQLReservedWords.AVG, false, new Constant("abc")); //$NON-NLS-1$ //$NON-NLS-2$
+ AggregateSymbol agg = new AggregateSymbol("abc", NonReserved.AVG, false, new Constant("abc")); //$NON-NLS-1$ //$NON-NLS-2$
helpTest(agg, "AVG('abc')"); //$NON-NLS-1$
}
public void testAggregateSymbol5() {
- AggregateSymbol agg = new AggregateSymbol("abc", SQLReservedWords.SUM, false, new Constant("abc")); //$NON-NLS-1$ //$NON-NLS-2$
+ AggregateSymbol agg = new AggregateSymbol("abc", NonReserved.SUM, false, new Constant("abc")); //$NON-NLS-1$ //$NON-NLS-2$
helpTest(agg, "SUM('abc')"); //$NON-NLS-1$
}
public void testAggregateSymbol6() {
- AggregateSymbol agg = new AggregateSymbol("abc", SQLReservedWords.MIN, false, new Constant("abc")); //$NON-NLS-1$ //$NON-NLS-2$
+ AggregateSymbol agg = new AggregateSymbol("abc", NonReserved.MIN, false, new Constant("abc")); //$NON-NLS-1$ //$NON-NLS-2$
helpTest(agg, "MIN('abc')"); //$NON-NLS-1$
}
public void testAggregateSymbol7() {
- AggregateSymbol agg = new AggregateSymbol("abc", SQLReservedWords.MAX, false, new Constant("abc")); //$NON-NLS-1$ //$NON-NLS-2$
+ AggregateSymbol agg = new AggregateSymbol("abc", NonReserved.MAX, false, new Constant("abc")); //$NON-NLS-1$ //$NON-NLS-2$
helpTest(agg, "MAX('abc')"); //$NON-NLS-1$
}
@@ -1821,45 +1819,6 @@
}
- public void testXQuery(){
-
- String xquerystring =
- "XQUERY <Items>\r\n" + //$NON-NLS-1$
- "{\r\n" + //$NON-NLS-1$
- "for $x in doc(\"xmltest.doc9893\")//ItemName\r\n" + //$NON-NLS-1$
- "return <Item>{$x/text()}</Item>\r\n" + //$NON-NLS-1$
- "}\r\n" + //$NON-NLS-1$
- "</Items>\r\n"; //$NON-NLS-1$
-
- XQuery xquery = new XQuery(xquerystring, null);
- helpTest(xquery, xquerystring);
- }
-
- public void testXQueryWithOption(){
-
- String xquerystring =
- "XQUERY <Items>\r\n" + //$NON-NLS-1$
- "{\r\n" + //$NON-NLS-1$
- "for $x in doc(\"xmltest.doc9893\")//ItemName\r\n" + //$NON-NLS-1$
- "return <Item>{$x/text()}</Item>\r\n" + //$NON-NLS-1$
- "}\r\n" + //$NON-NLS-1$
- "</Items>"; //$NON-NLS-1$
-
- String expectedString =
- "XQUERY <Items>\r\n" + //$NON-NLS-1$
- "{\r\n" + //$NON-NLS-1$
- "for $x in doc(\"xmltest.doc9893\")//ItemName\r\n" + //$NON-NLS-1$
- "return <Item>{$x/text()}</Item>\r\n" + //$NON-NLS-1$
- "}\r\n" + //$NON-NLS-1$
- "</Items> OPTION NOCACHE"; //$NON-NLS-1$
-
- XQuery xquery = new XQuery(xquerystring, null);
- Option option = new Option();
- option.setNoCache(true);
- xquery.setOption(option);
- helpTest(xquery, expectedString);
- }
-
/**
* For some reason this test was outputting
* SELECT 'A' AS FOO UNION SELECT 'A' AS FOO
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-04 21:35:06 UTC (rev 2180)
+++ trunk/engine/src/test/java/org/teiid/query/validator/TestValidator.java 2010-06-04 21:51:29 UTC (rev 2181)
@@ -35,6 +35,7 @@
import java.util.Map;
import java.util.Set;
+import org.junit.Ignore;
import org.junit.Test;
import org.teiid.api.exception.query.QueryMetadataException;
import org.teiid.api.exception.query.QueryResolverException;
@@ -64,10 +65,7 @@
import org.teiid.query.unittest.FakeMetadataObject;
import org.teiid.query.unittest.FakeMetadataStore;
import org.teiid.query.unittest.RealMetadataFactory;
-import org.teiid.query.validator.Validator;
-import org.teiid.query.validator.ValidatorReport;
-
@SuppressWarnings("nls")
public class TestValidator {
@@ -1963,11 +1961,11 @@
}
@Test public void testValidateNoExpressionName() {
- helpValidate("SELECT xmlelement(name a, xmlattributes('1'))", new String[] {"'1'"}, exampleMetadata2()); //$NON-NLS-1$ //$NON-NLS-2$
+ helpValidate("SELECT xmlelement(name a, xmlattributes('1'))", new String[] {"XMLATTRIBUTES('1')"}, exampleMetadata2()); //$NON-NLS-1$ //$NON-NLS-2$
}
@Test public void testValidateNoExpressionName1() {
- helpValidate("SELECT xmlforest('1')", new String[] {"'1'"}, exampleMetadata2()); //$NON-NLS-1$ //$NON-NLS-2$
+ helpValidate("SELECT xmlforest('1')", new String[] {"XMLFOREST('1')"}, exampleMetadata2()); //$NON-NLS-1$ //$NON-NLS-2$
}
@Test public void testXpathValueValid_defect15088() {
@@ -1980,11 +1978,6 @@
helpValidate(userSql, new String[] {"xpathValue('<?xml version=\"1.0\" encoding=\"utf-8\" ?><a><b><c>test</c></b></a>', '//*[local-name()=''bookName\"]')"}, FakeMetadataFactory.exampleBQTCached());
}
- @Test public void testXpathValueInvalidNamespaces() throws Exception {
- String userSql = "SELECT xpathValue('<?xml version=\"1.0\" encoding=\"utf-8\" ?><a><b><c>test</c></b></a>', '//*[local-name()=\"bookName\"]', 'xmlns==')"; //$NON-NLS-1$
- helpValidate(userSql, new String[] {"xpathValue('<?xml version=\"1.0\" encoding=\"utf-8\" ?><a><b><c>test</c></b></a>', '//*[local-name()=\"bookName\"]', 'xmlns==')"}, FakeMetadataFactory.exampleBQTCached());
- }
-
@Test public void testTextTableNegativeWidth() {
helpValidate("SELECT * from texttable(null columns x string width -1) as x", new String[] {"TEXTTABLE(null COLUMNS x string WIDTH -1) AS x"}, RealMetadataFactory.exampleBQTCached());
}
@@ -1997,4 +1990,29 @@
helpValidate("SELECT * from texttable(null columns x string width 1 DELIMITER 'z') as x", new String[] {"TEXTTABLE(null COLUMNS x string WIDTH 1 DELIMITER 'z') AS x"}, RealMetadataFactory.exampleBQTCached());
}
+ @Test public void testXMLNamespaces() {
+ helpValidate("select xmlforest(xmlnamespaces(no default, default 'http://foo'), e1 as \"table\") from pm1.g1", new String[] {"XMLNAMESPACES(NO DEFAULT, DEFAULT 'http://foo')"}, FakeMetadataFactory.example1Cached());
+ }
+
+ @Test public void testXMLNamespacesReserved() {
+ helpValidate("select xmlforest(xmlnamespaces('http://foo' as xmlns), e1 as \"table\") from pm1.g1", new String[] {"XMLNAMESPACES('http://foo' AS xmlns)"}, FakeMetadataFactory.example1Cached());
+ }
+
+ @Test public void testXMLTablePassingMultipleContext() {
+ helpValidate("select * from pm1.g1, xmltable('/' passing '<a/>', '<b/>') as x", new String[] {"XMLTABLE('/' PASSING '<a/>', '<b/>') AS x"}, FakeMetadataFactory.example1Cached());
+ }
+
+ @Ignore("this is actually handled by saxon and will show up during resolving")
+ @Test public void testXMLTablePassingSameName() {
+ helpValidate("select * from pm1.g1, xmltable('/' passing '<a/>' as a, '<b/>' as a) as x", new String[] {"xmltable('/' passing e1, e1 || 'x') as x"}, FakeMetadataFactory.example1Cached());
+ }
+
+ @Test public void testXMLTablePassingContextType() {
+ helpValidate("select * from pm1.g1, xmltable('/' passing 2) as x", new String[] {"XMLTABLE('/' PASSING 2) AS x"}, FakeMetadataFactory.example1Cached());
+ }
+
+ @Test public void testXMLTableMultipleOrdinals() {
+ helpValidate("select * from pm1.g1, xmltable('/' passing '<a/>' columns x for ordinality, y for ordinality) as x", new String[] {"XMLTABLE('/' PASSING '<a/>' COLUMNS x FOR ORDINALITY, y FOR ORDINALITY) AS x"}, FakeMetadataFactory.example1Cached());
+ }
+
}
Deleted: trunk/engine/src/test/java/org/teiid/query/xquery/HardcodedSqlEval.java
===================================================================
--- trunk/engine/src/test/java/org/teiid/query/xquery/HardcodedSqlEval.java 2010-06-04 21:35:06 UTC (rev 2180)
+++ trunk/engine/src/test/java/org/teiid/query/xquery/HardcodedSqlEval.java 2010-06-04 21:51:29 UTC (rev 2181)
@@ -1,71 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * See the COPYRIGHT.txt file distributed with this work for information
- * regarding copyright ownership. Some portions may be licensed
- * to Red Hat, Inc. under one or more contributor license agreements.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
- * 02110-1301 USA.
- */
-
-package org.teiid.query.xquery;
-
-import java.io.StringReader;
-import java.util.Map;
-
-import javax.xml.transform.Source;
-import javax.xml.transform.stream.StreamSource;
-
-import org.teiid.api.exception.query.ExpressionEvaluationException;
-import org.teiid.api.exception.query.QueryParserException;
-import org.teiid.common.buffer.BlockedException;
-import org.teiid.core.TeiidComponentException;
-import org.teiid.core.TeiidProcessingException;
-import org.teiid.query.xquery.XQuerySQLEvaluator;
-
-
-
-/**
- */
-public class HardcodedSqlEval implements XQuerySQLEvaluator {
-
- String result;
- Map<String, Object> params;
- public HardcodedSqlEval(String result) {
- this.result = result;
- }
-
- public Source executeSQL(String sql)
- throws QueryParserException, TeiidProcessingException, TeiidComponentException {
- if (this.result != null) {
- return new StreamSource(new StringReader(result));
- }
- return null;
- }
-
- /**
- * @see org.teiid.query.xquery.XQuerySQLEvaluator#close()
- */
- public void close() throws TeiidComponentException {
- }
-
- @Override
- public Object getParameterValue(String key)
- throws ExpressionEvaluationException, BlockedException,
- TeiidComponentException {
- return params.get(key);
- }
-
-}
Deleted: trunk/engine/src/test/java/org/teiid/query/xquery/TestXQueryEngine.java
===================================================================
--- trunk/engine/src/test/java/org/teiid/query/xquery/TestXQueryEngine.java 2010-06-04 21:35:06 UTC (rev 2180)
+++ trunk/engine/src/test/java/org/teiid/query/xquery/TestXQueryEngine.java 2010-06-04 21:51:29 UTC (rev 2181)
@@ -1,211 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * See the COPYRIGHT.txt file distributed with this work for information
- * regarding copyright ownership. Some portions may be licensed
- * to Red Hat, Inc. under one or more contributor license agreements.
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2.1 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
- * 02110-1301 USA.
- */
-
-package org.teiid.query.xquery;
-
-import java.io.File;
-import java.io.IOException;
-import java.io.StringWriter;
-import java.io.UnsupportedEncodingException;
-import java.net.URI;
-import java.sql.SQLXML;
-import java.util.HashMap;
-
-import junit.framework.TestCase;
-
-import org.jdom.Document;
-import org.jdom.Element;
-import org.jdom.output.XMLOutputter;
-import org.teiid.core.TeiidProcessingException;
-import org.teiid.core.types.SQLXMLImpl;
-import org.teiid.core.types.XMLTranslator;
-import org.teiid.core.util.FileUtil;
-import org.teiid.core.util.UnitTestUtil;
-import org.teiid.query.xquery.XQueryExpression;
-import org.teiid.query.xquery.XQuerySQLEvaluator;
-import org.teiid.query.xquery.saxon.SaxonXQueryExpression;
-
-
-/**
- * Test XQueryEngine and XQueryExpression implementations
- */
-public class TestXQueryEngine extends TestCase {
-
- /**
- * @param name
- */
- public TestXQueryEngine(String name) {
- super(name);
- }
-
-// =========================================================================
-// HELPERS
-// =========================================================================
- private void helpTestEngine(String xQuery, SQLXML expected, XQuerySQLEvaluator sqlEval) throws Exception{
- XQueryExpression expr = new SaxonXQueryExpression();
- helpTestEngine(expr, xQuery, expected, sqlEval);
- }
-
- private void helpTestEngine(XQueryExpression expr, String xQuery, SQLXML expected, XQuerySQLEvaluator sqlEval) throws Exception{
- expr.compileXQuery(xQuery);
- XMLTranslator actualResults = expr.evaluateXQuery(sqlEval);
- String result = actualResults.getString();
- assertEquals(expected.getString(), result);
- }
-
- private void helpTestEngineFails(String xQuery, Class<?> expectedFailure, XQuerySQLEvaluator sqlEval) throws Exception{
- XQueryExpression expr = new SaxonXQueryExpression();
- expr.compileXQuery(xQuery);
-
- try {
- expr.evaluateXQuery(sqlEval);
- fail("expected failure"); //$NON-NLS-1$
- } catch (TeiidProcessingException e) {
- assertEquals(expectedFailure, e.getClass());
- }
- }
-
-
-// =========================================================================
-// TESTS
-// =========================================================================
-
- /** simple test */
- public void test1() throws Exception {
-
- // Construct a JDOM tree, like we use in the server
- Element element = new Element("test");//$NON-NLS-1$
- Element element2 = new Element("name");//$NON-NLS-1$
- element2.addContent("Tim");//$NON-NLS-1$
- element.addContent(element2);
- element2 = new Element("name");//$NON-NLS-1$
- element2.addContent("Tom");//$NON-NLS-1$
- element.addContent(element2);
- element2 = new Element("name");//$NON-NLS-1$
- element2.addContent("Bill");//$NON-NLS-1$
- element.addContent(element2);
- Document doc = new Document(element);
- XMLOutputter xmlOutputter = new XMLOutputter();
-
- String xquery = "<friends>\n" + //$NON-NLS-1$
- "{\n" + //$NON-NLS-1$
-// "let $y := doc(\"goo\")//names\n" + //$NON-NLS-1$
- "for $x in doc(\"foo\")//name\n" + //$NON-NLS-1$
- "return <friend>{$x/text()}</friend>\n" + //$NON-NLS-1$
- "}\n" + //$NON-NLS-1$
- "</friends>"; //$NON-NLS-1$
-
- String output = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + //$NON-NLS-1$
- "<friends>" + //$NON-NLS-1$
- "<friend>Tim</friend>" + //$NON-NLS-1$
- "<friend>Tom</friend>" + //$NON-NLS-1$
- "<friend>Bill</friend>" + //$NON-NLS-1$
- "</friends>"; //$NON-NLS-1$
-
- helpTestEngine(xquery, new SQLXMLImpl(output), new HardcodedSqlEval(xmlOutputter.outputString(doc)));
- }
-
- /** defect 12387 */
- public void testDefect12387() throws Exception {
-
- // Construct a JDOM tree, like we use in the server
- Element element = new Element("test");//$NON-NLS-1$
- Element element2 = new Element("name");//$NON-NLS-1$
- element2.addContent("Tim");//$NON-NLS-1$
- element.addContent(element2);
- element2 = new Element("name");//$NON-NLS-1$
- element2.addContent("Tom");//$NON-NLS-1$
- element.addContent(element2);
- element2 = new Element("name");//$NON-NLS-1$
- element2.addContent("Bill");//$NON-NLS-1$
- element.addContent(element2);
- Document doc = new Document(element);
- XMLOutputter xmlOutputter = new XMLOutputter();
-
- String xquery = "<friends>\n" + //$NON-NLS-1$
- "{\n" + //$NON-NLS-1$
- "for $x in doc(foo)//name\n" + //$NON-NLS-1$
- "return <friend>{$x/text()}</friend>\n" + //$NON-NLS-1$
- "}\n" + //$NON-NLS-1$
- "</friends>"; //$NON-NLS-1$
-
- helpTestEngineFails(xquery, TeiidProcessingException.class, new HardcodedSqlEval(xmlOutputter.outputString(doc)));
- }
-
- public void testDocArgReadingFileURI() throws Exception {
- File f = UnitTestUtil.getTestDataFile("testExample.xml"); //$NON-NLS-1$
- URI uri = f.toURI();
- String xquery = "doc(\"" + uri.toString() + "\")"; //$NON-NLS-1$ //$NON-NLS-2$
-
- FileUtil util = new FileUtil(f.getCanonicalPath());
- String expectedStr = util.read().replaceAll("[ \t\r\n]", ""); //$NON-NLS-1$ //$NON-NLS-2$
-
- XQueryExpression expr = new SaxonXQueryExpression();
- expr.compileXQuery(xquery);
- XMLTranslator actualResults = expr.evaluateXQuery(new HardcodedSqlEval(null));
-
- assertEquals(expectedStr, actualResults.getString().replaceAll("[ \t\r\n]", "")); //$NON-NLS-1$ //$NON-NLS-2$
- }
-
- public void testInputParams() throws Exception {
- String sql = "SELECT * FROM xmltest.doc1"; //$NON-NLS-1$
- String xquery = "declare variable $itemid as xs:string external;" + //$NON-NLS-1$
- "<set>\n" + //$NON-NLS-1$
- "{\n" + //$NON-NLS-1$
- "for $x in doc(\""+sql+"\")/Catalogs/Catalog/Items\n" + //$NON-NLS-1$ //$NON-NLS-2$
- "return <Name>{$x/Item[@ItemID=$itemid]/Name/text()}</Name>\n" + //$NON-NLS-1$
- "}\n" + //$NON-NLS-1$
- "</set>"; //$NON-NLS-1$
-
- String inputdoc =
- "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + //$NON-NLS-1$
- "<Catalogs xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">\n" + //$NON-NLS-1$
- " <Catalog>\n" + //$NON-NLS-1$
- " <Items>\n" + //$NON-NLS-1$
- " <Item ItemID=\"001\">\n" + //$NON-NLS-1$
- " <Name>Lamp</Name>\n" + //$NON-NLS-1$
- " <Quantity>5</Quantity>\n" + //$NON-NLS-1$
- " </Item>\n" + //$NON-NLS-1$
- " <Item ItemID=\"002\">\n" + //$NON-NLS-1$
- " <Name>Screwdriver</Name>\n" + //$NON-NLS-1$
- " <Quantity>100</Quantity>\n" + //$NON-NLS-1$
- " </Item>\n" + //$NON-NLS-1$
- " <Item ItemID=\"003\">\n" + //$NON-NLS-1$
- " <Name>Goat</Name>\n" + //$NON-NLS-1$
- " <Quantity>4</Quantity>\n" + //$NON-NLS-1$
- " </Item>\n" + //$NON-NLS-1$
- " </Items>\n" + //$NON-NLS-1$
- " </Catalog>\n" + //$NON-NLS-1$
- "</Catalogs>"; //$NON-NLS-1$
-
- String expected = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + //$NON-NLS-1$
- "<set>" + //$NON-NLS-1$
- "<Name>Lamp</Name>" + //$NON-NLS-1$
- "</set>"; //$NON-NLS-1$
- XQueryExpression expr = new SaxonXQueryExpression();
- HardcodedSqlEval eval = new HardcodedSqlEval(inputdoc);
- eval.params = new HashMap<String, Object>();
- eval.params.put("itemid", "001"); //$NON-NLS-1$ //$NON-NLS-2$
- helpTestEngine(expr, xquery, new SQLXMLImpl(expected), eval);
- }
-
-}
Modified: trunk/pom.xml
===================================================================
--- trunk/pom.xml 2010-06-04 21:35:06 UTC (rev 2180)
+++ trunk/pom.xml 2010-06-04 21:51:29 UTC (rev 2181)
@@ -453,14 +453,15 @@
<version>2.0b4</version>
</dependency>
<dependency>
- <groupId>net.sf.saxon</groupId>
+ <groupId>net.sourceforge.saxon</groupId>
<artifactId>saxon</artifactId>
- <version>8.7</version>
+ <version>9.1.0.8</version>
</dependency>
<dependency>
- <groupId>net.sf.saxon</groupId>
- <artifactId>saxon-dom</artifactId>
- <version>8.7</version>
+ <groupId>net.sourceforge.saxon</groupId>
+ <artifactId>saxon</artifactId>
+ <classifier>dom</classifier>
+ <version>9.1.0.8</version>
</dependency>
<dependency>
<groupId>org.jboss.netty</groupId>
Modified: trunk/test-integration/common/src/test/java/org/teiid/connector/visitor/util/TestSQLStringVisitor.java
===================================================================
--- trunk/test-integration/common/src/test/java/org/teiid/connector/visitor/util/TestSQLStringVisitor.java 2010-06-04 21:35:06 UTC (rev 2180)
+++ trunk/test-integration/common/src/test/java/org/teiid/connector/visitor/util/TestSQLStringVisitor.java 2010-06-04 21:51:29 UTC (rev 2181)
@@ -65,8 +65,8 @@
import org.teiid.language.Insert;
import org.teiid.language.LanguageObject;
import org.teiid.language.Literal;
-import org.teiid.language.SQLReservedWords;
import org.teiid.language.Select;
+import org.teiid.language.SQLReservedWords.NonReserved;
import org.teiid.language.visitor.SQLStringVisitor;
import org.teiid.metadata.RuntimeMetadata;
import org.teiid.query.sql.lang.CompareCriteria;
@@ -87,7 +87,7 @@
*/
@Test public void testVisitIAggregate() throws Exception {
String expected = "COUNT(42)"; //$NON-NLS-1$
- assertEquals(expected, getString(TestAggregateImpl.example("COUNT", SQLReservedWords.COUNT, false, 42))); //$NON-NLS-1$
+ assertEquals(expected, getString(TestAggregateImpl.example("COUNT", NonReserved.COUNT, false, 42))); //$NON-NLS-1$
}
@Test public void testVisitIAggregateDistinct() throws Exception {
@@ -382,7 +382,7 @@
}
@Test public void testTimestampAddFunction() throws Exception {
- String sql = "select timestampadd(" +SQLReservedWords.SQL_TSI_DAY+ ", 2, timestampvalue) from bqt1.smalla"; //$NON-NLS-1$ //$NON-NLS-2$
+ String sql = "select timestampadd(" +NonReserved.SQL_TSI_DAY+ ", 2, timestampvalue) from bqt1.smalla"; //$NON-NLS-1$ //$NON-NLS-2$
Command command = FakeTranslationFactory.getInstance().getBQTTranslationUtility().parseCommand(sql);
assertEquals("SELECT timestampadd(SQL_TSI_DAY, 2, SmallA.TimestampValue) FROM SmallA", command.toString()); //$NON-NLS-1$
14 years, 6 months
teiid SVN: r2180 - in trunk/console/src/main/java/org/teiid/rhq: plugin and 1 other directory.
by teiid-commits@lists.jboss.org
Author: tejones
Date: 2010-06-04 17:35:06 -0400 (Fri, 04 Jun 2010)
New Revision: 2180
Modified:
trunk/console/src/main/java/org/teiid/rhq/admin/DQPManagementView.java
trunk/console/src/main/java/org/teiid/rhq/plugin/VDBComponent.java
Log:
TEIID-1113: Changed Get Requests for VDB to use method on Runtime Engine
Modified: trunk/console/src/main/java/org/teiid/rhq/admin/DQPManagementView.java
===================================================================
--- trunk/console/src/main/java/org/teiid/rhq/admin/DQPManagementView.java 2010-06-04 21:00:20 UTC (rev 2179)
+++ trunk/console/src/main/java/org/teiid/rhq/admin/DQPManagementView.java 2010-06-04 21:35:06 UTC (rev 2180)
@@ -213,6 +213,8 @@
Collection<Session> activeSessionsCollection = new ArrayList<Session>();
String vdbName = (String) valueMap
.get(PluginConstants.ComponentType.VDB.NAME);
+ String vdbVersion = (String) valueMap
+ .get(PluginConstants.ComponentType.VDB.VERSION);
if (operationName.equals(VDB.Operations.GET_PROPERTIES)) {
List<String> fieldNameList = operationResult.getFieldNameList();
@@ -228,8 +230,8 @@
activeSessionsCollection.iterator()));
} else if (operationName.equals(VDB.Operations.GET_REQUESTS)) {
List<String> fieldNameList = operationResult.getFieldNameList();
- MetaValue requestMetaValue = getRequests();
- getRequestCollectionValueForVDB(requestMetaValue, resultObject, vdbName);
+ MetaValue requestMetaValue = getRequestsForVDB(vdbName, Integer.parseInt(vdbVersion));
+ getRequestCollectionValue(requestMetaValue, resultObject);
operationResult.setContent(createReportResultList(fieldNameList,
resultObject.iterator()));
}
@@ -274,6 +276,26 @@
}
+ protected MetaValue getRequestsForVDB(String vdbName, int vdbVersion) {
+
+ MetaValue requestsCollection = null;
+ MetaValue[] args = new MetaValue[] {
+ MetaValueFactory.getInstance().create(vdbName),
+ MetaValueFactory.getInstance().create(vdbVersion)};
+
+ try {
+ requestsCollection = executeManagedOperation(mc,
+ PluginConstants.ComponentType.VDB.Operations.GET_REQUESTS,
+ args);
+ } catch (Exception e) {
+ final String msg = "Exception executing operation: " + Platform.Operations.GET_REQUESTS; //$NON-NLS-1$
+ LOG.error(msg, e);
+ }
+
+ return requestsCollection;
+
+ }
+
protected MetaValue getTransactions() {
MetaValue transactionsCollection = null;
@@ -472,35 +494,17 @@
return requestsCollection;
}
- public static <T> void getRequestCollectionValue(MetaValue pValue,
+ private void getRequestCollectionValue(MetaValue pValue,
Collection<Request> list) {
MetaType metaType = pValue.getMetaType();
if (metaType.isCollection()) {
for (MetaValue value : ((CollectionValueSupport) pValue)
.getElements()) {
if (value.getMetaType().isComposite()) {
- Request Request = (Request) MetaValueFactory.getInstance()
- .unwrap(value);
- list.add(Request);
- } else {
- throw new IllegalStateException(pValue
- + " is not a Composite type");
- }
- }
- }
- }
-
- private void getRequestCollectionValueForVDB(MetaValue pValue,
- Collection<Request> list, String vdbName) {
- MetaType metaType = pValue.getMetaType();
- if (metaType.isCollection()) {
- for (MetaValue value : ((CollectionValueSupport) pValue)
- .getElements()) {
- if (value.getMetaType().isComposite()) {
RequestMetadataMapper rmm = new RequestMetadataMapper();
RequestMetadata request = (RequestMetadata) rmm
.unwrapMetaValue(value);
- list.add(request);
+ list.add(request);
} else {
throw new IllegalStateException(pValue
+ " is not a Composite type");
Modified: trunk/console/src/main/java/org/teiid/rhq/plugin/VDBComponent.java
===================================================================
--- trunk/console/src/main/java/org/teiid/rhq/plugin/VDBComponent.java 2010-06-04 21:00:20 UTC (rev 2179)
+++ trunk/console/src/main/java/org/teiid/rhq/plugin/VDBComponent.java 2010-06-04 21:35:06 UTC (rev 2180)
@@ -101,6 +101,9 @@
String key = VDB.NAME;
valueMap.put(key, this.resourceConfiguration.getSimpleValue("name",
null));
+ String version = VDB.VERSION;
+ valueMap.put(version, this.resourceConfiguration.getSimpleValue("version",
+ null));
// Parameter logic for VDB Operations
if (name.equals(VDB.Operations.KILL_REQUEST)) {
14 years, 6 months
teiid SVN: r2179 - trunk/console/src/main/java/org/teiid/rhq/plugin.
by teiid-commits@lists.jboss.org
Author: tejones
Date: 2010-06-04 17:00:20 -0400 (Fri, 04 Jun 2010)
New Revision: 2179
Modified:
trunk/console/src/main/java/org/teiid/rhq/plugin/PlatformDiscoveryComponent.java
Log:
TEIID-1111: Added Teiid version to discovered resource
Modified: trunk/console/src/main/java/org/teiid/rhq/plugin/PlatformDiscoveryComponent.java
===================================================================
--- trunk/console/src/main/java/org/teiid/rhq/plugin/PlatformDiscoveryComponent.java 2010-06-04 20:48:04 UTC (rev 2178)
+++ trunk/console/src/main/java/org/teiid/rhq/plugin/PlatformDiscoveryComponent.java 2010-06-04 21:00:20 UTC (rev 2179)
@@ -67,7 +67,9 @@
PluginConstants.ComponentType.Platform.TEIID_TYPE,
PluginConstants.ComponentType.Platform.TEIID_SUB_TYPE),
PluginConstants.ComponentType.Platform.TEIID_RUNTIME_ENGINE);
-
+
+ String version = ProfileServiceUtil.getSimpleValue(mc, "runtimeVersion", String.class);
+
/**
*
* A discovered resource must have a unique key, that must stay the same
@@ -76,9 +78,8 @@
DiscoveredResourceDetails detail = new DiscoveredResourceDetails(
discoveryContext.getResourceType(), // ResourceType
mc.getName(), // Resource Key
- PluginConstants.ComponentType.Platform.TEIID_ENGINE_RESOURCE_NAME, // Resource
- // Name
- null, // Version TODO can we get that from discovery ?
+ PluginConstants.ComponentType.Platform.TEIID_ENGINE_RESOURCE_NAME, // Resource name
+ version,
PluginConstants.ComponentType.Platform.TEIID_ENGINE_RESOURCE_DESCRIPTION, // Description
discoveryContext.getDefaultPluginConfiguration(), // Plugin
// Config
14 years, 6 months
teiid SVN: r2178 - in trunk/console/src/main/java/org/teiid/rhq: plugin and 1 other directory.
by teiid-commits@lists.jboss.org
Author: tejones
Date: 2010-06-04 16:48:04 -0400 (Fri, 04 Jun 2010)
New Revision: 2178
Modified:
trunk/console/src/main/java/org/teiid/rhq/admin/DQPManagementView.java
trunk/console/src/main/java/org/teiid/rhq/plugin/VDBComponent.java
Log:
TEIID-1083: Changed to match up with engine changes
Modified: trunk/console/src/main/java/org/teiid/rhq/admin/DQPManagementView.java
===================================================================
--- trunk/console/src/main/java/org/teiid/rhq/admin/DQPManagementView.java 2010-06-04 19:58:22 UTC (rev 2177)
+++ trunk/console/src/main/java/org/teiid/rhq/admin/DQPManagementView.java 2010-06-04 20:48:04 UTC (rev 2178)
@@ -3,6 +3,7 @@
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Collection;
+import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
@@ -24,6 +25,8 @@
import org.teiid.adminapi.Request;
import org.teiid.adminapi.Session;
import org.teiid.adminapi.Transaction;
+import org.teiid.adminapi.impl.RequestMetadata;
+import org.teiid.adminapi.impl.RequestMetadataMapper;
import org.teiid.rhq.comm.ExecutedResult;
import org.teiid.rhq.plugin.util.PluginConstants;
import org.teiid.rhq.plugin.util.ProfileServiceUtil;
@@ -74,7 +77,8 @@
if (metric
.equals(PluginConstants.ComponentType.Platform.Metrics.LONG_RUNNING_QUERIES)) {
Collection<Request> longRunningQueries = new ArrayList<Request>();
- getRequestCollectionValue(getLongRunningQueries(), longRunningQueries);
+ getRequestCollectionValue(getLongRunningQueries(),
+ longRunningQueries);
resultObject = new Double(longRunningQueries.size());
}
}
@@ -88,10 +92,12 @@
Object resultObject = new Object();
- if (metric.equals(PluginConstants.ComponentType.VDB.Metrics.ERROR_COUNT)) {
+ if (metric
+ .equals(PluginConstants.ComponentType.VDB.Metrics.ERROR_COUNT)) {
// TODO remove version parameter after AdminAPI is changed
resultObject = getErrorCount((String) valueMap.get(VDB.NAME));
- } else if (metric.equals(PluginConstants.ComponentType.VDB.Metrics.STATUS)) {
+ } else if (metric
+ .equals(PluginConstants.ComponentType.VDB.Metrics.STATUS)) {
// TODO remove version parameter after AdminAPI is changed
resultObject = getVDBStatus((String) valueMap.get(VDB.NAME), 1);
} else if (metric
@@ -103,7 +109,8 @@
} else if (metric
.equals(PluginConstants.ComponentType.VDB.Metrics.LONG_RUNNING_QUERIES)) {
Collection<Request> longRunningQueries = new ArrayList<Request>();
- getRequestCollectionValue(getLongRunningQueries(), longRunningQueries);
+ getRequestCollectionValue(getLongRunningQueries(),
+ longRunningQueries);
resultObject = new Double(longRunningQueries.size());
}
@@ -136,7 +143,6 @@
Collection<Session> activeSessionsCollection = new ArrayList<Session>();
Collection<Transaction> transactionsCollection = new ArrayList<Transaction>();
-
if (operationName.equals(Platform.Operations.GET_LONGRUNNINGQUERIES)) {
List<String> fieldNameList = operationResult.getFieldNameList();
getRequestCollectionValue(getLongRunningQueries(), resultObject);
@@ -158,16 +164,18 @@
} else if (operationName.equals(Platform.Operations.GET_TRANSACTIONS)) {
List<String> fieldNameList = operationResult.getFieldNameList();
MetaValue transactionMetaValue = getTransactions();
- getTransactionCollectionValue(transactionMetaValue, transactionsCollection);
+ getTransactionCollectionValue(transactionMetaValue,
+ transactionsCollection);
operationResult.setContent(createReportResultList(fieldNameList,
resultObject.iterator()));
} else if (operationName.equals(Platform.Operations.KILL_TRANSACTION)) {
- Long sessionID = (Long) valueMap.get(Operation.Value.TRANSACTION_ID);
+ Long sessionID = (Long) valueMap
+ .get(Operation.Value.TRANSACTION_ID);
MetaValue[] args = new MetaValue[] { metaValueFactory
.create(sessionID) };
try {
- executeManagedOperation(mc, Platform.Operations.KILL_TRANSACTION,
- args);
+ executeManagedOperation(mc,
+ Platform.Operations.KILL_TRANSACTION, args);
} catch (Exception e) {
final String msg = "Exception executing operation: " + Platform.Operations.KILL_TRANSACTION; //$NON-NLS-1$
LOG.error(msg, e);
@@ -203,6 +211,8 @@
final String operationName, final Map<String, Object> valueMap) {
Collection<Request> resultObject = new ArrayList<Request>();
Collection<Session> activeSessionsCollection = new ArrayList<Session>();
+ String vdbName = (String) valueMap
+ .get(PluginConstants.ComponentType.VDB.NAME);
if (operationName.equals(VDB.Operations.GET_PROPERTIES)) {
List<String> fieldNameList = operationResult.getFieldNameList();
@@ -213,13 +223,13 @@
List<String> fieldNameList = operationResult.getFieldNameList();
MetaValue sessionMetaValue = getSessions();
getSessionCollectionValueForVDB(sessionMetaValue,
- activeSessionsCollection, (String)valueMap.get(PluginConstants.ComponentType.VDB.NAME));
+ activeSessionsCollection, vdbName);
operationResult.setContent(createReportResultList(fieldNameList,
activeSessionsCollection.iterator()));
} else if (operationName.equals(VDB.Operations.GET_REQUESTS)) {
List<String> fieldNameList = operationResult.getFieldNameList();
MetaValue requestMetaValue = getRequests();
- getRequestCollectionValueForVDB(requestMetaValue, resultObject, (String)valueMap.get(PluginConstants.ComponentType.VDB.NAME));
+ getRequestCollectionValueForVDB(requestMetaValue, resultObject, vdbName);
operationResult.setContent(createReportResultList(fieldNameList,
resultObject.iterator()));
}
@@ -281,7 +291,6 @@
}
-
public MetaValue getSessions() {
MetaValue sessionCollection = null;
@@ -407,7 +416,7 @@
* @throws Exception
*/
private int getErrorCount(String vdbName) {
-
+
ManagedComponent mcVdb = null;
try {
mcVdb = ProfileServiceUtil
@@ -423,7 +432,7 @@
final String msg = "Exception in getVDBStatus(): " + e.getMessage(); //$NON-NLS-1$
LOG.error(msg, e);
}
-
+
// Get models from VDB
int count = 0;
ManagedProperty property = mcVdb.getProperty("models");
@@ -480,19 +489,18 @@
}
}
}
-
- public static <T> void getRequestCollectionValueForVDB(MetaValue pValue,
+
+ private void getRequestCollectionValueForVDB(MetaValue pValue,
Collection<Request> list, String vdbName) {
MetaType metaType = pValue.getMetaType();
if (metaType.isCollection()) {
for (MetaValue value : ((CollectionValueSupport) pValue)
.getElements()) {
if (value.getMetaType().isComposite()) {
- Request request = (Request) MetaValueFactory.getInstance()
- .unwrap(value);
- if (request.getName().equals(vdbName)){
- list.add(request);
- }
+ RequestMetadataMapper rmm = new RequestMetadataMapper();
+ RequestMetadata request = (RequestMetadata) rmm
+ .unwrapMetaValue(value);
+ list.add(request);
} else {
throw new IllegalStateException(pValue
+ " is not a Composite type");
@@ -500,7 +508,15 @@
}
}
}
-
+
+ private Collection<Session> getSessionsForVDB(String vdbName) {
+ Collection<Session> activeSessionsCollection = Collections.emptyList();
+ MetaValue sessionMetaValue = getSessions();
+ getSessionCollectionValueForVDB(sessionMetaValue,
+ activeSessionsCollection, vdbName);
+ return activeSessionsCollection;
+ }
+
public static <T> void getTransactionCollectionValue(MetaValue pValue,
Collection<Transaction> list) {
MetaType metaType = pValue.getMetaType();
@@ -508,8 +524,8 @@
for (MetaValue value : ((CollectionValueSupport) pValue)
.getElements()) {
if (value.getMetaType().isComposite()) {
- Transaction transaction = (Transaction) MetaValueFactory.getInstance()
- .unwrap(value);
+ Transaction transaction = (Transaction) MetaValueFactory
+ .getInstance().unwrap(value);
list.add(transaction);
} else {
throw new IllegalStateException(pValue
@@ -519,7 +535,6 @@
}
}
-
public static <T> void getSessionCollectionValue(MetaValue pValue,
Collection<Session> list) {
MetaType metaType = pValue.getMetaType();
@@ -537,7 +552,7 @@
}
}
}
-
+
public static <T> void getSessionCollectionValueForVDB(MetaValue pValue,
Collection<Session> list, String vdbName) {
MetaType metaType = pValue.getMetaType();
@@ -547,8 +562,8 @@
if (value.getMetaType().isComposite()) {
Session session = (Session) MetaValueFactory.getInstance()
.unwrap(value);
- if (session.getName().equals(vdbName)){
- list.add(session);
+ if (session.getVDBName().equals(vdbName)) {
+ list.add(session);
}
} else {
throw new IllegalStateException(pValue
Modified: trunk/console/src/main/java/org/teiid/rhq/plugin/VDBComponent.java
===================================================================
--- trunk/console/src/main/java/org/teiid/rhq/plugin/VDBComponent.java 2010-06-04 19:58:22 UTC (rev 2177)
+++ trunk/console/src/main/java/org/teiid/rhq/plugin/VDBComponent.java 2010-06-04 20:48:04 UTC (rev 2178)
@@ -97,6 +97,11 @@
@Override
protected void setOperationArguments(String name,
Configuration configuration, Map<String, Object> valueMap) {
+ // Parameter logic for VDB Metrics
+ String key = VDB.NAME;
+ valueMap.put(key, this.resourceConfiguration.getSimpleValue("name",
+ null));
+
// Parameter logic for VDB Operations
if (name.equals(VDB.Operations.KILL_REQUEST)) {
valueMap.put(Operation.Value.REQUEST_ID, configuration.getSimple(
@@ -107,7 +112,7 @@
valueMap.put(Operation.Value.SESSION_ID, configuration.getSimple(
Operation.Value.SESSION_ID).getLongValue());
} else if (name.equals(Platform.Operations.GET_PROPERTIES)) {
- String key = ConnectionConstants.IDENTIFIER;
+ key = ConnectionConstants.IDENTIFIER;
valueMap.put(key, getComponentIdentifier());
} else if (name.equals(Platform.Operations.KILL_SESSION)) {
valueMap.put(Operation.Value.SESSION_ID, configuration.getSimple(
@@ -136,7 +141,7 @@
protected void setMetricArguments(String name, Configuration configuration,
Map<String, Object> valueMap) {
// Parameter logic for VDB Metrics
- String key = VDB.NAME;
+ String key = VDB.NAME;
valueMap.put(key, this.resourceConfiguration.getSimpleValue("name",
null));
}
14 years, 6 months
teiid SVN: r2177 - in trunk: engine/src/main/java/org/teiid/dqp/internal/process and 2 other directories.
by teiid-commits@lists.jboss.org
Author: rareddy
Date: 2010-06-04 15:58:22 -0400 (Fri, 04 Jun 2010)
New Revision: 2177
Modified:
trunk/client/src/main/java/org/teiid/adminapi/impl/DQPManagement.java
trunk/engine/src/main/java/org/teiid/dqp/internal/process/DQPCore.java
trunk/engine/src/test/java/org/teiid/dqp/internal/process/TestDQPCoreRequestHandling.java
trunk/jboss-integration/src/main/java/org/teiid/jboss/deployers/RuntimeEngineDeployer.java
Log:
TEIID-1112: Adding a managed operation on dqp to get all requests for a perticular VDB. Also fixed bug, where the sessionid was still being referred as the long instead of string.
Modified: trunk/client/src/main/java/org/teiid/adminapi/impl/DQPManagement.java
===================================================================
--- trunk/client/src/main/java/org/teiid/adminapi/impl/DQPManagement.java 2010-06-04 19:15:22 UTC (rev 2176)
+++ trunk/client/src/main/java/org/teiid/adminapi/impl/DQPManagement.java 2010-06-04 19:58:22 UTC (rev 2177)
@@ -28,7 +28,7 @@
public interface DQPManagement {
- List<RequestMetadata> getRequestsForSession(long sessionId) ;
+ List<RequestMetadata> getRequestsForSession(String sessionId) ;
List<RequestMetadata> getRequests();
WorkerPoolStatisticsMetadata getWorkManagerStatistics(String identifier);
void terminateSession(String terminateeId);
@@ -41,4 +41,5 @@
void terminateTransaction(String xid) throws AdminException ;
void mergeVDBs(String sourceVDBName, int sourceVDBVersion, String targetVDBName, int targetVDBVersion) throws AdminException;
List<RequestMetadata> getLongRunningRequests();
+ List<RequestMetadata> getRequestsUsingVDB(String vdbName, int vdbVersion) throws AdminException;
}
Modified: trunk/engine/src/main/java/org/teiid/dqp/internal/process/DQPCore.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/dqp/internal/process/DQPCore.java 2010-06-04 19:15:22 UTC (rev 2176)
+++ trunk/engine/src/main/java/org/teiid/dqp/internal/process/DQPCore.java 2010-06-04 19:58:22 UTC (rev 2177)
@@ -210,8 +210,8 @@
/**
* Return a list of {@link RequestMetadata} for the given session
*/
- public List<RequestMetadata> getRequestsForSession(long sessionId) {
- ClientState state = getClientState(String.valueOf(sessionId), false);
+ public List<RequestMetadata> getRequestsForSession(String sessionId) {
+ ClientState state = getClientState(sessionId, false);
if (state == null) {
return Collections.emptyList();
}
Modified: trunk/engine/src/test/java/org/teiid/dqp/internal/process/TestDQPCoreRequestHandling.java
===================================================================
--- trunk/engine/src/test/java/org/teiid/dqp/internal/process/TestDQPCoreRequestHandling.java 2010-06-04 19:15:22 UTC (rev 2176)
+++ trunk/engine/src/test/java/org/teiid/dqp/internal/process/TestDQPCoreRequestHandling.java 2010-06-04 19:58:22 UTC (rev 2177)
@@ -31,7 +31,6 @@
import org.teiid.adminapi.impl.RequestMetadata;
import org.teiid.client.RequestMessage;
import org.teiid.client.SourceWarning;
-import org.teiid.client.security.SessionToken;
import org.teiid.core.TeiidException;
import org.teiid.dqp.internal.datamgr.impl.FakeTransactionService;
import org.teiid.dqp.internal.process.DQPCore.ClientState;
@@ -44,7 +43,7 @@
*/
public class TestDQPCoreRequestHandling extends TestCase {
- private static final String SESSION_STRING = "2";
+ private static final String SESSION_STRING = "2"; //$NON-NLS-1$
public TestDQPCoreRequestHandling(String name) {
super(name);
@@ -65,7 +64,7 @@
public void testGetRequestsSessionToken1() {
DQPCore rm = new DQPCore();
Set reqs = new HashSet();
- Collection actualReqs = rm.getRequestsForSession(2);
+ Collection actualReqs = rm.getRequestsForSession(SESSION_STRING);
compareReqInfos(reqs, actualReqs);
}
@@ -79,7 +78,7 @@
RequestID id = addRequest(rm, SESSION_STRING, 1);
reqs.add(id);
- Collection<RequestMetadata> actualReqs = rm.getRequestsForSession(2);
+ Collection<RequestMetadata> actualReqs = rm.getRequestsForSession(SESSION_STRING);
compareReqInfos(reqs, actualReqs);
}
@@ -102,7 +101,7 @@
reqs.add(addRequest(rm, SESSION_STRING, 1));
reqs.add(addRequest(rm, SESSION_STRING, 2));
- Collection actualReqs = rm.getRequestsForSession(2);
+ Collection actualReqs = rm.getRequestsForSession(SESSION_STRING);
compareReqInfos(reqs, actualReqs);
}
Modified: trunk/jboss-integration/src/main/java/org/teiid/jboss/deployers/RuntimeEngineDeployer.java
===================================================================
--- trunk/jboss-integration/src/main/java/org/teiid/jboss/deployers/RuntimeEngineDeployer.java 2010-06-04 19:15:22 UTC (rev 2176)
+++ trunk/jboss-integration/src/main/java/org/teiid/jboss/deployers/RuntimeEngineDeployer.java 2010-06-04 19:58:22 UTC (rev 2177)
@@ -25,6 +25,7 @@
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.lang.reflect.Proxy;
+import java.util.ArrayList;
import java.util.Collection;
import java.util.Date;
import java.util.List;
@@ -236,9 +237,27 @@
@Override
@ManagementOperation(description="Requests for perticular session", impact=Impact.ReadOnly,params={@ManagementParameter(name="sessionId",description="The session Identifier")})
- public List<RequestMetadata> getRequestsForSession(long sessionId) {
+ public List<RequestMetadata> getRequestsForSession(String sessionId) {
return this.dqpCore.getRequestsForSession(sessionId);
}
+
+ @Override
+ @ManagementOperation(description="Requests using a certain VDB", impact=Impact.ReadOnly,params={@ManagementParameter(name="vdbName",description="VDB Name"), @ManagementParameter(name="vdbVersion",description="VDB Version")})
+ public List<RequestMetadata> getRequestsUsingVDB(String vdbName, int vdbVersion) throws AdminException {
+ List<RequestMetadata> requests = new ArrayList<RequestMetadata>();
+ try {
+ Collection<SessionMetadata> sessions = this.sessionService.getActiveSessions();
+ for (SessionMetadata session:sessions) {
+ if (session.getVDBName().equals(vdbName) && session.getVDBVersion() == vdbVersion) {
+ requests.addAll(this.dqpCore.getRequestsForSession(session.getSessionId()));
+ }
+ }
+ } catch (SessionServiceException e) {
+ throw new AdminComponentException(e);
+ }
+ return requests;
+ }
+
@Override
@ManagementOperation(description="Active requests", impact=Impact.ReadOnly)
14 years, 6 months
teiid SVN: r2176 - in trunk: hibernate-dialect and 1 other directories.
by teiid-commits@lists.jboss.org
Author: rareddy
Date: 2010-06-04 15:15:22 -0400 (Fri, 04 Jun 2010)
New Revision: 2176
Modified:
trunk/hibernate-dialect/pom.xml
trunk/jboss-integration/pom.xml
trunk/pom.xml
Log:
TEIID-1050: Upgrading the Maven repository to new JBoss's Nexus repo. The 3.2.3 version of the Hibernate was not available in the nexus, so I upgraded to 3.5.2. The most notable improvement is now developers can publish to snapshot repos and also sources are also deployed.
Modified: trunk/hibernate-dialect/pom.xml
===================================================================
--- trunk/hibernate-dialect/pom.xml 2010-06-03 23:05:59 UTC (rev 2175)
+++ trunk/hibernate-dialect/pom.xml 2010-06-04 19:15:22 UTC (rev 2176)
@@ -11,9 +11,9 @@
<description>Teiid Hibernate Dialect</description>
<dependencies>
<dependency>
- <groupId>hibernate</groupId>
- <artifactId>hibernate3</artifactId>
- <version>3.2.3.GA</version>
+ <groupId>org.hibernate</groupId>
+ <artifactId>hibernate-core</artifactId>
+ <version>3.5.2-Final</version>
</dependency>
</dependencies>
</project>
\ No newline at end of file
Modified: trunk/jboss-integration/pom.xml
===================================================================
--- trunk/jboss-integration/pom.xml 2010-06-03 23:05:59 UTC (rev 2175)
+++ trunk/jboss-integration/pom.xml 2010-06-04 19:15:22 UTC (rev 2176)
@@ -80,14 +80,15 @@
<version>5.0.3.GA</version>
<scope>test</scope>
</dependency>
-
+<!--
<dependency>
<groupId>org.jboss.aop</groupId>
<artifactId>jboss-aop</artifactId>
<classifier>client</classifier>
<version>2.1.1.GA</version>
<scope>test</scope>
- </dependency>
+ </dependency>
+-->
<dependency>
<groupId>org.jboss.remoting</groupId>
Modified: trunk/pom.xml
===================================================================
--- trunk/pom.xml 2010-06-03 23:05:59 UTC (rev 2175)
+++ trunk/pom.xml 2010-06-04 19:15:22 UTC (rev 2176)
@@ -13,6 +13,7 @@
<site.url>http://www.jboss.org/teiid</site.url>
</properties>
<scm>
+ <connection>scm:svn:https://anonsvn.jboss.org/repos/teiid/trunk</connection>
<developerConnection>scm:svn:https://svn.jboss.org/repos/teiid/trunk</developerConnection>
</scm>
<licenses>
@@ -172,11 +173,23 @@
</archive>
</configuration>
</plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-source-plugin</artifactId>
+ <executions>
+ <execution>
+ <id>attach-sources</id>
+ <goals>
+ <goal>jar</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>2.5</version>
- </plugin>
+ </plugin>
</plugins>
</build>
<reporting>
@@ -194,13 +207,10 @@
</reporting>
<repositories>
<repository>
- <id>jboss</id>
- <url>http://repository.jboss.com/maven2/</url>
+ <id>jboss-public-repository</id>
+ <name>JBoss Public Maven Repository Group</name>
+ <url>http://repository.jboss.org/nexus/content/groups/public/</url>
</repository>
- <repository>
- <id>jboss-snapshot</id>
- <url>http://snapshots.jboss.org/maven2</url>
- </repository>
</repositories>
<dependencies>
<dependency>
@@ -490,10 +500,16 @@
<module>jboss-integration</module>
<module>test-integration</module>
</modules>
- <distributionManagement>
- <repository>
- <id>repository.jboss.org</id>
- <url>${jboss.repository.root}</url>
- </repository>
- </distributionManagement>
+ <distributionManagement>
+ <repository>
+ <id>jboss-releases-repository</id>
+ <name>JBoss Releases Repository</name>
+ <url>https://repository.jboss.org/nexus/service/local/staging/deploy/maven2/</url>
+ </repository>
+ <snapshotRepository>
+ <id>jboss-snapshots-repository</id>
+ <name>JBoss Snapshots Repository</name>
+ <url>https://repository.jboss.org/nexus/content/repositories/snapshots/</url>
+ </snapshotRepository>
+ </distributionManagement>
</project>
14 years, 6 months
teiid SVN: r2175 - trunk/engine/src/main/java/org/teiid/dqp/internal/process.
by teiid-commits@lists.jboss.org
Author: rareddy
Date: 2010-06-03 19:05:59 -0400 (Thu, 03 Jun 2010)
New Revision: 2175
Modified:
trunk/engine/src/main/java/org/teiid/dqp/internal/process/DQPConfiguration.java
Log:
TEIID-1062: adding support for exposing the teiid runtime version through managed property.
Modified: trunk/engine/src/main/java/org/teiid/dqp/internal/process/DQPConfiguration.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/dqp/internal/process/DQPConfiguration.java 2010-06-03 21:55:23 UTC (rev 2174)
+++ trunk/engine/src/main/java/org/teiid/dqp/internal/process/DQPConfiguration.java 2010-06-03 23:05:59 UTC (rev 2175)
@@ -23,6 +23,7 @@
import org.jboss.managed.api.annotation.ManagementProperty;
import org.teiid.client.RequestMessage;
+import org.teiid.core.util.ApplicationInfo;
public class DQPConfiguration{
@@ -172,5 +173,10 @@
public void setQueryThresholdInSecs(int queryThresholdInSecs) {
this.queryThresholdInSecs = queryThresholdInSecs;
- }
+ }
+
+ @ManagementProperty(description="Teiid runtime version", readOnly=true)
+ public String getRuntimeVersion() {
+ return ApplicationInfo.getInstance().getBuildNumber();
+ }
}
14 years, 6 months
teiid SVN: r2174 - trunk/client/src/main/java/org/teiid/jdbc.
by teiid-commits@lists.jboss.org
Author: rareddy
Date: 2010-06-03 17:55:23 -0400 (Thu, 03 Jun 2010)
New Revision: 2174
Modified:
trunk/client/src/main/java/org/teiid/jdbc/TeiidDataSource.java
Log:
TEIID-1109: validation of the properties was missing in the "embedded" case that threw a SQLException whic would have avoided the NPE. Added the required check now.
Modified: trunk/client/src/main/java/org/teiid/jdbc/TeiidDataSource.java
===================================================================
--- trunk/client/src/main/java/org/teiid/jdbc/TeiidDataSource.java 2010-06-03 21:09:16 UTC (rev 2173)
+++ trunk/client/src/main/java/org/teiid/jdbc/TeiidDataSource.java 2010-06-03 21:55:23 UTC (rev 2174)
@@ -212,6 +212,7 @@
// check if this is embedded connection
if (getServerName() == null) {
+ super.validateProperties(userName, password);
final Properties props = buildEmbeddedProperties(userName, password);
String url = new JDBCURL(getDatabaseName(), null, props).getJDBCURL();
return driver.connect(url, props);
14 years, 6 months
teiid SVN: r2173 - trunk/metadata/src/main/java/org/teiid/metadata/index.
by teiid-commits@lists.jboss.org
Author: rareddy
Date: 2010-06-03 17:09:16 -0400 (Thu, 03 Jun 2010)
New Revision: 2173
Modified:
trunk/metadata/src/main/java/org/teiid/metadata/index/IndexMetadataFactory.java
Log:
TEIID-1074: Allowing to scan all the ".index" files in the case of that typed indexed files are not provided.
Modified: trunk/metadata/src/main/java/org/teiid/metadata/index/IndexMetadataFactory.java
===================================================================
--- trunk/metadata/src/main/java/org/teiid/metadata/index/IndexMetadataFactory.java 2010-06-02 14:58:30 UTC (rev 2172)
+++ trunk/metadata/src/main/java/org/teiid/metadata/index/IndexMetadataFactory.java 2010-06-03 21:09:16 UTC (rev 2173)
@@ -625,7 +625,11 @@
private IEntryResult[] queryIndex(char recordType, final char[] pattern, boolean isPrefix, boolean isCaseSensitive, boolean returnFirstMatch) {
// The the index file name for the record type
final String indexName = SimpleIndexUtil.getIndexFileNameForRecordType(recordType);
- Index[] search = SimpleIndexUtil.getIndexes(indexName, this.indexes);
+ Index[] search = SimpleIndexUtil.getIndexes(indexName, this.indexes);
+
+ if (search.length == 0) {
+ search = this.indexes;
+ }
try {
return SimpleIndexUtil.queryIndex(search, pattern, isPrefix, isCaseSensitive, returnFirstMatch);
14 years, 6 months
teiid SVN: r2172 - in trunk/build/kits/jboss-container/teiid-examples: portfolio/data and 1 other directories.
by teiid-commits@lists.jboss.org
Author: shawkins
Date: 2010-06-02 10:58:30 -0400 (Wed, 02 Jun 2010)
New Revision: 2172
Modified:
trunk/build/kits/jboss-container/teiid-examples/portfolio/data/marketdata-price.txt
trunk/build/kits/jboss-container/teiid-examples/portfolio/marketdata-file-ds.xml
trunk/build/kits/jboss-container/teiid-examples/simpleclient/JDBCClient.class
trunk/build/kits/jboss-container/teiid-examples/simpleclient/JDBCClient.java
Log:
TEIID-1102 fixing the example code related to the text change
Modified: trunk/build/kits/jboss-container/teiid-examples/portfolio/data/marketdata-price.txt
===================================================================
--- trunk/build/kits/jboss-container/teiid-examples/portfolio/data/marketdata-price.txt 2010-05-28 20:54:29 UTC (rev 2171)
+++ trunk/build/kits/jboss-container/teiid-examples/portfolio/data/marketdata-price.txt 2010-06-02 14:58:30 UTC (rev 2172)
@@ -1,5 +1,5 @@
SYMBOL,PRICE
-RHT 30.00
+RHT,30.00
BA,42.75
MON,78.75
ORCL,16.54
Modified: trunk/build/kits/jboss-container/teiid-examples/portfolio/marketdata-file-ds.xml
===================================================================
--- trunk/build/kits/jboss-container/teiid-examples/portfolio/marketdata-file-ds.xml 2010-05-28 20:54:29 UTC (rev 2171)
+++ trunk/build/kits/jboss-container/teiid-examples/portfolio/marketdata-file-ds.xml 2010-06-02 14:58:30 UTC (rev 2172)
@@ -3,7 +3,7 @@
<connection-factories>
<no-tx-connection-factory>
- <jndi-name>marketdata-file-connection</jndi-name>
+ <jndi-name>marketdata-file</jndi-name>
<rar-name>connector-file-${project.version}.rar</rar-name>
<connection-definition>javax.resource.cci.ConnectionFactory</connection-definition>
<!--
Modified: trunk/build/kits/jboss-container/teiid-examples/simpleclient/JDBCClient.class
===================================================================
(Binary files differ)
Modified: trunk/build/kits/jboss-container/teiid-examples/simpleclient/JDBCClient.java
===================================================================
--- trunk/build/kits/jboss-container/teiid-examples/simpleclient/JDBCClient.java 2010-05-28 20:54:29 UTC (rev 2171)
+++ trunk/build/kits/jboss-container/teiid-examples/simpleclient/JDBCClient.java 2010-06-02 14:58:30 UTC (rev 2172)
@@ -76,11 +76,14 @@
int columns = metadata.getColumnCount();
System.out.println("Results");
for (int row = 1; results.next(); row++) {
- System.out.println(row + ": ");
+ System.out.print(row + ": ");
for (int i = 0; i < columns; i++) {
+ if (i > 0) {
+ System.out.print(",");
+ }
System.out.print(results.getString(i+1));
- System.out.print(",");
}
+ System.out.println();
}
System.out.println("Query Plan");
System.out.println(statement.unwrap(TeiidStatement.class).getPlanDescription());
14 years, 6 months