teiid SVN: r2189 - trunk/connectors/translator-xml/src/test/java/org/teiid/translator/xml/streaming.
by teiid-commits@lists.jboss.org
Author: rareddy
Date: 2010-06-08 09:38:13 -0400 (Tue, 08 Jun 2010)
New Revision: 2189
Modified:
trunk/connectors/translator-xml/src/test/java/org/teiid/translator/xml/streaming/TestSoapExecution.java
Log:
enabling a commented test
Modified: trunk/connectors/translator-xml/src/test/java/org/teiid/translator/xml/streaming/TestSoapExecution.java
===================================================================
--- trunk/connectors/translator-xml/src/test/java/org/teiid/translator/xml/streaming/TestSoapExecution.java 2010-06-07 22:17:39 UTC (rev 2188)
+++ trunk/connectors/translator-xml/src/test/java/org/teiid/translator/xml/streaming/TestSoapExecution.java 2010-06-08 13:38:13 UTC (rev 2189)
@@ -105,7 +105,7 @@
return cf;
}
- //@Test
+ @Test
public void testSOAPSingleRequest() throws Exception {
XMLExecutionFactory factory = new XMLExecutionFactory();
14 years, 6 months
teiid SVN: r2188 - in trunk/console/src/main: resources/META-INF and 1 other directory.
by teiid-commits@lists.jboss.org
Author: tejones
Date: 2010-06-07 18:17:39 -0400 (Mon, 07 Jun 2010)
New Revision: 2188
Modified:
trunk/console/src/main/java/org/teiid/rhq/plugin/VDBComponent.java
trunk/console/src/main/java/org/teiid/rhq/plugin/VDBDiscoveryComponent.java
trunk/console/src/main/resources/META-INF/rhq-plugin.xml
Log:
TEIID-1105: Added Translator Override table and properties to the VDB tab
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-07 16:50:55 UTC (rev 2187)
+++ trunk/console/src/main/java/org/teiid/rhq/plugin/VDBComponent.java 2010-06-07 22:17:39 UTC (rev 2188)
@@ -42,6 +42,7 @@
import org.jboss.metatype.api.types.MetaType;
import org.jboss.metatype.api.types.SimpleMetaType;
import org.jboss.metatype.api.values.CollectionValueSupport;
+import org.jboss.metatype.api.values.CompositeValueSupport;
import org.jboss.metatype.api.values.EnumValueSupport;
import org.jboss.metatype.api.values.GenericValue;
import org.jboss.metatype.api.values.GenericValueSupport;
@@ -64,6 +65,7 @@
import org.rhq.core.pluginapi.configuration.ConfigurationUpdateReport;
import org.rhq.core.pluginapi.inventory.CreateResourceReport;
import org.rhq.core.pluginapi.inventory.ResourceContext;
+import org.teiid.adminapi.impl.PropertyMetadata;
import org.teiid.rhq.admin.DQPManagementView;
import org.teiid.rhq.comm.ConnectionConstants;
import org.teiid.rhq.plugin.util.PluginConstants;
@@ -98,13 +100,13 @@
protected void setOperationArguments(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));
- String version = VDB.VERSION;
- valueMap.put(version, this.resourceConfiguration.getSimpleValue("version",
- 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)) {
valueMap.put(Operation.Value.REQUEST_ID, configuration.getSimple(
@@ -144,7 +146,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));
}
@@ -274,18 +276,19 @@
sourceMappingList.add(singleSourceModelsPropertyList);
sourceMappingList.add(multiSourceModelsPropertyList);
PropertyMap model = null;
- Iterator<List<Property>> sourceMappingListIterator = sourceMappingList.iterator();
+ Iterator<List<Property>> sourceMappingListIterator = sourceMappingList
+ .iterator();
while (sourceMappingListIterator.hasNext()) {
List<Property> sourceList = sourceMappingListIterator.next();
for (int i = 0; i < sourceList.size(); i++) {
model = (PropertyMap) sourceList.get(i);
String sourceName = ((PropertySimple) model
.get("sourceName")).getStringValue(); //$NON-NLS-1$
- if (sourceName.equals("See below")) continue; //This is a multisource model which we will handle separately
+ if (sourceName.equals("See below"))
+ continue; // This is a multisource model which we will
+ // handle separately
String modelName = ((PropertySimple) model.get("name")) //$NON-NLS-1$
- .getStringValue();
- String translatorName = ((PropertySimple) model
- .get("translatorName")).getStringValue(); //$NON-NLS-1$
+ .getStringValue();
String dsName = ((PropertySimple) model.get("jndiName")) //$NON-NLS-1$
.getStringValue();
@@ -309,13 +312,6 @@
String sName = ProfileServiceUtil.getSimpleValue(
mo, "name", String.class);//$NON-NLS-1$
if (sName.equals(sourceName)) {
-
- ManagedProperty translatorProperty = mo
- .getProperty("translatorName"); //$NON-NLS-1$
- translatorProperty.setValue(ProfileServiceUtil
- .wrap(SimpleMetaType.STRING,
- translatorName));
-
// set the jndi name for the ds.
ManagedProperty jndiProperty = mo
.getProperty("connectionJndiName"); //$NON-NLS-1$
@@ -382,6 +378,8 @@
configuration.put(new PropertySimple("status", vdbStatus));
configuration.put(new PropertySimple("url", vdbURL));
+ getTranslators(mcVdb, configuration);
+
getModels(mcVdb, configuration);
return configuration;
@@ -563,4 +561,88 @@
}
}
+ /**
+ * @param mcVdb
+ * @param configuration
+ * @throws Exception
+ */
+ private void getTranslators(ManagedComponent mcVdb,
+ Configuration configuration) {
+ // Get models from VDB
+ ManagedProperty property = mcVdb.getProperty("overrideTranslators");
+ if (property == null) {
+ return;
+ }
+ List<ManagedObject> translators = (List<ManagedObject>) MetaValueFactory
+ .getInstance().unwrap(property.getValue());
+ CollectionValueSupport valueSupport = (CollectionValueSupport) property
+ .getValue();
+ MetaValue[] metaValues = valueSupport.getElements();
+
+ PropertyList translatorsList = new PropertyList("translators");
+ configuration.put(translatorsList);
+
+ for (MetaValue value : metaValues) {
+ GenericValueSupport genValueSupport = (GenericValueSupport) value;
+ ManagedObjectImpl managedObject = (ManagedObjectImpl) genValueSupport
+ .getValue();
+
+ String translatorName = ProfileServiceUtil.getSimpleValue(
+ managedObject, "name", String.class);
+ String translatorType = ProfileServiceUtil.getSimpleValue(
+ managedObject, "type", String.class);
+ ManagedProperty properties = managedObject.getProperty("property");
+
+ if (properties != null) {
+ List<PropertyMetadata> props = (List<PropertyMetadata>) MetaValueFactory
+ .getInstance().unwrap(properties.getValue());
+ for (PropertyMetadata propertyMetaData : props) {
+ String propertyName = propertyMetaData.getName();
+ String propertyValue = propertyMetaData.getValue();
+ PropertyMap translatorMap = null;
+
+ translatorMap = new PropertyMap("translatorMap",
+ new PropertySimple("name", translatorName),
+ new PropertySimple("type", translatorType),
+ new PropertySimple("propertyName", propertyName),
+ new PropertySimple("propertyValue", propertyValue));
+ // Only want translator name and value to show up for the first row,
+ // so we will blank them out here.
+ translatorName = "";
+ translatorType = "";
+ translatorsList.add(translatorMap);
+ }
+ }
+ }
+ }
+
+ /**
+ * @param <T>
+ * @param pValue
+ * @param list
+ */
+ public static <T> void getPropertyValues(MetaValue pValue,
+ Collection<Map<String, String>> list) {
+ Map<String, String> map = new HashMap<String, String>();
+ list.add(map);
+ MetaType metaType = pValue.getMetaType();
+ if (metaType.isCollection()) {
+ for (MetaValue value : ((CollectionValueSupport) pValue)
+ .getElements()) {
+ CompositeValueSupport compValue = ((CompositeValueSupport) value);
+ for (MetaValue propValue : compValue.values()) {
+ String propertyName = ((CompositeValueSupport) propValue)
+ .get("name").toString();
+ String propertyValue = ((CompositeValueSupport) propValue)
+ .get("value").toString();
+ map.put("name", propertyName);
+ map.put("value", propertyValue);
+ }
+ }
+ } else {
+ throw new IllegalStateException(pValue
+ + " is not a Collection type");
+ }
+ }
+
}
Modified: trunk/console/src/main/java/org/teiid/rhq/plugin/VDBDiscoveryComponent.java
===================================================================
--- trunk/console/src/main/java/org/teiid/rhq/plugin/VDBDiscoveryComponent.java 2010-06-07 16:50:55 UTC (rev 2187)
+++ trunk/console/src/main/java/org/teiid/rhq/plugin/VDBDiscoveryComponent.java 2010-06-07 22:17:39 UTC (rev 2188)
@@ -106,7 +106,7 @@
null // Process info from a process scan
);
- // Get plugin config map for models
+ // Get plugin config map for properties
Configuration configuration = detail.getPluginConfiguration();
configuration.put(new PropertySimple("name", vdbName));
Modified: trunk/console/src/main/resources/META-INF/rhq-plugin.xml
===================================================================
--- trunk/console/src/main/resources/META-INF/rhq-plugin.xml 2010-06-07 16:50:55 UTC (rev 2187)
+++ trunk/console/src/main/resources/META-INF/rhq-plugin.xml 2010-06-07 22:17:39 UTC (rev 2188)
@@ -467,6 +467,23 @@
<c:simple-property name="url" type="string"
description="The Virtual Database URL" required="false" readOnly="true" />
</c:group>
+ <c:group name="Translators" displayName="Translators" hiddenByDefault="false">
+ <c:list-property name="translators" displayName="Overrides" readOnly="true"
+ description="The translator overrides for this VDB">
+ <c:map-property name="map" description="Translator Overrides for this VDB">
+ <c:simple-property name="name" displayName="Name"
+ description="Name of this translator instance" required="true" readOnly="true" />
+ <c:simple-property name="type"
+ displayName="Translator type" description="Translator type"
+ required="false" readOnly="true" />
+ <c:simple-property name="propertyName"
+ displayName="Property Name" description="Property Name"
+ required="false" readOnly="true"/>
+ <c:simple-property name="propertyValue" displayName="Property Value"
+ description="Property Value" required="false" />
+ </c:map-property>
+ </c:list-property>
+ </c:group>
<c:group name="Models" displayName="Models" hiddenByDefault="false">
<c:list-property name="singleSourceModels" readOnly="true"
description="The source models for this VDB">
14 years, 6 months
teiid SVN: r2187 - in trunk: runtime/src/main/java/org/teiid/services and 1 other directory.
by teiid-commits@lists.jboss.org
Author: rareddy
Date: 2010-06-07 12:50:55 -0400 (Mon, 07 Jun 2010)
New Revision: 2187
Modified:
trunk/common-core/src/main/java/org/teiid/core/CoreConstants.java
trunk/runtime/src/main/java/org/teiid/services/TeiidLoginContext.java
Log:
TEIID-1110: fixing the NPE in the case that no user name and password supplied. If the user name is not supplied it is assumed as 'anonymous'
Modified: trunk/common-core/src/main/java/org/teiid/core/CoreConstants.java
===================================================================
--- trunk/common-core/src/main/java/org/teiid/core/CoreConstants.java 2010-06-07 16:27:14 UTC (rev 2186)
+++ trunk/common-core/src/main/java/org/teiid/core/CoreConstants.java 2010-06-07 16:50:55 UTC (rev 2187)
@@ -106,7 +106,7 @@
/**
* Constant for the anonymous Teiid system username
*/
- public static final String DEFAULT_ANON_USERNAME = "teiidanonymous";
+ public static final String DEFAULT_ANON_USERNAME = "anonymous"; //$NON-NLS-1$
}
Modified: trunk/runtime/src/main/java/org/teiid/services/TeiidLoginContext.java
===================================================================
--- trunk/runtime/src/main/java/org/teiid/services/TeiidLoginContext.java 2010-06-07 16:27:14 UTC (rev 2186)
+++ trunk/runtime/src/main/java/org/teiid/services/TeiidLoginContext.java 2010-06-07 16:50:55 UTC (rev 2187)
@@ -57,12 +57,11 @@
private String securitydomain;
private Object credentials;
- public void authenticateUser(String username, Credentials credential, String applicationName, List<String> domains) throws LoginException {
+ public void authenticateUser(String username, final Credentials credential, String applicationName, List<String> domains) throws LoginException {
LogManager.logDetail(LogConstants.CTX_SECURITY, new Object[] {"authenticateUser", username, applicationName}); //$NON-NLS-1$
final String baseUsername = getBaseUsername(username);
- final char[] password = credential.getCredentialsAsCharArray();
// If username specifies a domain (user@domain) only that domain is authenticated against.
// If username specifies no domain, then all domains are tried in order.
@@ -78,6 +77,10 @@
nc.setName(baseUsername);
} else if (callbacks[i] instanceof PasswordCallback) {
PasswordCallback pc = (PasswordCallback)callbacks[i];
+ char[] password = null;
+ if (credential != null) {
+ password = credential.getCredentialsAsCharArray();
+ }
pc.setPassword(password);
credentials = password;
} else {
14 years, 6 months
teiid SVN: r2186 - in trunk: api/src/main/java/org/teiid/language/visitor and 42 other directories.
by teiid-commits@lists.jboss.org
Author: shawkins
Date: 2010-06-07 12:27:14 -0400 (Mon, 07 Jun 2010)
New Revision: 2186
Added:
trunk/api/src/main/java/org/teiid/language/SQLConstants.java
trunk/engine/src/main/java/org/teiid/query/sql/symbol/XMLQuery.java
Removed:
trunk/api/src/main/java/org/teiid/language/SQLReservedWords.java
trunk/engine/src/main/java/org/teiid/query/resolver/command/XQueryResolver.java
trunk/engine/src/test/java/org/teiid/query/xquery/saxon/
Modified:
trunk/api/src/main/java/org/teiid/language/Comparison.java
trunk/api/src/main/java/org/teiid/language/visitor/SQLStringVisitor.java
trunk/common-core/src/main/java/org/teiid/core/types/XMLType.java
trunk/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/ExtractFunctionModifier.java
trunk/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/SQLConversionVisitor.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/oracle/OracleExecutionFactory.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/connectors/translator-salesforce/src/main/java/org/teiid/translator/salesforce/NameUtil.java
trunk/engine/src/main/java/org/teiid/common/buffer/impl/BufferManagerImpl.java
trunk/engine/src/main/java/org/teiid/dqp/internal/process/DataTierManagerImpl.java
trunk/engine/src/main/java/org/teiid/dqp/internal/process/MetaDataProcessor.java
trunk/engine/src/main/java/org/teiid/query/eval/Evaluator.java
trunk/engine/src/main/java/org/teiid/query/function/FunctionForm.java
trunk/engine/src/main/java/org/teiid/query/function/FunctionMethods.java
trunk/engine/src/main/java/org/teiid/query/function/source/XMLSystemFunctions.java
trunk/engine/src/main/java/org/teiid/query/optimizer/relational/PlanToProcessConverter.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/RulePushAggregates.java
trunk/engine/src/main/java/org/teiid/query/optimizer/relational/rules/RuleRemoveOptionalJoins.java
trunk/engine/src/main/java/org/teiid/query/parser/SQLParserUtil.java
trunk/engine/src/main/java/org/teiid/query/processor/proc/ExecDynamicSqlInstruction.java
trunk/engine/src/main/java/org/teiid/query/processor/relational/GroupingNode.java
trunk/engine/src/main/java/org/teiid/query/processor/relational/XMLTableNode.java
trunk/engine/src/main/java/org/teiid/query/processor/xml/XMLUtil.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/ProcedureReservedWords.java
trunk/engine/src/main/java/org/teiid/query/sql/lang/Option.java
trunk/engine/src/main/java/org/teiid/query/sql/lang/XMLTable.java
trunk/engine/src/main/java/org/teiid/query/sql/navigator/PreOrPostOrderNavigator.java
trunk/engine/src/main/java/org/teiid/query/sql/proc/RaiseErrorStatement.java
trunk/engine/src/main/java/org/teiid/query/sql/symbol/AggregateSymbol.java
trunk/engine/src/main/java/org/teiid/query/sql/visitor/SQLStringVisitor.java
trunk/engine/src/main/java/org/teiid/query/validator/AggregateValidationVisitor.java
trunk/engine/src/main/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/execution/i18n.properties
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/query/function/TestFunction.java
trunk/engine/src/test/java/org/teiid/query/function/TestFunctionLibrary.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/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/test-integration/common/src/test/java/org/teiid/connector/visitor/util/TestSQLStringVisitor.java
Log:
TEIID-1087 TEIID-171 TEIID-1005 adding xmlquery, refining xmltable, and changing sqlreservedwords into sqlcontants.
Modified: trunk/api/src/main/java/org/teiid/language/Comparison.java
===================================================================
--- trunk/api/src/main/java/org/teiid/language/Comparison.java 2010-06-06 15:12:19 UTC (rev 2185)
+++ trunk/api/src/main/java/org/teiid/language/Comparison.java 2010-06-07 16:27:14 UTC (rev 2186)
@@ -22,7 +22,7 @@
package org.teiid.language;
-import org.teiid.language.SQLReservedWords.Tokens;
+import org.teiid.language.SQLConstants.Tokens;
import org.teiid.language.visitor.LanguageObjectVisitor;
/**
Copied: trunk/api/src/main/java/org/teiid/language/SQLConstants.java (from rev 2181, trunk/api/src/main/java/org/teiid/language/SQLReservedWords.java)
===================================================================
--- trunk/api/src/main/java/org/teiid/language/SQLConstants.java (rev 0)
+++ trunk/api/src/main/java/org/teiid/language/SQLConstants.java 2010-06-07 16:27:14 UTC (rev 2186)
@@ -0,0 +1,404 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA.
+ */
+
+package org.teiid.language;
+
+import java.lang.reflect.Field;
+import java.util.Set;
+import java.util.HashSet;
+
+/**
+ * SQL Constants for Teiid.
+ */
+public class SQLConstants {
+
+ public interface Tokens {
+ public static final String ALL_COLS = "*"; //$NON-NLS-1$
+ public static final String SPACE = " "; //$NON-NLS-1$
+ public static final String COMMA = ","; //$NON-NLS-1$
+ public static final String DOT = "."; //$NON-NLS-1$
+ public static final String QUOTE = "'"; //$NON-NLS-1$
+ public static final String EQ = "="; //$NON-NLS-1$
+ public static final String NE = "<>"; //$NON-NLS-1$
+ public static final String LT = "<"; //$NON-NLS-1$
+ public static final String GT = ">"; //$NON-NLS-1$
+ public static final String LE = "<="; //$NON-NLS-1$
+ public static final String GE = ">="; //$NON-NLS-1$
+ 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$
+ //xmlquery
+ public static final String RETURNING = "RETURNING"; //$NON-NLS-1$
+ public static final String SEQUENCE = "SEQUENCE"; //$NON-NLS-1$
+ public static final String EMPTY = "EMPTY"; //$NON-NLS-1$
+ }
+
+ public interface Reserved {
+ //Teiid specific
+ public static final String BIGDECIMAL = "BIGDECIMAL"; //$NON-NLS-1$
+ public static final String BIGINTEGER = "BIGINTEGER"; //$NON-NLS-1$
+ public static final String BREAK = "BREAK"; //$NON-NLS-1$
+ 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 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 STRING = "STRING"; //$NON-NLS-1$
+ public static final String VIRTUAL = "VIRTUAL"; //$NON-NLS-1$
+ public static final String WHILE = "WHILE"; //$NON-NLS-1$
+
+ //SQL2003 keywords
+ public static final String ADD = "ADD"; //$NON-NLS-1$
+ public static final String ANY = "ANY"; //$NON-NLS-1$
+ public static final String ALL = "ALL"; //$NON-NLS-1$
+ public static final String ALLOCATE = "ALLOCATE"; //$NON-NLS-1$
+ public static final String ALTER = "ALTER"; //$NON-NLS-1$
+ public static final String AND = "AND"; //$NON-NLS-1$
+ public static final String ARE = "ARE"; //$NON-NLS-1$
+ public static final String ARRAY = "ARRAY"; //$NON-NLS-1$s
+ public static final String AS = "AS"; //$NON-NLS-1$
+ public static final String ASC = "ASC"; //$NON-NLS-1$
+ public static final String ASENSITIVE = "ASENSITIVE"; //$NON-NLS-1$
+ 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 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$
+ public static final String BLOB = "BLOB"; //$NON-NLS-1$
+ public static final String BOTH = "BOTH"; //$NON-NLS-1$
+ public static final String BY = "BY"; //$NON-NLS-1$
+ public static final String CALL = "CALL"; //$NON-NLS-1$
+ public static final String CALLED = "CALLED"; //$NON-NLS-1$
+ public static final String CASE = "CASE"; //$NON-NLS-1$
+ public static final String CAST = "CAST"; //$NON-NLS-1$
+ public static final String CASCADED = "CASCADED"; //$NON-NLS-1$
+ public static final String CHAR = "CHAR"; //$NON-NLS-1$
+ public static final String CHARACTER = "CHARACTER"; //$NON-NLS-1$
+ public static final String CHECK = "CHECK"; //$NON-NLS-1$
+ public static final String CLOB = "CLOB"; //$NON-NLS-1$
+ public static final String CLOSE = "CLOSE"; //$NON-NLS-1$
+ public static final String COLLATE = "COLLATE"; //$NON-NLS-1$
+ public static final String COLUMN = "COLUMN"; //$NON-NLS-1$
+ public static final String COMMIT = "COMMIT"; //$NON-NLS-1$
+ public static final String CONNECT = "CONNECT"; //$NON-NLS-1$
+ 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 CORRESPONDING = "CORRESPONDING"; //$NON-NLS-1$
+ public static final String CREATE = "CREATE"; //$NON-NLS-1$
+ public static final String CROSS = "CROSS"; //$NON-NLS-1$
+ public static final String CURRENT_DATE = "CURRENT_DATE"; //$NON-NLS-1$
+ public static final String CURRENT_TIME = "CURRENT_TIME"; //$NON-NLS-1$
+ public static final String CURRENT_TIMESTAMP = "CURRENT_TIMESTAMP"; //$NON-NLS-1$
+ public static final String CURRENT_USER = "CURRENT_USER"; //$NON-NLS-1$
+ public static final String CURSOR = "CURSOR"; //$NON-NLS-1$
+ public static final String CYCLE = "CYCLE"; //$NON-NLS-1$
+ public static final String DATE = "DATE"; //$NON-NLS-1$
+ public static final String DAY = "DAY"; //$NON-NLS-1$
+ public static final String DEALLOCATE = "DEALLOCATE"; //$NON-NLS-1$
+ public static final String DEC = "DEC"; //$NON-NLS-1$
+ public static final String DECIMAL = "DECIMAL"; //$NON-NLS-1$
+ public static final String DECLARE = "DECLARE"; //$NON-NLS-1$
+ public static final String DEFAULT = "DEFAULT"; //$NON-NLS-1$
+ public static final String DELETE = "DELETE"; //$NON-NLS-1$
+ public static final String DEREF = "DEREF"; //$NON-NLS-1$
+ public static final String DESC = "DESC"; //$NON-NLS-1$
+ public static final String DESCRIBE = "DESCRIBE"; //$NON-NLS-1$
+ public static final String DETERMINISTIC = "DETERMINISTIC"; //$NON-NLS-1$
+ public static final String DISCONNECT = "DISCONNECT"; //$NON-NLS-1$
+ public static final String DISTINCT = "DISTINCT"; //$NON-NLS-1$
+ public static final String DOUBLE = "DOUBLE"; //$NON-NLS-1$
+ public static final String DROP = "DROP"; //$NON-NLS-1$
+ public static final String DYNAMIC = "DYNAMIC"; //$NON-NLS-1$
+ public static final String EACH = "EACH"; //$NON-NLS-1$
+ public static final String ELEMENT = "ELEMENT"; //$NON-NLS-1$
+ public static final String ELSE = "ELSE"; //$NON-NLS-1$
+ public static final String END = "END"; //$NON-NLS-1$
+ public static final String ESCAPE = "ESCAPE"; //$NON-NLS-1$
+ public static final String EXCEPT = "EXCEPT"; //$NON-NLS-1$
+ public static final String EXEC = "EXEC"; //$NON-NLS-1$
+ public static final String EXECUTE = "EXECUTE"; //$NON-NLS-1$
+ public static final String EXISTS = "EXISTS"; //$NON-NLS-1$
+ public static final String EXTERNAL = "EXTERNAL"; //$NON-NLS-1$
+ public static final String FALSE = "FALSE"; //$NON-NLS-1$
+ public static final String FETCH = "FETCH"; //$NON-NLS-1$
+ public static final String FILTER = "FILTER"; //$NON-NLS-1$
+ public static final String FLOAT = "FLOAT"; //$NON-NLS-1$
+ public static final String FOR = "FOR"; //$NON-NLS-1$
+ public static final String FOREIGN = "FOREIGN"; //$NON-NLS-1$
+ public static final String FREE = "FREE"; //$NON-NLS-1$
+ public static final String FROM = "FROM"; //$NON-NLS-1$
+ public static final String FULL = "FULL"; //$NON-NLS-1$
+ public static final String FUNCTION = "FUNCTION"; //$NON-NLS-1$
+ public static final String GET = "GET"; //$NON-NLS-1$
+ public static final String GLOBAL = "GLOBAL"; //$NON-NLS-1$
+ public static final String GRANT = "GRANT"; //$NON-NLS-1$
+ public static final String GROUP = "GROUP"; //$NON-NLS-1$
+ public static final String GROUPING = "GROUPING"; //$NON-NLS-1$
+ public static final String HAS = "HAS"; //$NON-NLS-1$
+ public static final String HAVING = "HAVING"; //$NON-NLS-1$
+ public static final String HOLD = "HOLD"; //$NON-NLS-1$
+ public static final String HOUR = "HOUR"; //$NON-NLS-1$
+ public static final String IDENTITY = "IDENTITY"; //$NON-NLS-1$
+ public static final String INDICATOR = "INDICATOR"; //$NON-NLS-1$
+ public static final String IF = "IF"; //$NON-NLS-1$
+ public static final String IMMEDIATE = "IMMEDIATE"; //$NON-NLS-1$
+ public static final String IN = "IN"; //$NON-NLS-1$
+ public static final String INOUT = "INOUT"; //$NON-NLS-1$
+ public static final String INNER = "INNER"; //$NON-NLS-1$
+ public static final String INPUT = "INPUT"; //$NON-NLS-1$
+ public static final String INSENSITIVE = "INSENSITIVE"; //$NON-NLS-1$
+ public static final String INSERT = "INSERT"; //$NON-NLS-1$
+ public static final String INTEGER = "INTEGER"; //$NON-NLS-1$
+ public static final String INTERSECT = "INTERSECT"; //$NON-NLS-1$
+ public static final String INTERVAL = "INTERVAL"; //$NON-NLS-1$
+ public static final String INT = "INT"; //$NON-NLS-1$
+ public static final String INTO = "INTO"; //$NON-NLS-1$
+ public static final String IS = "IS"; //$NON-NLS-1$
+ public static final String ISOLATION = "ISOLATION"; //$NON-NLS-1$
+ public static final String JOIN = "JOIN"; //$NON-NLS-1$
+ public static final String LANGUAGE = "LANGUAGE"; //$NON-NLS-1$
+ public static final String LARGE = "LARGE"; //$NON-NLS-1$
+ public static final String LATERAL = "LATERAL"; //$NON-NLS-1$
+ public static final String LEADING = "LEADING"; //$NON-NLS-1$
+ public static final String LEFT = "LEFT"; //$NON-NLS-1$
+ public static final String LIKE = "LIKE"; //$NON-NLS-1$
+ public static final String LOCAL = "LOCAL"; //$NON-NLS-1$
+ 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 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$
+ public static final String MODIFIES = "MODIFIES"; //$NON-NLS-1$
+ public static final String MODULE = "MODULE"; //$NON-NLS-1$
+ public static final String MONTH = "MONTH"; //$NON-NLS-1$
+ public static final String MULTISET = "MULTISET"; //$NON-NLS-1$
+ public static final String NATIONAL = "NATIONAL"; //$NON-NLS-1$
+ public static final String NATURAL = "NATURAL"; //$NON-NLS-1$
+ public static final String NCHAR = "NCHAR"; //$NON-NLS-1$
+ public static final String NCLOB = "NCLOB"; //$NON-NLS-1$
+ public static final String NEW = "NEW"; //$NON-NLS-1$
+ public static final String NO = "NO"; //$NON-NLS-1$
+ public static final String NONE = "NONE"; //$NON-NLS-1$
+ public static final String NOT = "NOT"; //$NON-NLS-1$
+ public static final String NULL = "NULL"; //$NON-NLS-1$
+ public static final String NUMERIC = "NUMERIC"; //$NON-NLS-1$
+ public static final String OBJECT = "OBJECT"; //$NON-NLS-1$
+ public static final String OF = "OF"; //$NON-NLS-1$
+ public static final String OLD = "OLD"; //$NON-NLS-1$
+ public static final String ON = "ON"; //$NON-NLS-1$
+ public static final String ONLY = "ONLY"; //$NON-NLS-1$
+ public static final String OPEN = "OPEN"; //$NON-NLS-1$
+ public static final String OR = "OR"; //$NON-NLS-1$
+ public static final String ORDER = "ORDER"; //$NON-NLS-1$
+ public static final String OUT = "OUT"; //$NON-NLS-1$
+ public static final String OUTER = "OUTER"; //$NON-NLS-1$
+ public static final String OUTPUT = "OUTPUT"; //$NON-NLS-1$
+ public static final String OPTION = "OPTION"; //$NON-NLS-1$
+ public static final String OVER = "OVER"; //$NON-NLS-1$
+ public static final String OVERLAPS = "OVERLAPS"; //$NON-NLS-1$
+ public static final String PARAMETER = "PARAMETER"; //$NON-NLS-1$
+ public static final String PARTITION = "PARTITION"; //$NON-NLS-1$
+ public static final String PRECISION = "PRECISION"; //$NON-NLS-1$
+ public static final String PREPARE = "PREPARE"; //$NON-NLS-1$
+ public static final String PRIMARY = "PRIMARY"; //$NON-NLS-1$
+ public static final String PROCEDURE = "PROCEDURE"; //$NON-NLS-1$
+ public static final String RANGE = "RANGE"; //$NON-NLS-1$
+ public static final String READS = "READS"; //$NON-NLS-1$
+ public static final String REAL = "REAL"; //$NON-NLS-1$
+ public static final String RECURSIVE = "RECURSIVE"; //$NON-NLS-1$
+ public static final String REFERENCES = "REFERENCES"; //$NON-NLS-1$
+ public static final String REFERENCING = "REFERENCING"; //$NON-NLS-1$
+ public static final String RELEASE = "RELEASE"; //$NON-NLS-1$
+ public static final String RETURN = "RETURN"; //$NON-NLS-1$
+ public static final String RETURNS = "RETURNS"; //$NON-NLS-1$
+ public static final String REVOKE = "REVOKE"; //$NON-NLS-1$
+ public static final String RIGHT = "RIGHT"; //$NON-NLS-1$
+ public static final String ROLLBACK = "ROLLBACK"; //$NON-NLS-1$
+ public static final String ROLLUP = "ROLLUP"; //$NON-NLS-1$
+ public static final String ROW = "ROW"; //$NON-NLS-1$
+ public static final String ROWS = "ROWS"; //$NON-NLS-1$
+ public static final String SAVEPOINT = "SAVEPOINT"; //$NON-NLS-1$
+ public static final String SCROLL = "SCROLL"; //$NON-NLS-1$
+ public static final String SEARCH = "SEARCH"; //$NON-NLS-1$
+ public static final String SECOND = "SECOND"; //$NON-NLS-1$
+ public static final String SELECT = "SELECT"; //$NON-NLS-1$
+ public static final String SENSITIVE = "SENSITIVE"; //$NON-NLS-1$
+ public static final String SESSION_USER = "SESSION_USER"; //$NON-NLS-1$
+ public static final String SET = "SET"; //$NON-NLS-1$
+ public static final String SHORT = "SHORT"; //$NON-NLS-1$
+ public static final String SIILAR = "SIMILAR"; //$NON-NLS-1$
+ public static final String SMALLINT = "SMALLINT"; //$NON-NLS-1$
+ public static final String SOME = "SOME"; //$NON-NLS-1$
+ public static final String SPECIFIC = "SPECIFIC"; //$NON-NLS-1$
+ public static final String SPECIFICTYPE = "SPECIFICTYPE"; //$NON-NLS-1$
+ public static final String SQL = "SQL"; //$NON-NLS-1$
+ public static final String SQLEXCEPTION = "SQLEXCEPTION"; //$NON-NLS-1$
+ public static final String SQLSTATE = "SQLSTATE"; //$NON-NLS-1$
+ public static final String SQLWARNING = "SQLWARNING"; //$NON-NLS-1$
+ public static final String SUBMULTILIST = "SUBMULTILIST"; //$NON-NLS-1$
+ public static final String START = "START"; //$NON-NLS-1$
+ public static final String STATIC = "STATIC"; //$NON-NLS-1$
+ 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 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$
+ public static final String TIMESTAMP = "TIMESTAMP"; //$NON-NLS-1$
+ public static final String TIMEZONE_HOUR = "TIMEZONE_HOUR"; //$NON-NLS-1$
+ public static final String TIMEZONE_MINUTE = "TIMEZONE_MINUTE"; //$NON-NLS-1$
+ public static final String TO = "TO"; //$NON-NLS-1$
+ public static final String TREAT = "TREAT"; //$NON-NLS-1$
+ public static final String TRAILING = "TRAILING"; //$NON-NLS-1$
+ public static final String TRANSLATE = "TRANSLATE"; //$NON-NLS-1$
+ public static final String TRANSLATION = "TRANSLATION"; //$NON-NLS-1$
+ public static final String TRIGGER = "TRIGGER"; //$NON-NLS-1$
+ public static final String TRUE = "TRUE"; //$NON-NLS-1$
+ public static final String UNION = "UNION"; //$NON-NLS-1$
+ public static final String UNIQUE = "UNIQUE"; //$NON-NLS-1$
+ public static final String UNKNOWN = "UNKNOWN"; //$NON-NLS-1$
+ public static final String UPDATE = "UPDATE"; //$NON-NLS-1$
+ public static final String USER = "USER"; //$NON-NLS-1$
+ public static final String USING = "USING"; //$NON-NLS-1$
+ public static final String VALUE = "VALUE"; //$NON-NLS-1$
+ public static final String VALUES = "VALUES"; //$NON-NLS-1$
+ public static final String VARCHAR = "VARCHAR"; //$NON-NLS-1$
+ public static final String VARYING = "VARYING"; //$NON-NLS-1$
+ public static final String WHEN = "WHEN"; //$NON-NLS-1$
+ public static final String WHENEVER = "WHENEVER"; //$NON-NLS-1$
+ public static final String WHERE = "WHERE"; //$NON-NLS-1$
+ public static final String WINDOW = "WINDOW"; //$NON-NLS-1$
+ public static final String WITH = "WITH"; //$NON-NLS-1$
+ public static final String WITHIN = "WITHIN"; //$NON-NLS-1$
+ public static final String WITHOUT = "WITHOUT"; //$NON-NLS-1$
+ public static final String YEAR = "YEAR"; //$NON-NLS-1$
+
+ //SQL/XML
+
+ public static final String XML = "XML"; //$NON-NLS-1$
+ public static final String XMLAGG = "XMLAGG"; //$NON-NLS-1$
+ public static final String XMLATTRIBUTES = "XMLATTRIBUTES"; //$NON-NLS-1$
+ public static final String XMLBINARY = "XMLBINARY"; //$NON-NLS-1$
+ public static final String XMLCONCAT = "XMLCONCAT"; //$NON-NLS-1$
+ public static final String XMLCOMMENT = "XMLCOMMENT"; //$NON-NLS-1$
+ public static final String XMLELEMENT = "XMLELEMENT"; //$NON-NLS-1$
+ public static final String XMLFOREST = "XMLFOREST"; //$NON-NLS-1$
+ public static final String XMLNAMESPACES = "XMLNAMESPACES"; //$NON-NLS-1$
+ public static final String XMLPARSE = "XMLPARSE"; //$NON-NLS-1$
+ public static final String XMLPI = "XMLPI"; //$NON-NLS-1$
+ public static final String XMLROOT = "XMLROOT"; //$NON-NLS-1$
+ public static final String XMLSERIALIZE = "XMLSERIALIZE"; //$NON-NLS-1$
+
+ //SQL/MED
+
+ public static final String DATALINK = "DATALINK"; //$NON-NLS-1$
+ public static final String DLNEWCOPY = "DLNEWCOPY"; //$NON-NLS-1$
+ public static final String DLPREVIOUSCOPY = "DLPREVIOUSCOPY"; //$NON-NLS-1$
+ public static final String DLURLCOMPLETE = "DLURLCOMPLETE"; //$NON-NLS-1$
+ public static final String DLURLCOMPLETEWRITE = "DLURELCOMPLETEWRITE"; //$NON-NLS-1$
+ public static final String DLURLCOMPLETEONLY = "DLURLCOMPLETEONLY"; //$NON-NLS-1$
+ public static final String DLURLPATH = "DLURLPATH"; //$NON-NLS-1$
+ public static final String DLURLPATHWRITE = "DLURLPATHWRITE"; //$NON-NLS-1$
+ public static final String DLURLPATHONLY = "DLURLPATHONLY"; //$NON-NLS-1$
+ public static final String DLURLSCHEME = "DLURLSCHEME"; //$NON-NLS-1$
+ public static final String DLURLSERVER = "DLURLSEVER"; //$NON-NLS-1$
+ public static final String DLVALUE = "DLVALUE"; //$NON-NLS-1$
+ public static final String IMPORT = "IMPORT"; //$NON-NLS-1$
+ }
+
+ /**
+ * Set of CAPITALIZED reserved words for checking whether a string is a reserved word.
+ */
+ private static final Set<String> RESERVED_WORDS = new HashSet<String>();
+
+ // Initialize RESERVED_WORDS set - This is a poor man's enum. To much legacy code expects the constants to be Strings.
+ static {
+ Field[] fields = SQLConstants.Reserved.class.getDeclaredFields();
+ for (Field field : fields) {
+ if (field.getType() == String.class) {
+ try {
+ if (!RESERVED_WORDS.add((String)field.get(null))) {
+ throw new AssertionError("Duplicate value for " + field.getName()); //$NON-NLS-1$
+ }
+ } catch (Exception e) {
+ }
+ }
+ }
+ }
+
+ /** Can't construct */
+ private SQLConstants() {}
+
+ /**
+ * Check whether a string is a reserved word.
+ * @param str String to check
+ * @return True if reserved word, false if not or null
+ */
+ public static final boolean isReservedWord(String str) {
+ if(str == null) {
+ return false;
+ }
+ return RESERVED_WORDS.contains(str.toUpperCase());
+ }
+}
Deleted: trunk/api/src/main/java/org/teiid/language/SQLReservedWords.java
===================================================================
--- trunk/api/src/main/java/org/teiid/language/SQLReservedWords.java 2010-06-06 15:12:19 UTC (rev 2185)
+++ trunk/api/src/main/java/org/teiid/language/SQLReservedWords.java 2010-06-07 16:27:14 UTC (rev 2186)
@@ -1,398 +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.language;
-
-import java.lang.reflect.Field;
-import java.util.Set;
-import java.util.HashSet;
-
-/**
- * Reserved words for Teiid.
- */
-public class SQLReservedWords {
-
- public interface Tokens {
- public static final String ALL_COLS = "*"; //$NON-NLS-1$
- public static final String SPACE = " "; //$NON-NLS-1$
- public static final String COMMA = ","; //$NON-NLS-1$
- public static final String DOT = "."; //$NON-NLS-1$
- public static final String QUOTE = "'"; //$NON-NLS-1$
- public static final String EQ = "="; //$NON-NLS-1$
- public static final String NE = "<>"; //$NON-NLS-1$
- public static final String LT = "<"; //$NON-NLS-1$
- public static final String GT = ">"; //$NON-NLS-1$
- public static final String LE = "<="; //$NON-NLS-1$
- public static final String GE = ">="; //$NON-NLS-1$
- 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$
- public static final String BIGINTEGER = "BIGINTEGER"; //$NON-NLS-1$
- public static final String BREAK = "BREAK"; //$NON-NLS-1$
- 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 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 STRING = "STRING"; //$NON-NLS-1$
- public static final String VIRTUAL = "VIRTUAL"; //$NON-NLS-1$
- public static final String WHILE = "WHILE"; //$NON-NLS-1$
-
- //SQL2003 keywords
- public static final String ADD = "ADD"; //$NON-NLS-1$
- public static final String ANY = "ANY"; //$NON-NLS-1$
- public static final String ALL = "ALL"; //$NON-NLS-1$
- public static final String ALLOCATE = "ALLOCATE"; //$NON-NLS-1$
- public static final String ALTER = "ALTER"; //$NON-NLS-1$
- public static final String AND = "AND"; //$NON-NLS-1$
- public static final String ARE = "ARE"; //$NON-NLS-1$
- public static final String ARRAY = "ARRAY"; //$NON-NLS-1$s
- public static final String AS = "AS"; //$NON-NLS-1$
- public static final String ASC = "ASC"; //$NON-NLS-1$
- public static final String ASENSITIVE = "ASENSITIVE"; //$NON-NLS-1$
- 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 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$
- public static final String BLOB = "BLOB"; //$NON-NLS-1$
- public static final String BOTH = "BOTH"; //$NON-NLS-1$
- public static final String BY = "BY"; //$NON-NLS-1$
- public static final String CALL = "CALL"; //$NON-NLS-1$
- public static final String CALLED = "CALLED"; //$NON-NLS-1$
- public static final String CASE = "CASE"; //$NON-NLS-1$
- public static final String CAST = "CAST"; //$NON-NLS-1$
- public static final String CASCADED = "CASCADED"; //$NON-NLS-1$
- public static final String CHAR = "CHAR"; //$NON-NLS-1$
- public static final String CHARACTER = "CHARACTER"; //$NON-NLS-1$
- public static final String CHECK = "CHECK"; //$NON-NLS-1$
- public static final String CLOB = "CLOB"; //$NON-NLS-1$
- public static final String CLOSE = "CLOSE"; //$NON-NLS-1$
- public static final String COLLATE = "COLLATE"; //$NON-NLS-1$
- public static final String COLUMN = "COLUMN"; //$NON-NLS-1$
- public static final String COMMIT = "COMMIT"; //$NON-NLS-1$
- public static final String CONNECT = "CONNECT"; //$NON-NLS-1$
- 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 CORRESPONDING = "CORRESPONDING"; //$NON-NLS-1$
- public static final String CREATE = "CREATE"; //$NON-NLS-1$
- public static final String CROSS = "CROSS"; //$NON-NLS-1$
- public static final String CURRENT_DATE = "CURRENT_DATE"; //$NON-NLS-1$
- public static final String CURRENT_TIME = "CURRENT_TIME"; //$NON-NLS-1$
- public static final String CURRENT_TIMESTAMP = "CURRENT_TIMESTAMP"; //$NON-NLS-1$
- public static final String CURRENT_USER = "CURRENT_USER"; //$NON-NLS-1$
- public static final String CURSOR = "CURSOR"; //$NON-NLS-1$
- public static final String CYCLE = "CYCLE"; //$NON-NLS-1$
- public static final String DATE = "DATE"; //$NON-NLS-1$
- public static final String DAY = "DAY"; //$NON-NLS-1$
- public static final String DEALLOCATE = "DEALLOCATE"; //$NON-NLS-1$
- public static final String DEC = "DEC"; //$NON-NLS-1$
- public static final String DECIMAL = "DECIMAL"; //$NON-NLS-1$
- public static final String DECLARE = "DECLARE"; //$NON-NLS-1$
- public static final String DEFAULT = "DEFAULT"; //$NON-NLS-1$
- public static final String DELETE = "DELETE"; //$NON-NLS-1$
- public static final String DEREF = "DEREF"; //$NON-NLS-1$
- public static final String DESC = "DESC"; //$NON-NLS-1$
- public static final String DESCRIBE = "DESCRIBE"; //$NON-NLS-1$
- public static final String DETERMINISTIC = "DETERMINISTIC"; //$NON-NLS-1$
- public static final String DISCONNECT = "DISCONNECT"; //$NON-NLS-1$
- public static final String DISTINCT = "DISTINCT"; //$NON-NLS-1$
- public static final String DOUBLE = "DOUBLE"; //$NON-NLS-1$
- public static final String DROP = "DROP"; //$NON-NLS-1$
- public static final String DYNAMIC = "DYNAMIC"; //$NON-NLS-1$
- public static final String EACH = "EACH"; //$NON-NLS-1$
- public static final String ELEMENT = "ELEMENT"; //$NON-NLS-1$
- public static final String ELSE = "ELSE"; //$NON-NLS-1$
- public static final String END = "END"; //$NON-NLS-1$
- public static final String ESCAPE = "ESCAPE"; //$NON-NLS-1$
- public static final String EXCEPT = "EXCEPT"; //$NON-NLS-1$
- public static final String EXEC = "EXEC"; //$NON-NLS-1$
- public static final String EXECUTE = "EXECUTE"; //$NON-NLS-1$
- public static final String EXISTS = "EXISTS"; //$NON-NLS-1$
- public static final String EXTERNAL = "EXTERNAL"; //$NON-NLS-1$
- public static final String FALSE = "FALSE"; //$NON-NLS-1$
- public static final String FETCH = "FETCH"; //$NON-NLS-1$
- public static final String FILTER = "FILTER"; //$NON-NLS-1$
- public static final String FLOAT = "FLOAT"; //$NON-NLS-1$
- public static final String FOR = "FOR"; //$NON-NLS-1$
- public static final String FOREIGN = "FOREIGN"; //$NON-NLS-1$
- public static final String FREE = "FREE"; //$NON-NLS-1$
- public static final String FROM = "FROM"; //$NON-NLS-1$
- public static final String FULL = "FULL"; //$NON-NLS-1$
- public static final String FUNCTION = "FUNCTION"; //$NON-NLS-1$
- public static final String GET = "GET"; //$NON-NLS-1$
- public static final String GLOBAL = "GLOBAL"; //$NON-NLS-1$
- public static final String GRANT = "GRANT"; //$NON-NLS-1$
- public static final String GROUP = "GROUP"; //$NON-NLS-1$
- public static final String GROUPING = "GROUPING"; //$NON-NLS-1$
- public static final String HAS = "HAS"; //$NON-NLS-1$
- public static final String HAVING = "HAVING"; //$NON-NLS-1$
- public static final String HOLD = "HOLD"; //$NON-NLS-1$
- public static final String HOUR = "HOUR"; //$NON-NLS-1$
- public static final String IDENTITY = "IDENTITY"; //$NON-NLS-1$
- public static final String INDICATOR = "INDICATOR"; //$NON-NLS-1$
- public static final String IF = "IF"; //$NON-NLS-1$
- public static final String IMMEDIATE = "IMMEDIATE"; //$NON-NLS-1$
- public static final String IN = "IN"; //$NON-NLS-1$
- public static final String INOUT = "INOUT"; //$NON-NLS-1$
- public static final String INNER = "INNER"; //$NON-NLS-1$
- public static final String INPUT = "INPUT"; //$NON-NLS-1$
- public static final String INSENSITIVE = "INSENSITIVE"; //$NON-NLS-1$
- public static final String INSERT = "INSERT"; //$NON-NLS-1$
- public static final String INTEGER = "INTEGER"; //$NON-NLS-1$
- public static final String INTERSECT = "INTERSECT"; //$NON-NLS-1$
- public static final String INTERVAL = "INTERVAL"; //$NON-NLS-1$
- public static final String INT = "INT"; //$NON-NLS-1$
- public static final String INTO = "INTO"; //$NON-NLS-1$
- public static final String IS = "IS"; //$NON-NLS-1$
- public static final String ISOLATION = "ISOLATION"; //$NON-NLS-1$
- public static final String JOIN = "JOIN"; //$NON-NLS-1$
- public static final String LANGUAGE = "LANGUAGE"; //$NON-NLS-1$
- public static final String LARGE = "LARGE"; //$NON-NLS-1$
- public static final String LATERAL = "LATERAL"; //$NON-NLS-1$
- public static final String LEADING = "LEADING"; //$NON-NLS-1$
- public static final String LEFT = "LEFT"; //$NON-NLS-1$
- public static final String LIKE = "LIKE"; //$NON-NLS-1$
- public static final String LOCAL = "LOCAL"; //$NON-NLS-1$
- 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 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$
- public static final String MODIFIES = "MODIFIES"; //$NON-NLS-1$
- public static final String MODULE = "MODULE"; //$NON-NLS-1$
- public static final String MONTH = "MONTH"; //$NON-NLS-1$
- public static final String MULTISET = "MULTISET"; //$NON-NLS-1$
- public static final String NATIONAL = "NATIONAL"; //$NON-NLS-1$
- public static final String NATURAL = "NATURAL"; //$NON-NLS-1$
- public static final String NCHAR = "NCHAR"; //$NON-NLS-1$
- public static final String NCLOB = "NCLOB"; //$NON-NLS-1$
- public static final String NEW = "NEW"; //$NON-NLS-1$
- public static final String NO = "NO"; //$NON-NLS-1$
- public static final String NONE = "NONE"; //$NON-NLS-1$
- public static final String NOT = "NOT"; //$NON-NLS-1$
- public static final String NULL = "NULL"; //$NON-NLS-1$
- public static final String NUMERIC = "NUMERIC"; //$NON-NLS-1$
- public static final String OBJECT = "OBJECT"; //$NON-NLS-1$
- public static final String OF = "OF"; //$NON-NLS-1$
- public static final String OLD = "OLD"; //$NON-NLS-1$
- public static final String ON = "ON"; //$NON-NLS-1$
- public static final String ONLY = "ONLY"; //$NON-NLS-1$
- public static final String OPEN = "OPEN"; //$NON-NLS-1$
- public static final String OR = "OR"; //$NON-NLS-1$
- public static final String ORDER = "ORDER"; //$NON-NLS-1$
- public static final String OUT = "OUT"; //$NON-NLS-1$
- public static final String OUTER = "OUTER"; //$NON-NLS-1$
- public static final String OUTPUT = "OUTPUT"; //$NON-NLS-1$
- public static final String OPTION = "OPTION"; //$NON-NLS-1$
- public static final String OVER = "OVER"; //$NON-NLS-1$
- public static final String OVERLAPS = "OVERLAPS"; //$NON-NLS-1$
- public static final String PARAMETER = "PARAMETER"; //$NON-NLS-1$
- public static final String PARTITION = "PARTITION"; //$NON-NLS-1$
- public static final String PRECISION = "PRECISION"; //$NON-NLS-1$
- public static final String PREPARE = "PREPARE"; //$NON-NLS-1$
- public static final String PRIMARY = "PRIMARY"; //$NON-NLS-1$
- public static final String PROCEDURE = "PROCEDURE"; //$NON-NLS-1$
- public static final String RANGE = "RANGE"; //$NON-NLS-1$
- public static final String READS = "READS"; //$NON-NLS-1$
- public static final String REAL = "REAL"; //$NON-NLS-1$
- public static final String RECURSIVE = "RECURSIVE"; //$NON-NLS-1$
- public static final String REFERENCES = "REFERENCES"; //$NON-NLS-1$
- public static final String REFERENCING = "REFERENCING"; //$NON-NLS-1$
- public static final String RELEASE = "RELEASE"; //$NON-NLS-1$
- public static final String RETURN = "RETURN"; //$NON-NLS-1$
- public static final String RETURNS = "RETURNS"; //$NON-NLS-1$
- public static final String REVOKE = "REVOKE"; //$NON-NLS-1$
- public static final String RIGHT = "RIGHT"; //$NON-NLS-1$
- public static final String ROLLBACK = "ROLLBACK"; //$NON-NLS-1$
- public static final String ROLLUP = "ROLLUP"; //$NON-NLS-1$
- public static final String ROW = "ROW"; //$NON-NLS-1$
- public static final String ROWS = "ROWS"; //$NON-NLS-1$
- public static final String SAVEPOINT = "SAVEPOINT"; //$NON-NLS-1$
- public static final String SCROLL = "SCROLL"; //$NON-NLS-1$
- public static final String SEARCH = "SEARCH"; //$NON-NLS-1$
- public static final String SECOND = "SECOND"; //$NON-NLS-1$
- public static final String SELECT = "SELECT"; //$NON-NLS-1$
- public static final String SENSITIVE = "SENSITIVE"; //$NON-NLS-1$
- public static final String SESSION_USER = "SESSION_USER"; //$NON-NLS-1$
- public static final String SET = "SET"; //$NON-NLS-1$
- public static final String SHORT = "SHORT"; //$NON-NLS-1$
- public static final String SIILAR = "SIMILAR"; //$NON-NLS-1$
- public static final String SMALLINT = "SMALLINT"; //$NON-NLS-1$
- public static final String SOME = "SOME"; //$NON-NLS-1$
- public static final String SPECIFIC = "SPECIFIC"; //$NON-NLS-1$
- public static final String SPECIFICTYPE = "SPECIFICTYPE"; //$NON-NLS-1$
- public static final String SQL = "SQL"; //$NON-NLS-1$
- public static final String SQLEXCEPTION = "SQLEXCEPTION"; //$NON-NLS-1$
- public static final String SQLSTATE = "SQLSTATE"; //$NON-NLS-1$
- public static final String SQLWARNING = "SQLWARNING"; //$NON-NLS-1$
- public static final String SUBMULTILIST = "SUBMULTILIST"; //$NON-NLS-1$
- public static final String START = "START"; //$NON-NLS-1$
- public static final String STATIC = "STATIC"; //$NON-NLS-1$
- 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 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$
- public static final String TIMESTAMP = "TIMESTAMP"; //$NON-NLS-1$
- public static final String TIMEZONE_HOUR = "TIMEZONE_HOUR"; //$NON-NLS-1$
- public static final String TIMEZONE_MINUTE = "TIMEZONE_MINUTE"; //$NON-NLS-1$
- public static final String TO = "TO"; //$NON-NLS-1$
- public static final String TREAT = "TREAT"; //$NON-NLS-1$
- public static final String TRAILING = "TRAILING"; //$NON-NLS-1$
- public static final String TRANSLATE = "TRANSLATE"; //$NON-NLS-1$
- public static final String TRANSLATION = "TRANSLATION"; //$NON-NLS-1$
- public static final String TRIGGER = "TRIGGER"; //$NON-NLS-1$
- public static final String TRUE = "TRUE"; //$NON-NLS-1$
- public static final String UNION = "UNION"; //$NON-NLS-1$
- public static final String UNIQUE = "UNIQUE"; //$NON-NLS-1$
- public static final String UNKNOWN = "UNKNOWN"; //$NON-NLS-1$
- public static final String UPDATE = "UPDATE"; //$NON-NLS-1$
- public static final String USER = "USER"; //$NON-NLS-1$
- public static final String USING = "USING"; //$NON-NLS-1$
- public static final String VALUE = "VALUE"; //$NON-NLS-1$
- public static final String VALUES = "VALUES"; //$NON-NLS-1$
- public static final String VARCHAR = "VARCHAR"; //$NON-NLS-1$
- public static final String VARYING = "VARYING"; //$NON-NLS-1$
- public static final String WHEN = "WHEN"; //$NON-NLS-1$
- public static final String WHENEVER = "WHENEVER"; //$NON-NLS-1$
- public static final String WHERE = "WHERE"; //$NON-NLS-1$
- public static final String WINDOW = "WINDOW"; //$NON-NLS-1$
- public static final String WITH = "WITH"; //$NON-NLS-1$
- public static final String WITHIN = "WITHIN"; //$NON-NLS-1$
- public static final String WITHOUT = "WITHOUT"; //$NON-NLS-1$
- public static final String YEAR = "YEAR"; //$NON-NLS-1$
-
- //SQL/XML
-
- public static final String XML = "XML"; //$NON-NLS-1$
- public static final String XMLAGG = "XMLAGG"; //$NON-NLS-1$
- public static final String XMLATTRIBUTES = "XMLATTRIBUTES"; //$NON-NLS-1$
- public static final String XMLBINARY = "XMLBINARY"; //$NON-NLS-1$
- public static final String XMLCONCAT = "XMLCONCAT"; //$NON-NLS-1$
- public static final String XMLCOMMENT = "XMLCOMMENT"; //$NON-NLS-1$
- public static final String XMLELEMENT = "XMLELEMENT"; //$NON-NLS-1$
- public static final String XMLFOREST = "XMLFOREST"; //$NON-NLS-1$
- public static final String XMLNAMESPACES = "XMLNAMESPACES"; //$NON-NLS-1$
- public static final String XMLPARSE = "XMLPARSE"; //$NON-NLS-1$
- public static final String XMLPI = "XMLPI"; //$NON-NLS-1$
- public static final String XMLROOT = "XMLROOT"; //$NON-NLS-1$
- public static final String XMLSERIALIZE = "XMLSERIALIZE"; //$NON-NLS-1$
-
- //SQL/MED
-
- public static final String DATALINK = "DATALINK"; //$NON-NLS-1$
- public static final String DLNEWCOPY = "DLNEWCOPY"; //$NON-NLS-1$
- public static final String DLPREVIOUSCOPY = "DLPREVIOUSCOPY"; //$NON-NLS-1$
- public static final String DLURLCOMPLETE = "DLURLCOMPLETE"; //$NON-NLS-1$
- public static final String DLURLCOMPLETEWRITE = "DLURELCOMPLETEWRITE"; //$NON-NLS-1$
- public static final String DLURLCOMPLETEONLY = "DLURLCOMPLETEONLY"; //$NON-NLS-1$
- public static final String DLURLPATH = "DLURLPATH"; //$NON-NLS-1$
- public static final String DLURLPATHWRITE = "DLURLPATHWRITE"; //$NON-NLS-1$
- public static final String DLURLPATHONLY = "DLURLPATHONLY"; //$NON-NLS-1$
- public static final String DLURLSCHEME = "DLURLSCHEME"; //$NON-NLS-1$
- public static final String DLURLSERVER = "DLURLSEVER"; //$NON-NLS-1$
- public static final String DLVALUE = "DLVALUE"; //$NON-NLS-1$
- public static final String IMPORT = "IMPORT"; //$NON-NLS-1$
-
- /**
- * Set of CAPITALIZED reserved words for checking whether a string is a reserved word.
- */
- private static final Set<String> RESERVED_WORDS = new HashSet<String>();
-
- // Initialize RESERVED_WORDS set - This is a poor man's enum. To much legacy code expects the constants to be Strings.
- static {
- Field[] fields = SQLReservedWords.class.getDeclaredFields();
- for (Field field : fields) {
- if (field.getType() == String.class) {
- try {
- if (!RESERVED_WORDS.add((String)field.get(null))) {
- throw new AssertionError("Duplicate value for " + field.getName()); //$NON-NLS-1$
- }
- } catch (Exception e) {
- }
- }
- }
- }
-
- /** Can't construct */
- private SQLReservedWords() {}
-
- /**
- * Check whether a string is a reserved word.
- * @param str String to check
- * @return True if reserved word, false if not or null
- */
- public static final boolean isReservedWord(String str) {
- if(str == null) {
- return false;
- }
- return RESERVED_WORDS.contains(str.toUpperCase());
- }
-}
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-06 15:12:19 UTC (rev 2185)
+++ trunk/api/src/main/java/org/teiid/language/visitor/SQLStringVisitor.java 2010-06-07 16:27:14 UTC (rev 2186)
@@ -22,6 +22,8 @@
package org.teiid.language.visitor;
+import static org.teiid.language.SQLConstants.Reserved.*;
+
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
@@ -57,7 +59,6 @@
import org.teiid.language.Not;
import org.teiid.language.OrderBy;
import org.teiid.language.QueryExpression;
-import org.teiid.language.SQLReservedWords;
import org.teiid.language.ScalarSubquery;
import org.teiid.language.SearchedCase;
import org.teiid.language.SearchedWhenClause;
@@ -70,8 +71,8 @@
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.SQLConstants.NonReserved;
+import org.teiid.language.SQLConstants.Tokens;
import org.teiid.language.SortSpecification.Ordering;
import org.teiid.metadata.AbstractMetadataRecord;
@@ -165,7 +166,7 @@
.append(Tokens.LPAREN);
if ( obj.isDistinct()) {
- buffer.append(SQLReservedWords.DISTINCT)
+ buffer.append(DISTINCT)
.append(Tokens.SPACE);
}
@@ -212,15 +213,15 @@
* @see com.metamatrix.data.visitor.LanguageObjectVisitor#visit(org.teiid.language.Delete)
*/
public void visit(Delete obj) {
- buffer.append(SQLReservedWords.DELETE)
+ buffer.append(DELETE)
.append(Tokens.SPACE);
buffer.append(getSourceComment(obj));
- buffer.append(SQLReservedWords.FROM)
+ buffer.append(FROM)
.append(Tokens.SPACE);
append(obj.getTable());
if (obj.getWhere() != null) {
buffer.append(Tokens.SPACE)
- .append(SQLReservedWords.WHERE)
+ .append(WHERE)
.append(Tokens.SPACE);
append(obj.getWhere());
}
@@ -311,7 +312,7 @@
* @see com.metamatrix.data.visitor.LanguageObjectVisitor#visit(com.metamatrix.data.language.IExecute)
*/
public void visit(Call obj) {
- buffer.append(SQLReservedWords.EXEC)
+ buffer.append(EXEC)
.append(Tokens.SPACE);
if(obj.getMetadataObject() != null) {
@@ -342,7 +343,7 @@
* @see com.metamatrix.data.visitor.LanguageObjectVisitor#visit(com.metamatrix.data.language.IExistsCriteria)
*/
public void visit(Exists obj) {
- buffer.append(SQLReservedWords.EXISTS)
+ buffer.append(EXISTS)
.append(Tokens.SPACE)
.append(Tokens.LPAREN);
append(obj.getSubquery());
@@ -360,7 +361,7 @@
String name = obj.getName();
List<Expression> args = obj.getParameters();
- if(name.equalsIgnoreCase(SQLReservedWords.CONVERT) || name.equalsIgnoreCase(SQLReservedWords.CAST)) {
+ if(name.equalsIgnoreCase(CONVERT) || name.equalsIgnoreCase(CAST)) {
Object typeValue = ((Literal)args.get(1)).getValue();
@@ -369,12 +370,12 @@
append(args.get(0));
- if(name.equalsIgnoreCase(SQLReservedWords.CONVERT)) {
+ if(name.equalsIgnoreCase(CONVERT)) {
buffer.append(Tokens.COMMA);
buffer.append(Tokens.SPACE);
} else {
buffer.append(Tokens.SPACE);
- buffer.append(SQLReservedWords.AS);
+ buffer.append(AS);
buffer.append(Tokens.SPACE);
}
buffer.append(typeValue);
@@ -429,7 +430,7 @@
if (obj.getCorrelationName() != null) {
buffer.append(Tokens.SPACE);
if (useAsInGroupAlias()){
- buffer.append(SQLReservedWords.AS)
+ buffer.append(AS)
.append(Tokens.SPACE);
}
buffer.append(obj.getCorrelationName());
@@ -451,9 +452,9 @@
* @see com.metamatrix.data.visitor.LanguageObjectVisitor#visit(org.teiid.language.GroupBy)
*/
public void visit(GroupBy obj) {
- buffer.append(SQLReservedWords.GROUP)
+ buffer.append(GROUP)
.append(Tokens.SPACE)
- .append(SQLReservedWords.BY)
+ .append(BY)
.append(Tokens.SPACE);
append(obj.getElements());
}
@@ -465,10 +466,10 @@
append(obj.getLeftExpression());
if (obj.isNegated()) {
buffer.append(Tokens.SPACE)
- .append(SQLReservedWords.NOT);
+ .append(NOT);
}
buffer.append(Tokens.SPACE)
- .append(SQLReservedWords.IN)
+ .append(IN)
.append(Tokens.SPACE)
.append(Tokens.LPAREN);
append(obj.getRightExpressions());
@@ -481,7 +482,7 @@
buffer.append(Tokens.RPAREN);
buffer.append(Tokens.SPACE);
if(useAsInGroupAlias()) {
- buffer.append(SQLReservedWords.AS);
+ buffer.append(AS);
buffer.append(Tokens.SPACE);
}
buffer.append(obj.getCorrelationName());
@@ -491,9 +492,9 @@
* @see com.metamatrix.data.visitor.LanguageObjectVisitor#visit(org.teiid.language.Insert)
*/
public void visit(Insert obj) {
- buffer.append(SQLReservedWords.INSERT).append(Tokens.SPACE);
+ buffer.append(INSERT).append(Tokens.SPACE);
buffer.append(getSourceComment(obj));
- buffer.append(SQLReservedWords.INTO).append(Tokens.SPACE);
+ buffer.append(INTO).append(Tokens.SPACE);
append(obj.getTable());
buffer.append(Tokens.SPACE).append(Tokens.LPAREN);
@@ -513,7 +514,7 @@
@Override
public void visit(ExpressionValueSource obj) {
- buffer.append(SQLReservedWords.VALUES).append(Tokens.SPACE).append(Tokens.LPAREN);
+ buffer.append(VALUES).append(Tokens.SPACE).append(Tokens.LPAREN);
append(obj.getValues());
buffer.append(Tokens.RPAREN);
}
@@ -521,13 +522,13 @@
public void visit(IsNull obj) {
append(obj.getExpression());
buffer.append(Tokens.SPACE)
- .append(SQLReservedWords.IS)
+ .append(IS)
.append(Tokens.SPACE);
if (obj.isNegated()) {
- buffer.append(SQLReservedWords.NOT)
+ buffer.append(NOT)
.append(Tokens.SPACE);
}
- buffer.append(SQLReservedWords.NULL);
+ buffer.append(NULL);
}
public void visit(Join obj) {
@@ -543,30 +544,30 @@
switch(obj.getJoinType()) {
case CROSS_JOIN:
- buffer.append(SQLReservedWords.CROSS);
+ buffer.append(CROSS);
break;
case FULL_OUTER_JOIN:
- buffer.append(SQLReservedWords.FULL)
+ buffer.append(FULL)
.append(Tokens.SPACE)
- .append(SQLReservedWords.OUTER);
+ .append(OUTER);
break;
case INNER_JOIN:
- buffer.append(SQLReservedWords.INNER);
+ buffer.append(INNER);
break;
case LEFT_OUTER_JOIN:
- buffer.append(SQLReservedWords.LEFT)
+ buffer.append(LEFT)
.append(Tokens.SPACE)
- .append(SQLReservedWords.OUTER);
+ .append(OUTER);
break;
case RIGHT_OUTER_JOIN:
- buffer.append(SQLReservedWords.RIGHT)
+ buffer.append(RIGHT)
.append(Tokens.SPACE)
- .append(SQLReservedWords.OUTER);
+ .append(OUTER);
break;
default: buffer.append(UNDEFINED);
}
buffer.append(Tokens.SPACE)
- .append(SQLReservedWords.JOIN)
+ .append(JOIN)
.append(Tokens.SPACE);
TableReference rightItem = obj.getRightItem();
@@ -581,7 +582,7 @@
final Condition condition = obj.getCondition();
if (condition != null) {
buffer.append(Tokens.SPACE)
- .append(SQLReservedWords.ON)
+ .append(ON)
.append(Tokens.SPACE);
append(condition);
}
@@ -591,15 +592,15 @@
append(obj.getLeftExpression());
if (obj.isNegated()) {
buffer.append(Tokens.SPACE)
- .append(SQLReservedWords.NOT);
+ .append(NOT);
}
buffer.append(Tokens.SPACE)
- .append(SQLReservedWords.LIKE)
+ .append(LIKE)
.append(Tokens.SPACE);
append(obj.getRightExpression());
if (obj.getEscapeCharacter() != null) {
buffer.append(Tokens.SPACE)
- .append(SQLReservedWords.ESCAPE)
+ .append(ESCAPE)
.append(Tokens.SPACE)
.append(Tokens.QUOTE)
.append(obj.getEscapeCharacter().toString())
@@ -609,7 +610,7 @@
}
public void visit(Limit obj) {
- buffer.append(SQLReservedWords.LIMIT)
+ buffer.append(LIMIT)
.append(Tokens.SPACE);
if (obj.getRowOffset() > 0) {
buffer.append(obj.getRowOffset())
@@ -623,7 +624,7 @@
if (obj.isBindValue()) {
buffer.append("?"); //$NON-NLS-1$
} else if (obj.getValue() == null) {
- buffer.append(SQLReservedWords.NULL);
+ buffer.append(NULL);
} else {
Class<?> type = obj.getType();
String val = obj.getValue().toString();
@@ -654,7 +655,7 @@
}
public void visit(Not obj) {
- buffer.append(SQLReservedWords.NOT)
+ buffer.append(NOT)
.append(Tokens.SPACE)
.append(Tokens.LPAREN);
append(obj.getCriteria());
@@ -662,9 +663,9 @@
}
public void visit(OrderBy obj) {
- buffer.append(SQLReservedWords.ORDER)
+ buffer.append(ORDER)
.append(Tokens.SPACE)
- .append(SQLReservedWords.BY)
+ .append(BY)
.append(Tokens.SPACE);
append(obj.getSortSpecifications());
}
@@ -673,7 +674,7 @@
append(obj.getExpression());
if (obj.getOrdering() == Ordering.DESC) {
buffer.append(Tokens.SPACE)
- .append(SQLReservedWords.DESC);
+ .append(DESC);
} // Don't print default "ASC"
}
@@ -682,10 +683,10 @@
}
public void visit(Select obj) {
- buffer.append(SQLReservedWords.SELECT).append(Tokens.SPACE);
+ buffer.append(SELECT).append(Tokens.SPACE);
buffer.append(getSourceComment(obj));
if (obj.isDistinct()) {
- buffer.append(SQLReservedWords.DISTINCT).append(Tokens.SPACE);
+ buffer.append(DISTINCT).append(Tokens.SPACE);
}
if (useSelectLimit() && obj.getLimit() != null) {
append(obj.getLimit());
@@ -693,12 +694,12 @@
}
append(obj.getDerivedColumns());
if (obj.getFrom() != null && !obj.getFrom().isEmpty()) {
- buffer.append(Tokens.SPACE).append(SQLReservedWords.FROM).append(Tokens.SPACE);
+ buffer.append(Tokens.SPACE).append(FROM).append(Tokens.SPACE);
append(obj.getFrom());
}
if (obj.getWhere() != null) {
buffer.append(Tokens.SPACE)
- .append(SQLReservedWords.WHERE)
+ .append(WHERE)
.append(Tokens.SPACE);
append(obj.getWhere());
}
@@ -708,7 +709,7 @@
}
if (obj.getHaving() != null) {
buffer.append(Tokens.SPACE)
- .append(SQLReservedWords.HAVING)
+ .append(HAVING)
.append(Tokens.SPACE);
append(obj.getHaving());
}
@@ -723,26 +724,26 @@
}
public void visit(SearchedCase obj) {
- buffer.append(SQLReservedWords.CASE);
+ buffer.append(CASE);
for (SearchedWhenClause swc : obj.getCases()) {
append(swc);
}
if (obj.getElseExpression() != null) {
buffer.append(Tokens.SPACE)
- .append(SQLReservedWords.ELSE)
+ .append(ELSE)
.append(Tokens.SPACE);
append(obj.getElseExpression());
}
buffer.append(Tokens.SPACE)
- .append(SQLReservedWords.END);
+ .append(END);
}
@Override
public void visit(SearchedWhenClause obj) {
- buffer.append(Tokens.SPACE).append(SQLReservedWords.WHEN)
+ buffer.append(Tokens.SPACE).append(WHEN)
.append(Tokens.SPACE);
append(obj.getCondition());
- buffer.append(Tokens.SPACE).append(SQLReservedWords.THEN)
+ buffer.append(Tokens.SPACE).append(THEN)
.append(Tokens.SPACE);
append(obj.getResult());
}
@@ -761,7 +762,7 @@
append(obj.getExpression());
if (obj.getAlias() != null) {
buffer.append(Tokens.SPACE)
- .append(SQLReservedWords.AS)
+ .append(AS)
.append(Tokens.SPACE)
.append(obj.getAlias());
}
@@ -782,8 +783,8 @@
}
buffer.append(Tokens.SPACE);
switch(obj.getQuantifier()) {
- case ALL: buffer.append(SQLReservedWords.ALL); break;
- case SOME: buffer.append(SQLReservedWords.SOME); break;
+ case ALL: buffer.append(ALL); break;
+ case SOME: buffer.append(SOME); break;
default: buffer.append(UNDEFINED);
}
buffer.append(Tokens.SPACE);
@@ -796,10 +797,10 @@
append(obj.getLeftExpression());
if (obj.isNegated()) {
buffer.append(Tokens.SPACE)
- .append(SQLReservedWords.NOT);
+ .append(NOT);
}
buffer.append(Tokens.SPACE)
- .append(SQLReservedWords.IN)
+ .append(IN)
.append(Tokens.SPACE)
.append(Tokens.LPAREN);
append(obj.getSubquery());
@@ -807,17 +808,17 @@
}
public void visit(Update obj) {
- buffer.append(SQLReservedWords.UPDATE)
+ buffer.append(UPDATE)
.append(Tokens.SPACE);
buffer.append(getSourceComment(obj));
append(obj.getTable());
buffer.append(Tokens.SPACE)
- .append(SQLReservedWords.SET)
+ .append(SET)
.append(Tokens.SPACE);
append(obj.getChanges());
if (obj.getWhere() != null) {
buffer.append(Tokens.SPACE)
- .append(SQLReservedWords.WHERE)
+ .append(WHERE)
.append(Tokens.SPACE);
append(obj.getWhere());
}
@@ -838,7 +839,7 @@
if(obj.isAll()) {
buffer.append(Tokens.SPACE);
- buffer.append(SQLReservedWords.ALL);
+ buffer.append(ALL);
}
buffer.append(Tokens.SPACE);
Modified: trunk/common-core/src/main/java/org/teiid/core/types/XMLType.java
===================================================================
--- trunk/common-core/src/main/java/org/teiid/core/types/XMLType.java 2010-06-06 15:12:19 UTC (rev 2185)
+++ trunk/common-core/src/main/java/org/teiid/core/types/XMLType.java 2010-06-07 16:27:14 UTC (rev 2186)
@@ -46,7 +46,7 @@
public final class XMLType extends Streamable<SQLXML> implements SQLXML {
public enum Type {
- UNKNOWN, DOCUMENT, FRAGMENT, SIBLINGS, COMMENT, PI, TEXT
+ UNKNOWN, DOCUMENT, FRAGMENT, SEQUENCE, COMMENT, PI, TEXT
}
private static final long serialVersionUID = -7922647237095135723L;
Modified: trunk/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/ExtractFunctionModifier.java
===================================================================
--- trunk/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/ExtractFunctionModifier.java 2010-06-06 15:12:19 UTC (rev 2185)
+++ trunk/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/ExtractFunctionModifier.java 2010-06-07 16:27:14 UTC (rev 2186)
@@ -29,8 +29,8 @@
import org.teiid.language.Expression;
import org.teiid.language.Function;
-import org.teiid.language.SQLReservedWords;
-import org.teiid.language.SQLReservedWords.Tokens;
+import org.teiid.language.SQLConstants.Reserved;
+import org.teiid.language.SQLConstants.Tokens;
import org.teiid.translator.SourceSystemFunctions;
@@ -75,7 +75,7 @@
objs.add("EXTRACT("); //$NON-NLS-1$
objs.add(FUNCTION_PART_MAP.get(function.getName().toLowerCase()));
objs.add(Tokens.SPACE);
- objs.add(SQLReservedWords.FROM);
+ objs.add(Reserved.FROM);
objs.add(Tokens.SPACE);
objs.add(args.get(0));
objs.add(Tokens.RPAREN);
Modified: trunk/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/SQLConversionVisitor.java
===================================================================
--- trunk/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/SQLConversionVisitor.java 2010-06-06 15:12:19 UTC (rev 2185)
+++ trunk/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/SQLConversionVisitor.java 2010-06-07 16:27:14 UTC (rev 2186)
@@ -45,12 +45,12 @@
import org.teiid.language.LanguageObject;
import org.teiid.language.Like;
import org.teiid.language.Literal;
-import org.teiid.language.SQLReservedWords;
import org.teiid.language.SearchedCase;
import org.teiid.language.SetClause;
import org.teiid.language.SortSpecification;
import org.teiid.language.Argument.Direction;
-import org.teiid.language.SQLReservedWords.Tokens;
+import org.teiid.language.SQLConstants.Reserved;
+import org.teiid.language.SQLConstants.Tokens;
import org.teiid.language.SetQuery.Operation;
import org.teiid.language.SortSpecification.Ordering;
import org.teiid.language.visitor.SQLStringVisitor;
@@ -154,7 +154,7 @@
*/
private void translateSQLType(Class type, Object obj, StringBuilder valuesbuffer) {
if (obj == null) {
- valuesbuffer.append(SQLReservedWords.NULL);
+ valuesbuffer.append(Reserved.NULL);
} else {
if(Number.class.isAssignableFrom(type)) {
boolean useFormatting = false;
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-06 15:12:19 UTC (rev 2185)
+++ trunk/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/hsql/AddDiffModifier.java 2010-06-07 16:27:14 UTC (rev 2186)
@@ -31,7 +31,7 @@
import org.teiid.language.Function;
import org.teiid.language.LanguageFactory;
import org.teiid.language.Literal;
-import org.teiid.language.SQLReservedWords.NonReserved;
+import org.teiid.language.SQLConstants.NonReserved;
import org.teiid.translator.TypeFacility;
import org.teiid.translator.jdbc.ExtractFunctionModifier;
import org.teiid.translator.jdbc.FunctionModifier;
Modified: trunk/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/oracle/OracleExecutionFactory.java
===================================================================
--- trunk/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/oracle/OracleExecutionFactory.java 2010-06-06 15:12:19 UTC (rev 2185)
+++ trunk/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/oracle/OracleExecutionFactory.java 2010-06-07 16:27:14 UTC (rev 2186)
@@ -47,7 +47,7 @@
import org.teiid.language.NamedTable;
import org.teiid.language.QueryExpression;
import org.teiid.language.Select;
-import org.teiid.language.SQLReservedWords.Tokens;
+import org.teiid.language.SQLConstants.Tokens;
import org.teiid.language.SetQuery.Operation;
import org.teiid.language.visitor.CollectorVisitor;
import org.teiid.logging.LogConstants;
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-06 15:12:19 UTC (rev 2185)
+++ trunk/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/postgresql/PostgreSQLExecutionFactory.java 2010-06-07 16:27:14 UTC (rev 2186)
@@ -35,7 +35,7 @@
import org.teiid.language.LanguageObject;
import org.teiid.language.Limit;
import org.teiid.language.Literal;
-import org.teiid.language.SQLReservedWords.NonReserved;
+import org.teiid.language.SQLConstants.NonReserved;
import org.teiid.translator.Translator;
import org.teiid.translator.TranslatorException;
import org.teiid.translator.ExecutionContext;
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-06 15:12:19 UTC (rev 2185)
+++ trunk/connectors/translator-jdbc/src/test/java/org/teiid/translator/jdbc/TestEscapeSyntaxModifier.java 2010-06-07 16:27:14 UTC (rev 2186)
@@ -29,7 +29,7 @@
import org.teiid.cdk.CommandBuilder;
import org.teiid.language.Function;
import org.teiid.language.Literal;
-import org.teiid.language.SQLReservedWords.NonReserved;
+import org.teiid.language.SQLConstants.NonReserved;
import org.teiid.query.unittest.TimestampUtil;
import org.teiid.translator.jdbc.EscapeSyntaxModifier;
Modified: trunk/connectors/translator-salesforce/src/main/java/org/teiid/translator/salesforce/NameUtil.java
===================================================================
--- trunk/connectors/translator-salesforce/src/main/java/org/teiid/translator/salesforce/NameUtil.java 2010-06-06 15:12:19 UTC (rev 2185)
+++ trunk/connectors/translator-salesforce/src/main/java/org/teiid/translator/salesforce/NameUtil.java 2010-06-07 16:27:14 UTC (rev 2186)
@@ -7,7 +7,7 @@
*/
package org.teiid.translator.salesforce;
-import org.teiid.language.SQLReservedWords;
+import org.teiid.language.SQLConstants;
public class NameUtil {
@@ -28,7 +28,7 @@
* @return
*/
private static String checkReservedWords( String normal ) {
- if (SQLReservedWords.isReservedWord(normal)) {
+ if (SQLConstants.isReservedWord(normal)) {
normal = normal + "_"; //$NON-NLS-1$
}
return normal;
Modified: trunk/engine/src/main/java/org/teiid/common/buffer/impl/BufferManagerImpl.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/common/buffer/impl/BufferManagerImpl.java 2010-06-06 15:12:19 UTC (rev 2185)
+++ trunk/engine/src/main/java/org/teiid/common/buffer/impl/BufferManagerImpl.java 2010-06-07 16:27:14 UTC (rev 2186)
@@ -385,6 +385,7 @@
return new XMLType(sqlxml);
}
});
+ XMLUtil.setBufferManager(this);
}
@Override
Modified: trunk/engine/src/main/java/org/teiid/dqp/internal/process/DataTierManagerImpl.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/dqp/internal/process/DataTierManagerImpl.java 2010-06-06 15:12:19 UTC (rev 2185)
+++ trunk/engine/src/main/java/org/teiid/dqp/internal/process/DataTierManagerImpl.java 2010-06-07 16:27:14 UTC (rev 2186)
@@ -55,7 +55,7 @@
import org.teiid.dqp.message.AtomicRequestMessage;
import org.teiid.dqp.message.RequestID;
import org.teiid.dqp.service.BufferService;
-import org.teiid.language.SQLReservedWords;
+import org.teiid.language.SQLConstants.Reserved;
import org.teiid.metadata.AbstractMetadataRecord;
import org.teiid.metadata.Column;
import org.teiid.metadata.CompositeMetadataStore;
@@ -393,7 +393,7 @@
String keyElementName)
throws TeiidComponentException, TeiidProcessingException {
- String query = SQLReservedWords.SELECT + ' ' + keyElementName + " ," + returnElementName + ' ' + SQLReservedWords.FROM + ' ' + codeTableName; //$NON-NLS-1$
+ String query = Reserved.SELECT + ' ' + keyElementName + " ," + returnElementName + ' ' + Reserved.FROM + ' ' + codeTableName; //$NON-NLS-1$
final CacheKey codeRequestId = this.codeTableCache.createCacheRequest(codeTableName, returnElementName, keyElementName, context);
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-06 15:12:19 UTC (rev 2185)
+++ trunk/engine/src/main/java/org/teiid/dqp/internal/process/MetaDataProcessor.java 2010-06-07 16:27:14 UTC (rev 2186)
@@ -45,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.NonReserved;
+import org.teiid.language.SQLConstants.NonReserved;
import org.teiid.query.analysis.AnalysisRecord;
import org.teiid.query.metadata.QueryMetadataInterface;
import org.teiid.query.metadata.SupportConstants;
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-06 15:12:19 UTC (rev 2185)
+++ trunk/engine/src/main/java/org/teiid/query/eval/Evaluator.java 2010-06-07 16:27:14 UTC (rev 2186)
@@ -22,17 +22,31 @@
package org.teiid.query.eval;
+import java.io.IOException;
+import java.io.Writer;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Collections;
+import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
+import java.util.Properties;
import java.util.Set;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import java.util.regex.PatternSyntaxException;
+import javax.xml.transform.OutputKeys;
+import javax.xml.transform.TransformerException;
+
+import net.sf.saxon.expr.PathMap.PathMapRoot;
+import net.sf.saxon.om.Item;
+import net.sf.saxon.om.NodeInfo;
+import net.sf.saxon.om.SequenceIterator;
+import net.sf.saxon.query.QueryResult;
+import net.sf.saxon.trans.XPathException;
+
import org.teiid.api.exception.query.CriteriaEvaluationException;
import org.teiid.api.exception.query.ExpressionEvaluationException;
import org.teiid.api.exception.query.FunctionExecutionException;
@@ -41,8 +55,10 @@
import org.teiid.core.TeiidComponentException;
import org.teiid.core.TeiidProcessingException;
import org.teiid.core.types.DataTypeManager;
+import org.teiid.core.types.SQLXMLImpl;
import org.teiid.core.types.Sequencable;
import org.teiid.core.types.TransformationException;
+import org.teiid.core.types.XMLTranslator;
import org.teiid.core.types.XMLType;
import org.teiid.core.types.XMLType.Type;
import org.teiid.core.types.basic.StringToSQLXMLTransform;
@@ -55,6 +71,7 @@
import org.teiid.query.function.source.XMLSystemFunctions;
import org.teiid.query.function.source.XMLSystemFunctions.NameValuePair;
import org.teiid.query.processor.ProcessorDataManager;
+import org.teiid.query.processor.xml.XMLUtil;
import org.teiid.query.sql.LanguageObject;
import org.teiid.query.sql.lang.AbstractSetCriteria;
import org.teiid.query.sql.lang.CollectionValueIterator;
@@ -86,12 +103,14 @@
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.XMLQuery;
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;
import org.teiid.query.util.CommandContext;
import org.teiid.query.util.ErrorMessageKeys;
+import org.teiid.query.xquery.saxon.SaxonXQueryExpression;
public class Evaluator {
@@ -622,10 +641,92 @@
throw new FunctionExecutionException(e, e.getMessage());
}
throw new FunctionExecutionException(QueryPlugin.Util.getString("Evaluator.xmlserialize")); //$NON-NLS-1$
+ } else if (expression instanceof XMLQuery) {
+ XMLQuery xmlQuery = (XMLQuery)expression;
+ boolean contentOnly = true;
+ boolean emptyOnEmpty = true;
+ if (xmlQuery.getReturningContent() != null) {
+ contentOnly = xmlQuery.getReturningContent();
+ }
+ if (xmlQuery.getEmptyOnEmpty() != null) {
+ emptyOnEmpty = xmlQuery.getEmptyOnEmpty();
+ }
+ try {
+ SequenceIterator iter = evaluateXQuery(xmlQuery.getXQueryExpression(), xmlQuery.getContextRoot(), xmlQuery.getPassing(), tuple);
+ return createXMLType(iter, xmlQuery.getXQueryExpression(), contentOnly, emptyOnEmpty);
+ } catch (TeiidProcessingException e) {
+ throw new FunctionExecutionException(e, QueryPlugin.Util.getString("Evaluator.xmlquery", e.getMessage())); //$NON-NLS-1$
+ } catch (XPathException e) {
+ throw new FunctionExecutionException(e, QueryPlugin.Util.getString("Evaluator.xmlquery", e.getMessage())); //$NON-NLS-1$
+ }
} else {
throw new TeiidComponentException(ErrorMessageKeys.PROCESSOR_0016, QueryPlugin.Util.getString(ErrorMessageKeys.PROCESSOR_0016, expression.getClass().getName()));
}
}
+
+ public XMLType createXMLType(final SequenceIterator iter, final SaxonXQueryExpression expr, boolean contentOnly, boolean emptyOnEmpty) throws XPathException, TeiidComponentException, TeiidProcessingException {
+ Item item = iter.next();
+ if (item == null) {
+ if (contentOnly) {
+ throw new FunctionExecutionException(QueryPlugin.Util.getString("Evaluator.xmlquery_content_empty")); //$NON-NLS-1$
+ }
+ if (!emptyOnEmpty) {
+ return null;
+ }
+ }
+ XMLType.Type type = Type.SEQUENCE;
+ if (item instanceof NodeInfo) {
+ NodeInfo info = (NodeInfo)item;
+ switch (info.getNodeKind()) {
+ case net.sf.saxon.type.Type.DOCUMENT:
+ type = Type.DOCUMENT;
+ break;
+ case net.sf.saxon.type.Type.ELEMENT:
+ type = Type.FRAGMENT;
+ break;
+ case net.sf.saxon.type.Type.TEXT:
+ type = Type.TEXT;
+ break;
+ }
+ }
+ Item next = iter.next();
+ if (next != null) {
+ type = Type.SEQUENCE;
+ }
+ if (contentOnly && type != Type.DOCUMENT && type != Type.FRAGMENT) {
+ throw new FunctionExecutionException(QueryPlugin.Util.getString("Evaluator.xmlquery_content")); //$NON-NLS-1$
+ }
+ SQLXMLImpl xml = XMLUtil.saveToBufferManager(new XMLTranslator() {
+
+ @Override
+ public void translate(Writer writer) throws TransformerException,
+ IOException {
+ Properties props = new Properties();
+ props.setProperty(OutputKeys.METHOD, "xml"); //$NON-NLS-1$
+ //props.setProperty(OutputKeys.INDENT, "yes"); //$NON-NLS-1$
+ props.setProperty(OutputKeys.OMIT_XML_DECLARATION, "yes"); //$NON-NLS-1$
+ QueryResult.serializeSequence(iter.getAnother(), expr.getConfig(), writer, props);
+ }
+ });
+ XMLType value = new XMLType(xml);
+ value.setType(type);
+ return value;
+ }
+
+ public SequenceIterator evaluateXQuery(SaxonXQueryExpression xquery, PathMapRoot contextRoot, List<DerivedColumn> cols, List<?> tuple)
+ throws BlockedException, TeiidComponentException, TeiidProcessingException {
+ HashMap<String, Object> parameters = new HashMap<String, Object>();
+ Object contextItem = null;
+ for (DerivedColumn passing : cols) {
+ Object value = this.evaluate(passing.getExpression(), tuple);
+ if (passing.getAlias() == null) {
+ contextItem = value;
+ } else {
+ parameters.put(passing.getAlias(), value);
+ }
+ }
+ return xquery.evaluateXQuery(contextItem, contextRoot, parameters);
+ }
private NameValuePair<Object>[] getNameValuePairs(List tuple, List<DerivedColumn> args)
throws ExpressionEvaluationException, BlockedException, TeiidComponentException {
Modified: trunk/engine/src/main/java/org/teiid/query/function/FunctionForm.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/function/FunctionForm.java 2010-06-06 15:12:19 UTC (rev 2185)
+++ trunk/engine/src/main/java/org/teiid/query/function/FunctionForm.java 2010-06-07 16:27:14 UTC (rev 2186)
@@ -23,12 +23,15 @@
package org.teiid.query.function;
import java.io.Serializable;
-import java.util.*;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
import org.teiid.core.util.Assertion;
import org.teiid.core.util.HashCodeUtil;
-import org.teiid.language.SQLReservedWords;
-import org.teiid.query.function.metadata.*;
+import org.teiid.language.SQLConstants.Reserved;
+import org.teiid.query.function.metadata.FunctionMethod;
+import org.teiid.query.function.metadata.FunctionParameter;
/**
@@ -171,7 +174,7 @@
str.append(", "); //$NON-NLS-1$
} else {
str.append(" "); //$NON-NLS-1$
- str.append(SQLReservedWords.AS);
+ str.append(Reserved.AS);
str.append(" "); //$NON-NLS-1$
}
str.append(inputParamNames.get(1));
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-06 15:12:19 UTC (rev 2185)
+++ trunk/engine/src/main/java/org/teiid/query/function/FunctionMethods.java 2010-06-07 16:27:14 UTC (rev 2186)
@@ -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.NonReserved;
+import org.teiid.language.SQLConstants.NonReserved;
import org.teiid.query.QueryPlugin;
import org.teiid.query.util.CommandContext;
import org.teiid.query.util.ErrorMessageKeys;
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-06 15:12:19 UTC (rev 2185)
+++ trunk/engine/src/main/java/org/teiid/query/function/source/XMLSystemFunctions.java 2010-06-07 16:27:14 UTC (rev 2186)
@@ -183,7 +183,7 @@
}
}
}, context.getStreamingBatchSize()));
- result.setType(Type.SIBLINGS);
+ result.setType(Type.SEQUENCE);
return result;
}
@@ -268,7 +268,7 @@
}
}
}, context.getStreamingBatchSize()));
- result.setType(Type.SIBLINGS);
+ result.setType(Type.SEQUENCE);
return result;
}
@@ -341,7 +341,7 @@
}
switch(type) {
case FRAGMENT:
- case SIBLINGS:
+ case SEQUENCE:
case PI:
case COMMENT: //write the value directly to the writer
eventWriter.flush();
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-06 15:12:19 UTC (rev 2185)
+++ trunk/engine/src/main/java/org/teiid/query/optimizer/relational/PlanToProcessConverter.java 2010-06-07 16:27:14 UTC (rev 2186)
@@ -28,6 +28,8 @@
import java.util.List;
import java.util.Map;
+import net.sf.saxon.expr.PathMap.PathMapRoot;
+
import org.teiid.api.exception.query.QueryMetadataException;
import org.teiid.api.exception.query.QueryPlannerException;
import org.teiid.core.CoreConstants;
@@ -384,7 +386,7 @@
for (int col : projectionIndexes) {
filteredColumns.add(xt.getColumns().get(col));
}
- xt.getXQueryExpression().useDocumentProjection(filteredColumns, analysisRecord);
+ PathMapRoot root = xt.getXQueryExpression().useDocumentProjection(filteredColumns, analysisRecord);
xtn.setProjectedColumns(filteredColumns);
xtn.setTable(xt);
processNode = xtn;
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-06 15:12:19 UTC (rev 2185)
+++ trunk/engine/src/main/java/org/teiid/query/optimizer/relational/rules/CapabilitiesUtil.java 2010-06-07 16:27:14 UTC (rev 2186)
@@ -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.NonReserved;
+import org.teiid.language.SQLConstants.NonReserved;
import org.teiid.query.function.FunctionLibrary;
import org.teiid.query.metadata.QueryMetadataInterface;
import org.teiid.query.optimizer.capabilities.CapabilitiesFinder;
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-06 15:12:19 UTC (rev 2185)
+++ trunk/engine/src/main/java/org/teiid/query/optimizer/relational/rules/RulePushAggregates.java 2010-06-07 16:27:14 UTC (rev 2186)
@@ -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.NonReserved;
+import org.teiid.language.SQLConstants.NonReserved;
import org.teiid.query.analysis.AnalysisRecord;
import org.teiid.query.function.FunctionLibrary;
import org.teiid.query.metadata.QueryMetadataInterface;
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-06 15:12:19 UTC (rev 2185)
+++ trunk/engine/src/main/java/org/teiid/query/optimizer/relational/rules/RuleRemoveOptionalJoins.java 2010-06-07 16:27:14 UTC (rev 2186)
@@ -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.NonReserved;
+import org.teiid.language.SQLConstants.NonReserved;
import org.teiid.query.analysis.AnalysisRecord;
import org.teiid.query.metadata.QueryMetadataInterface;
import org.teiid.query.optimizer.capabilities.CapabilitiesFinder;
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-06 15:12:19 UTC (rev 2185)
+++ trunk/engine/src/main/java/org/teiid/query/parser/SQLParserUtil.java 2010-06-07 16:27:14 UTC (rev 2186)
@@ -28,8 +28,8 @@
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.language.SQLConstants.NonReserved;
+import org.teiid.language.SQLConstants.Reserved;
import org.teiid.query.QueryPlugin;
import org.teiid.query.sql.lang.Command;
import org.teiid.query.sql.lang.FromClause;
@@ -210,17 +210,17 @@
return JoinType.JOIN_INNER;
}
String joinType = joinTypeToken.image;
- if(joinType.equalsIgnoreCase(SQLReservedWords.INNER)) {
+ if(joinType.equalsIgnoreCase(Reserved.INNER)) {
return JoinType.JOIN_INNER;
- } else if(joinType.equalsIgnoreCase(SQLReservedWords.CROSS)) {
+ } else if(joinType.equalsIgnoreCase(Reserved.CROSS)) {
return JoinType.JOIN_CROSS;
- } else if(joinType.equalsIgnoreCase(SQLReservedWords.LEFT)) {
+ } else if(joinType.equalsIgnoreCase(Reserved.LEFT)) {
return JoinType.JOIN_LEFT_OUTER;
- } else if(joinType.equalsIgnoreCase(SQLReservedWords.RIGHT)) {
+ } else if(joinType.equalsIgnoreCase(Reserved.RIGHT)) {
return JoinType.JOIN_RIGHT_OUTER;
- } else if(joinType.equalsIgnoreCase(SQLReservedWords.FULL)) {
+ } else if(joinType.equalsIgnoreCase(Reserved.FULL)) {
return JoinType.JOIN_FULL_OUTER;
- } else if(joinType.equalsIgnoreCase(SQLReservedWords.UNION)) {
+ } else if(joinType.equalsIgnoreCase(Reserved.UNION)) {
return JoinType.JOIN_UNION;
} else {
Object[] params = new Object[] { joinType };
@@ -258,7 +258,7 @@
} 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)) {
+ } else if(functionType.equals(Reserved.XMLAGG)) {
int num = info.anonMaxCount++;
return "xmlagg" + (num == 0 ? "" : ""+num);//$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
} else {
Modified: trunk/engine/src/main/java/org/teiid/query/processor/proc/ExecDynamicSqlInstruction.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/processor/proc/ExecDynamicSqlInstruction.java 2010-06-06 15:12:19 UTC (rev 2185)
+++ trunk/engine/src/main/java/org/teiid/query/processor/proc/ExecDynamicSqlInstruction.java 2010-06-07 16:27:14 UTC (rev 2186)
@@ -38,7 +38,8 @@
import org.teiid.core.TeiidProcessingException;
import org.teiid.core.id.IDGenerator;
import org.teiid.core.types.DataTypeManager;
-import org.teiid.language.SQLReservedWords;
+import org.teiid.language.SQLConstants;
+import org.teiid.language.SQLConstants.Reserved;
import org.teiid.logging.LogManager;
import org.teiid.query.analysis.AnalysisRecord;
import org.teiid.query.execution.QueryExecPlugin;
@@ -146,9 +147,9 @@
if (dynamicCommand.getUsing() != null
&& !dynamicCommand.getUsing().isEmpty()) {
- metadataStore.addTempGroup(SQLReservedWords.USING, new LinkedList(dynamicCommand.getUsing().getClauseMap().keySet()));
- GroupSymbol using = new GroupSymbol(SQLReservedWords.USING);
- using.setMetadataID(metadataStore.getTempGroupID(SQLReservedWords.USING));
+ metadataStore.addTempGroup(Reserved.USING, new LinkedList(dynamicCommand.getUsing().getClauseMap().keySet()));
+ GroupSymbol using = new GroupSymbol(Reserved.USING);
+ using.setMetadataID(metadataStore.getTempGroupID(Reserved.USING));
command.addExternalGroupToContext(using);
metadataStore.addTempGroup(ProcedureReservedWords.DVARS, new LinkedList(dynamicCommand.getUsing().getClauseMap().keySet()));
using = new GroupSymbol(ProcedureReservedWords.DVARS);
@@ -234,7 +235,7 @@
new Object[] { this, " The using variable ", //$NON-NLS-1$
setClause.getSymbol(), " has value :", assignment }); //$NON-NLS-1$
localContext.setValue(setClause.getSymbol(), assignment);
- localContext.setValue(new ElementSymbol(SQLReservedWords.USING + ElementSymbol.SEPARATOR + setClause.getSymbol().getShortName()), assignment);
+ localContext.setValue(new ElementSymbol(Reserved.USING + ElementSymbol.SEPARATOR + setClause.getSymbol().getShortName()), assignment);
}
}
}
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-06 15:12:19 UTC (rev 2185)
+++ trunk/engine/src/main/java/org/teiid/query/processor/relational/GroupingNode.java 2010-06-07 16:27:14 UTC (rev 2186)
@@ -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.NonReserved;
+import org.teiid.language.SQLConstants.NonReserved;
import org.teiid.query.eval.Evaluator;
import org.teiid.query.function.aggregate.AggregateFunction;
import org.teiid.query.function.aggregate.Avg;
Modified: trunk/engine/src/main/java/org/teiid/query/processor/relational/XMLTableNode.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/processor/relational/XMLTableNode.java 2010-06-06 15:12:19 UTC (rev 2185)
+++ trunk/engine/src/main/java/org/teiid/query/processor/relational/XMLTableNode.java 2010-06-07 16:27:14 UTC (rev 2186)
@@ -22,22 +22,13 @@
package org.teiid.query.processor.relational;
-import java.io.IOException;
-import java.io.Writer;
import java.util.ArrayList;
import java.util.Collections;
-import java.util.HashMap;
import java.util.List;
-import java.util.Properties;
-import javax.xml.transform.OutputKeys;
-import javax.xml.transform.TransformerException;
-
-import net.sf.saxon.Configuration;
+import net.sf.saxon.expr.PathMap.PathMapRoot;
import net.sf.saxon.om.Item;
-import net.sf.saxon.om.NodeInfo;
import net.sf.saxon.om.SequenceIterator;
-import net.sf.saxon.query.QueryResult;
import net.sf.saxon.sxpath.XPathDynamicContext;
import net.sf.saxon.sxpath.XPathExpression;
import net.sf.saxon.trans.XPathException;
@@ -49,44 +40,19 @@
import org.teiid.core.TeiidComponentException;
import org.teiid.core.TeiidProcessingException;
import org.teiid.core.types.DataTypeManager;
-import org.teiid.core.types.SQLXMLImpl;
-import org.teiid.core.types.Streamable;
-import org.teiid.core.types.TransformationException;
-import org.teiid.core.types.XMLTranslator;
import org.teiid.core.types.XMLType;
-import org.teiid.core.types.XMLType.Type;
-import org.teiid.query.processor.xml.XMLUtil;
+import org.teiid.query.execution.QueryExecPlugin;
import org.teiid.query.sql.lang.XMLTable;
import org.teiid.query.sql.lang.XMLTable.XMLColumn;
-import org.teiid.query.sql.symbol.DerivedColumn;
/**
* Handles xml table processing.
*/
public class XMLTableNode extends SubqueryAwareRelationalNode {
- private static final class QueryResultTranslator extends XMLTranslator {
- private final SequenceIterator pathIter;
- private final Configuration config;
-
- private QueryResultTranslator(SequenceIterator pathIter, Configuration config) {
- this.pathIter = pathIter;
- this.config = config;
- }
-
- @Override
- public void translate(Writer writer) throws TransformerException,
- IOException {
- Properties props = new Properties();
- props.setProperty(OutputKeys.METHOD, "xml"); //$NON-NLS-1$
- //props.setProperty(OutputKeys.INDENT, "yes"); //$NON-NLS-1$
- props.setProperty(OutputKeys.OMIT_XML_DECLARATION, "yes"); //$NON-NLS-1$
- QueryResult.serializeSequence(pathIter, config, writer, props);
- }
- }
-
private XMLTable table;
private List<XMLColumn> projectedColumns;
+ private PathMapRoot contextRoot;
private SequenceIterator result;
private int rowCount = 0;
@@ -119,6 +85,10 @@
this.projectedColumns = projectedColumns;
}
+ public void setContextRoot(PathMapRoot contextRoot) {
+ this.contextRoot = contextRoot;
+ }
+
@Override
public XMLTableNode clone() {
XMLTableNode clone = new XMLTableNode(getID());
@@ -134,34 +104,23 @@
if (result == null) {
setReferenceValues(this.table);
- HashMap<String, Object> parameters = new HashMap<String, Object>();
- Object contextItem = null;
- for (DerivedColumn passing : this.table.getPassing()) {
- Object value = getEvaluator(Collections.emptyMap()).evaluate(passing.getExpression(), null);
- if (passing.getAlias() == null) {
- contextItem = value;
- } else {
- parameters.put(passing.getAlias(), value);
- }
- }
- result = this.table.getXQueryExpression().evaluateXQuery(contextItem, parameters);
+ result = getEvaluator(Collections.emptyMap()).evaluateXQuery(this.table.getXQueryExpression(), this.contextRoot, this.table.getPassing(), null);
}
while (!isBatchFull() && !isLastBatch()) {
- try {
- processRow();
- } catch (XPathException e) {
- e.printStackTrace();
- }
+ processRow();
}
return pullBatch();
}
- private void processRow() throws XPathException,
- ExpressionEvaluationException, BlockedException,
- TeiidComponentException, TeiidProcessingException,
- TransformationException {
- Item item = result.next();
+ private void processRow() throws ExpressionEvaluationException, BlockedException,
+ TeiidComponentException, TeiidProcessingException {
+ Item item;
+ try {
+ item = result.next();
+ } catch (XPathException e) {
+ throw new TeiidProcessingException(e, QueryExecPlugin.Util.getString("XMLTableNode.error", e.getMessage())); //$NON-NLS-1$
+ }
rowCount++;
if (item == null) {
terminateBatches();
@@ -172,48 +131,40 @@
if (proColumn.isOrdinal()) {
tuple.add(rowCount);
} else {
- XPathExpression path = proColumn.getPathExpression();
- XPathDynamicContext dynamicContext = path.createDynamicContext(item);
- SequenceIterator pathIter = path.iterate(dynamicContext);
- Item colItem = pathIter.next();
- if (colItem == null) {
- if (proColumn.getDefaultExpression() != null) {
- tuple.add(getEvaluator(Collections.emptyMap()).evaluate(proColumn.getDefaultExpression(), null));
- } else {
- tuple.add(null);
- }
- continue;
- }
- if (proColumn.getSymbol().getType() == DataTypeManager.DefaultDataClasses.XML) {
- Item next = pathIter.next();
- XMLType.Type type = Type.FRAGMENT;
- if (next != null) {
- if (next instanceof NodeInfo || colItem instanceof NodeInfo) {
- type = Type.SIBLINGS;
+ try {
+ XPathExpression path = proColumn.getPathExpression();
+ XPathDynamicContext dynamicContext = path.createDynamicContext(item);
+ SequenceIterator pathIter = path.iterate(dynamicContext);
+ Item colItem = pathIter.next();
+ if (colItem == null) {
+ if (proColumn.getDefaultExpression() != null) {
+ tuple.add(getEvaluator(Collections.emptyMap()).evaluate(proColumn.getDefaultExpression(), null));
} else {
- type = Type.TEXT;
+ tuple.add(null);
}
+ continue;
}
- pathIter = pathIter.getAnother();
- SQLXMLImpl xml = XMLUtil.saveToBufferManager(getBufferManager(), new QueryResultTranslator(pathIter, this.table.getXQueryExpression().getConfig()), Streamable.STREAMING_BATCH_SIZE_IN_BYTES);
- XMLType value = new XMLType(xml);
- value.setType(type);
+ if (proColumn.getSymbol().getType() == DataTypeManager.DefaultDataClasses.XML) {
+ XMLType value = getEvaluator(Collections.emptyMap()).createXMLType(pathIter.getAnother(), table.getXQueryExpression(), false, false);
+ tuple.add(value);
+ continue;
+ }
+ if (pathIter.next() != null) {
+ throw new TeiidProcessingException(QueryExecPlugin.Util.getString("XMLTableName.multi_value", proColumn.getName())); //$NON-NLS-1$
+ }
+ Object value = Value.convertToJava(colItem);
+ if (value instanceof Item) {
+ value = ((Item)value).getStringValue();
+ }
+ value = DataTypeManager.convertToRuntimeType(value);
+ value = DataTypeManager.transformValue(value, proColumn.getSymbol().getType());
tuple.add(value);
- continue;
+ } catch (XPathException e) {
+ throw new TeiidProcessingException(e, QueryExecPlugin.Util.getString("XMLTableNode.path_error", proColumn.getName())); //$NON-NLS-1$
}
- if (pathIter.next() != null) {
- throw new TeiidProcessingException("Unexpected multi-valued result was returned for XML Column " + proColumn.getName() + ". All path expressions should return at most a single result.");
- }
- Object value = Value.convertToJava(colItem);
- if (value instanceof Item) {
- value = ((Item)value).getStringValue();
- }
- value = DataTypeManager.convertToRuntimeType(value);
- value = DataTypeManager.transformValue(value, proColumn.getSymbol().getType());
- tuple.add(value);
}
}
addBatchRow(tuple);
}
-
+
}
\ No newline at end of file
Modified: trunk/engine/src/main/java/org/teiid/query/processor/xml/XMLUtil.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/processor/xml/XMLUtil.java 2010-06-06 15:12:19 UTC (rev 2185)
+++ trunk/engine/src/main/java/org/teiid/query/processor/xml/XMLUtil.java 2010-06-07 16:27:14 UTC (rev 2186)
@@ -33,6 +33,7 @@
import org.teiid.common.buffer.BufferManager;
import org.teiid.common.buffer.FileStore;
import org.teiid.common.buffer.FileStore.FileStoreOutputStream;
+import org.teiid.common.buffer.impl.BufferManagerImpl;
import org.teiid.core.TeiidComponentException;
import org.teiid.core.TeiidProcessingException;
import org.teiid.core.types.InputStreamFactory;
@@ -47,6 +48,17 @@
*/
public class XMLUtil {
+ //horrible hack
+ private static BufferManager bufferManager;
+
+ public static void setBufferManager(BufferManager bufferManager) {
+ XMLUtil.bufferManager = bufferManager;
+ }
+
+ public static SQLXMLImpl saveToBufferManager(XMLTranslator translator) throws TeiidComponentException, TeiidProcessingException {
+ return saveToBufferManager(bufferManager, translator, Streamable.STREAMING_BATCH_SIZE_IN_BYTES);
+ }
+
/**
* This method saves the given XML object to the buffer manager's disk process
* Documents less than the maxMemorySize will be held directly in memory
Deleted: trunk/engine/src/main/java/org/teiid/query/resolver/command/XQueryResolver.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/resolver/command/XQueryResolver.java 2010-06-06 15:12:19 UTC (rev 2185)
+++ trunk/engine/src/main/java/org/teiid/query/resolver/command/XQueryResolver.java 2010-06-07 16:27:14 UTC (rev 2186)
@@ -1,53 +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.resolver.command;
-
-import org.teiid.api.exception.query.QueryMetadataException;
-import org.teiid.api.exception.query.QueryResolverException;
-import org.teiid.core.TeiidComponentException;
-import org.teiid.query.analysis.AnalysisRecord;
-import org.teiid.query.metadata.TempMetadataAdapter;
-import org.teiid.query.resolver.CommandResolver;
-import org.teiid.query.sql.lang.Command;
-
-
-
-/**
- * Resolves XQueries, which in metamatrix currently involves
- * taking the arguments to the doc() functions, adding them as
- * the sub commands of the XQuery, which are then themselves
- * resolved by the Resolver framework.
- *
- * XQuery resolution does not currently involve making sure the
- * XQuery's XPath statements referring to the virtual documents are
- * valid for those documents.
- */
-public class XQueryResolver implements CommandResolver {
-
- /**
- * @see org.teiid.query.resolver.CommandResolver#resolveCommand(org.teiid.query.sql.lang.Command, org.teiid.query.metadata.TempMetadataAdapter, org.teiid.query.analysis.AnalysisRecord, boolean)
- */
- public void resolveCommand(Command command, TempMetadataAdapter metadata, AnalysisRecord analysis, boolean resolveNullLiterals)
- throws QueryMetadataException, QueryResolverException, TeiidComponentException {
- }
-}
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-06 15:12:19 UTC (rev 2185)
+++ trunk/engine/src/main/java/org/teiid/query/resolver/util/ResolverVisitor.java 2010-06-07 16:27:14 UTC (rev 2186)
@@ -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.XMLQuery;
import org.teiid.query.sql.symbol.XMLSerialize;
import org.teiid.query.util.ErrorMessageKeys;
@@ -338,6 +339,15 @@
handleException(new QueryResolverException(e, QueryPlugin.Util.getString("XMLSerialize.resolvingError", obj))); //$NON-NLS-1$
}
}
+
+ @Override
+ public void visit(XMLQuery obj) {
+ try {
+ obj.compileXqueryExpression();
+ } catch (QueryResolverException e) {
+ handleException(e);
+ }
+ }
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-06 15:12:19 UTC (rev 2185)
+++ trunk/engine/src/main/java/org/teiid/query/rewriter/QueryRewriter.java 2010-06-07 16:27:14 UTC (rev 2186)
@@ -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.NonReserved;
+import org.teiid.language.SQLConstants.NonReserved;
import org.teiid.query.eval.Evaluator;
import org.teiid.query.execution.QueryExecPlugin;
import org.teiid.query.function.FunctionDescriptor;
@@ -140,6 +140,7 @@
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.XMLQuery;
import org.teiid.query.sql.symbol.XMLSerialize;
import org.teiid.query.sql.util.SymbolMap;
import org.teiid.query.sql.util.ValueIterator;
@@ -1909,6 +1910,8 @@
rewriteExpressions(expression);
} else if (expression instanceof XMLSerialize) {
rewriteExpressions(expression);
+ } else if (expression instanceof XMLQuery) {
+ rewriteExpressions(expression);
}
if(dataMgr == null) {
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-06 15:12:19 UTC (rev 2185)
+++ trunk/engine/src/main/java/org/teiid/query/sql/LanguageVisitor.java 2010-06-07 16:27:14 UTC (rev 2186)
@@ -133,4 +133,5 @@
public void visit(XMLTable obj) {}
public void visit(DerivedColumn obj) {}
public void visit(XMLSerialize obj) {}
+ public void visit(XMLQuery obj) {}
}
Modified: trunk/engine/src/main/java/org/teiid/query/sql/ProcedureReservedWords.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/sql/ProcedureReservedWords.java 2010-06-06 15:12:19 UTC (rev 2185)
+++ trunk/engine/src/main/java/org/teiid/query/sql/ProcedureReservedWords.java 2010-06-07 16:27:14 UTC (rev 2186)
@@ -26,7 +26,8 @@
import java.util.HashSet;
import java.util.Set;
-import org.teiid.language.SQLReservedWords;
+import org.teiid.language.SQLConstants;
+import org.teiid.language.SQLConstants.Reserved;
/**
* Special variable names in stored procedure language.
@@ -34,7 +35,7 @@
public class ProcedureReservedWords {
@Deprecated
- public static final String INPUT = SQLReservedWords.INPUT;
+ public static final String INPUT = Reserved.INPUT;
public static final String INPUTS = "INPUTS"; //$NON-NLS-1$
@@ -53,7 +54,7 @@
// Initialize RESERVED_WORDS set - This is a poor man's enum. To much legacy code expects the constants to be Strings.
static {
- Field[] fields = SQLReservedWords.class.getDeclaredFields();
+ Field[] fields = SQLConstants.class.getDeclaredFields();
for (Field field : fields) {
if (field.getType() == String.class) {
try {
Modified: trunk/engine/src/main/java/org/teiid/query/sql/lang/Option.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/sql/lang/Option.java 2010-06-06 15:12:19 UTC (rev 2185)
+++ trunk/engine/src/main/java/org/teiid/query/sql/lang/Option.java 2010-06-07 16:27:14 UTC (rev 2186)
@@ -27,7 +27,7 @@
import org.teiid.core.util.EquivalenceUtil;
import org.teiid.core.util.HashCodeUtil;
-import org.teiid.language.SQLReservedWords;
+import org.teiid.language.SQLConstants.Reserved;
import org.teiid.query.sql.LanguageObject;
import org.teiid.query.sql.LanguageVisitor;
import org.teiid.query.sql.visitor.SQLStringVisitor;
@@ -40,8 +40,8 @@
*/
public class Option implements LanguageObject {
- public final static String MAKEDEP = SQLReservedWords.MAKEDEP;
- public final static String MAKENOTDEP = SQLReservedWords.MAKENOTDEP;
+ public final static String MAKEDEP = Reserved.MAKEDEP;
+ public final static String MAKENOTDEP = Reserved.MAKENOTDEP;
public final static String OPTIONAL = "optional"; //$NON-NLS-1$
private List<String> makeDependentGroups;
Modified: trunk/engine/src/main/java/org/teiid/query/sql/lang/XMLTable.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/sql/lang/XMLTable.java 2010-06-06 15:12:19 UTC (rev 2185)
+++ trunk/engine/src/main/java/org/teiid/query/sql/lang/XMLTable.java 2010-06-07 16:27:14 UTC (rev 2186)
@@ -178,6 +178,16 @@
if (defaultColumn != null) {
clone.defaultColumn = this.defaultColumn;
}
+ if (this.namespaces != null) {
+ clone.namespaces = this.namespaces.clone();
+ }
+ if (this.passing != null) {
+ for (DerivedColumn col : this.passing) {
+ clone.passing.add(col.clone());
+ }
+ }
+ clone.xquery = this.xquery;
+ clone.xqueryExpression = this.xqueryExpression;
return clone;
}
@@ -195,7 +205,10 @@
return false;
}
XMLTable other = (XMLTable)obj;
- return this.columns.equals(other.columns);
+ return this.columns.equals(other.columns)
+ && EquivalenceUtil.areEqual(this.namespaces, other.namespaces)
+ && this.xquery.equals(other.xquery)
+ && this.passing.equals(other.passing);
}
public void rewriteDefaultColumn() {
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-06 15:12:19 UTC (rev 2185)
+++ trunk/engine/src/main/java/org/teiid/query/sql/navigator/PreOrPostOrderNavigator.java 2010-06-07 16:27:14 UTC (rev 2186)
@@ -98,6 +98,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.XMLQuery;
import org.teiid.query.sql.symbol.XMLSerialize;
@@ -562,6 +563,14 @@
}
@Override
+ public void visit(XMLQuery obj) {
+ preVisitVisitor(obj);
+ visitNode(obj.getNamespaces());
+ visitNodes(obj.getPassing());
+ postVisitVisitor(obj);
+ }
+
+ @Override
public void visit(DerivedColumn obj) {
preVisitVisitor(obj);
visitNode(obj.getExpression());
Modified: trunk/engine/src/main/java/org/teiid/query/sql/proc/RaiseErrorStatement.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/sql/proc/RaiseErrorStatement.java 2010-06-06 15:12:19 UTC (rev 2185)
+++ trunk/engine/src/main/java/org/teiid/query/sql/proc/RaiseErrorStatement.java 2010-06-07 16:27:14 UTC (rev 2186)
@@ -22,7 +22,7 @@
package org.teiid.query.sql.proc;
-import org.teiid.language.SQLReservedWords;
+import org.teiid.language.SQLConstants.Reserved;
import org.teiid.query.sql.LanguageVisitor;
import org.teiid.query.sql.symbol.ElementSymbol;
import org.teiid.query.sql.symbol.Expression;
@@ -58,10 +58,10 @@
* matter that it has an invalid ID or GroupSymbol. Setting the type to
* String allows for the expression to be converted to String as necessary.
*/
- ElementSymbol result = new ElementSymbol(SQLReservedWords.ERROR);
- result.setMetadataID(SQLReservedWords.ERROR);
+ ElementSymbol result = new ElementSymbol(Reserved.ERROR);
+ result.setMetadataID(Reserved.ERROR);
result.setType(String.class);
- result.setGroupSymbol(new GroupSymbol(SQLReservedWords.ERROR));
+ result.setGroupSymbol(new GroupSymbol(Reserved.ERROR));
return result;
}
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-06 15:12:19 UTC (rev 2185)
+++ trunk/engine/src/main/java/org/teiid/query/sql/symbol/AggregateSymbol.java 2010-06-07 16:27:14 UTC (rev 2186)
@@ -30,8 +30,8 @@
import org.teiid.core.types.DataTypeManager;
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.language.SQLConstants.NonReserved;
+import org.teiid.language.SQLConstants.Reserved;
import org.teiid.query.QueryPlugin;
import org.teiid.query.sql.LanguageVisitor;
import org.teiid.query.sql.lang.OrderBy;
@@ -75,7 +75,7 @@
AGGREGATE_FUNCTIONS.add(NonReserved.AVG);
AGGREGATE_FUNCTIONS.add(NonReserved.MIN);
AGGREGATE_FUNCTIONS.add(NonReserved.MAX);
- AGGREGATE_FUNCTIONS.add(SQLReservedWords.XMLAGG);
+ AGGREGATE_FUNCTIONS.add(Reserved.XMLAGG);
SUM_TYPES = new HashMap<Class<?>, Class<?>>();
SUM_TYPES.put(DataTypeManager.DefaultDataClasses.BYTE, DataTypeManager.DefaultDataClasses.LONG);
@@ -114,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.NonReserved#COUNT}, etc)
+ * @param aggregateFunction Aggregate function type ({@link org.teiid.language.SQLConstants.NonReserved#COUNT}, etc)
* @param isDistinct True if DISTINCT flag is set
* @param expression Contained expression
*/
@@ -129,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.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
+ * @see org.teiid.language.SQLConstants.NonReserved#COUNT
+ * @see org.teiid.language.SQLConstants.NonReserved#SUM
+ * @see org.teiid.language.SQLConstants.NonReserved#AVG
+ * @see org.teiid.language.SQLConstants.NonReserved#MIN
+ * @see org.teiid.language.SQLConstants.NonReserved#MAX
*/
private void setAggregateFunction(String aggregateFunction) {
// Validate aggregate
@@ -147,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.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
+ * @see org.teiid.language.SQLConstants.NonReserved#COUNT
+ * @see org.teiid.language.SQLConstants.NonReserved#SUM
+ * @see org.teiid.language.SQLConstants.NonReserved#AVG
+ * @see org.teiid.language.SQLConstants.NonReserved#MIN
+ * @see org.teiid.language.SQLConstants.NonReserved#MAX
*/
public String getAggregateFunction() {
return this.aggregate;
Added: trunk/engine/src/main/java/org/teiid/query/sql/symbol/XMLQuery.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/sql/symbol/XMLQuery.java (rev 0)
+++ trunk/engine/src/main/java/org/teiid/query/sql/symbol/XMLQuery.java 2010-06-07 16:27:14 UTC (rev 2186)
@@ -0,0 +1,140 @@
+package org.teiid.query.sql.symbol;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import net.sf.saxon.expr.PathMap.PathMapRoot;
+
+import org.teiid.api.exception.query.QueryResolverException;
+import org.teiid.core.types.DataTypeManager;
+import org.teiid.core.util.EquivalenceUtil;
+import org.teiid.query.analysis.AnalysisRecord;
+import org.teiid.query.sql.LanguageVisitor;
+import org.teiid.query.sql.visitor.SQLStringVisitor;
+import org.teiid.query.xquery.saxon.SaxonXQueryExpression;
+
+public class XMLQuery implements Expression {
+
+ private XMLNamespaces namespaces;
+ private String xquery;
+ private List<DerivedColumn> passing = new ArrayList<DerivedColumn>();
+ private Boolean emptyOnEmpty;
+ private Boolean returningContent;
+
+ private SaxonXQueryExpression xqueryExpression;
+ private PathMapRoot contextRoot;
+
+ @Override
+ public Class<?> getType() {
+ return DataTypeManager.DefaultDataClasses.XML;
+ }
+
+ public Boolean getEmptyOnEmpty() {
+ return emptyOnEmpty;
+ }
+
+ public void setEmptyOnEmpty(Boolean emptyOnEmpty) {
+ this.emptyOnEmpty = emptyOnEmpty;
+ }
+
+ public Boolean getReturningContent() {
+ return returningContent;
+ }
+
+ public void setReturningContent(Boolean returningContent) {
+ this.returningContent = returningContent;
+ }
+
+ @Override
+ public boolean isResolved() {
+ return xqueryExpression != null;
+ }
+
+ public List<DerivedColumn> getPassing() {
+ return passing;
+ }
+
+ //TODO: display the analysis record info
+ public void compileXqueryExpression() throws QueryResolverException {
+ this.xqueryExpression = new SaxonXQueryExpression(xquery, namespaces, passing, null);
+ this.contextRoot = this.xqueryExpression.useDocumentProjection(null, new AnalysisRecord(false, false));
+ }
+
+ public SaxonXQueryExpression getXQueryExpression() {
+ return xqueryExpression;
+ }
+
+ public PathMapRoot getContextRoot() {
+ return contextRoot;
+ }
+
+ public void setPassing(List<DerivedColumn> passing) {
+ this.passing = passing;
+ }
+
+ public String getXquery() {
+ return xquery;
+ }
+
+ public void setXquery(String xquery) {
+ this.xquery = xquery;
+ }
+
+ public XMLNamespaces getNamespaces() {
+ return namespaces;
+ }
+
+ public void setNamespaces(XMLNamespaces namespaces) {
+ this.namespaces = namespaces;
+ }
+
+ @Override
+ public void acceptVisitor(LanguageVisitor visitor) {
+ visitor.visit(this);
+ }
+
+ @Override
+ public XMLQuery clone() {
+ XMLQuery clone = new XMLQuery();
+ if (this.namespaces != null) {
+ clone.namespaces = this.namespaces.clone();
+ }
+ if (this.passing != null) {
+ for (DerivedColumn col : this.passing) {
+ clone.passing.add(col.clone());
+ }
+ }
+ clone.xquery = this.xquery;
+ clone.xqueryExpression = this.xqueryExpression;
+ clone.emptyOnEmpty = this.emptyOnEmpty;
+ clone.returningContent = this.returningContent;
+ return clone;
+ }
+
+ @Override
+ public boolean equals(Object obj) {
+ if (obj == this) {
+ return true;
+ }
+ if (!(obj instanceof XMLQuery)) {
+ return false;
+ }
+ XMLQuery other = (XMLQuery)obj;
+ return EquivalenceUtil.areEqual(this.namespaces, other.namespaces)
+ && this.passing.equals(other.passing)
+ && this.xquery.equals(other.xquery)
+ && EquivalenceUtil.areEqual(this.emptyOnEmpty, other.emptyOnEmpty)
+ && EquivalenceUtil.areEqual(this.returningContent, other.returningContent);
+ }
+
+ @Override
+ public int hashCode() {
+ return this.xquery.hashCode();
+ }
+
+ @Override
+ public String toString() {
+ return SQLStringVisitor.getSQLString(this);
+ }
+
+}
Property changes on: trunk/engine/src/main/java/org/teiid/query/sql/symbol/XMLQuery.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
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-06 15:12:19 UTC (rev 2185)
+++ trunk/engine/src/main/java/org/teiid/query/sql/visitor/SQLStringVisitor.java 2010-06-07 16:27:14 UTC (rev 2186)
@@ -22,6 +22,8 @@
package org.teiid.query.sql.visitor;
+import static org.teiid.language.SQLConstants.Reserved.*;
+
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
@@ -31,9 +33,9 @@
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.language.SQLConstants;
+import org.teiid.language.SQLConstants.NonReserved;
+import org.teiid.language.SQLConstants.Tokens;
import org.teiid.query.function.FunctionLibrary;
import org.teiid.query.sql.LanguageObject;
import org.teiid.query.sql.LanguageVisitor;
@@ -118,6 +120,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.XMLQuery;
import org.teiid.query.sql.symbol.XMLSerialize;
import org.teiid.query.sql.symbol.XMLNamespaces.NamespaceItem;
import org.teiid.translator.SourceSystemFunctions;
@@ -193,43 +196,43 @@
parts.add(SPACE);
if (obj.isNegated()) {
- parts.add(SQLReservedWords.NOT);
+ parts.add(NOT);
parts.add(SPACE);
}
- parts.add(SQLReservedWords.BETWEEN);
+ parts.add(BETWEEN);
parts.add(SPACE);
parts.add(registerNode(obj.getLowerExpression()));
parts.add(SPACE);
- parts.add(SQLReservedWords.AND);
+ parts.add(AND);
parts.add(SPACE);
parts.add(registerNode(obj.getUpperExpression()));
}
public void visit(CaseExpression obj) {
- parts.add(SQLReservedWords.CASE);
+ parts.add(CASE);
parts.add(SPACE);
parts.add(registerNode(obj.getExpression()) );
parts.add(SPACE);
for (int i = 0; i < obj.getWhenCount(); i++) {
- parts.add(SQLReservedWords.WHEN);
+ parts.add(WHEN);
parts.add(SPACE);
parts.add(registerNode(obj.getWhenExpression(i)) );
parts.add(SPACE);
- parts.add(SQLReservedWords.THEN);
+ parts.add(THEN);
parts.add(SPACE);
parts.add(registerNode(obj.getThenExpression(i)));
parts.add(SPACE);
}
if (obj.getElseExpression() != null) {
- parts.add(SQLReservedWords.ELSE);
+ parts.add(ELSE);
parts.add(SPACE);
parts.add(registerNode(obj.getElseExpression()));
parts.add(SPACE);
}
- parts.add(SQLReservedWords.END);
+ parts.add(END);
}
public void visit(CompareCriteria obj) {
@@ -249,9 +252,9 @@
int operator = obj.getOperator();
String operatorStr = ""; //$NON-NLS-1$
if(operator == CompoundCriteria.AND) {
- operatorStr = SQLReservedWords.AND;
+ operatorStr = AND;
} else if(operator == CompoundCriteria.OR) {
- operatorStr = SQLReservedWords.OR;
+ operatorStr = OR;
}
// Get criteria
@@ -299,17 +302,17 @@
public void visit(Delete obj) {
//add delete clause
- parts.add(SQLReservedWords.DELETE);
+ parts.add(DELETE);
parts.add(SPACE);
//add from clause
- parts.add(SQLReservedWords.FROM);
+ parts.add(FROM);
parts.add(SPACE);
parts.add(registerNode(obj.getGroup()));
//add where clause
if(obj.getCriteria() != null) {
parts.add(SPACE);
- parts.add(SQLReservedWords.WHERE);
+ parts.add(WHERE);
parts.add(SPACE);
parts.add(registerNode(obj.getCriteria()));
}
@@ -327,10 +330,10 @@
// operator and beginning of list
parts.add(SPACE);
if (obj.isNegated()) {
- parts.add(SQLReservedWords.NOT);
+ parts.add(NOT);
parts.add(SPACE);
}
- parts.add(SQLReservedWords.IN);
+ parts.add(IN);
parts.add(" (<dependent values>)"); //$NON-NLS-1$
}
@@ -339,13 +342,13 @@
List clauses = obj.getClauses();
if(clauses.size() == 1) {
replaceStringParts(new Object[] {
- SQLReservedWords.FROM, SPACE,
+ FROM, SPACE,
registerNode( (FromClause) clauses.get(0) ) });
} else if(clauses.size() > 1) {
parts = new Object[2 + clauses.size() + (clauses.size()-1)];
// Add first clause
- parts[0] = SQLReservedWords.FROM;
+ parts[0] = FROM;
parts[1] = SPACE;
Iterator clauseIter = clauses.iterator();
parts[2] = registerNode((FromClause) clauseIter.next());
@@ -359,7 +362,7 @@
replaceStringParts(parts);
} else {
// Shouldn't happen, but being tolerant
- replaceStringParts(new Object[] { SQLReservedWords.FROM });
+ replaceStringParts(new Object[] { FROM });
}
}
@@ -368,15 +371,15 @@
List symbols = obj.getSymbols();
if(symbols.size() == 1) {
replaceStringParts(new Object[] {
- SQLReservedWords.GROUP, SPACE, SQLReservedWords.BY, SPACE,
+ GROUP, SPACE, BY, SPACE,
registerNode( (Expression) symbols.get(0) ) });
} else if(symbols.size() > 1) {
parts = new Object[4 + symbols.size() + (symbols.size()-1)];
// Add first clause
- parts[0] = SQLReservedWords.GROUP;
+ parts[0] = GROUP;
parts[1] = SPACE;
- parts[2] = SQLReservedWords.BY;
+ parts[2] = BY;
parts[3] = SPACE;
Iterator symbolIter = symbols.iterator();
parts[4] = registerNode((Expression) symbolIter.next());
@@ -390,7 +393,7 @@
replaceStringParts(parts);
} else {
// Shouldn't happen, but being tolerant
- replaceStringParts(new Object[] { SQLReservedWords.GROUP, SPACE, SQLReservedWords.BY });
+ replaceStringParts(new Object[] { GROUP, SPACE, BY });
}
}
@@ -400,7 +403,7 @@
if ( obj.getQueryExpression() != null ) {
parts.add(registerNode(obj.getQueryExpression()));
} else {
- parts.add(SQLReservedWords.VALUES);
+ parts.add(VALUES);
parts.add(" ("); //$NON-NLS-1$
Iterator valueIter = obj.getValues().iterator();
while(valueIter.hasNext()) {
@@ -421,13 +424,13 @@
}
public void visit(Create obj) {
- parts.add(SQLReservedWords.CREATE);
+ parts.add(CREATE);
parts.add(SPACE);
- parts.add(SQLReservedWords.LOCAL);
+ parts.add(LOCAL);
parts.add(SPACE);
- parts.add(SQLReservedWords.TEMPORARY);
+ parts.add(TEMPORARY);
parts.add(SPACE);
- parts.add(SQLReservedWords.TABLE);
+ parts.add(TABLE);
parts.add(SPACE);
parts.add(registerNode(obj.getTable()));
parts.add(SPACE);
@@ -450,17 +453,17 @@
}
public void visit(Drop obj) {
- parts.add(SQLReservedWords.DROP);
+ parts.add(DROP);
parts.add(SPACE);
- parts.add(SQLReservedWords.TABLE);
+ parts.add(TABLE);
parts.add(SPACE);
parts.add(registerNode(obj.getTable()));
}
private void formatBasicInsert(Insert obj) {
- parts.add(SQLReservedWords.INSERT);
+ parts.add(INSERT);
parts.add(SPACE);
- parts.add(SQLReservedWords.INTO);
+ parts.add(INTO);
parts.add(SPACE);
parts.add(registerNode(obj.getGroup()));
parts.add(SPACE);
@@ -489,13 +492,13 @@
Object exprPart = registerNode(expr);
parts.add(exprPart);
parts.add(SPACE);
- parts.add(SQLReservedWords.IS);
+ parts.add(IS);
parts.add(SPACE);
if (obj.isNegated()) {
- parts.add(SQLReservedWords.NOT);
+ parts.add(NOT);
parts.add(SPACE);
}
- parts.add(SQLReservedWords.NULL);
+ parts.add(NULL);
}
public void visit(JoinPredicate obj) {
@@ -534,7 +537,7 @@
List joinCriteria = obj.getJoinCriteria();
if(joinCriteria != null && joinCriteria.size() > 0) {
parts.add(SPACE);
- parts.add(SQLReservedWords.ON);
+ parts.add(ON);
parts.add(SPACE);
Iterator critIter = joinCriteria.iterator();
while(critIter.hasNext()) {
@@ -549,7 +552,7 @@
if(critIter.hasNext()) {
parts.add(SPACE);
- parts.add(SQLReservedWords.AND);
+ parts.add(AND);
parts.add(SPACE);
}
}
@@ -586,21 +589,21 @@
public void visit(JoinType obj) {
Object[] parts = null;
if(obj.equals(JoinType.JOIN_INNER)) {
- parts = new Object[] { SQLReservedWords.INNER, SPACE, SQLReservedWords.JOIN };
+ parts = new Object[] { INNER, SPACE, JOIN };
} else if(obj.equals(JoinType.JOIN_CROSS)) {
- parts = new Object[] { SQLReservedWords.CROSS, SPACE, SQLReservedWords.JOIN };
+ parts = new Object[] { CROSS, SPACE, JOIN };
} else if(obj.equals(JoinType.JOIN_LEFT_OUTER)) {
- parts = new Object[] { SQLReservedWords.LEFT, SPACE, SQLReservedWords.OUTER, SPACE, SQLReservedWords.JOIN };
+ parts = new Object[] { LEFT, SPACE, OUTER, SPACE, JOIN };
} else if(obj.equals(JoinType.JOIN_RIGHT_OUTER)) {
- parts = new Object[] { SQLReservedWords.RIGHT, SPACE, SQLReservedWords.OUTER, SPACE, SQLReservedWords.JOIN };
+ parts = new Object[] { RIGHT, SPACE, OUTER, SPACE, JOIN };
} else if(obj.equals(JoinType.JOIN_FULL_OUTER)) {
- parts = new Object[] { SQLReservedWords.FULL, SPACE, SQLReservedWords.OUTER, SPACE, SQLReservedWords.JOIN };
+ parts = new Object[] { FULL, SPACE, OUTER, SPACE, JOIN };
} else if(obj.equals(JoinType.JOIN_UNION)) {
- parts = new Object[] { SQLReservedWords.UNION, SPACE, SQLReservedWords.JOIN };
+ parts = new Object[] { UNION, SPACE, JOIN };
} else if (obj.equals(JoinType.JOIN_SEMI)) {
- parts = new Object[] { "SEMI", SPACE, SQLReservedWords.JOIN }; //$NON-NLS-1$
+ parts = new Object[] { "SEMI", SPACE, JOIN }; //$NON-NLS-1$
} else if (obj.equals(JoinType.JOIN_ANTI_SEMI)) {
- parts = new Object[] { "ANTI SEMI", SPACE, SQLReservedWords.JOIN }; //$NON-NLS-1$
+ parts = new Object[] { "ANTI SEMI", SPACE, JOIN }; //$NON-NLS-1$
}
replaceStringParts(parts);
@@ -611,17 +614,17 @@
parts.add(SPACE);
if (obj.isNegated()) {
- parts.add(SQLReservedWords.NOT);
+ parts.add(NOT);
parts.add(SPACE);
}
- parts.add(SQLReservedWords.LIKE);
+ parts.add(LIKE);
parts.add(SPACE);
parts.add(registerNode(obj.getRightExpression()));
if(obj.getEscapeChar() != MatchCriteria.NULL_ESCAPE_CHAR) {
parts.add(SPACE);
- parts.add(SQLReservedWords.ESCAPE);
+ parts.add(ESCAPE);
parts.add(" '"); //$NON-NLS-1$
parts.add("" + obj.getEscapeChar()); //$NON-NLS-1$
parts.add("'"); //$NON-NLS-1$
@@ -629,19 +632,19 @@
}
public void visit(NotCriteria obj) {
- parts.add(SQLReservedWords.NOT);
+ parts.add(NOT);
parts.add(" ("); //$NON-NLS-1$
parts.add(registerNode(obj.getCriteria()));
parts.add(")"); //$NON-NLS-1$
}
public void visit(Option obj) {
- parts.add(SQLReservedWords.OPTION);
+ parts.add(OPTION);
Collection groups = obj.getDependentGroups();
if(groups != null && groups.size() > 0) {
parts.add(" "); //$NON-NLS-1$
- parts.add(SQLReservedWords.MAKEDEP);
+ parts.add(MAKEDEP);
parts.add(" "); //$NON-NLS-1$
Iterator iter = groups.iterator();
@@ -658,7 +661,7 @@
groups = obj.getNotDependentGroups();
if(groups != null && groups.size() > 0) {
parts.add(" "); //$NON-NLS-1$
- parts.add(SQLReservedWords.MAKENOTDEP);
+ parts.add(MAKENOTDEP);
parts.add(" "); //$NON-NLS-1$
Iterator iter = groups.iterator();
@@ -675,7 +678,7 @@
groups = obj.getNoCacheGroups();
if(groups != null && groups.size() > 0) {
parts.add(" "); //$NON-NLS-1$
- parts.add(SQLReservedWords.NOCACHE);
+ parts.add(NOCACHE);
parts.add(" "); //$NON-NLS-1$
Iterator iter = groups.iterator();
@@ -689,15 +692,15 @@
}
}else if(obj.isNoCache()){
parts.add(" "); //$NON-NLS-1$
- parts.add(SQLReservedWords.NOCACHE);
+ parts.add(NOCACHE);
}
}
public void visit(OrderBy obj) {
- parts.add(SQLReservedWords.ORDER);
+ parts.add(ORDER);
parts.add(SPACE);
- parts.add(SQLReservedWords.BY);
+ parts.add(BY);
parts.add(SPACE);
for (Iterator<OrderByItem> iterator = obj.getOrderByItems().iterator(); iterator.hasNext();) {
OrderByItem item = iterator.next();
@@ -719,20 +722,20 @@
}
if(!obj.isAscending()) {
parts.add(SPACE);
- parts.add(SQLReservedWords.DESC);
+ parts.add(DESC);
} // Don't print default "ASC"
}
public void visit(DynamicCommand obj) {
- parts.add(SQLReservedWords.EXECUTE);
+ parts.add(EXECUTE);
parts.add(SPACE);
- parts.add(SQLReservedWords.STRING);
+ parts.add(STRING);
parts.add(SPACE);
parts.add(registerNode(obj.getSql()));
if(obj.isAsClauseSet()){
parts.add(SPACE);
- parts.add(SQLReservedWords.AS);
+ parts.add(AS);
parts.add(SPACE);
for (int i = 0; i < obj.getAsColumns().size(); i++) {
ElementSymbol symbol = (ElementSymbol)obj.getAsColumns().get(i);
@@ -748,21 +751,21 @@
if(obj.getIntoGroup() != null){
parts.add(SPACE);
- parts.add(SQLReservedWords.INTO);
+ parts.add(INTO);
parts.add(SPACE);
parts.add(registerNode(obj.getIntoGroup()));
}
if(obj.getUsing() != null && !obj.getUsing().isEmpty()) {
parts.add(SPACE);
- parts.add(SQLReservedWords.USING);
+ parts.add(USING);
parts.add(SPACE);
parts.add(registerNode(obj.getUsing()));
}
if (obj.getUpdatingModelCount() > 0) {
parts.add(SPACE);
- parts.add(SQLReservedWords.UPDATE);
+ parts.add(UPDATE);
parts.add(SPACE);
if (obj.getUpdatingModelCount() > 1) {
parts.add("*"); //$NON-NLS-1$
@@ -796,7 +799,7 @@
if(obj.getInto() != null){
parts.add(SPACE);
- parts.add(SQLReservedWords.INTO);
+ parts.add(INTO);
parts.add(SPACE);
parts.add(registerNode(obj.getInto()));
}
@@ -809,7 +812,7 @@
// Where clause
if(obj.getCriteria() != null) {
parts.add(SPACE);
- parts.add(SQLReservedWords.WHERE);
+ parts.add(WHERE);
parts.add(SPACE);
parts.add(registerNode(obj.getCriteria()));
}
@@ -823,7 +826,7 @@
// Having clause
if(obj.getHaving() != null) {
parts.add(SPACE);
- parts.add(SQLReservedWords.HAVING);
+ parts.add(HAVING);
parts.add(SPACE);
parts.add(registerNode(obj.getHaving()));
}
@@ -847,33 +850,33 @@
}
public void visit(SearchedCaseExpression obj) {
- parts.add(SQLReservedWords.CASE);
+ parts.add(CASE);
for (int i = 0; i < obj.getWhenCount(); i++) {
parts.add(SPACE);
- parts.add(SQLReservedWords.WHEN);
+ parts.add(WHEN);
parts.add(SPACE);
parts.add(registerNode(obj.getWhenCriteria(i)));
parts.add(SPACE);
- parts.add(SQLReservedWords.THEN);
+ parts.add(THEN);
parts.add(SPACE);
parts.add(registerNode(obj.getThenExpression(i)));
}
parts.add(SPACE);
if (obj.getElseExpression() != null) {
- parts.add(SQLReservedWords.ELSE);
+ parts.add(ELSE);
parts.add(SPACE);
parts.add(registerNode(obj.getElseExpression()));
parts.add(SPACE);
}
- parts.add(SQLReservedWords.END);
+ parts.add(END);
}
public void visit(Select obj) {
- parts.add(SQLReservedWords.SELECT);
+ parts.add(SELECT);
parts.add(SPACE);
if(obj.isDistinct()) {
- parts.add(SQLReservedWords.DISTINCT);
+ parts.add(DISTINCT);
parts.add(SPACE);
}
@@ -894,10 +897,10 @@
// operator and beginning of list
parts.add(SPACE);
if (obj.isNegated()) {
- parts.add(SQLReservedWords.NOT);
+ parts.add(NOT);
parts.add(SPACE);
}
- parts.add(SQLReservedWords.IN);
+ parts.add(IN);
parts.add(" ("); //$NON-NLS-1$
// value list
@@ -936,7 +939,7 @@
parts.add(SPACE);
if(obj.isAll()) {
- parts.add(SQLReservedWords.ALL);
+ parts.add(ALL);
parts.add(SPACE);
}
@@ -968,7 +971,7 @@
public void visit(StoredProcedure obj) {
addCacheHint(obj);
//exec clause
- parts.add(SQLReservedWords.EXEC);
+ parts.add(EXEC);
parts.add(SPACE);
parts.add(obj.getProcedureName());
parts.add("("); //$NON-NLS-1$
@@ -1022,7 +1025,7 @@
public void visit(SubqueryFromClause obj) {
addOptionComment(obj);
if (obj.isTable()) {
- parts.add(SQLReservedWords.TABLE);
+ parts.add(TABLE);
}
parts.add("(");//$NON-NLS-1$
parts.add(registerNode(obj.getCommand()));
@@ -1039,10 +1042,10 @@
// operator and beginning of list
parts.add(SPACE);
if (obj.isNegated()) {
- parts.add(SQLReservedWords.NOT);
+ parts.add(NOT);
parts.add(SPACE);
}
- parts.add(SQLReservedWords.IN);
+ parts.add(IN);
parts.add(" ("); //$NON-NLS-1$
parts.add(registerNode(obj.getCommand()));
parts.add(")"); //$NON-NLS-1$
@@ -1057,13 +1060,13 @@
public void visit(Update obj) {
// Update clause
- parts.add(SQLReservedWords.UPDATE);
+ parts.add(UPDATE);
parts.add(SPACE);
parts.add(registerNode(obj.getGroup()));
parts.add(SPACE);
// Set clause
- parts.add(SQLReservedWords.SET);
+ parts.add(SET);
parts.add(SPACE);
parts.add(registerNode(obj.getChangeList()));
@@ -1071,7 +1074,7 @@
// Where clause
if(obj.getCriteria() != null) {
parts.add(SPACE);
- parts.add(SQLReservedWords.WHERE);
+ parts.add(WHERE);
parts.add(SPACE);
parts.add(registerNode(obj.getCriteria()));
}
@@ -1094,7 +1097,7 @@
parts.add("("); //$NON-NLS-1$
if(obj.isDistinct()) {
- parts.add(SQLReservedWords.DISTINCT);
+ parts.add(DISTINCT);
parts.add(" "); //$NON-NLS-1$
}
@@ -1114,7 +1117,7 @@
public void visit(AliasSymbol obj) {
parts.add(registerNode(obj.getSymbol()));
parts.add(SPACE);
- parts.add(SQLReservedWords.AS);
+ parts.add(AS);
parts.add(SPACE);
parts.add(escapeSinglePart(obj.getOutputName()));
}
@@ -1134,7 +1137,7 @@
constantParts = new Object[] {"?"}; //$NON-NLS-1$
} else if(obj.isNull()) {
if(type.equals(DataTypeManager.DefaultDataClasses.BOOLEAN)) {
- constantParts = new Object[] {SQLReservedWords.UNKNOWN};
+ constantParts = new Object[] {UNKNOWN};
} else {
constantParts = new Object[] {"null"}; //$NON-NLS-1$
}
@@ -1142,13 +1145,15 @@
if(Number.class.isAssignableFrom(type)) {
constantParts = new Object[] { obj.getValue().toString() };
} else if(type.equals(DataTypeManager.DefaultDataClasses.BOOLEAN)) {
- constantParts = new Object[] { obj.getValue().equals(Boolean.TRUE) ? SQLReservedWords.TRUE : SQLReservedWords.FALSE};
+ constantParts = new Object[] { obj.getValue().equals(Boolean.TRUE) ? TRUE : FALSE};
} else if(type.equals(DataTypeManager.DefaultDataClasses.TIMESTAMP)) {
constantParts = new Object[] { "{ts'", obj.getValue().toString(), "'}" }; //$NON-NLS-1$ //$NON-NLS-2$
} else if(type.equals(DataTypeManager.DefaultDataClasses.TIME)) {
constantParts = new Object[] { "{t'", obj.getValue().toString(), "'}" }; //$NON-NLS-1$ //$NON-NLS-2$
} else if(type.equals(DataTypeManager.DefaultDataClasses.DATE)) {
constantParts = new Object[] { "{d'", obj.getValue().toString(), "'}" }; //$NON-NLS-1$ //$NON-NLS-2$
+ } else if(type.equals(DataTypeManager.DefaultDataClasses.XML)){
+ constantParts = new Object[] { "{x '", escapeStringValue(obj.getValue().toString(), "'"), "'}" }; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
} else {
String strValue = obj.getValue().toString();
strValue = escapeStringValue(strValue, "'"); //$NON-NLS-1$
@@ -1204,18 +1209,18 @@
// Hide this function, which is implicit
parts.add(registerNode(args[0]));
- } else if(name.equalsIgnoreCase(SQLReservedWords.CONVERT) || name.equalsIgnoreCase(SQLReservedWords.CAST)) {
+ } else if(name.equalsIgnoreCase(CONVERT) || name.equalsIgnoreCase(CAST)) {
parts.add(name);
parts.add("("); //$NON-NLS-1$
if(args != null && args.length > 0) {
parts.add(registerNode(args[0]));
- if(name.equalsIgnoreCase(SQLReservedWords.CONVERT)) {
+ if(name.equalsIgnoreCase(CONVERT)) {
parts.add(", "); //$NON-NLS-1$
} else {
parts.add(" "); //$NON-NLS-1$
- parts.add(SQLReservedWords.AS);
+ parts.add(AS);
parts.add(" "); //$NON-NLS-1$
}
@@ -1291,7 +1296,7 @@
if(alias != null) {
parts.add(SPACE);
- parts.add(SQLReservedWords.AS);
+ parts.add(AS);
parts.add(SPACE);
parts.add(escapeSinglePart(alias));
}
@@ -1310,12 +1315,12 @@
public void visit(Block obj) {
List statements = obj.getStatements();
if(statements.size() == 1) {
- replaceStringParts(new Object[] { SQLReservedWords.BEGIN, "\n", //$NON-NLS-1$
- registerNode((Statement)obj.getStatements().get(0)), "\n", SQLReservedWords.END}); //$NON-NLS-1$
+ replaceStringParts(new Object[] { BEGIN, "\n", //$NON-NLS-1$
+ registerNode((Statement)obj.getStatements().get(0)), "\n", END}); //$NON-NLS-1$
} else if(statements.size() > 1) {
List parts = new ArrayList();
// Add first clause
- parts.add(SQLReservedWords.BEGIN);
+ parts.add(BEGIN);
parts.add("\n"); //$NON-NLS-1$
Iterator stmtIter = statements.iterator();
while(stmtIter.hasNext()) {
@@ -1323,12 +1328,12 @@
parts.add(registerNode((Statement) stmtIter.next()));
parts.add("\n"); //$NON-NLS-1$
}
- parts.add(SQLReservedWords.END);
+ parts.add(END);
replaceStringParts(parts.toArray());
} else {
// Shouldn't happen, but being tolerant
- replaceStringParts(new Object[] { SQLReservedWords.BEGIN, "\n", //$NON-NLS-1$
- SQLReservedWords.END });
+ replaceStringParts(new Object[] { BEGIN, "\n", //$NON-NLS-1$
+ END });
}
}
@@ -1338,19 +1343,19 @@
}
public void visit(CreateUpdateProcedureCommand obj) {
- parts.add(SQLReservedWords.CREATE);
+ parts.add(CREATE);
parts.add(SPACE);
if(!obj.isUpdateProcedure()){
- parts.add(SQLReservedWords.VIRTUAL);
+ parts.add(VIRTUAL);
parts.add(SPACE);
}
- parts.add(SQLReservedWords.PROCEDURE);
+ parts.add(PROCEDURE);
parts.add("\n"); //$NON-NLS-1$
parts.add(registerNode(obj.getBlock()));
}
public void visit(DeclareStatement obj) {
- parts.add(SQLReservedWords.DECLARE);
+ parts.add(DECLARE);
parts.add(SPACE);
parts.add(obj.getVariableType());
parts.add(SPACE);
@@ -1371,14 +1376,14 @@
}
public void visit(IfStatement obj) {
- parts.add(SQLReservedWords.IF);
+ parts.add(IF);
parts.add("("); //$NON-NLS-1$
parts.add(registerNode(obj.getCondition()));
parts.add(")\n"); //$NON-NLS-1$
parts.add(registerNode(obj.getIfBlock()));
if(obj.hasElseBlock()) {
parts.add("\n"); //$NON-NLS-1$
- parts.add(SQLReservedWords.ELSE);
+ parts.add(ELSE);
parts.add("\n"); //$NON-NLS-1$
parts.add(registerNode(obj.getElseBlock()));
}
@@ -1389,19 +1394,19 @@
}
public void visit(HasCriteria obj) {
- parts.add( SQLReservedWords.HAS);
+ parts.add( HAS);
parts.add(SPACE);
parts.add(registerNode(obj.getSelector()));
}
public void visit(TranslateCriteria obj) {
- parts.add(SQLReservedWords.TRANSLATE);
+ parts.add(TRANSLATE);
parts.add(SPACE);
parts.add(registerNode(obj.getSelector()));
if(obj.hasTranslations()) {
parts.add(SPACE);
- parts.add(SQLReservedWords.WITH);
+ parts.add(WITH);
parts.add(SPACE);
parts.add("("); //$NON-NLS-1$
Iterator critIter = obj.getTranslations().iterator();
@@ -1441,29 +1446,29 @@
parts.add("<> "); //$NON-NLS-1$
break;
case CriteriaSelector.IN:
- parts.add(SQLReservedWords.IN);
+ parts.add(IN);
parts.add(SPACE);
break;
case CriteriaSelector.IS_NULL:
- parts.add(SQLReservedWords.IS);
+ parts.add(IS);
parts.add(SPACE);
- parts.add(SQLReservedWords.NULL);
+ parts.add(NULL);
parts.add(SPACE);
break;
case CriteriaSelector.LIKE:
- parts.add(SQLReservedWords.LIKE);
+ parts.add(LIKE);
parts.add(SPACE);
break;
case CriteriaSelector.BETWEEN:
- parts.add(SQLReservedWords.BETWEEN);
+ parts.add(BETWEEN);
parts.add(SPACE);
break;
}
- parts.add(SQLReservedWords.CRITERIA);
+ parts.add(CRITERIA);
if(obj.hasElements()) {
parts.add(SPACE);
- parts.add(SQLReservedWords.ON);
+ parts.add(ON);
parts.add(SPACE);
parts.add("("); //$NON-NLS-1$
@@ -1481,7 +1486,7 @@
public void visit(RaiseErrorStatement obj) {
Object parts[] = new Object[4];
- parts[0] = SQLReservedWords.ERROR;
+ parts[0] = ERROR;
parts[1] = SPACE;
parts[2] = registerNode(obj.getExpression());
parts[3] = ";"; //$NON-NLS-1$
@@ -1489,23 +1494,23 @@
}
public void visit(BreakStatement obj) {
- parts.add(SQLReservedWords.BREAK);
+ parts.add(BREAK);
parts.add(";"); //$NON-NLS-1$
}
public void visit(ContinueStatement obj) {
- parts.add(SQLReservedWords.CONTINUE);
+ parts.add(CONTINUE);
parts.add(";"); //$NON-NLS-1$
}
public void visit(LoopStatement obj) {
- parts.add(SQLReservedWords.LOOP);
+ parts.add(LOOP);
parts.add(" "); //$NON-NLS-1$
- parts.add(SQLReservedWords.ON);
+ parts.add(ON);
parts.add(" ("); //$NON-NLS-1$
parts.add(registerNode(obj.getCommand()));
parts.add(") "); //$NON-NLS-1$
- parts.add(SQLReservedWords.AS);
+ parts.add(AS);
parts.add(" "); //$NON-NLS-1$
parts.add(obj.getCursorName());
parts.add("\n"); //$NON-NLS-1$
@@ -1513,7 +1518,7 @@
}
public void visit(WhileStatement obj) {
- parts.add(SQLReservedWords.WHILE);
+ parts.add(WHILE);
parts.add("("); //$NON-NLS-1$
parts.add(registerNode(obj.getCondition()));
parts.add(")\n"); //$NON-NLS-1$
@@ -1522,7 +1527,7 @@
public void visit(ExistsCriteria obj) {
// operator and beginning of list
- parts.add(SQLReservedWords.EXISTS);
+ parts.add(EXISTS);
parts.add(" ("); //$NON-NLS-1$
parts.add(registerNode(obj.getCommand()));
parts.add(")"); //$NON-NLS-1$
@@ -1618,7 +1623,7 @@
}
public void visit(Limit obj) {
- parts.add(SQLReservedWords.LIMIT);
+ parts.add(LIMIT);
if (obj.getOffset() != null) {
parts.add(SPACE);
parts.add(registerNode(obj.getOffset()));
@@ -1660,7 +1665,7 @@
if (obj.getQuote() != null) {
parts.add(SPACE);
if (obj.isEscape()) {
- parts.add(SQLReservedWords.ESCAPE);
+ parts.add(ESCAPE);
} else {
parts.add(NonReserved.QUOTE);
}
@@ -1683,7 +1688,7 @@
}
parts.add(")");//$NON-NLS-1$
parts.add(SPACE);
- parts.add(SQLReservedWords.AS);
+ parts.add(AS);
parts.add(SPACE);
outputDisplayName(obj.getName());
}
@@ -1712,7 +1717,7 @@
outputDisplayName(col.getName());
parts.add(SPACE);
if (col.isOrdinal()) {
- parts.add(SQLReservedWords.FOR);
+ parts.add(FOR);
parts.add(SPACE);
parts.add(NonReserved.ORDINALITY);
} else {
@@ -1725,7 +1730,7 @@
}
if (col.getDefaultExpression() != null) {
parts.add(SPACE);
- parts.add(SQLReservedWords.DEFAULT);
+ parts.add(DEFAULT);
parts.add(SPACE);
parts.add(registerNode(col.getDefaultExpression()));
}
@@ -1737,17 +1742,57 @@
}
parts.add(")");//$NON-NLS-1$
parts.add(SPACE);
- parts.add(SQLReservedWords.AS);
+ parts.add(AS);
parts.add(SPACE);
outputDisplayName(obj.getName());
}
@Override
+ public void visit(XMLQuery obj) {
+ parts.add("XMLQUERY("); //$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.getReturningContent() != null) {
+ parts.add(SPACE);
+ parts.add(NonReserved.RETURNING);
+ parts.add(SPACE);
+ if (obj.getReturningContent()) {
+ parts.add(NonReserved.CONTENT);
+ } else {
+ parts.add(NonReserved.SEQUENCE);
+ if (obj.getEmptyOnEmpty() != null) {
+ parts.add(SPACE);
+ if (obj.getEmptyOnEmpty()) {
+ parts.add(NonReserved.EMPTY);
+ } else {
+ parts.add(NULL);
+ }
+ parts.add(SPACE);
+ parts.add(ON);
+ parts.add(SPACE);
+ parts.add(NonReserved.EMPTY);
+ }
+ }
+ }
+ parts.add(")");//$NON-NLS-1$
+ }
+
+ @Override
public void visit(DerivedColumn obj) {
parts.add(registerNode(obj.getExpression()));
if (obj.getAlias() != null) {
parts.add(SPACE);
- parts.add(SQLReservedWords.AS);
+ parts.add(AS);
parts.add(SPACE);
outputDisplayName(obj.getAlias());
}
@@ -1755,22 +1800,22 @@
@Override
public void visit(XMLSerialize obj) {
- parts.add(SQLReservedWords.XMLSERIALIZE);
- parts.add(SQLReservedWords.Tokens.LPAREN);
+ parts.add(XMLSERIALIZE);
+ parts.add(Tokens.LPAREN);
if (obj.isDocument()) {
- parts.add(SQLReservedWords.NonReserved.DOCUMENT);
+ parts.add(NonReserved.DOCUMENT);
} else {
- parts.add(SQLReservedWords.NonReserved.CONTENT);
+ parts.add(NonReserved.CONTENT);
}
parts.add(SPACE);
parts.add(registerNode(obj.getExpression()));
if (obj.getTypeString() != null) {
parts.add(SPACE);
- parts.add(SQLReservedWords.AS);
+ parts.add(AS);
parts.add(SPACE);
parts.add(obj.getTypeString());
}
- parts.add(SQLReservedWords.Tokens.RPAREN);
+ parts.add(Tokens.RPAREN);
}
public static String escapeSinglePart(String part) {
@@ -1802,7 +1847,7 @@
if(string == null) {
return false;
}
- return SQLReservedWords.isReservedWord(string);
+ return SQLConstants.isReservedWord(string);
}
}
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-06 15:12:19 UTC (rev 2185)
+++ trunk/engine/src/main/java/org/teiid/query/validator/AggregateValidationVisitor.java 2010-06-07 16:27:14 UTC (rev 2186)
@@ -26,8 +26,8 @@
import java.util.Set;
import org.teiid.core.types.DataTypeManager;
-import org.teiid.language.SQLReservedWords;
-import org.teiid.language.SQLReservedWords.NonReserved;
+import org.teiid.language.SQLConstants.NonReserved;
+import org.teiid.language.SQLConstants.Reserved;
import org.teiid.query.QueryPlugin;
import org.teiid.query.sql.LanguageObject;
import org.teiid.query.sql.navigator.PreOrderNavigator;
@@ -75,7 +75,7 @@
String aggregateFunction = obj.getAggregateFunction();
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) {
+ } else if (aggregateFunction.equals(Reserved.XMLAGG) && obj.getType() != DataTypeManager.DefaultDataClasses.XML) {
handleValidationError(QueryPlugin.Util.getString("AggregateValidationVisitor.non_xml", new Object[] {aggregateFunction, obj}), obj); //$NON-NLS-1$
}
if((obj.isDistinct() || aggregateFunction.equals(NonReserved.MIN) || aggregateFunction.equals(NonReserved.MAX)) && DataTypeManager.isNonComparable(DataTypeManager.getDataTypeName(aggExp.getType()))) {
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-06 15:12:19 UTC (rev 2185)
+++ trunk/engine/src/main/java/org/teiid/query/validator/ValidationVisitor.java 2010-06-07 16:27:14 UTC (rev 2186)
@@ -106,6 +106,7 @@
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.symbol.XMLQuery;
import org.teiid.query.sql.util.SymbolMap;
import org.teiid.query.sql.visitor.AggregateSymbolCollectorVisitor;
import org.teiid.query.sql.visitor.CommandCollectorVisitor;
@@ -117,6 +118,7 @@
import org.teiid.query.sql.visitor.SQLStringVisitor;
import org.teiid.query.sql.visitor.ValueIteratorProviderCollectorVisitor;
import org.teiid.query.util.ErrorMessageKeys;
+import org.teiid.query.xquery.saxon.SaxonXQueryExpression;
import org.teiid.translator.SourceSystemFunctions;
public class ValidationVisitor extends AbstractValidationVisitor {
@@ -1156,10 +1158,34 @@
@Override
public void visit(XMLTable obj) {
- boolean context = false;
+ List<DerivedColumn> passing = obj.getPassing();
+ validatePassing(obj, obj.getXQueryExpression(), passing);
+ 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(XMLQuery obj) {
+ validatePassing(obj, obj.getXQueryExpression(), obj.getPassing());
+ }
+
+ private void validatePassing(LanguageObject obj, SaxonXQueryExpression xqe, List<DerivedColumn> passing) {
+ boolean context = false;
boolean hadError = false;
HashSet<String> names = new HashSet<String>();
- for (DerivedColumn dc : obj.getPassing()) {
+ for (DerivedColumn dc : passing) {
if (dc.getAlias() == null) {
Class<?> type = dc.getExpression().getType();
if (type != DataTypeManager.DefaultDataClasses.XML &&
@@ -1175,29 +1201,14 @@
handleValidationError(QueryPlugin.Util.getString("ValidationVisitor.duplicate_passing", dc.getAlias()), obj); //$NON-NLS-1$
}
}
- if (obj.getXQueryExpression().usesContextItem() && !context) {
+ if (xqe.usesContextItem() && !context) {
handleValidationError(QueryPlugin.Util.getString("ValidationVisitor.context_required"), 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$
@@ -1205,15 +1216,11 @@
}
continue;
}
- if (hasDefault || noDefault) {
+ if (hasDefault) {
handleValidationError(QueryPlugin.Util.getString("ValidationVisitor.xml_namespaces"), obj); //$NON-NLS-1$
break;
}
- if (item.getUri() == null) {
- noDefault = true;
- } else {
- hasDefault = true;
- }
+ hasDefault = true;
}
}
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-06 15:12:19 UTC (rev 2185)
+++ trunk/engine/src/main/java/org/teiid/query/xquery/saxon/SaxonXQueryExpression.java 2010-06-07 16:27:14 UTC (rev 2186)
@@ -121,11 +121,10 @@
};
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 {
+ throws QueryResolverException {
config.setErrorListener(ERROR_LISTENER);
StaticQueryContext context = new StaticQueryContext(config);
IndependentContext ic = new IndependentContext(config);
@@ -153,6 +152,7 @@
try {
context.declareGlobalVariable(StructuredQName.fromClarkName(derivedColumn.getAlias()), SequenceType.ANY_SEQUENCE, null, true);
} catch (XPathException e) {
+ //this is always expected to work
throw new TeiidRuntimeException(e, "Could not define global variable"); //$NON-NLS-1$
}
}
@@ -170,7 +170,7 @@
return this.xQuery.usesContextItem();
}
- public void useDocumentProjection(List<XMLTable.XMLColumn> columns, AnalysisRecord record) {
+ public PathMapRoot useDocumentProjection(List<XMLTable.XMLColumn> columns, AnalysisRecord record) {
PathMap map = this.xQuery.getPathMap();
PathMapRoot parentRoot;
try {
@@ -179,7 +179,7 @@
if (record.recordDebug()) {
record.println("Document projection will not be used, since multiple context item exist."); //$NON-NLS-1$
}
- return;
+ return null;
}
if (parentRoot == null) {
//TODO: this seems like we could omit the context item altogether
@@ -187,7 +187,7 @@
if (record.recordDebug()) {
record.println("Document projection will not be used, since no context item reference was found in the XQuery"); //$NON-NLS-1$
}
- return;
+ return null;
}
HashSet<PathMapNode> finalNodes = new HashSet<PathMapNode>();
getReturnableNodes(parentRoot, finalNodes);
@@ -198,11 +198,11 @@
if (record.recordDebug()) {
record.println("Document projection will not be used, since multiple return items exist"); //$NON-NLS-1$
}
- return;
+ return null;
}
parentRoot = projectColumns(parentRoot, columns, finalNodes.iterator().next(), record);
if (parentRoot == null) {
- return;
+ return null;
}
} else {
for (Iterator iter = finalNodes.iterator(); iter.hasNext(); ) {
@@ -215,14 +215,14 @@
if (record.recordDebug()) {
record.println("Document projection will not be used since there are unknown dependencies (most likely a user defined function)."); //$NON-NLS-1$
}
- return;
+ return null;
}
- contextRoot = parentRoot;
if (record.recordDebug()) {
StringBuilder sb = new StringBuilder();
- showArcs(sb, contextRoot, 0);
+ showArcs(sb, parentRoot, 0);
record.println("Using path filtering for XQuery context item: \n" + sb.toString()); //$NON-NLS-1$
}
+ return parentRoot;
}
private PathMapRoot projectColumns(PathMapRoot parentRoot, List<XMLTable.XMLColumn> columns, PathMapNode finalNode, AnalysisRecord record) {
@@ -299,7 +299,7 @@
}
private void processColumns(List<XMLTable.XMLColumn> columns, IndependentContext ic)
- throws TeiidProcessingException {
+ throws QueryResolverException {
if (columns == null) {
return;
}
@@ -314,14 +314,18 @@
path = xmlColumn.getName();
}
path = path.trim();
- if (path.startsWith("/") && !path.startsWith("//")) { //$NON-NLS-1$ //$NON-NLS-2$
- path = path.substring(1);
+ if (path.startsWith("/")) { //$NON-NLS-1$
+ if (path.startsWith("//")) { //$NON-NLS-1$
+ path = '.' + path;
+ } else {
+ path = path.substring(1);
+ }
}
XPathExpression exp;
try {
exp = eval.createExpression(path);
} catch (XPathException e) {
- throw new TeiidProcessingException(e, "Invalid path expression");
+ throw new QueryResolverException(e, QueryPlugin.Util.getString("SaxonXQueryExpression.invalid_path", xmlColumn.getName(), xmlColumn.getPath())); //$NON-NLS-1$
}
xmlColumn.setPathExpression(exp);
}
@@ -344,7 +348,7 @@
throw new AssertionError("Unknown type"); //$NON-NLS-1$
}
- public SequenceIterator evaluateXQuery(Object context, Map<String, Object> parameterValues) throws TeiidProcessingException {
+ public SequenceIterator evaluateXQuery(Object context, PathMapRoot contextRoot, Map<String, Object> parameterValues) throws TeiidProcessingException {
DynamicQueryContext dynamicContext = new DynamicQueryContext(config);
for (Map.Entry<String, Object> entry : parameterValues.entrySet()) {
@@ -368,7 +372,7 @@
try {
doc = config.buildDocument(source);
} catch (XPathException e) {
- throw new TeiidProcessingException(e);
+ throw new TeiidProcessingException(e, QueryPlugin.Util.getString("SaxonXQueryExpression.bad_context")); //$NON-NLS-1$
}
dynamicContext.setContextItem(doc);
}
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-06 15:12:19 UTC (rev 2185)
+++ trunk/engine/src/main/javacc/org/teiid/query/parser/SQLParser.jj 2010-06-07 16:27:14 UTC (rev 2186)
@@ -361,6 +361,7 @@
| < TIMETYPE: "{" "t" >
| < TIMESTAMPTYPE: "{" "ts" >
| < BOOLEANTYPE: "{" "b" >
+| < XMLTYPE: "{" "x" >
| < INTEGERVAL: (<MINUS>)?(<DIGIT>)+ >
| < FLOATVAL: (<MINUS>)? (<DIGIT>)* <PERIOD> (<DIGIT>)+
@@ -2027,6 +2028,61 @@
}
}
+XMLQuery xmlQuery(ParseInfo info) :
+{
+ String xquery = null;
+ XMLNamespaces xmlNamespaces = null;
+ DerivedColumn passing = null;
+ ArrayList<DerivedColumn> passingValues = new ArrayList<DerivedColumn>();
+ Boolean content = null;
+ Boolean empty = 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>, { "returning".equalsIgnoreCase(getToken(1).image) }) <ID>
+ (
+ LOOKAHEAD(<ID>, { "content".equalsIgnoreCase(getToken(1).image) }) <ID> { content = true; }
+ |
+ LOOKAHEAD(<ID>, { "sequence".equalsIgnoreCase(getToken(1).image) }) (<ID> { content = false; }
+ [
+ (<NULL> { empty = false; }
+ |
+ nonReserved("EMPTY") { empty = true; }
+ )
+ <ON> nonReserved("EMPTY")
+ ])
+ )
+ ]
+ <RPAREN>
+ {
+ XMLQuery result = new XMLQuery();
+ result.setXquery(xquery);
+ result.setNamespaces(xmlNamespaces);
+ result.setPassing(passingValues);
+ result.setEmptyOnEmpty(empty);
+ result.setReturningContent(content);
+ return result;
+ }
+}
+
XMLTable xmlTable(ParseInfo info) :
{
String xquery = null;
@@ -3283,7 +3339,11 @@
{
return expression;
}
- |
+ | LOOKAHEAD(<ID>, { "xmlQuery".equalsIgnoreCase(getToken(1).image) }) expression = xmlQuery(info)
+ {
+ return expression;
+ }
+ |
( funcName = id()
{
funcName = validateFunctionName(funcName);
@@ -3578,7 +3638,8 @@
( (<BOOLEANTYPE> { escapeType=DataTypeManager.DefaultDataClasses.BOOLEAN; } |
<TIMESTAMPTYPE> { escapeType=DataTypeManager.DefaultDataClasses.TIMESTAMP; } |
<DATETYPE> { escapeType=DataTypeManager.DefaultDataClasses.DATE; } |
- <TIMETYPE> { escapeType=DataTypeManager.DefaultDataClasses.TIME; }) strVal=stringVal() {
+ <TIMETYPE> { escapeType=DataTypeManager.DefaultDataClasses.TIME; } |
+ <XMLTYPE> { escapeType=DataTypeManager.DefaultDataClasses.XML; }) strVal=stringVal() {
try {
constant = new Constant(DataTypeManager.transformValue(strVal, escapeType), escapeType);
} catch (TransformationException e) {
Modified: trunk/engine/src/main/resources/org/teiid/query/execution/i18n.properties
===================================================================
--- trunk/engine/src/main/resources/org/teiid/query/execution/i18n.properties 2010-06-06 15:12:19 UTC (rev 2185)
+++ trunk/engine/src/main/resources/org/teiid/query/execution/i18n.properties 2010-06-07 16:27:14 UTC (rev 2186)
@@ -216,3 +216,7 @@
TextTableNode.character_not_allowed=Text parse error: Non-whitespace character found between the qualifier and the delimiter in text line {0}.
TextTableNode.unknown_escape=Text parse error: Unknown escape sequence \\{0} in text line {1}.
TextTableNode.invalid_width=Text parse error: Fixed width line width {0} is smaller than the expected {1} on text line {2}
+
+XMLTableNode.error=Error evaluating XQuery row context for XMLTable: {0}
+XMLTableNode.path_error=Error evaluating XMLTable column path expression for column: {0}
+XMLTableName.multi_value=Unexpected multi-valued result was returned for XMLTable column "{0}". Path expressions for non-XML type columns should return at most a single result.
Modified: trunk/engine/src/main/resources/org/teiid/query/i18n.properties
===================================================================
--- trunk/engine/src/main/resources/org/teiid/query/i18n.properties 2010-06-06 15:12:19 UTC (rev 2185)
+++ trunk/engine/src/main/resources/org/teiid/query/i18n.properties 2010-06-07 16:27:14 UTC (rev 2186)
@@ -815,8 +815,11 @@
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}
+Evaluator.xmlserialize=XMLSerialize: data exception - not an xml document
+Evaluator.xmlquery=Error evaluating XMLQuery: {0}
+Evaluator.xmlquery_content=XQuery evaluation was expected to return content, but it returned a sequence.
+Evaluator.xmlquery_content_empty=XQuery evaluation was expected to return content, but was empty.
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}
@@ -897,6 +900,7 @@
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}"
+ValidationVisitor.context_required=The XQuery requires a context item, but none exists in the PASSING clause.
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.
@@ -909,6 +913,8 @@
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.
+SaxonXQueryExpression.invalid_path=Column "{0}" has an invalid path expression: {1}
+SaxonXQueryExpression.bad_context=Error building Source for context item.
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-06 15:12:19 UTC (rev 2185)
+++ trunk/engine/src/test/java/org/teiid/dqp/internal/datamgr/language/TestAggregateImpl.java 2010-06-07 16:27:14 UTC (rev 2186)
@@ -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.NonReserved;
+import org.teiid.language.SQLConstants.NonReserved;
import org.teiid.query.sql.symbol.AggregateSymbol;
import org.teiid.query.sql.symbol.Constant;
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-06 15:12:19 UTC (rev 2185)
+++ trunk/engine/src/test/java/org/teiid/query/function/TestFunction.java 2010-06-07 16:27:14 UTC (rev 2186)
@@ -34,7 +34,7 @@
import org.junit.Test;
import org.teiid.api.exception.query.FunctionExecutionException;
-import org.teiid.language.SQLReservedWords.NonReserved;
+import org.teiid.language.SQLConstants.NonReserved;
import org.teiid.query.function.FunctionMethods;
import org.teiid.query.sql.symbol.Constant;
import org.teiid.query.unittest.TimestampUtil;
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-06 15:12:19 UTC (rev 2185)
+++ trunk/engine/src/test/java/org/teiid/query/function/TestFunctionLibrary.java 2010-06-07 16:27:14 UTC (rev 2186)
@@ -47,7 +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.NonReserved;
+import org.teiid.language.SQLConstants.NonReserved;
import org.teiid.query.function.metadata.FunctionMethod;
import org.teiid.query.unittest.TimestampUtil;
import org.teiid.query.util.CommandContext;
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-06 15:12:19 UTC (rev 2185)
+++ trunk/engine/src/test/java/org/teiid/query/optimizer/relational/rules/TestCapabilitiesUtil.java 2010-06-07 16:27:14 UTC (rev 2186)
@@ -27,7 +27,7 @@
import org.teiid.api.exception.query.QueryMetadataException;
import org.teiid.core.TeiidComponentException;
-import org.teiid.language.SQLReservedWords.NonReserved;
+import org.teiid.language.SQLConstants.NonReserved;
import org.teiid.query.optimizer.capabilities.BasicSourceCapabilities;
import org.teiid.query.optimizer.capabilities.DefaultCapabilitiesFinder;
import org.teiid.query.optimizer.capabilities.FakeCapabilitiesFinder;
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-06 15:12:19 UTC (rev 2185)
+++ trunk/engine/src/test/java/org/teiid/query/parser/TestParser.java 2010-06-07 16:27:14 UTC (rev 2186)
@@ -38,7 +38,7 @@
import org.teiid.client.metadata.ParameterInfo;
import org.teiid.core.TeiidException;
import org.teiid.core.types.DataTypeManager;
-import org.teiid.language.SQLReservedWords;
+import org.teiid.language.SQLConstants.Reserved;
import org.teiid.query.sql.lang.BetweenCriteria;
import org.teiid.query.sql.lang.Command;
import org.teiid.query.sql.lang.CompareCriteria;
@@ -114,6 +114,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.XMLQuery;
import org.teiid.query.sql.symbol.XMLSerialize;
@SuppressWarnings("nls")
@@ -6741,7 +6742,7 @@
@Test public void testXmlAggWithOrderBy() throws Exception {
String sql = "SELECT xmlAgg(1 order by e2)"; //$NON-NLS-1$
- AggregateSymbol as = new AggregateSymbol("foo", SQLReservedWords.XMLAGG, false, new Constant(1));
+ AggregateSymbol as = new AggregateSymbol("foo", Reserved.XMLAGG, false, new Constant(1));
as.setOrderBy(new OrderBy(Arrays.asList(new ElementSymbol("e2"))));
Query query = new Query();
query.setSelect(new Select(Arrays.asList(as)));
@@ -6813,5 +6814,14 @@
f.setTypeString("CLOB");
helpTestExpression("xmlserialize(document x as CLOB)", "XMLSERIALIZE(DOCUMENT x AS CLOB)", f);
}
+
+ @Test public void testXmlQuery() throws Exception {
+ XMLQuery f = new XMLQuery();
+ f.setXquery("/x");
+ f.setEmptyOnEmpty(false);
+ f.setReturningContent(false);
+ f.setPassing(Arrays.asList(new DerivedColumn(null, new ElementSymbol("foo"))));
+ helpTestExpression("xmlquery('/x' passing foo returning sequence null on empty)", "XMLQUERY('/x' PASSING foo RETURNING SEQUENCE NULL ON EMPTY)", f);
+ }
}
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-06 15:12:19 UTC (rev 2185)
+++ trunk/engine/src/test/java/org/teiid/query/processor/TestSQLXMLProcessing.java 2010-06-07 16:27:14 UTC (rev 2186)
@@ -27,8 +27,8 @@
import java.util.Arrays;
import java.util.List;
-import org.junit.Ignore;
import org.junit.Test;
+import org.teiid.core.TeiidProcessingException;
import org.teiid.query.unittest.FakeMetadataFactory;
@SuppressWarnings({"nls", "unchecked"})
@@ -294,12 +294,14 @@
helpProcess(plan, dataManager, expected);
}
- @Ignore
- @Test public void testXmlTableForOrdinality() {
- String sql = "select * from xmltable('/a/b' passing convert('<a><b><c>1</c></b><b>1</b><b><c>1</c></b><b>1</b></a>', xml) as a columns x for ordinality, c integer path '.') as x"; //$NON-NLS-1$
+ @Test public void testXmlTableForOrdinalityAndDefaultPath() {
+ String sql = "select * from xmltable('/a/b' passing convert('<a><b><c>1</c></b><b>1</b><b><c>1</c></b><b>1</b></a>', xml) columns x for ordinality, c integer) as x"; //$NON-NLS-1$
List<?>[] expected = new List<?>[] {
- Arrays.asList("<b>first</b>"),
+ Arrays.asList(1, 1),
+ Arrays.asList(2, null),
+ Arrays.asList(3, 1),
+ Arrays.asList(4, null),
};
FakeDataManager dataManager = new FakeDataManager();
@@ -309,5 +311,78 @@
helpProcess(plan, dataManager, expected);
}
+
+ @Test public void testXmlTableDescendantPath() {
+ String sql = "select * from xmltable('<a>{for $i in (1 to 5) return $i}</a>' columns x string path '//text()') as x"; //$NON-NLS-1$
+
+ List<?>[] expected = new List<?>[] {
+ Arrays.asList("1 2 3 4 5"),
+ };
+
+ FakeDataManager dataManager = new FakeDataManager();
+ sampleData1(dataManager);
+
+ ProcessorPlan plan = helpGetPlan(helpParse(sql), FakeMetadataFactory.example1Cached());
+
+ helpProcess(plan, dataManager, expected);
+ }
+ @Test public void testXmlQuery() {
+ String sql = "select xmlquery('for $i in (1 to 5) return $i' returning sequence)"; //$NON-NLS-1$
+
+ List<?>[] expected = new List<?>[] {
+ Arrays.asList("1 2 3 4 5"),
+ };
+
+ FakeDataManager dataManager = new FakeDataManager();
+ sampleData1(dataManager);
+
+ ProcessorPlan plan = helpGetPlan(helpParse(sql), FakeMetadataFactory.example1Cached());
+
+ helpProcess(plan, dataManager, expected);
+ }
+
+ @Test(expected=TeiidProcessingException.class) public void testXmlQueryContentError() throws Exception {
+ String sql = "select xmlquery('for $i in $e1 return $i' passing e1 as e1) from pm1.g1 order by e1 limit 1"; //$NON-NLS-1$
+
+ List<?>[] expected = new List<?>[] {
+ };
+
+ FakeDataManager dataManager = new FakeDataManager();
+ sampleData1(dataManager);
+
+ ProcessorPlan plan = helpGetPlan(helpParse(sql), FakeMetadataFactory.example1Cached());
+
+ helpProcess(plan, createCommandContext(), dataManager, expected);
+ }
+
+ @Test(expected=TeiidProcessingException.class) public void testXmlQueryEmpty() throws Exception {
+ String sql = "select xmlquery('/a' passing xmlelement(x, e1)) from pm1.g1 order by e1 limit 1"; //$NON-NLS-1$
+
+ List<?>[] expected = new List<?>[] {
+ };
+
+ FakeDataManager dataManager = new FakeDataManager();
+ sampleData1(dataManager);
+
+ ProcessorPlan plan = helpGetPlan(helpParse(sql), FakeMetadataFactory.example1Cached());
+
+ helpProcess(plan, createCommandContext(), dataManager, expected);
+ }
+
+ @Test public void testXmlQueryEmptyNull() throws Exception {
+ String sql = "select xmlquery('/a' passing {x '<x/>'} returning sequence null on empty)"; //$NON-NLS-1$
+
+ List<?>[] expected = new List<?>[] {
+ Arrays.asList((String)null)
+ };
+
+ FakeDataManager dataManager = new FakeDataManager();
+ sampleData1(dataManager);
+
+ ProcessorPlan plan = helpGetPlan(helpParse(sql), FakeMetadataFactory.example1Cached());
+
+ helpProcess(plan, createCommandContext(), dataManager, expected);
+ }
+
}
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-06 15:12:19 UTC (rev 2185)
+++ trunk/engine/src/test/java/org/teiid/query/sql/symbol/TestAggregateSymbol.java 2010-06-07 16:27:14 UTC (rev 2186)
@@ -25,7 +25,7 @@
import junit.framework.TestCase;
import org.teiid.core.util.UnitTestUtil;
-import org.teiid.language.SQLReservedWords.NonReserved;
+import org.teiid.language.SQLConstants.NonReserved;
import org.teiid.query.sql.symbol.AggregateSymbol;
import org.teiid.query.sql.symbol.Constant;
import org.teiid.query.sql.symbol.ElementSymbol;
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-06 15:12:19 UTC (rev 2185)
+++ trunk/engine/src/test/java/org/teiid/query/sql/visitor/TestExpressionMappingVisitor.java 2010-06-07 16:27:14 UTC (rev 2186)
@@ -31,7 +31,7 @@
import java.util.Map;
import org.junit.Test;
-import org.teiid.language.SQLReservedWords.NonReserved;
+import org.teiid.language.SQLConstants.NonReserved;
import org.teiid.query.sql.LanguageObject;
import org.teiid.query.sql.lang.CompareCriteria;
import org.teiid.query.sql.lang.Select;
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-06 15:12:19 UTC (rev 2185)
+++ trunk/engine/src/test/java/org/teiid/query/sql/visitor/TestSQLStringVisitor.java 2010-06-07 16:27:14 UTC (rev 2186)
@@ -31,7 +31,7 @@
import org.teiid.client.metadata.ParameterInfo;
import org.teiid.core.types.DataTypeManager;
-import org.teiid.language.SQLReservedWords.NonReserved;
+import org.teiid.language.SQLConstants.NonReserved;
import org.teiid.query.parser.QueryParser;
import org.teiid.query.resolver.QueryResolver;
import org.teiid.query.sql.LanguageObject;
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-06 15:12:19 UTC (rev 2185)
+++ trunk/engine/src/test/java/org/teiid/query/validator/TestValidator.java 2010-06-07 16:27:14 UTC (rev 2186)
@@ -1999,12 +1999,12 @@
}
@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());
+ helpValidate("select * from pm1.g1, xmltable('/' passing {x '<a/>'}, {x '<b/>'}) as x", new String[] {"XMLTABLE('/' PASSING {x '<a/>'}, {x '<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());
+ helpValidate("select * from pm1.g1, xmltable('/' passing {x '<a/>'} as a, {x '<b/>'} as a) as x", new String[] {"xmltable('/' passing e1, e1 || 'x') as x"}, FakeMetadataFactory.example1Cached());
}
@Test public void testXMLTablePassingContextType() {
@@ -2012,7 +2012,15 @@
}
@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());
+ helpValidate("select * from pm1.g1, xmltable('/' passing {x '<a/>'} columns x for ordinality, y for ordinality) as x", new String[] {"XMLTABLE('/' PASSING {x '<a/>'} COLUMNS x FOR ORDINALITY, y FOR ORDINALITY) AS x"}, FakeMetadataFactory.example1Cached());
}
+
+ @Test public void testXMLTableContextRequired() {
+ helpValidate("select * from xmltable('/a/b' passing convert('<a/>', xml) as a columns x for ordinality, c integer path '.') as x", new String[] {"XMLTABLE('/a/b' PASSING convert('<a/>', xml) AS a COLUMNS x FOR ORDINALITY, c integer PATH '.') AS x"}, FakeMetadataFactory.example1Cached());
+ }
+ @Test public void testXMLQueryPassingContextType() {
+ helpValidate("select xmlquery('/' passing 2)", new String[] {"XMLQUERY('/' PASSING 2)"}, FakeMetadataFactory.example1Cached());
+ }
+
}
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-06 15:12:19 UTC (rev 2185)
+++ trunk/test-integration/common/src/test/java/org/teiid/connector/visitor/util/TestSQLStringVisitor.java 2010-06-07 16:27:14 UTC (rev 2186)
@@ -66,7 +66,7 @@
import org.teiid.language.LanguageObject;
import org.teiid.language.Literal;
import org.teiid.language.Select;
-import org.teiid.language.SQLReservedWords.NonReserved;
+import org.teiid.language.SQLConstants.NonReserved;
import org.teiid.language.visitor.SQLStringVisitor;
import org.teiid.metadata.RuntimeMetadata;
import org.teiid.query.sql.lang.CompareCriteria;
14 years, 6 months
teiid SVN: r2185 - in trunk/engine/src: main/java/org/teiid/query/processor/relational and 8 other directories.
by teiid-commits@lists.jboss.org
Author: shawkins
Date: 2010-06-06 11:12:19 -0400 (Sun, 06 Jun 2010)
New Revision: 2185
Added:
trunk/engine/src/test/java/org/teiid/query/xquery/saxon/
trunk/engine/src/test/java/org/teiid/query/xquery/saxon/TestSaxonXQueryExpression.java
Modified:
trunk/engine/src/main/java/org/teiid/query/optimizer/relational/PlanToProcessConverter.java
trunk/engine/src/main/java/org/teiid/query/processor/relational/RelationalNode.java
trunk/engine/src/main/java/org/teiid/query/processor/relational/SubqueryAwareRelationalNode.java
trunk/engine/src/main/java/org/teiid/query/processor/relational/TextTableNode.java
trunk/engine/src/main/java/org/teiid/query/processor/relational/XMLTableNode.java
trunk/engine/src/main/java/org/teiid/query/rewriter/QueryRewriter.java
trunk/engine/src/main/java/org/teiid/query/sql/lang/XMLTable.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/resources/org/teiid/query/i18n.properties
trunk/engine/src/test/java/org/teiid/query/processor/TestSQLXMLProcessing.java
Log:
TEIID-1087 TEIID-171 refining 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.
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-05 01:49:35 UTC (rev 2184)
+++ trunk/engine/src/main/java/org/teiid/query/optimizer/relational/PlanToProcessConverter.java 2010-06-06 15:12:19 UTC (rev 2185)
@@ -22,9 +22,11 @@
package org.teiid.query.optimizer.relational;
+import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;
+import java.util.Map;
import org.teiid.api.exception.query.QueryMetadataException;
import org.teiid.api.exception.query.QueryPlannerException;
@@ -69,6 +71,7 @@
import org.teiid.query.processor.relational.SortNode;
import org.teiid.query.processor.relational.TextTableNode;
import org.teiid.query.processor.relational.UnionAllNode;
+import org.teiid.query.processor.relational.XMLTableNode;
import org.teiid.query.processor.relational.JoinNode.JoinStrategyType;
import org.teiid.query.processor.relational.MergeJoinStrategy.SortOption;
import org.teiid.query.processor.relational.SortUtility.Mode;
@@ -83,6 +86,7 @@
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.lang.XMLTable.XMLColumn;
import org.teiid.query.sql.symbol.ElementSymbol;
import org.teiid.query.sql.symbol.Expression;
import org.teiid.query.sql.symbol.GroupSymbol;
@@ -369,15 +373,30 @@
}
Object source = node.getProperty(NodeConstants.Info.TABLE_FUNCTION);
if (source instanceof XMLTable) {
- return null;
+ XMLTable xt = (XMLTable)source;
+ XMLTableNode xtn = new XMLTableNode(getID());
+ //we handle the projection filtering once here rather than repeating the
+ //path analysis on a per plan basis
+ Map elementMap = RelationalNode.createLookupMap(xt.getProjectedSymbols());
+ List cols = (List) node.getProperty(NodeConstants.Info.OUTPUT_COLS);
+ int[] projectionIndexes = RelationalNode.getProjectionIndexes(elementMap, cols);
+ ArrayList<XMLColumn> filteredColumns = new ArrayList<XMLColumn>(projectionIndexes.length);
+ for (int col : projectionIndexes) {
+ filteredColumns.add(xt.getColumns().get(col));
+ }
+ xt.getXQueryExpression().useDocumentProjection(filteredColumns, analysisRecord);
+ xtn.setProjectedColumns(filteredColumns);
+ xtn.setTable(xt);
+ processNode = xtn;
+ break;
}
- if (!(source instanceof TextTable)) {
- return null;
+ if (source instanceof TextTable) {
+ TextTableNode ttn = new TextTableNode(getID());
+ ttn.setTable((TextTable)source);
+ processNode = ttn;
+ break;
}
- TextTableNode ttn = new TextTableNode(getID());
- ttn.setTable((TextTable)source);
- processNode = ttn;
- break;
+ return null;
case NodeConstants.Types.SET_OP:
Operation setOp = (Operation) node.getProperty(NodeConstants.Info.SET_OPERATION);
boolean useAll = ((Boolean) node.getProperty(NodeConstants.Info.USE_ALL)).booleanValue();
Modified: trunk/engine/src/main/java/org/teiid/query/processor/relational/RelationalNode.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/processor/relational/RelationalNode.java 2010-06-05 01:49:35 UTC (rev 2184)
+++ trunk/engine/src/main/java/org/teiid/query/processor/relational/RelationalNode.java 2010-06-06 15:12:19 UTC (rev 2185)
@@ -338,7 +338,7 @@
/**
* Helper method for all the node that will filter the elements needed for the next node.
*/
- protected int[] getProjectionIndexes(Map<SingleElementSymbol, Integer> tupleElements, List<SingleElementSymbol> projectElements) {
+ public static int[] getProjectionIndexes(Map<SingleElementSymbol, Integer> tupleElements, List<SingleElementSymbol> projectElements) {
int[] result = new int[projectElements.size()];
int i = 0;
Modified: trunk/engine/src/main/java/org/teiid/query/processor/relational/SubqueryAwareRelationalNode.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/processor/relational/SubqueryAwareRelationalNode.java 2010-06-05 01:49:35 UTC (rev 2184)
+++ trunk/engine/src/main/java/org/teiid/query/processor/relational/SubqueryAwareRelationalNode.java 2010-06-06 15:12:19 UTC (rev 2185)
@@ -22,9 +22,16 @@
package org.teiid.query.processor.relational;
+import java.util.Collections;
import java.util.Map;
+import org.teiid.api.exception.query.ExpressionEvaluationException;
+import org.teiid.common.buffer.BlockedException;
+import org.teiid.core.TeiidComponentException;
import org.teiid.query.eval.Evaluator;
+import org.teiid.query.sql.lang.TableFunctionReference;
+import org.teiid.query.sql.symbol.ElementSymbol;
+import org.teiid.query.sql.symbol.Expression;
public abstract class SubqueryAwareRelationalNode extends RelationalNode {
@@ -57,5 +64,14 @@
evaluator.close();
}
}
+
+ protected void setReferenceValues(TableFunctionReference ref) throws ExpressionEvaluationException, BlockedException, TeiidComponentException {
+ if (ref.getCorrelatedReferences() == null) {
+ return;
+ }
+ for (Map.Entry<ElementSymbol, Expression> entry : ref.getCorrelatedReferences().asMap().entrySet()) {
+ getContext().getVariableContext().setValue(entry.getKey(), getEvaluator(Collections.emptyMap()).evaluate(entry.getValue(), null));
+ }
+ }
}
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-05 01:49:35 UTC (rev 2184)
+++ trunk/engine/src/main/java/org/teiid/query/processor/relational/TextTableNode.java 2010-06-06 15:12:19 UTC (rev 2185)
@@ -43,6 +43,7 @@
import org.teiid.core.types.TransformationException;
import org.teiid.query.execution.QueryExecPlugin;
import org.teiid.query.processor.ProcessorDataManager;
+import org.teiid.query.sql.lang.TableFunctionReference;
import org.teiid.query.sql.lang.TextTable;
import org.teiid.query.sql.lang.TextTable.TextColumn;
import org.teiid.query.sql.symbol.ElementSymbol;
@@ -69,7 +70,6 @@
private char quote;
private char delimiter;
private int lineWidth;
- private Map elementMap;
private int[] projectionIndexes;
//per file state
@@ -85,7 +85,7 @@
public void initialize(CommandContext context, BufferManager bufferManager,
ProcessorDataManager dataMgr) {
super.initialize(context, bufferManager, dataMgr);
- if (elementMap != null) {
+ if (projectionIndexes != null) {
return;
}
if (table.getSkip() != null) {
@@ -112,7 +112,7 @@
quote = table.getQuote();
}
}
- this.elementMap = createLookupMap(table.getProjectedSymbols());
+ Map elementMap = createLookupMap(table.getProjectedSymbols());
this.projectionIndexes = getProjectionIndexes(elementMap, getElements());
}
@@ -215,11 +215,7 @@
private void initReader() throws ExpressionEvaluationException,
BlockedException, TeiidComponentException, TeiidProcessingException {
- if (table.getCorrelatedReferences() != null) {
- for (Map.Entry<ElementSymbol, Expression> entry : table.getCorrelatedReferences().asMap().entrySet()) {
- getContext().getVariableContext().setValue(entry.getKey(), getEvaluator(Collections.emptyMap()).evaluate(entry.getValue(), null));
- }
- }
+ setReferenceValues(this.table);
ClobType file = (ClobType)getEvaluator(Collections.emptyMap()).evaluate(table.getFile(), null);
if (file == null) {
Modified: trunk/engine/src/main/java/org/teiid/query/processor/relational/XMLTableNode.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/processor/relational/XMLTableNode.java 2010-06-05 01:49:35 UTC (rev 2184)
+++ trunk/engine/src/main/java/org/teiid/query/processor/relational/XMLTableNode.java 2010-06-06 15:12:19 UTC (rev 2185)
@@ -22,82 +22,198 @@
package org.teiid.query.processor.relational;
-import java.util.Map;
+import java.io.IOException;
+import java.io.Writer;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Properties;
-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 javax.xml.transform.OutputKeys;
+import javax.xml.transform.TransformerException;
+import net.sf.saxon.Configuration;
+import net.sf.saxon.om.Item;
+import net.sf.saxon.om.NodeInfo;
+import net.sf.saxon.om.SequenceIterator;
+import net.sf.saxon.query.QueryResult;
+import net.sf.saxon.sxpath.XPathDynamicContext;
+import net.sf.saxon.sxpath.XPathExpression;
+import net.sf.saxon.trans.XPathException;
+import net.sf.saxon.value.Value;
+
+import org.teiid.api.exception.query.ExpressionEvaluationException;
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.core.types.DataTypeManager;
+import org.teiid.core.types.SQLXMLImpl;
+import org.teiid.core.types.Streamable;
+import org.teiid.core.types.TransformationException;
+import org.teiid.core.types.XMLTranslator;
+import org.teiid.core.types.XMLType;
+import org.teiid.core.types.XMLType.Type;
+import org.teiid.query.processor.xml.XMLUtil;
import org.teiid.query.sql.lang.XMLTable;
-import org.teiid.query.util.CommandContext;
+import org.teiid.query.sql.lang.XMLTable.XMLColumn;
+import org.teiid.query.sql.symbol.DerivedColumn;
/**
- * Handles xml processing.
+ * Handles xml table processing.
*/
public class XMLTableNode extends SubqueryAwareRelationalNode {
+ private static final class QueryResultTranslator extends XMLTranslator {
+ private final SequenceIterator pathIter;
+ private final Configuration config;
+
+ private QueryResultTranslator(SequenceIterator pathIter, Configuration config) {
+ this.pathIter = pathIter;
+ this.config = config;
+ }
+
+ @Override
+ public void translate(Writer writer) throws TransformerException,
+ IOException {
+ Properties props = new Properties();
+ props.setProperty(OutputKeys.METHOD, "xml"); //$NON-NLS-1$
+ //props.setProperty(OutputKeys.INDENT, "yes"); //$NON-NLS-1$
+ props.setProperty(OutputKeys.OMIT_XML_DECLARATION, "yes"); //$NON-NLS-1$
+ QueryResult.serializeSequence(pathIter, config, writer, props);
+ }
+ }
+
private XMLTable table;
+ private List<XMLColumn> projectedColumns;
- //initialized state
- private Map elementMap;
- private int[] projectionIndexes;
+ private SequenceIterator result;
+ private int rowCount = 0;
- //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();
}
+ @Override
+ public void reset() {
+ super.reset();
+ if (this.result != null) {
+ result.close();
+ result = null;
+ }
+ rowCount = 0;
+ }
+
public void setTable(XMLTable table) {
this.table = table;
}
-
+
+ public void setProjectedColumns(List<XMLColumn> projectedColumns) {
+ this.projectedColumns = projectedColumns;
+ }
+
@Override
public XMLTableNode clone() {
XMLTableNode clone = new XMLTableNode(getID());
this.copy(this, clone);
clone.setTable(table);
+ clone.setProjectedColumns(projectedColumns);
return clone;
}
@Override
protected TupleBatch nextBatchDirect() throws BlockedException,
TeiidComponentException, TeiidProcessingException {
- return null;
+
+ if (result == null) {
+ setReferenceValues(this.table);
+ HashMap<String, Object> parameters = new HashMap<String, Object>();
+ Object contextItem = null;
+ for (DerivedColumn passing : this.table.getPassing()) {
+ Object value = getEvaluator(Collections.emptyMap()).evaluate(passing.getExpression(), null);
+ if (passing.getAlias() == null) {
+ contextItem = value;
+ } else {
+ parameters.put(passing.getAlias(), value);
+ }
+ }
+ result = this.table.getXQueryExpression().evaluateXQuery(contextItem, parameters);
+ }
+
+ while (!isBatchFull() && !isLastBatch()) {
+ try {
+ processRow();
+ } catch (XPathException e) {
+ e.printStackTrace();
+ }
+ }
+ return pullBatch();
}
-
- public static void main(String[] args) {
-
+ private void processRow() throws XPathException,
+ ExpressionEvaluationException, BlockedException,
+ TeiidComponentException, TeiidProcessingException,
+ TransformationException {
+ Item item = result.next();
+ rowCount++;
+ if (item == null) {
+ terminateBatches();
+ return;
+ }
+ List<Object> tuple = new ArrayList<Object>(projectedColumns.size());
+ for (XMLColumn proColumn : projectedColumns) {
+ if (proColumn.isOrdinal()) {
+ tuple.add(rowCount);
+ } else {
+ XPathExpression path = proColumn.getPathExpression();
+ XPathDynamicContext dynamicContext = path.createDynamicContext(item);
+ SequenceIterator pathIter = path.iterate(dynamicContext);
+ Item colItem = pathIter.next();
+ if (colItem == null) {
+ if (proColumn.getDefaultExpression() != null) {
+ tuple.add(getEvaluator(Collections.emptyMap()).evaluate(proColumn.getDefaultExpression(), null));
+ } else {
+ tuple.add(null);
+ }
+ continue;
+ }
+ if (proColumn.getSymbol().getType() == DataTypeManager.DefaultDataClasses.XML) {
+ Item next = pathIter.next();
+ XMLType.Type type = Type.FRAGMENT;
+ if (next != null) {
+ if (next instanceof NodeInfo || colItem instanceof NodeInfo) {
+ type = Type.SIBLINGS;
+ } else {
+ type = Type.TEXT;
+ }
+ }
+ pathIter = pathIter.getAnother();
+ SQLXMLImpl xml = XMLUtil.saveToBufferManager(getBufferManager(), new QueryResultTranslator(pathIter, this.table.getXQueryExpression().getConfig()), Streamable.STREAMING_BATCH_SIZE_IN_BYTES);
+ XMLType value = new XMLType(xml);
+ value.setType(type);
+ tuple.add(value);
+ continue;
+ }
+ if (pathIter.next() != null) {
+ throw new TeiidProcessingException("Unexpected multi-valued result was returned for XML Column " + proColumn.getName() + ". All path expressions should return at most a single result.");
+ }
+ Object value = Value.convertToJava(colItem);
+ if (value instanceof Item) {
+ value = ((Item)value).getStringValue();
+ }
+ value = DataTypeManager.convertToRuntimeType(value);
+ value = DataTypeManager.transformValue(value, proColumn.getSymbol().getType());
+ tuple.add(value);
+ }
+ }
+ addBatchRow(tuple);
}
-
+
}
\ No newline at end of file
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-05 01:49:35 UTC (rev 2184)
+++ trunk/engine/src/main/java/org/teiid/query/rewriter/QueryRewriter.java 2010-06-06 15:12:19 UTC (rev 2185)
@@ -47,8 +47,8 @@
import org.teiid.api.exception.query.QueryResolverException;
import org.teiid.api.exception.query.QueryValidatorException;
import org.teiid.core.TeiidComponentException;
+import org.teiid.core.TeiidException;
import org.teiid.core.TeiidProcessingException;
-import org.teiid.core.TeiidException;
import org.teiid.core.TeiidRuntimeException;
import org.teiid.core.types.DataTypeManager;
import org.teiid.core.util.Assertion;
@@ -926,6 +926,8 @@
TextTable tt = (TextTable)clause;
tt.setFile(rewriteExpressionDirect(tt.getFile()));
} else if (clause instanceof XMLTable) {
+ XMLTable xt = (XMLTable)clause;
+ xt.rewriteDefaultColumn();
rewriteExpressions(clause);
}
return clause;
Modified: trunk/engine/src/main/java/org/teiid/query/sql/lang/XMLTable.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/sql/lang/XMLTable.java 2010-06-05 01:49:35 UTC (rev 2184)
+++ trunk/engine/src/main/java/org/teiid/query/sql/lang/XMLTable.java 2010-06-06 15:12:19 UTC (rev 2185)
@@ -105,7 +105,7 @@
private XMLNamespaces namespaces;
private String xquery;
private List<DerivedColumn> passing = new ArrayList<DerivedColumn>();
- private ElementSymbol defaultColumn;
+ private XMLColumn defaultColumn;
private SaxonXQueryExpression xqueryExpression;
@@ -114,10 +114,14 @@
}
public void compileXqueryExpression() throws TeiidProcessingException {
- this.xqueryExpression = new SaxonXQueryExpression(xquery, namespaces, passing, columns);
+ List<XMLColumn> cols = this.columns;
+ if (cols.isEmpty()) {
+ cols = Arrays.asList(defaultColumn);
+ }
+ this.xqueryExpression = new SaxonXQueryExpression(xquery, namespaces, passing, cols);
}
- public SaxonXQueryExpression getXqueryExpression() {
+ public SaxonXQueryExpression getXQueryExpression() {
return xqueryExpression;
}
@@ -155,10 +159,9 @@
return super.getProjectedSymbols();
}
if (defaultColumn == null) {
- defaultColumn = new ElementSymbol("COLUMN_VALUE"); //$NON-NLS-1$
- defaultColumn.setType(DataTypeManager.DefaultDataClasses.XML);
+ defaultColumn = new XMLColumn("OBJECT_VALUE", DataTypeManager.DefaultDataTypes.XML, ".", null); //$NON-NLS-1$ //$NON-NLS-2$
}
- return Arrays.asList(defaultColumn);
+ return Arrays.asList(defaultColumn.getSymbol());
}
@Override
@@ -194,5 +197,12 @@
XMLTable other = (XMLTable)obj;
return this.columns.equals(other.columns);
}
+
+ public void rewriteDefaultColumn() {
+ if (this.columns.isEmpty() && defaultColumn != null) {
+ this.columns.add(defaultColumn);
+ defaultColumn = null;
+ }
+ }
}
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-05 01:49:35 UTC (rev 2184)
+++ trunk/engine/src/main/java/org/teiid/query/validator/ValidationVisitor.java 2010-06-06 15:12:19 UTC (rev 2185)
@@ -1162,8 +1162,7 @@
for (DerivedColumn dc : obj.getPassing()) {
if (dc.getAlias() == null) {
Class<?> type = dc.getExpression().getType();
- if (type != DataTypeManager.DefaultDataClasses.STRING &&
- type != DataTypeManager.DefaultDataClasses.XML &&
+ if (type != DataTypeManager.DefaultDataClasses.XML &&
type != DataTypeManager.DefaultDataClasses.CLOB) {
handleValidationError(QueryPlugin.Util.getString("ValidationVisitor.context_item_type"), obj); //$NON-NLS-1$
}
@@ -1176,6 +1175,9 @@
handleValidationError(QueryPlugin.Util.getString("ValidationVisitor.duplicate_passing", dc.getAlias()), obj); //$NON-NLS-1$
}
}
+ if (obj.getXQueryExpression().usesContextItem() && !context) {
+ handleValidationError(QueryPlugin.Util.getString("ValidationVisitor.context_required"), obj); //$NON-NLS-1$
+ }
boolean hasOrdinal = false;
for (XMLColumn xc : obj.getColumns()) {
if (!xc.isOrdinal()) {
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-05 01:49:35 UTC (rev 2184)
+++ trunk/engine/src/main/java/org/teiid/query/xquery/saxon/SaxonXQueryExpression.java 2010-06-06 15:12:19 UTC (rev 2185)
@@ -22,15 +22,14 @@
package org.teiid.query.xquery.saxon;
-import java.io.StringReader;
import java.sql.Clob;
import java.sql.SQLException;
import java.sql.SQLXML;
import java.util.Arrays;
+import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
-import java.util.Properties;
import javax.xml.transform.ErrorListener;
import javax.xml.transform.Source;
@@ -41,8 +40,10 @@
import net.sf.saxon.Configuration;
import net.sf.saxon.event.ProxyReceiver;
import net.sf.saxon.expr.AxisExpression;
+import net.sf.saxon.expr.ContextItemExpression;
import net.sf.saxon.expr.Expression;
import net.sf.saxon.expr.PathMap;
+import net.sf.saxon.expr.RootExpression;
import net.sf.saxon.expr.PathMap.PathMapArc;
import net.sf.saxon.expr.PathMap.PathMapNode;
import net.sf.saxon.expr.PathMap.PathMapNodeSet;
@@ -54,9 +55,7 @@
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;
@@ -72,16 +71,15 @@
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.analysis.AnalysisRecord;
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;
+@SuppressWarnings("serial")
public class SaxonXQueryExpression {
private static final Expression DUMMY_EXPRESSION = new Expression() {
@@ -148,10 +146,8 @@
}
}
}
- boolean hasContext = false;
for (DerivedColumn derivedColumn : passing) {
if (derivedColumn.getAlias() == null) {
- hasContext = true; //skip the context item
continue;
}
try {
@@ -159,92 +155,156 @@
} catch (XPathException e) {
throw new TeiidRuntimeException(e, "Could not define global variable"); //$NON-NLS-1$
}
- ic.declareVariable("", derivedColumn.getAlias()); //$NON-NLS-1$
}
- XPathEvaluator eval = new XPathEvaluator(config);
- eval.setStaticContext(ic);
-
- processColumns(columns, eval);
+ processColumns(columns, ic);
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) {
+
+ public boolean usesContextItem() {
+ return this.xQuery.usesContextItem();
+ }
+
+ public void useDocumentProjection(List<XMLTable.XMLColumn> columns, AnalysisRecord record) {
+ PathMap map = this.xQuery.getPathMap();
+ PathMapRoot parentRoot;
+ try {
+ parentRoot = map.getContextRoot();
+ } catch (IllegalStateException e) {
+ if (record.recordDebug()) {
+ record.println("Document projection will not be used, since multiple context item exist."); //$NON-NLS-1$
+ }
+ return;
+ }
+ if (parentRoot == null) {
+ //TODO: this seems like we could omit the context item altogether
+ //this.xQuery.usesContextItem() should also be false
+ if (record.recordDebug()) {
+ record.println("Document projection will not be used, since no context item reference was found in the XQuery"); //$NON-NLS-1$
+ }
+ return;
+ }
+ HashSet<PathMapNode> finalNodes = new HashSet<PathMapNode>();
+ getReturnableNodes(parentRoot, finalNodes);
+
+ if (!finalNodes.isEmpty()) {
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();
- }
- }
- }
+ if (finalNodes.size() != 1) {
+ if (record.recordDebug()) {
+ record.println("Document projection will not be used, since multiple return items exist"); //$NON-NLS-1$
}
+ return;
+ }
+ parentRoot = projectColumns(parentRoot, columns, finalNodes.iterator().next(), record);
+ if (parentRoot == null) {
+ return;
}
} else {
- for (Iterator iter = set.iterator(); iter.hasNext(); ) {
+ for (Iterator iter = finalNodes.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();
+ if (parentRoot.hasUnknownDependencies()) {
+ if (record.recordDebug()) {
+ record.println("Document projection will not be used since there are unknown dependencies (most likely a user defined function)."); //$NON-NLS-1$
+ }
+ return;
+ }
+ contextRoot = parentRoot;
+ if (record.recordDebug()) {
+ 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$
+ record.println("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)
+ private PathMapRoot projectColumns(PathMapRoot parentRoot, List<XMLTable.XMLColumn> columns, PathMapNode finalNode, AnalysisRecord record) {
+ for (XMLColumn xmlColumn : columns) {
+ if (xmlColumn.isOrdinal()) {
+ continue;
+ }
+ Expression internalExpression = xmlColumn.getPathExpression().getInternalExpression();
+ PathMap subMap = new PathMap(internalExpression);
+ PathMapRoot subContextRoot = null;
+ for (PathMapRoot root : subMap.getPathMapRoots()) {
+ if (root.getRootExpression() instanceof ContextItemExpression || root.getRootExpression() instanceof RootExpression) {
+ if (subContextRoot != null) {
+ if (record.recordDebug()) {
+ record.println("Document projection will not be used, since multiple context item exist in column path " + xmlColumn.getPath()); //$NON-NLS-1$
+ }
+ return null;
+ }
+ subContextRoot = root;
+ }
+ }
+ if (subContextRoot == null) {
+ //special case for handling '.', which the pathmap logic doesn't consider as a root
+ if (internalExpression instanceof ContextItemExpression) {
+ addReturnedArcs(xmlColumn, finalNode);
+ }
+ continue;
+ }
+ for (PathMapArc arc : subContextRoot.getArcs()) {
+ finalNode.createArc(arc.getStep(), arc.getTarget());
+ }
+ HashSet<PathMapNode> subFinalNodes = new HashSet<PathMapNode>();
+ getReturnableNodes(subContextRoot, subFinalNodes);
+ for (Iterator iter = subFinalNodes.iterator(); iter.hasNext(); ) {
+ PathMapNode subNode = (PathMapNode)iter.next();
+ addReturnedArcs(xmlColumn, subNode);
+ }
+ }
+ //Workaround to rerun the reduction algorithm - by making a copy of the old version
+ PathMap newMap = new PathMap(DUMMY_EXPRESSION);
+ PathMapRoot newRoot = newMap.makeNewRoot(parentRoot.getRootExpression());
+ if (parentRoot.isAtomized()) {
+ newRoot.setAtomized();
+ }
+ if (parentRoot.isReturnable()) {
+ newRoot.setReturnable(true);
+ }
+ if (parentRoot.hasUnknownDependencies()) {
+ newRoot.setHasUnknownDependencies();
+ }
+ for (PathMapArc arc : parentRoot.getArcs()) {
+ newRoot.createArc(arc.getStep(), arc.getTarget());
+ }
+ return newMap.reduceToDownwardsAxes(newRoot);
+ }
+
+ private void addReturnedArcs(XMLColumn xmlColumn, PathMapNode subNode) {
+ if (xmlColumn.getSymbol().getType() == DataTypeManager.DefaultDataClasses.XML) {
+ subNode.createArc(new AxisExpression(Axis.DESCENDANT_OR_SELF, AnyNodeTest.getInstance()));
+ } else {
+ //this may not always be needed, but it doesn't harm anything
+ subNode.createArc(new AxisExpression(Axis.CHILD, NodeKindTest.TEXT));
+ subNode.setAtomized();
+ }
+ }
+
+ private void getReturnableNodes(PathMapNode node, HashSet<PathMapNode> finalNodes) {
+ if (node.isReturnable()) {
+ finalNodes.add(node);
+ }
+ for (PathMapArc arc : node.getArcs()) {
+ getReturnableNodes(arc.getTarget(), finalNodes);
+ }
+ }
+
+ private void processColumns(List<XMLTable.XMLColumn> columns, IndependentContext ic)
throws TeiidProcessingException {
if (columns == null) {
return;
}
+ XPathEvaluator eval = new XPathEvaluator(config);
+ eval.setStaticContext(ic);
for (XMLColumn xmlColumn : columns) {
if (xmlColumn.isOrdinal()) {
continue;
@@ -254,7 +314,7 @@
path = xmlColumn.getName();
}
path = path.trim();
- if (path.startsWith("/") && !path.startsWith("//")) {
+ if (path.startsWith("/") && !path.startsWith("//")) { //$NON-NLS-1$ //$NON-NLS-2$
path = path.substring(1);
}
XPathExpression exp;
@@ -275,9 +335,6 @@
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());
}
@@ -292,12 +349,8 @@
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) {
- throw new TeiidProcessingException(e);
- }
+ if(value instanceof SQLXML || value instanceof Clob) {
+ value = convertToSource(value);
}
dynamicContext.setParameter(entry.getKey(), value);
}
@@ -320,9 +373,7 @@
dynamicContext.setContextItem(doc);
}
try {
- //return this.xQuery.iterator(dynamicContext);
- QueryResult.serializeSequence(xQuery.iterator(dynamicContext), config, System.out, new Properties());
- return null;
+ return xQuery.iterator(dynamicContext);
} catch (TransformerException e) {
throw new TeiidProcessingException(e, QueryPlugin.Util.getString("SaxonXQueryExpression.bad_xquery")); //$NON-NLS-1$
}
Modified: trunk/engine/src/main/resources/org/teiid/query/i18n.properties
===================================================================
--- trunk/engine/src/main/resources/org/teiid/query/i18n.properties 2010-06-05 01:49:35 UTC (rev 2184)
+++ trunk/engine/src/main/resources/org/teiid/query/i18n.properties 2010-06-06 15:12:19 UTC (rev 2185)
@@ -892,7 +892,7 @@
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.context_item_type=XMLTABLE or XMLQUERY PASSING context item must be an XML or CLOB value.
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.
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-05 01:49:35 UTC (rev 2184)
+++ trunk/engine/src/test/java/org/teiid/query/processor/TestSQLXMLProcessing.java 2010-06-06 15:12:19 UTC (rev 2185)
@@ -29,16 +29,15 @@
import org.junit.Ignore;
import org.junit.Test;
-import org.teiid.query.processor.ProcessorPlan;
import org.teiid.query.unittest.FakeMetadataFactory;
-@SuppressWarnings("nls")
+@SuppressWarnings({"nls", "unchecked"})
public class TestSQLXMLProcessing {
@Test public void testXmlElementTextContent() throws Exception {
String sql = "SELECT xmlelement(foo, '<bar>', convert('<bar1/>', xml))"; //$NON-NLS-1$
- List[] expected = new List[] {
+ List<?>[] expected = new List<?>[] {
Arrays.asList("<foo><bar><bar1/></foo>"),
};
@@ -57,7 +56,7 @@
@Test public void testXmlElementTextContent1() throws Exception {
String sql = "SELECT xmlelement(foo, '<bar>', convert('<?xml version=\"1.0\" encoding=\"UTF-8\"?><bar1/>', xml))"; //$NON-NLS-1$
- List[] expected = new List[] {
+ List<?>[] expected = new List<?>[] {
Arrays.asList("<foo><bar><bar1></bar1></foo>"),
};
@@ -72,7 +71,7 @@
@Test public void testXmlElement() {
String sql = "SELECT xmlelement(e1, e2) from pm1.g1 order by e1, e2"; //$NON-NLS-1$
- List[] expected = new List[] {
+ List<?>[] expected = new List<?>[] {
Arrays.asList("<e1>1</e1>"),
Arrays.asList("<e1>0</e1>"),
Arrays.asList("<e1>0</e1>"),
@@ -92,7 +91,7 @@
@Test public void testXmlElementWithConcat() {
String sql = "SELECT xmlelement(e1, e2, xmlconcat(xmlelement(x), xmlelement(y, e3))) from pm1.g1 order by e1, e2"; //$NON-NLS-1$
- List[] expected = new List[] {
+ List<?>[] expected = new List<?>[] {
Arrays.asList("<e1>1<x></x><y>false</y></e1>"),
Arrays.asList("<e1>0<x></x><y>false</y></e1>"),
Arrays.asList("<e1>0<x></x><y>false</y></e1>"),
@@ -112,7 +111,7 @@
@Test public void testXmlElementWithForest() {
String sql = "SELECT xmlelement(x, xmlforest(e1, e2, '1' as val)) from pm1.g1 order by e1, e2 limit 2"; //$NON-NLS-1$
- List[] expected = new List[] {
+ List<?>[] expected = new List<?>[] {
Arrays.asList("<x><e2>1</e2><val>1</val></x>"), //note e1 is not present, because it's null
Arrays.asList("<x><e1>a</e1><e2>0</e2><val>1</val></x>"),
};
@@ -128,7 +127,7 @@
@Test public void testXmlElementWithAttributes() {
String sql = "SELECT xmlelement(x, xmlattributes(e1, e2, '1' as val)) from pm1.g1 order by e1, e2 limit 2"; //$NON-NLS-1$
- List[] expected = new List[] {
+ List<?>[] expected = new List<?>[] {
Arrays.asList("<x e2=\"1\" val=\"1\"></x>"), //note e1 is not present, because it's null
Arrays.asList("<x e1=\"a\" e2=\"0\" val=\"1\"></x>"),
};
@@ -144,7 +143,7 @@
@Test public void testXmlElementWithPi() {
String sql = "SELECT xmlelement(x, xmlpi(name e1, ' 1'))"; //$NON-NLS-1$
- List[] expected = new List[] {
+ List<?>[] expected = new List<?>[] {
Arrays.asList("<x><?e1 1?></x>"),
};
@@ -159,7 +158,7 @@
@Test public void testXmlElementWithNamespaces() {
String sql = "SELECT xmlelement(x, xmlnamespaces(no default, 'http://foo' as x, 'http://foo1' as y), xmlattributes(e1), e2) from pm1.g1 order by e1, e2 limit 2"; //$NON-NLS-1$
- List[] expected = new List[] {
+ List<?>[] expected = new List<?>[] {
Arrays.asList("<x xmlns=\"\" xmlns:x=\"http://foo\" xmlns:y=\"http://foo1\">1</x>"), //note e1 is not present, because it's null
Arrays.asList("<x xmlns=\"\" xmlns:x=\"http://foo\" xmlns:y=\"http://foo1\" e1=\"a\">0</x>"),
};
@@ -175,7 +174,7 @@
@Test public void testXmlAgg() {
String sql = "SELECT xmlelement(parent, xmlAgg(xmlelement(x, xmlattributes(e1, e2)))) from pm1.g1"; //$NON-NLS-1$
- List[] expected = new List[] {
+ List<?>[] expected = new List<?>[] {
Arrays.asList("<parent><x e1=\"a\" e2=\"0\"></x><x e2=\"1\"></x><x e1=\"a\" e2=\"3\"></x><x e1=\"c\" e2=\"1\"></x><x e1=\"b\" e2=\"2\"></x><x e1=\"a\" e2=\"0\"></x></parent>"),
};
@@ -190,7 +189,7 @@
@Test public void testXmlAggOrderBy() {
String sql = "SELECT xmlelement(parent, xmlAgg(xmlelement(x, xmlattributes(e1, e2)) order by e2)) from pm1.g1"; //$NON-NLS-1$
- List[] expected = new List[] {
+ 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>"),
};
@@ -205,7 +204,7 @@
@Test public void testXmlSerialize() {
String sql = "SELECT xmlserialize(document xmlelement(parent) as string)"; //$NON-NLS-1$
- List[] expected = new List[] {
+ List<?>[] expected = new List<?>[] {
Arrays.asList("<parent></parent>"),
};
@@ -217,12 +216,12 @@
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$
+ String sql = "select * from xmltable('/a/b' passing convert('<a><b>first</b><b x=\"attr\">second</b></a>', xml) columns x string path '@x', val string path '/.') as x"; //$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>"),
+ List<?>[] expected = new List<?>[] {
+ Arrays.asList(null, "first"),
+ Arrays.asList("attr", "second"),
};
FakeDataManager dataManager = new FakeDataManager();
@@ -232,5 +231,83 @@
helpProcess(plan, dataManager, expected);
}
+
+ @Test public void testXmlTableDefaultAndParent() {
+ String sql = "select * from xmltable('/a/b' passing convert('<a y=\"rev\"><b>first</b><b x=\"1\">second</b></a>', xml) columns x integer path '@x' default -1, val string path '../@y') as x"; //$NON-NLS-1$
+
+ List<?>[] expected = new List<?>[] {
+ Arrays.asList(-1, "rev"),
+ Arrays.asList(1, "rev"),
+ };
+
+ FakeDataManager dataManager = new FakeDataManager();
+ sampleData1(dataManager);
+
+ ProcessorPlan plan = helpGetPlan(helpParse(sql), FakeMetadataFactory.example1Cached());
+
+ helpProcess(plan, dataManager, expected);
+ }
+
+ @Test public void testXmlTableReturnXml() {
+ String sql = "select * from xmltable('/a/b' passing convert('<a><b>first</b><b x=\"1\">second</b></a>', xml) columns val xml path '.') as x"; //$NON-NLS-1$
+
+ List<?>[] expected = new List<?>[] {
+ Arrays.asList("<b>first</b>"),
+ Arrays.asList("<b x=\"1\">second</b>"),
+ };
+
+ FakeDataManager dataManager = new FakeDataManager();
+ sampleData1(dataManager);
+
+ ProcessorPlan plan = helpGetPlan(helpParse(sql), FakeMetadataFactory.example1Cached());
+
+ helpProcess(plan, dataManager, expected);
+ }
+
+ @Test public void testXmlTableNoColumns() {
+ String sql = "select * from xmltable('/a' passing convert('<a><b>first</b><b x=\"1\">second</b></a>', xml)) as x"; //$NON-NLS-1$
+
+ List<?>[] expected = new List<?>[] {
+ Arrays.asList("<a><b>first</b><b x=\"1\">second</b></a>"),
+ };
+
+ FakeDataManager dataManager = new FakeDataManager();
+ sampleData1(dataManager);
+
+ ProcessorPlan plan = helpGetPlan(helpParse(sql), FakeMetadataFactory.example1Cached());
+
+ helpProcess(plan, dataManager, expected);
+ }
+
+ @Test public void testXmlTablePassing() {
+ String sql = "select * from xmltable('<root>{for $x in $a/a/b return <c>{$x}</c>}</root>' passing convert('<a><b>first</b><b x=\"1\">second</b></a>', xml) as a columns x xml path 'c[1]/b') as x"; //$NON-NLS-1$
+
+ List<?>[] expected = new List<?>[] {
+ Arrays.asList("<b>first</b>"),
+ };
+
+ FakeDataManager dataManager = new FakeDataManager();
+ sampleData1(dataManager);
+
+ ProcessorPlan plan = helpGetPlan(helpParse(sql), FakeMetadataFactory.example1Cached());
+
+ helpProcess(plan, dataManager, expected);
+ }
+
+ @Ignore
+ @Test public void testXmlTableForOrdinality() {
+ String sql = "select * from xmltable('/a/b' passing convert('<a><b><c>1</c></b><b>1</b><b><c>1</c></b><b>1</b></a>', xml) as a columns x for ordinality, c integer path '.') as x"; //$NON-NLS-1$
+
+ List<?>[] expected = new List<?>[] {
+ Arrays.asList("<b>first</b>"),
+ };
+
+ FakeDataManager dataManager = new FakeDataManager();
+ sampleData1(dataManager);
+
+ ProcessorPlan plan = helpGetPlan(helpParse(sql), FakeMetadataFactory.example1Cached());
+
+ helpProcess(plan, dataManager, expected);
+ }
}
Added: trunk/engine/src/test/java/org/teiid/query/xquery/saxon/TestSaxonXQueryExpression.java
===================================================================
--- trunk/engine/src/test/java/org/teiid/query/xquery/saxon/TestSaxonXQueryExpression.java (rev 0)
+++ trunk/engine/src/test/java/org/teiid/query/xquery/saxon/TestSaxonXQueryExpression.java 2010-06-06 15:12:19 UTC (rev 2185)
@@ -0,0 +1,66 @@
+package org.teiid.query.xquery.saxon;
+
+import java.util.Arrays;
+import java.util.HashMap;
+
+import net.sf.saxon.om.SequenceIterator;
+
+import org.junit.Ignore;
+import org.teiid.core.types.SQLXMLImpl;
+import org.teiid.core.types.XMLType;
+import org.teiid.query.sql.lang.XMLTable;
+import org.teiid.query.sql.symbol.DerivedColumn;
+import org.teiid.query.sql.symbol.ElementSymbol;
+import org.teiid.query.sql.symbol.XMLNamespaces;
+
+@Ignore
+public class TestSaxonXQueryExpression {
+
+ public static void main(String[] args) throws Exception {
+ String xquery =
+ "/Catalogs/Catalog/Items"; //$NON-NLS-1$
+
+ String inputdoc =
+ "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + //$NON-NLS-1$
+ "<Catalogs xmlns=\"foo\" 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\" x=\"1\">\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$
+
+/* Configuration config = new Configuration();
+ XPathExpression exp = new XPathEvaluator(config).createExpression("text()");
+ Expression expr = exp.getInternalExpression();
+ PathMap map = new PathMap(expr);
+ map.diagnosticDump(System.out);
+ PathMapRoot root = map.getContextRoot();
+ StringBuilder sb = new StringBuilder();
+ SaxonXQueryExpression.showArcs(sb, root.getArcs(), 0);
+ System.out.println(sb);
+ Source s = config.buildDocument(new StreamSource(new StringReader("<a Name='foo'><b><c Name='bar'>hello<d>world</d></c></b></a>")));
+ Object o = new XPathEvaluator(config).createExpression("//c").evaluateSingle(s);
+ XPathDynamicContext dc = exp.createDynamicContext((Item)o);
+ System.out.println(exp.evaluateSingle(dc).getStringValue());
+*/
+ XMLNamespaces namespaces = new XMLNamespaces(Arrays.asList(new XMLNamespaces.NamespaceItem("foo", null)));
+ SaxonXQueryExpression se = new SaxonXQueryExpression(xquery, namespaces, Arrays.asList(new DerivedColumn(null, new ElementSymbol("x"))), Arrays.asList(new XMLTable.XMLColumn("y", "string", "/elem", null), new XMLTable.XMLColumn("x", "string", "../@attr", null)));
+ HashMap<String, Object> values = new HashMap<String, Object>();
+ values.put("y", new SQLXMLImpl(inputdoc));
+ SequenceIterator iter = se.evaluateXQuery(new XMLType(new SQLXMLImpl(inputdoc)), values);
+ }
+
+
+}
Property changes on: trunk/engine/src/test/java/org/teiid/query/xquery/saxon/TestSaxonXQueryExpression.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
14 years, 6 months
teiid SVN: r2184 - trunk/console/src/main/resources/META-INF.
by teiid-commits@lists.jboss.org
Author: tejones
Date: 2010-06-04 21:49:35 -0400 (Fri, 04 Jun 2010)
New Revision: 2184
Modified:
trunk/console/src/main/resources/META-INF/rhq-plugin.xml
Log:
TEIID-1113: Changed Get Requests for VDB to use method on Runtime Engine
Modified: trunk/console/src/main/resources/META-INF/rhq-plugin.xml
===================================================================
--- trunk/console/src/main/resources/META-INF/rhq-plugin.xml 2010-06-05 01:49:16 UTC (rev 2183)
+++ trunk/console/src/main/resources/META-INF/rhq-plugin.xml 2010-06-05 01:49:35 UTC (rev 2184)
@@ -400,7 +400,7 @@
</results>
</operation>
- <operation name="getRequests" displayName="View VDB requests"
+ <operation name="getRequestsUsingVDB" displayName="View VDB requests"
description="Get current requests executing against this VDB">
<results>
14 years, 6 months
teiid SVN: r2183 - trunk/console/src/main/java/org/teiid/rhq/plugin/util.
by teiid-commits@lists.jboss.org
Author: tejones
Date: 2010-06-04 21:49:16 -0400 (Fri, 04 Jun 2010)
New Revision: 2183
Modified:
trunk/console/src/main/java/org/teiid/rhq/plugin/util/PluginConstants.java
Log:
TEIID-1113: Changed Get Requests for VDB to use method on Runtime Engine
Modified: trunk/console/src/main/java/org/teiid/rhq/plugin/util/PluginConstants.java
===================================================================
--- trunk/console/src/main/java/org/teiid/rhq/plugin/util/PluginConstants.java 2010-06-05 01:22:19 UTC (rev 2182)
+++ trunk/console/src/main/java/org/teiid/rhq/plugin/util/PluginConstants.java 2010-06-05 01:49:16 UTC (rev 2183)
@@ -95,6 +95,7 @@
public final static String TYPE = "teiid"; //$NON-NLS-1$
public final static String SUBTYPE = "vdb"; //$NON-NLS-1$
public final static String NAME = "Enterprise Virtual Database"; //$NON-NLS-1$
+ public final static String VERSION = "version"; //$NON-NLS-1$
public final static String DESCRIPTION = "JBoss Enterprise Virtual Database (VDB)"; //$NON-NLS-1$
public static interface Operations {
@@ -104,7 +105,7 @@
public final static String KILL_REQUEST = "cancelRequest"; //$NON-NLS-1$
public final static String KILL_SESSION = "terminateSession"; //$NON-NLS-1$
public final static String GET_PROPERTIES = "getProperties"; //$NON-NLS-1$
- public final static String GET_REQUESTS = "getRequests"; //$NON-NLS-1$
+ public final static String GET_REQUESTS = "getRequestsUsingVDB"; //$NON-NLS-1$
public final static String GET_SESSIONS = "getSessions"; //$NON-NLS-1$
}
14 years, 6 months
teiid SVN: r2182 - in trunk/engine/src: test/java/org/teiid/query/processor and 1 other directory.
by teiid-commits@lists.jboss.org
Author: shawkins
Date: 2010-06-04 21:22:19 -0400 (Fri, 04 Jun 2010)
New Revision: 2182
Modified:
trunk/engine/src/main/java/org/teiid/query/optimizer/relational/rules/NewCalculateCostUtil.java
trunk/engine/src/test/java/org/teiid/query/processor/TestTextTable.java
Log:
TEIID-1108 fix for npe in costing with a table function
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:51:29 UTC (rev 2181)
+++ trunk/engine/src/main/java/org/teiid/query/optimizer/relational/rules/NewCalculateCostUtil.java 2010-06-05 01:22:19 UTC (rev 2182)
@@ -834,8 +834,11 @@
PlanNode sourceNode = FrameUtil.findOriginatingNode(current, new HashSet<GroupSymbol>(Arrays.asList(elementSymbol.getGroupSymbol())));
if (sourceNode != null) {
SymbolMap symbolMap = (SymbolMap)sourceNode.getProperty(NodeConstants.Info.SYMBOL_MAP);
- Expression expr = symbolMap.getMappedExpression(elementSymbol);
- ndv = getNDV(ElementCollectorVisitor.getElements(expr, true), sourceNode.getFirstChild(), cardinality, metadata);
+ //symbolMap will be null for table functions
+ if (symbolMap != null) {
+ Expression expr = symbolMap.getMappedExpression(elementSymbol);
+ ndv = getNDV(ElementCollectorVisitor.getElements(expr, true), sourceNode.getFirstChild(), cardinality, metadata);
+ }
}
}
if (ndv == UNKNOWN_VALUE) {
Modified: trunk/engine/src/test/java/org/teiid/query/processor/TestTextTable.java
===================================================================
--- trunk/engine/src/test/java/org/teiid/query/processor/TestTextTable.java 2010-06-04 21:51:29 UTC (rev 2181)
+++ trunk/engine/src/test/java/org/teiid/query/processor/TestTextTable.java 2010-06-05 01:22:19 UTC (rev 2182)
@@ -166,6 +166,16 @@
process(sql, expected);
}
+ @Test public void testTextTableCriteria() throws Exception {
+ String sql = "select x.* from texttable('a' || ',' || '1' COLUMNS x string, y integer) x where x.y = 1"; //$NON-NLS-1$
+
+ List[] expected = new List[] {
+ Arrays.asList("a", 1),
+ };
+
+ process(sql, expected);
+ }
+
public static void process(String sql, List[] expectedResults) throws Exception {
FakeDataManager dataManager = new FakeDataManager();
sampleData1(dataManager);
14 years, 6 months