teiid SVN: r2097 - in trunk: documentation/reference/src/main/docbook/en-US/content and 6 other directories.
by teiid-commits@lists.jboss.org
Author: shawkins
Date: 2010-05-04 15:00:28 -0400 (Tue, 04 May 2010)
New Revision: 2097
Modified:
trunk/connector-api/src/main/java/org/teiid/connector/api/SourceSystemFunctions.java
trunk/documentation/reference/src/main/docbook/en-US/content/scalar_functions.xml
trunk/engine/src/main/java/com/metamatrix/query/function/source/SystemSource.java
trunk/engine/src/main/java/com/metamatrix/query/function/source/XMLSystemFunctions.java
trunk/engine/src/main/java/com/metamatrix/query/…
[View More]optimizer/relational/rules/RuleAssignOutputElements.java
trunk/engine/src/main/javacc/com/metamatrix/query/parser/SQLParser.jj
trunk/engine/src/main/resources/com/metamatrix/query/i18n.properties
trunk/engine/src/test/java/com/metamatrix/query/function/TestFunctionLibrary.java
trunk/engine/src/test/java/com/metamatrix/query/processor/TestProcessor.java
Log:
TEIID-171 adding support for the xmlelement function
Modified: trunk/connector-api/src/main/java/org/teiid/connector/api/SourceSystemFunctions.java
===================================================================
--- trunk/connector-api/src/main/java/org/teiid/connector/api/SourceSystemFunctions.java 2010-05-04 14:06:31 UTC (rev 2096)
+++ trunk/connector-api/src/main/java/org/teiid/connector/api/SourceSystemFunctions.java 2010-05-04 19:00:28 UTC (rev 2097)
@@ -137,5 +137,6 @@
//xml
public static final String XPATHVALUE = "xpathvalue"; //$NON-NLS-1$
public static final String XSLTRANSFORM = "xsltransform"; //$NON-NLS-1$
+ public static final String XMLELEMENT = "xmlelement"; //$NON-NLS-1$
}
Modified: trunk/documentation/reference/src/main/docbook/en-US/content/scalar_functions.xml
===================================================================
--- trunk/documentation/reference/src/main/docbook/en-US/content/scalar_functions.xml 2010-05-04 14:06:31 UTC (rev 2096)
+++ trunk/documentation/reference/src/main/docbook/en-US/content/scalar_functions.xml 2010-05-04 19:00:28 UTC (rev 2097)
@@ -1957,6 +1957,23 @@
</para>
</entry>
</row>
+ <row>
+ <entry>
+ <para><code>XMLELEMENT(name [, content]*)</code></para>
+ </entry>
+ <entry>
+ <para>Returns an XML element with the given name and conent. If the content value is of a type other than xml,
+ it will be escaped when added to the parent element. Null content values are ignored.
+ Whitespace in XML or the string values of the content is preserved, but no whitespace is added between content values.</para>
+ <para>Example: with an xml_value of <doc/>, <code>xmlelement('myelement', 1, '<2/>', xml_value)</code>
+ Returns: <code><myelement>1&lt;2/&gt;<doc/>></code>
+ </para>
+ </entry>
+ <entry>
+ <para>Name in {string}. Content can be any type. Return value is xml.
+ </para>
+ </entry>
+ </row>
</tbody>
</tgroup>
</informaltable>
Modified: trunk/engine/src/main/java/com/metamatrix/query/function/source/SystemSource.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/query/function/source/SystemSource.java 2010-05-04 14:06:31 UTC (rev 2096)
+++ trunk/engine/src/main/java/com/metamatrix/query/function/source/SystemSource.java 2010-05-04 19:00:28 UTC (rev 2097)
@@ -168,6 +168,7 @@
// xml functions
addXpathFunction();
addXslTransformFunction();
+ addXmlElement();
addSecurityFunctions();
@@ -904,6 +905,14 @@
new FunctionParameter("result", DataTypeManager.DefaultDataTypes.CLOB, QueryPlugin.Util.getString("SystemSource.xsltransform_result")) ) ); //$NON-NLS-1$ //$NON-NLS-2$
}
+ private void addXmlElement() {
+ functions.add(new FunctionMethod(SourceSystemFunctions.XMLELEMENT, QueryPlugin.Util.getString("SystemSource.xsltransform_description"), XML, XML_FUNCTION_CLASS, "xmlElement", //$NON-NLS-1$ //$NON-NLS-2$
+ new FunctionParameter[] {
+ new FunctionParameter("name", DataTypeManager.DefaultDataTypes.STRING, QueryPlugin.Util.getString("SystemSource.xmlelement_param1")), //$NON-NLS-1$ //$NON-NLS-2$
+ new FunctionParameter("value", DataTypeManager.DefaultDataTypes.OBJECT, QueryPlugin.Util.getString("SystemSource.xmlelement_param2"), true)}, //$NON-NLS-1$ //$NON-NLS-2$
+ new FunctionParameter("result", DataTypeManager.DefaultDataTypes.XML, QueryPlugin.Util.getString("SystemSource.xmlement_result")) ) ); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
private void addTimeZoneFunctions() {
functions.add(new FunctionMethod(SourceSystemFunctions.MODIFYTIMEZONE, QueryPlugin.Util.getString("SystemSource.modifyTimeZone_description"), DATETIME, FUNCTION_CLASS, "modifyTimeZone", //$NON-NLS-1$ //$NON-NLS-2$
new FunctionParameter[] {
Modified: trunk/engine/src/main/java/com/metamatrix/query/function/source/XMLSystemFunctions.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/query/function/source/XMLSystemFunctions.java 2010-05-04 14:06:31 UTC (rev 2096)
+++ trunk/engine/src/main/java/com/metamatrix/query/function/source/XMLSystemFunctions.java 2010-05-04 19:00:28 UTC (rev 2097)
@@ -29,6 +29,14 @@
import java.sql.SQLException;
import java.sql.SQLXML;
+import javax.xml.stream.EventFilter;
+import javax.xml.stream.XMLEventFactory;
+import javax.xml.stream.XMLEventReader;
+import javax.xml.stream.XMLEventWriter;
+import javax.xml.stream.XMLInputFactory;
+import javax.xml.stream.XMLOutputFactory;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.events.XMLEvent;
import javax.xml.transform.Source;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerException;
@@ -38,10 +46,12 @@
import net.sf.saxon.trans.XPathException;
+import com.metamatrix.api.exception.MetaMatrixComponentException;
import com.metamatrix.api.exception.query.FunctionExecutionException;
import com.metamatrix.common.types.ClobType;
import com.metamatrix.common.types.DataTypeManager;
import com.metamatrix.common.types.Streamable;
+import com.metamatrix.common.types.TransformationException;
import com.metamatrix.common.types.XMLTranslator;
import com.metamatrix.common.types.XMLType;
import com.metamatrix.internal.core.xml.XPathHelper;
@@ -49,9 +59,6 @@
import com.metamatrix.query.processor.xml.XMLUtil;
import com.metamatrix.query.util.CommandContext;
-
-
-
/**
* This class contains scalar system functions supporting for XML manipulation.
*
@@ -60,10 +67,6 @@
public class XMLSystemFunctions {
public static Object xpathValue(Object document, Object xpathStr) throws FunctionExecutionException {
- if(document == null || xpathStr == null) {
- return null;
- }
-
Reader stream = null;
if (document instanceof SQLXML) {
@@ -93,6 +96,7 @@
Reader reader = xmlResults.getCharacterStream();
final Source xmlSource = new StreamSource(reader);
try {
+ //this creates a non-validated sqlxml - it may not be valid xml/root-less xml
SQLXML result = XMLUtil.saveToBufferManager(context.getBufferManager(), new XMLTranslator() {
@Override
@@ -115,5 +119,67 @@
}
}
}
-
+
+ /**
+ * Basic support for xmlelement. Attributes are not yet supported.
+ * @param context
+ * @param name
+ * @param contents
+ * @return
+ * @throws MetaMatrixComponentException
+ */
+ public static XMLType xmlElement(CommandContext context, final String name, final Object... contents) throws MetaMatrixComponentException {
+ return new XMLType(XMLUtil.saveToBufferManager(context.getBufferManager(), new XMLTranslator() {
+
+ @Override
+ public void translate(Writer writer) throws TransformerException,
+ IOException {
+ try {
+ XMLOutputFactory factory = XMLOutputFactory.newInstance();
+ XMLEventWriter eventWriter = factory.createXMLEventWriter(writer);
+ XMLEventFactory eventFactory = XMLEventFactory.newInstance();
+ eventWriter.add(eventFactory.createStartElement("", null, name)); //$NON-NLS-1$
+ for (Object object : contents) {
+ if (object == null) {
+ continue;
+ }
+ if (object instanceof XMLType) {
+ Reader r = null;
+ try {
+ r = ((XMLType)object).getCharacterStream();
+ XMLInputFactory inputFactory = XMLInputFactory.newInstance();
+ XMLEventReader xmlEventReader = inputFactory.createFilteredReader(inputFactory.createXMLEventReader(r), new EventFilter() {
+
+ @Override
+ public boolean accept(XMLEvent event) {
+ return !event.isStartDocument() && !event.isEndDocument();
+ }
+ });
+ eventWriter.add(xmlEventReader);
+ } catch (SQLException e) {
+ throw new IOException(e);
+ } finally {
+ if (r != null) {
+ r.close();
+ }
+ }
+ } else {
+ try {
+ String result = DataTypeManager.transformValue(object, DataTypeManager.DefaultDataClasses.STRING);
+ eventWriter.add(eventFactory.createCharacters(result));
+ } catch (TransformationException e) {
+ throw new TransformerException(e);
+ }
+ }
+ }
+ eventWriter.add(eventFactory.createEndElement("", null, name)); //$NON-NLS-1$
+ } catch (XMLStreamException e) {
+ throw new TransformerException(e);
+ } finally {
+
+ }
+ }
+ }, context.getStreamingBatchSize()));
+ }
+
}
Modified: trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/rules/RuleAssignOutputElements.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/rules/RuleAssignOutputElements.java 2010-05-04 14:06:31 UTC (rev 2096)
+++ trunk/engine/src/main/java/com/metamatrix/query/optimizer/relational/rules/RuleAssignOutputElements.java 2010-05-04 19:00:28 UTC (rev 2097)
@@ -194,12 +194,15 @@
break;
}
default: {
- GroupSymbol intoGroup = (GroupSymbol)root.getProperty(NodeConstants.Info.INTO_GROUP);
- if (intoGroup != null) { //if this is a project into, treat the nodes under the source as a new plan root
- PlanNode intoRoot = NodeEditor.findNodePreOrder(root, NodeConstants.Types.SOURCE);
- execute(intoRoot.getFirstChild(), metadata, capFinder, rules, analysisRecord, context);
- return;
- }
+ if (root.getType() == NodeConstants.Types.PROJECT) {
+ GroupSymbol intoGroup = (GroupSymbol)root.getProperty(NodeConstants.Info.INTO_GROUP);
+ if (intoGroup != null) { //if this is a project into, treat the nodes under the source as a new plan root
+ PlanNode intoRoot = NodeEditor.findNodePreOrder(root, NodeConstants.Types.SOURCE);
+ execute(intoRoot.getFirstChild(), metadata, capFinder, rules, analysisRecord, context);
+ return;
+ }
+ root.setProperty(NodeConstants.Info.PROJECT_COLS, outputElements);
+ }
List<SingleElementSymbol> requiredInput = collectRequiredInputSymbols(root);
Modified: trunk/engine/src/main/javacc/com/metamatrix/query/parser/SQLParser.jj
===================================================================
--- trunk/engine/src/main/javacc/com/metamatrix/query/parser/SQLParser.jj 2010-05-04 14:06:31 UTC (rev 2096)
+++ trunk/engine/src/main/javacc/com/metamatrix/query/parser/SQLParser.jj 2010-05-04 19:00:28 UTC (rev 2097)
@@ -2904,7 +2904,7 @@
(
(funcToken = <LEFT> | funcToken = <RIGHT> | funcToken = <CHAR> | funcToken = <USER>
| funcToken = <YEAR> | funcToken = <MONTH> | funcToken = <HOUR>
- | funcToken = <MINUTE> | funcToken = <SECOND>)
+ | funcToken = <MINUTE> | funcToken = <SECOND> | funcToken = <XMLELEMENT>)
<LPAREN>
[
expression = expression(info)
Modified: trunk/engine/src/main/resources/com/metamatrix/query/i18n.properties
===================================================================
--- trunk/engine/src/main/resources/com/metamatrix/query/i18n.properties 2010-05-04 14:06:31 UTC (rev 2096)
+++ trunk/engine/src/main/resources/com/metamatrix/query/i18n.properties 2010-05-04 19:00:28 UTC (rev 2097)
@@ -771,6 +771,10 @@
SystemSource.xsltransform_param1=Source document
SystemSource.xsltransform_param2=XSL stylesheet
SystemSource.xsltransform_result=Clob result
+SystemSource.xmlelement_description=Create an XML element.
+SystemSource.xmlelement_param1=Element name
+SystemSource.xmlelement_param2=Element contents
+SystemSource.xmlelement_result=XML result
SystemSource.modifyTimeZone_description=Modify the time zone of this timestamp by adding or subtracting time
SystemSource.modifyTimeZone_param1=Timestamp
SystemSource.modifyTimeZone_param2=Starting time zone
Modified: trunk/engine/src/test/java/com/metamatrix/query/function/TestFunctionLibrary.java
===================================================================
--- trunk/engine/src/test/java/com/metamatrix/query/function/TestFunctionLibrary.java 2010-05-04 14:06:31 UTC (rev 2096)
+++ trunk/engine/src/test/java/com/metamatrix/query/function/TestFunctionLibrary.java 2010-05-04 19:00:28 UTC (rev 2097)
@@ -1339,5 +1339,15 @@
String xml = ObjectConverterUtil.convertToString(result.getCharacterStream());
assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?><Catalogs xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"><Catalog><Items><Item ItemID=\"001\"><Name>Lamp</Name></Item></Items></Catalog></Catalogs>", xml);
}
-
+
+ @Test public void testInvokeXmlElement() throws Exception {
+ CommandContext c = new CommandContext();
+ c.setBufferManager(BufferManagerFactory.getStandaloneBufferManager());
+ XMLType result = (XMLType)helpInvokeMethod("xmlelement", new Class[] {DataTypeManager.DefaultDataClasses.STRING, DataTypeManager.DefaultDataClasses.OBJECT, DataTypeManager.DefaultDataClasses.OBJECT},
+ new Object[] {"foo", "<bar>", new XMLType(new SQLXMLImpl("<?xml version=\"1.0\" encoding=\"UTF-8\"?><Catalogs xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"><Catalog><Items><Item ItemID=\"001\"><Name>Lamp</Name><Quantity>5</Quantity></Item></Items></Catalog></Catalogs>"))}, c);
+
+ String xml = ObjectConverterUtil.convertToString(result.getCharacterStream());
+ assertEquals("<foo><bar><Catalogs xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"><Catalog><Items><Item ItemID=\"001\"><Name>Lamp</Name><Quantity>5</Quantity></Item></Items></Catalog></Catalogs></foo>", xml);
+ }
+
}
Modified: trunk/engine/src/test/java/com/metamatrix/query/processor/TestProcessor.java
===================================================================
--- trunk/engine/src/test/java/com/metamatrix/query/processor/TestProcessor.java 2010-05-04 14:06:31 UTC (rev 2096)
+++ trunk/engine/src/test/java/com/metamatrix/query/processor/TestProcessor.java 2010-05-04 19:00:28 UTC (rev 2097)
@@ -302,6 +302,7 @@
CommandContext context = new CommandContext("0", "test", "user", null, "myvdb", 1, props, DEBUG, false); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$
context.setProcessorBatchSize(2000);
context.setConnectorBatchSize(2000);
+ context.setBufferManager(BufferManagerFactory.getStandaloneBufferManager());
return context;
}
@@ -7482,6 +7483,25 @@
helpProcess(plan, dataManager, expected);
}
-
+ @Test public void testXmlElement() {
+ String sql = "SELECT xmlelement(e1, e2) from pm1.g1 order by e1, e2"; //$NON-NLS-1$
+
+ List[] expected = new List[] {
+ Arrays.asList(new String[] {null}),
+ Arrays.asList("<a>0</a>"),
+ Arrays.asList("<a>0</a>"),
+ Arrays.asList("<a>3</a>"),
+ Arrays.asList("<b>2</b>"),
+ Arrays.asList("<c>1</c>"),
+ };
+
+ FakeDataManager dataManager = new FakeDataManager();
+ sampleData1(dataManager);
+
+ ProcessorPlan plan = helpGetPlan(helpParse(sql), FakeMetadataFactory.example1Cached());
+
+ helpProcess(plan, dataManager, expected);
+ }
+
private static final boolean DEBUG = false;
}
[View Less]
14 years, 8 months
teiid SVN: r2096 - trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/oracle.
by teiid-commits@lists.jboss.org
Author: shawkins
Date: 2010-05-04 10:06:31 -0400 (Tue, 04 May 2010)
New Revision: 2096
Modified:
trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/oracle/OracleSQLTranslator.java
Log:
fixing ctc issues: date handling regression
Modified: trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/oracle/OracleSQLTranslator.java
===================================================================
--- trunk/connectors/connector-jdbc/src/main/java/org/teiid/…
[View More]connector/jdbc/oracle/OracleSQLTranslator.java 2010-05-03 21:30:20 UTC (rev 2095)
+++ trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/oracle/OracleSQLTranslator.java 2010-05-04 14:06:31 UTC (rev 2096)
@@ -150,10 +150,11 @@
if ("date".equals(((ColumnReference)ex).getMetadataObject().getNativeType())) { //$NON-NLS-1$
format = "YYYY-MM-DD HH24:MI:SS"; //$NON-NLS-1$
}
- } else if (!(ex instanceof Function)) {
+ } else if (!(ex instanceof Function) && !(ex instanceof Literal)) {
+ //this isn't needed in every case, but it's simpler than inspecting the expression more
ex = ConvertModifier.createConvertFunction(getLanguageFactory(), function.getParameters().get(0), TypeFacility.RUNTIME_NAMES.TIMESTAMP);
}
- return Arrays.asList("to_char(", ex, ", '"+format+"')"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ return Arrays.asList("to_char(", ex, ", '", format, "')"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
}
});
convertModifier.addConvert(FunctionModifier.STRING, FunctionModifier.DATE, new ConvertModifier.FormatModifier("to_date", "YYYY-MM-DD")); //$NON-NLS-1$ //$NON-NLS-2$
[View Less]
14 years, 8 months
teiid SVN: r2095 - in trunk/engine/src: test/java/com/metamatrix/common/buffer/impl and 1 other directory.
by teiid-commits@lists.jboss.org
Author: shawkins
Date: 2010-05-03 17:30:20 -0400 (Mon, 03 May 2010)
New Revision: 2095
Modified:
trunk/engine/src/main/java/org/teiid/dqp/internal/process/RequestWorkItem.java
trunk/engine/src/test/java/com/metamatrix/common/buffer/impl/TestFileStorageManager.java
Log:
fixes for windows build issues
Modified: trunk/engine/src/main/java/org/teiid/dqp/internal/process/RequestWorkItem.java
===================================================================
--- trunk/engine/src/main/java/…
[View More]org/teiid/dqp/internal/process/RequestWorkItem.java 2010-05-03 20:24:22 UTC (rev 2094)
+++ trunk/engine/src/main/java/org/teiid/dqp/internal/process/RequestWorkItem.java 2010-05-03 21:30:20 UTC (rev 2095)
@@ -250,15 +250,6 @@
this.processor.getContext().setTimeSliceEnd(System.currentTimeMillis() + this.processorTimeslice);
sendResultsIfNeeded(null);
collector.collectTuples();
- doneProducingBatches = this.resultsBuffer.isFinal();
- if (doneProducingBatches && cid != null) {
- boolean sessionScope = this.processor.getContext().isSessionFunctionEvaluated();
- CachedResults cr = new CachedResults();
- cr.setCommand(originalCommand);
- cr.setAnalysisRecord(analysisRecord);
- cr.setResults(this.resultsBuffer);
- dqpCore.getRsCache().put(cid, sessionScope, cr);
- }
}
if (doneProducingBatches) {
if (this.transactionState == TransactionState.ACTIVE) {
@@ -390,6 +381,17 @@
* Send results if they have been requested. This should only be called from the processing thread.
*/
protected boolean sendResultsIfNeeded(TupleBatch batch) throws MetaMatrixComponentException {
+ if (batch != null) {
+ doneProducingBatches = batch.getTerminationFlag();
+ if (doneProducingBatches && cid != null) {
+ boolean sessionScope = this.processor.getContext().isSessionFunctionEvaluated();
+ CachedResults cr = new CachedResults();
+ cr.setCommand(originalCommand);
+ cr.setAnalysisRecord(analysisRecord);
+ cr.setResults(this.resultsBuffer);
+ dqpCore.getRsCache().put(cid, sessionScope, cr);
+ }
+ }
ResultsMessage response = null;
ResultsReceiver<ResultsMessage> receiver = null;
boolean result = true;
Modified: trunk/engine/src/test/java/com/metamatrix/common/buffer/impl/TestFileStorageManager.java
===================================================================
--- trunk/engine/src/test/java/com/metamatrix/common/buffer/impl/TestFileStorageManager.java 2010-05-03 20:24:22 UTC (rev 2094)
+++ trunk/engine/src/test/java/com/metamatrix/common/buffer/impl/TestFileStorageManager.java 2010-05-03 21:30:20 UTC (rev 2095)
@@ -54,7 +54,7 @@
@Test public void testAddGetBatch1() throws Exception {
StorageManager sm = getStorageManager(null, null, null);
- String tsID = "local1:0"; //$NON-NLS-1$
+ String tsID = "0"; //$NON-NLS-1$
// Add one batch
FileStore store = sm.createFileStore(tsID);
writeBytes(store);
@@ -64,7 +64,7 @@
@Test public void testCreatesSpillFiles() throws Exception {
FileStorageManager sm = getStorageManager(1024, null, null); // 1KB
- String tsID = "local1:0"; //$NON-NLS-1$
+ String tsID = "0"; //$NON-NLS-1$
// Add one batch
FileStore store = sm.createFileStore(tsID);
writeBytes(store);
[View Less]
14 years, 8 months
teiid SVN: r2094 - in trunk: connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/oracle and 2 other directories.
by teiid-commits@lists.jboss.org
Author: shawkins
Date: 2010-05-03 16:24:22 -0400 (Mon, 03 May 2010)
New Revision: 2094
Modified:
trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/oracle/OracleCapabilities.java
trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/oracle/OracleSQLTranslator.java
trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/oracle/TestOracleTranslator.java
trunk/engine/src/main/java/com/metamatrix/query/validator/…
[View More]AggregateValidationVisitor.java
trunk/engine/src/test/java/com/metamatrix/query/validator/TestValidator.java
Log:
fixing ctc issues: date handling regress, distinct agg validation, and adding cot oracle pushdown
Modified: trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/oracle/OracleCapabilities.java
===================================================================
--- trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/oracle/OracleCapabilities.java 2010-05-03 19:31:05 UTC (rev 2093)
+++ trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/oracle/OracleCapabilities.java 2010-05-03 20:24:22 UTC (rev 2094)
@@ -26,6 +26,7 @@
import java.util.*;
+import org.teiid.connector.api.SourceSystemFunctions;
import org.teiid.connector.jdbc.JDBCCapabilities;
@@ -47,7 +48,8 @@
supportedFunctions.add("ASIN"); //$NON-NLS-1$
supportedFunctions.add("ATAN"); //$NON-NLS-1$
supportedFunctions.add("ATAN2"); //$NON-NLS-1$
- supportedFunctions.add("COS"); //$NON-NLS-1$
+ supportedFunctions.add("COS"); //$NON-NLS-1$
+ supportedFunctions.add(SourceSystemFunctions.COT);
supportedFunctions.add("EXP"); //$NON-NLS-1$
supportedFunctions.add("FLOOR"); //$NON-NLS-1$
supportedFunctions.add("CEILING"); //$NON-NLS-1$
Modified: trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/oracle/OracleSQLTranslator.java
===================================================================
--- trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/oracle/OracleSQLTranslator.java 2010-05-03 19:31:05 UTC (rev 2093)
+++ trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/oracle/OracleSQLTranslator.java 2010-05-03 20:24:22 UTC (rev 2094)
@@ -39,6 +39,7 @@
import org.teiid.connector.api.ConnectorException;
import org.teiid.connector.api.ExecutionContext;
import org.teiid.connector.api.SourceSystemFunctions;
+import org.teiid.connector.api.TypeFacility;
import org.teiid.connector.jdbc.JDBCManagedConnectionFactory;
import org.teiid.connector.jdbc.JDBCPlugin;
import org.teiid.connector.jdbc.translator.AliasModifier;
@@ -50,10 +51,12 @@
import org.teiid.connector.language.ColumnReference;
import org.teiid.connector.language.Command;
import org.teiid.connector.language.DerivedColumn;
+import org.teiid.connector.language.Expression;
import org.teiid.connector.language.ExpressionValueSource;
import org.teiid.connector.language.Function;
import org.teiid.connector.language.Insert;
import org.teiid.connector.language.Limit;
+import org.teiid.connector.language.Literal;
import org.teiid.connector.language.NamedTable;
import org.teiid.connector.language.QueryExpression;
import org.teiid.connector.language.Select;
@@ -103,7 +106,14 @@
registerFunctionModifier(SourceSystemFunctions.SUBSTRING, new AliasModifier("substr"));//$NON-NLS-1$
registerFunctionModifier(SourceSystemFunctions.LEFT, new LeftOrRightFunctionModifier(getLanguageFactory()));
registerFunctionModifier(SourceSystemFunctions.RIGHT, new LeftOrRightFunctionModifier(getLanguageFactory()));
- registerFunctionModifier(SourceSystemFunctions.CONCAT, new ConcatFunctionModifier(getLanguageFactory()));
+ registerFunctionModifier(SourceSystemFunctions.CONCAT, new ConcatFunctionModifier(getLanguageFactory()));
+ registerFunctionModifier(SourceSystemFunctions.COT, new FunctionModifier() {
+ @Override
+ public List<?> translate(Function function) {
+ function.setName(SourceSystemFunctions.TAN);
+ return Arrays.asList(getLanguageFactory().createFunction(SourceSystemFunctions.DIVIDE_OP, new Expression[] {new Literal(1, TypeFacility.RUNTIME_TYPES.INTEGER), function}, TypeFacility.RUNTIME_TYPES.DOUBLE));
+ }
+ });
//spatial functions
registerFunctionModifier(RELATE, new OracleSpatialFunctionModifier());
@@ -130,7 +140,22 @@
});
convertModifier.addConvert(FunctionModifier.DATE, FunctionModifier.STRING, new ConvertModifier.FormatModifier("to_char", "YYYY-MM-DD")); //$NON-NLS-1$ //$NON-NLS-2$
convertModifier.addConvert(FunctionModifier.TIME, FunctionModifier.STRING, new ConvertModifier.FormatModifier("to_char", "HH24:MI:SS")); //$NON-NLS-1$ //$NON-NLS-2$
- convertModifier.addConvert(FunctionModifier.TIMESTAMP, FunctionModifier.STRING, new ConvertModifier.FormatModifier("to_char", "YYYY-MM-DD HH24:MI:SS.FF")); //$NON-NLS-1$ //$NON-NLS-2$
+ convertModifier.addConvert(FunctionModifier.TIMESTAMP, FunctionModifier.STRING, new FunctionModifier() {
+ @Override
+ public List<?> translate(Function function) {
+ //if column and type is date, just use date format
+ Expression ex = function.getParameters().get(0);
+ String format = "YYYY-MM-DD HH24:MI:SS.FF"; //$NON-NLS-1$
+ if (ex instanceof ColumnReference) {
+ if ("date".equals(((ColumnReference)ex).getMetadataObject().getNativeType())) { //$NON-NLS-1$
+ format = "YYYY-MM-DD HH24:MI:SS"; //$NON-NLS-1$
+ }
+ } else if (!(ex instanceof Function)) {
+ ex = ConvertModifier.createConvertFunction(getLanguageFactory(), function.getParameters().get(0), TypeFacility.RUNTIME_NAMES.TIMESTAMP);
+ }
+ return Arrays.asList("to_char(", ex, ", '"+format+"')"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+ }
+ });
convertModifier.addConvert(FunctionModifier.STRING, FunctionModifier.DATE, new ConvertModifier.FormatModifier("to_date", "YYYY-MM-DD")); //$NON-NLS-1$ //$NON-NLS-2$
convertModifier.addConvert(FunctionModifier.STRING, FunctionModifier.TIME, new ConvertModifier.FormatModifier("to_date", "HH24:MI:SS")); //$NON-NLS-1$ //$NON-NLS-2$
convertModifier.addConvert(FunctionModifier.STRING, FunctionModifier.TIMESTAMP, new ConvertModifier.FormatModifier("to_timestamp", "YYYY-MM-DD HH24:MI:SS.FF")); //$NON-NLS-1$ //$NON-NLS-2$
Modified: trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/oracle/TestOracleTranslator.java
===================================================================
--- trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/oracle/TestOracleTranslator.java 2010-05-03 19:31:05 UTC (rev 2093)
+++ trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/oracle/TestOracleTranslator.java 2010-05-03 20:24:22 UTC (rev 2094)
@@ -140,6 +140,17 @@
input, output,
TRANSLATOR);
}
+
+ /**
+ * here we use the date form of the conversion
+ */
+ @Test public void testConversion6a() throws Exception {
+ String input = "SELECT convert(timestampvalue, string) FROM BQT1.SMALLA"; //$NON-NLS-1$
+ String output = "SELECT to_char(SmallishA.timestampvalue, 'YYYY-MM-DD HH24:MI:SS') FROM SmallishA"; //$NON-NLS-1$
+
+ helpTestVisitor(getOracleSpecificMetadata(), input, EMPTY_CONTEXT, null, output);
+ }
+
@Test public void testConversion8() throws Exception {
String input = "SELECT nvl(INTNUM, 'otherString') FROM BQT1.SMALLA"; //$NON-NLS-1$
String output = "SELECT nvl(to_char(SmallA.IntNum), 'otherString') FROM SmallA"; //$NON-NLS-1$
@@ -705,14 +716,17 @@
String[] elemNames = new String[] {
"DoubleNum", //$NON-NLS-1$
"ID", //$NON-NLS-1$
+ "timestampvalue", //$NON-NLS-1$
};
String[] elemTypes = new String[] {
DataTypeManager.DefaultDataTypes.DOUBLE,
DataTypeManager.DefaultDataTypes.INTEGER,
+ DataTypeManager.DefaultDataTypes.TIMESTAMP,
};
List<Column> cols = RealMetadataFactory.createElements(table, elemNames, elemTypes);
cols.get(1).setAutoIncremented(true);
cols.get(1).setNameInSource("ID:SEQUENCE=MYSEQUENCE.nextVal"); //$NON-NLS-1$
+ cols.get(2).setNativeType("date"); //$NON-NLS-1$
RealMetadataFactory.createElements(dual, new String[] {"something"}, new String[] {DataTypeManager.DefaultDataTypes.STRING}); //$NON-NLS-1$
CompositeMetadataStore store = new CompositeMetadataStore(metadataStore);
@@ -757,9 +771,15 @@
String input = "(select intkey from bqt1.smalla limit 50, 100) union select intnum from bqt1.smalla order by intkey"; //$NON-NLS-1$
String output = "SELECT c_0 FROM (SELECT VIEW_FOR_LIMIT.*, ROWNUM ROWNUM_ FROM (SELECT g_1.IntKey AS c_0 FROM SmallA g_1) VIEW_FOR_LIMIT WHERE ROWNUM <= 150) WHERE ROWNUM_ > 50 UNION SELECT g_0.IntNum AS c_0 FROM SmallA g_0 ORDER BY c_0 NULLS FIRST"; //$NON-NLS-1$
- CommandBuilder commandBuilder = new CommandBuilder(FakeMetadataFactory.exampleBQTCached());
+ CommandBuilder commandBuilder = new CommandBuilder(FakeMetadataFactory.exampleBQTCached());
Command obj = commandBuilder.getCommand(input, true, true);
this.helpTestVisitor(obj, EMPTY_CONTEXT, null, output);
}
+
+ @Test public void testCot() throws Exception {
+ String sql = "select cot(doublenum) from BQT1.Smalla"; //$NON-NLS-1$
+ String expected = "SELECT (1 / tan(SmallA.DoubleNum)) FROM SmallA"; //$NON-NLS-1$
+ helpTestVisitor(FakeMetadataFactory.exampleBQTCached(), sql, EMPTY_CONTEXT, null, expected);
+ }
}
Modified: trunk/engine/src/main/java/com/metamatrix/query/validator/AggregateValidationVisitor.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/query/validator/AggregateValidationVisitor.java 2010-05-03 19:31:05 UTC (rev 2093)
+++ trunk/engine/src/main/java/com/metamatrix/query/validator/AggregateValidationVisitor.java 2010-05-03 20:24:22 UTC (rev 2094)
@@ -75,7 +75,7 @@
if((aggregateFunction.equals(SQLReservedWords.SUM) || aggregateFunction.equals(SQLReservedWords.AVG)) && obj.getType() == null) {
handleValidationError(QueryPlugin.Util.getString(ErrorMessageKeys.VALIDATOR_0041, new Object[] {aggregateFunction, obj}), obj);
}
- if((aggregateFunction.equals(SQLReservedWords.MIN) || aggregateFunction.equals(SQLReservedWords.MAX)) && DataTypeManager.isNonComparable(DataTypeManager.getDataTypeName(aggExp.getType()))) {
+ if((obj.isDistinct() || aggregateFunction.equals(SQLReservedWords.MIN) || aggregateFunction.equals(SQLReservedWords.MAX)) && DataTypeManager.isNonComparable(DataTypeManager.getDataTypeName(aggExp.getType()))) {
handleValidationError(QueryPlugin.Util.getString("AggregateValidationVisitor.non_comparable", new Object[] {aggregateFunction, obj}), obj); //$NON-NLS-1$
}
validateBelow = false;
Modified: trunk/engine/src/test/java/com/metamatrix/query/validator/TestValidator.java
===================================================================
--- trunk/engine/src/test/java/com/metamatrix/query/validator/TestValidator.java 2010-05-03 19:31:05 UTC (rev 2093)
+++ trunk/engine/src/test/java/com/metamatrix/query/validator/TestValidator.java 2010-05-03 20:24:22 UTC (rev 2094)
@@ -487,6 +487,11 @@
new String[] {"MAX(ObjectValue)"}, FakeMetadataFactory.exampleBQTCached() ); //$NON-NLS-1$
}
+ @Test public void testInvalidAggregate9() {
+ helpValidate("SELECT count(distinct ObjectValue) FROM BQT1.SmallA GROUP BY StringKey", //$NON-NLS-1$
+ new String[] {"COUNT(DISTINCT ObjectValue)"}, FakeMetadataFactory.exampleBQTCached() ); //$NON-NLS-1$
+ }
+
@Test public void testInvalidAggregateIssue190644() {
helpValidate("SELECT e3 + 1 from pm1.g1 GROUP BY e2 + 1 HAVING e2 + 1 = 5", new String[] {"e3"}, FakeMetadataFactory.example1Cached()); //$NON-NLS-1$ //$NON-NLS-2$
}
[View Less]
14 years, 8 months
teiid SVN: r2093 - in trunk: engine/src/main/java/com/metamatrix/query/function/source and 1 other directory.
by teiid-commits@lists.jboss.org
Author: shawkins
Date: 2010-05-03 15:31:05 -0400 (Mon, 03 May 2010)
New Revision: 2093
Modified:
trunk/common-core/src/main/java/com/metamatrix/common/types/DataTypeManager.java
trunk/engine/src/main/java/com/metamatrix/query/function/source/XMLSystemFunctions.java
Log:
TEIID-1020 promoting stylesheet application to a system function, rather than a statement property. also correcting the reference and adding a hasrole call with only a single parameter
Modified: trunk/common-core/src/…
[View More]main/java/com/metamatrix/common/types/DataTypeManager.java
===================================================================
--- trunk/common-core/src/main/java/com/metamatrix/common/types/DataTypeManager.java 2010-05-03 17:13:39 UTC (rev 2092)
+++ trunk/common-core/src/main/java/com/metamatrix/common/types/DataTypeManager.java 2010-05-03 19:31:05 UTC (rev 2093)
@@ -27,12 +27,7 @@
import java.math.BigInteger;
import java.sql.Blob;
import java.sql.Clob;
-//## JDBC4.0-begin ##
import java.sql.SQLXML;
-//## JDBC4.0-end ##
-/*## JDBC3.0-JDK1.5-begin ##
-import com.metamatrix.core.jdbc.SQLXML;
-## JDBC3.0-JDK1.5-end ##*/
import java.sql.Time;
import java.sql.Timestamp;
import java.util.ArrayList;
@@ -172,37 +167,25 @@
}
public static final class DefaultDataClasses {
- /*
- * Here we explicitly instantiate the classes, so that JRE loads the
- * class files using the default class loader and initializes the static
- * modifiers correctly.
- *
- * Using JDK 1.4, referring to Class as "STRING = String.class" was
- * yeilding a null, rather than a String class, however using as below
- * did not show that side effect.
- */
- public static final Class STRING = "".getClass(); //$NON-NLS-1$
- public static final Class BOOLEAN = (Boolean.TRUE).getClass();
- public static final Class BYTE = (new Byte((byte) 0)).getClass();
- public static final Class SHORT = (new Short((short) 0)).getClass();
- public static final Class CHAR = (new Character('a')).getClass();
- public static final Class INTEGER = (new Integer(0)).getClass();
- public static final Class LONG = (new Long(0)).getClass();
- public static final Class BIG_INTEGER = (new java.math.BigInteger("0")).getClass(); //$NON-NLS-1$
- public static final Class FLOAT = (new Float(0)).getClass();
- public static final Class DOUBLE = (new Double(0)).getClass();
- public static final Class BIG_DECIMAL = (new java.math.BigDecimal("0")).getClass(); //$NON-NLS-1$
- public static final Class DATE = (new java.sql.Date(System
- .currentTimeMillis())).getClass();
- public static final Class TIME = (new java.sql.Time(System
- .currentTimeMillis())).getClass();
- public static final Class TIMESTAMP = (new java.sql.Timestamp(System
- .currentTimeMillis())).getClass();
- public static final Class OBJECT = (new Object()).getClass();
- public static final Class NULL = (new NullType()).getClass();
- public static final Class BLOB = (new BlobType()).getClass();
- public static final Class CLOB = (new ClobType()).getClass();
- public static final Class XML = (new XMLType()).getClass();
+ public static final Class<String> STRING = String.class;
+ public static final Class<Boolean> BOOLEAN = Boolean.class;
+ public static final Class<Byte> BYTE = Byte.class;
+ public static final Class<Short> SHORT = Short.class;
+ public static final Class<Character> CHAR = Character.class;
+ public static final Class<Integer> INTEGER = Integer.class;
+ public static final Class<Long> LONG = Long.class;
+ public static final Class<BigInteger> BIG_INTEGER = BigInteger.class;
+ public static final Class<Float> FLOAT = Float.class;
+ public static final Class<Double> DOUBLE = Double.class;
+ public static final Class<BigDecimal> BIG_DECIMAL = BigDecimal.class;
+ public static final Class<java.sql.Date> DATE = java.sql.Date.class;
+ public static final Class<Time> TIME = Time.class;
+ public static final Class<Timestamp> TIMESTAMP = Timestamp.class;
+ public static final Class<Object> OBJECT = Object.class;
+ public static final Class<NullType> NULL = NullType.class;
+ public static final Class<BlobType> BLOB = BlobType.class;
+ public static final Class<ClobType> CLOB = ClobType.class;
+ public static final Class<XMLType> XML = XMLType.class;
}
/**
Modified: trunk/engine/src/main/java/com/metamatrix/query/function/source/XMLSystemFunctions.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/query/function/source/XMLSystemFunctions.java 2010-05-03 17:13:39 UTC (rev 2092)
+++ trunk/engine/src/main/java/com/metamatrix/query/function/source/XMLSystemFunctions.java 2010-05-03 19:31:05 UTC (rev 2093)
@@ -87,7 +87,6 @@
}
}
- @SuppressWarnings("unchecked")
public static ClobType xslTransform(CommandContext context, XMLType xmlResults, XMLType styleSheet) throws Exception {
Reader styleSheetReader = styleSheet.getCharacterStream();
final Source styleSource = new StreamSource(styleSheetReader);
[View Less]
14 years, 8 months