teiid SVN: r2679 - in trunk: api/src/main/java/org/teiid/translator and 6 other directories.
by teiid-commits@lists.jboss.org
Author: shawkins
Date: 2010-10-25 12:56:38 -0400 (Mon, 25 Oct 2010)
New Revision: 2679
Modified:
trunk/api/src/main/java/org/teiid/translator/SourceSystemFunctions.java
trunk/build/kits/jboss-container/teiid-releasenotes.html
trunk/documentation/reference/src/main/docbook/en-US/content/scalar_functions.xml
trunk/engine/pom.xml
trunk/engine/src/main/java/org/teiid/query/function/source/SystemSource.java
trunk/engine/src/main/java/org/teiid/query/function/source/XMLSystemFunctions.java
trunk/engine/src/main/resources/org/teiid/query/i18n.properties
trunk/engine/src/test/java/org/teiid/query/function/source/TestXMLSystemFunctions.java
trunk/pom.xml
Log:
TEIID-1306 adding json to xml support for json integration. this adds the asl 2 json simple library from google code.
Modified: trunk/api/src/main/java/org/teiid/translator/SourceSystemFunctions.java
===================================================================
--- trunk/api/src/main/java/org/teiid/translator/SourceSystemFunctions.java 2010-10-25 16:31:58 UTC (rev 2678)
+++ trunk/api/src/main/java/org/teiid/translator/SourceSystemFunctions.java 2010-10-25 16:56:38 UTC (rev 2679)
@@ -142,5 +142,7 @@
public static final String XMLCONCAT = "xmlconcat"; //$NON-NLS-1$
public static final String XMLCOMMENT = "xmlcomment"; //$NON-NLS-1$
public static final String XMLPI = "xmlpi"; //$NON-NLS-1$
+
+ public static final String JSONTOXML = "jsontoxml"; //$NON-NLS-1$
}
Modified: trunk/build/kits/jboss-container/teiid-releasenotes.html
===================================================================
--- trunk/build/kits/jboss-container/teiid-releasenotes.html 2010-10-25 16:31:58 UTC (rev 2678)
+++ trunk/build/kits/jboss-container/teiid-releasenotes.html 2010-10-25 16:56:38 UTC (rev 2679)
@@ -31,6 +31,7 @@
<LI><B>Non-Recursive Common Table Expressions</B> - The WITH clause (and associated pushdown) for non-recursive queries is now supported.
<LI><B>Explicit Table Syntax</B> - TABLE x can now be used as a shortcut for SELECT * FROM x
</UL>
+ <LI><B>JSON Support</B> - JSON, which could be obtained through the ws-translator using http calls or other methods, can be converted to XML using the system function jsonToXml. XMLTABLE and other integration logic can then be used on the JSON results.
<LI><B>Transaction Statements</B> - JDBC/ODBC now accepts START TRANSACTION, COMMIT, and ROLLBACK statements to control local transactions.
<LI><B>Procedure Result Caching</B> - virtual procedure definitions may use a cache hint to cache results in the result set cache.
<LI><B>Improved Plan Caching</B> - plans used by internal materialization and stored procedure plans will be automatically cached in the prepared plan cache. Improvements were also made to reduce the memory footprint of the plans.
@@ -52,7 +53,7 @@
<h4>from 7.1</h4>
<ul>
<li>Subqueries are no longer allowed to be SELECT INTO.
- <li>INSERT/UPDATE/DELETE cannot be used to create implicit return cursors in non-update virtual procedures. You can instead use "integer_var = UPDATE ...; SELECT integer_var;".
+ <li>INSERT/UPDATE/DELETE cannot be used to create implicit return cursors in non-update virtual procedures. You can instead use "UPDATE ...; SELECT VARIABLES.ROWCOUNT;".
<li>The SYSADMIN schema was created to hold procedures and tables that should not be generally accessible. SYS and pg_catalog are now always accessible - permissions do not apply to these schemas. The SYS.getBinaryVDBResource, SYS.getCharacterVDBResource, and SYS.getVDBResourcePaths have been replaced with the
SYSADMIN.VDBResources table. The Matviews table and the refreshMatView/refreshMatViewRow procedures were also moved into SYSADMIN.
<li>Overwriting an existing VDB will cause old connections to be terminated. Production systems should rely on VDB versioning.
@@ -60,8 +61,8 @@
<li>Model visibility no longer restricts access to tables and procedures. Setting visible to false will only hide entries from system tables. Data roles should be used to restrict data access.
<li>Admin API "getWorkManagerStats" methods renamed to "getWorkerPoolStats". Also, "setRuntimeProperty" and "getProcesses" methods were removed.
<li>By default the "ENV" system function is now turned off. To enable it, edit the teiid-jboss-beans.xml configuration file.
- <li>The use of VARIABLES.ROWCOUNT is now reserved. Use a different
- <li>Direct assignments in virtual procedures using stored procedures (e.g. var = EXEC foo()) are only valid if the procedure has a return parameter and no result set.
+ <li>The use of VARIABLES.ROWCOUNT is now reserved.
+ <li>Exec statements of the form "var = EXEC foo()" are only valid if the procedure foo has a return parameter.
</ul>
<h4>from 7.0</h4>
<ul>
@@ -144,6 +145,7 @@
The following components have been updated:
<h4>From 7.1</h4>
<ul>
+ <li>json-simple 1.1 was added.
<li>Netty was upgraded to 3.2.1
</ul>
<h4>From 7.0</h4>
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-10-25 16:31:58 UTC (rev 2678)
+++ trunk/documentation/reference/src/main/docbook/en-US/content/scalar_functions.xml 2010-10-25 16:56:38 UTC (rev 2679)
@@ -1916,6 +1916,44 @@
<title>XML Functions</title>
<para>XML functions provide functionality for working with XML data. </para>
<section>
+ <title>JSONTOXML</title>
+ <para>Returns an xml document from JSON.</para>
+ <para><synopsis>JSONTOXML(rootElementName, json)</synopsis></para>
+ <para>rootElementName is a string, json is in {clob, blob}. Return value is xml.</para>
+ <para>The appropriate UTF encoding (8, 16LE. 16BE, 32LE, 32BE) will be detected for JSON blobs. If another encoding is used, see the to_chars function.</para>
+ <para>The result is always a well-formed XML document.</para>
+ <para>The mapping to XML uses the following rules:
+ <itemizedlist>
+ <listitem>
+ <para>The current element name is initially the rootElementName, and becomes the object value name as the JSON structure is traversed.</para>
+ </listitem>
+ <listitem>
+ <para>All element names must be valid xml 1.1 names. Invalid names are fully escaped according to the SQLXML specification.</para>
+ </listitem>
+ <listitem>
+ <para>Each object or primitive value will be enclosed in an element with the current name.</para>
+ </listitem>
+ <listitem>
+ <para>Unless an array value is the root, it will not be enclosed in an additional element.</para>
+ </listitem>
+ </itemizedlist>
+ </para>
+ <example>
+ <title>Sample JSON to XML for jsonToXml('person', x)</title>
+ <para>JSON:</para>
+ <programlisting language="JSON">{ "firstName" : "John" , "children" : [ "Randy", "Judy" ] }</programlisting>
+ <para>XML:</para>
+ <programlisting language="XML"><![CDATA[<?xml version="1.0" ?><person><firstName>John</firstName><children>Randy</children><children>Judy<children></person>]]></programlisting>
+ </example>
+ <example>
+ <title>Sample JSON to XML for jsonToXml('person', x) with a root array.</title>
+ <para>JSON:</para>
+ <programlisting language="JSON">[{ "firstName" : "George" }, { "firstName" : "Jerry" }]</programlisting>
+ <para>XML (Notice there is an extra "person" wrapping element to keep the XML well-formed):</para>
+ <programlisting language="XML"><![CDATA[<?xml version="1.0" ?><person><person><firstName>George</firstName></person><person><firstName>Jerry</firstName></person></person>]]></programlisting>
+ </example>
+ </section>
+ <section>
<title>XMLCOMMENT</title>
<para>Returns an xml comment.</para>
<para><synopsis>XMLCOMMENT(comment)</synopsis></para>
Modified: trunk/engine/pom.xml
===================================================================
--- trunk/engine/pom.xml 2010-10-25 16:31:58 UTC (rev 2678)
+++ trunk/engine/pom.xml 2010-10-25 16:56:38 UTC (rev 2679)
@@ -86,6 +86,11 @@
<classifier>dom</classifier>
<artifactId>saxon</artifactId>
</dependency>
+
+ <dependency>
+ <groupId>com.googlecode.json-simple</groupId>
+ <artifactId>json-simple</artifactId>
+ </dependency>
</dependencies>
Modified: trunk/engine/src/main/java/org/teiid/query/function/source/SystemSource.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/function/source/SystemSource.java 2010-10-25 16:31:58 UTC (rev 2678)
+++ trunk/engine/src/main/java/org/teiid/query/function/source/SystemSource.java 2010-10-25 16:56:38 UTC (rev 2679)
@@ -179,6 +179,7 @@
addXmlConcat();
addXmlComment();
addXmlPi();
+ addJsonToXml();
addSecurityFunctions();
@@ -970,6 +971,19 @@
new FunctionParameter("result", DataTypeManager.DefaultDataTypes.XML, QueryPlugin.Util.getString("SystemSource.xmlpi_result")) ) ); //$NON-NLS-1$ //$NON-NLS-2$
}
+ private void addJsonToXml() {
+ functions.add(new FunctionMethod(SourceSystemFunctions.JSONTOXML, QueryPlugin.Util.getString("SystemSource.jsonToXml_description"), XML, XML_FUNCTION_CLASS, "jsonToXml", //$NON-NLS-1$ //$NON-NLS-2$
+ new FunctionParameter[] {
+ new FunctionParameter("rootElementName", DataTypeManager.DefaultDataTypes.STRING, QueryPlugin.Util.getString("SystemSource.jsonToXml_param1")), //$NON-NLS-1$ //$NON-NLS-2$
+ new FunctionParameter("json", DataTypeManager.DefaultDataTypes.CLOB, QueryPlugin.Util.getString("SystemSource.jsonToXml_param2"))}, //$NON-NLS-1$ //$NON-NLS-2$
+ new FunctionParameter("result", DataTypeManager.DefaultDataTypes.XML, QueryPlugin.Util.getString("SystemSource.jsonToXml_result")) ) ); //$NON-NLS-1$ //$NON-NLS-2$
+ functions.add(new FunctionMethod(SourceSystemFunctions.JSONTOXML, QueryPlugin.Util.getString("SystemSource.jsonToXml_description"), XML, XML_FUNCTION_CLASS, "jsonToXml", //$NON-NLS-1$ //$NON-NLS-2$
+ new FunctionParameter[] {
+ new FunctionParameter("rootElementName", DataTypeManager.DefaultDataTypes.STRING, QueryPlugin.Util.getString("SystemSource.jsonToXml_param1")), //$NON-NLS-1$ //$NON-NLS-2$
+ new FunctionParameter("json", DataTypeManager.DefaultDataTypes.BLOB, QueryPlugin.Util.getString("SystemSource.jsonToXml_param2"))}, //$NON-NLS-1$ //$NON-NLS-2$
+ new FunctionParameter("result", DataTypeManager.DefaultDataTypes.XML, QueryPlugin.Util.getString("SystemSource.jsonToXml_result")) ) ); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
private void addXmlConcat() {
functions.add(new FunctionMethod(SourceSystemFunctions.XMLCONCAT, QueryPlugin.Util.getString("SystemSource.xmlconcat_description"), XML, FunctionMethod.CAN_PUSHDOWN, XML_FUNCTION_CLASS, "xmlConcat", //$NON-NLS-1$ //$NON-NLS-2$
new FunctionParameter[] {
Modified: trunk/engine/src/main/java/org/teiid/query/function/source/XMLSystemFunctions.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/function/source/XMLSystemFunctions.java 2010-10-25 16:31:58 UTC (rev 2678)
+++ trunk/engine/src/main/java/org/teiid/query/function/source/XMLSystemFunctions.java 2010-10-25 16:56:38 UTC (rev 2679)
@@ -24,10 +24,14 @@
import java.io.BufferedReader;
import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.PushbackInputStream;
import java.io.Reader;
import java.io.StringReader;
import java.io.Writer;
import java.nio.CharBuffer;
+import java.nio.charset.Charset;
import java.sql.Blob;
import java.sql.Clob;
import java.sql.Date;
@@ -36,6 +40,7 @@
import java.sql.Time;
import java.sql.Timestamp;
import java.util.Collections;
+import java.util.LinkedList;
import java.util.List;
import javax.xml.XMLConstants;
@@ -48,6 +53,7 @@
import javax.xml.stream.XMLInputFactory;
import javax.xml.stream.XMLOutputFactory;
import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamWriter;
import javax.xml.stream.events.XMLEvent;
import javax.xml.transform.Source;
import javax.xml.transform.Transformer;
@@ -69,6 +75,9 @@
import net.sf.saxon.value.DayTimeDurationValue;
import net.sf.saxon.value.TimeValue;
+import org.json.simple.parser.ContentHandler;
+import org.json.simple.parser.JSONParser;
+import org.json.simple.parser.ParseException;
import org.teiid.core.TeiidComponentException;
import org.teiid.core.TeiidProcessingException;
import org.teiid.core.types.ClobImpl;
@@ -91,6 +100,135 @@
*/
public class XMLSystemFunctions {
+ private static final Charset UTF_32BE = Charset.forName("UTF-32BE"); //$NON-NLS-1$
+ private static final Charset UTF_16BE = Charset.forName("UTF-16BE"); //$NON-NLS-1$
+ private static final Charset UTF_32LE = Charset.forName("UTF-32LE"); //$NON-NLS-1$
+ private static final Charset UTF_16LE = Charset.forName("UTF-16LE"); //$NON-NLS-1$
+ private static final Charset UTF_8 = Charset.forName("UTF-8"); //$NON-NLS-1$
+
+ //TODO: this could be done fully streaming without holding the intermediate xml output
+ private static final class JsonToXmlContentHandler implements
+ ContentHandler {
+ private final XMLStreamWriter streamWriter;
+ private String currentName;
+ private LinkedList<Boolean> inArray = new LinkedList<Boolean>();
+
+ private JsonToXmlContentHandler(String rootName,
+ XMLStreamWriter streamWriter) {
+ this.streamWriter = streamWriter;
+ this.currentName = rootName;
+ }
+
+ @Override
+ public boolean startObjectEntry(String key)
+ throws org.json.simple.parser.ParseException, IOException {
+ currentName = key;
+ start();
+ return true;
+ }
+
+ @Override
+ public boolean startObject() throws org.json.simple.parser.ParseException,
+ IOException {
+ if (inArray.peek()) {
+ start();
+ }
+ inArray.push(false);
+ return true;
+ }
+
+ private void start()
+ throws IOException {
+ try {
+ streamWriter.writeStartElement(escapeName(currentName, true));
+ } catch (XMLStreamException e) {
+ throw new IOException(e);
+ }
+ }
+
+ @Override
+ public void startJSON() throws org.json.simple.parser.ParseException,
+ IOException {
+ try {
+ streamWriter.writeStartDocument();
+ } catch (XMLStreamException e) {
+ throw new IOException(e);
+ }
+ inArray.push(false);
+ start();
+ }
+
+ @Override
+ public boolean startArray() throws org.json.simple.parser.ParseException,
+ IOException {
+ inArray.push(true);
+ return true;
+ }
+
+ @Override
+ public boolean primitive(Object value)
+ throws org.json.simple.parser.ParseException, IOException {
+ if (inArray.peek()) {
+ start();
+ }
+ if (value != null) {
+ try {
+ streamWriter.writeCharacters(value.toString());
+ } catch (XMLStreamException e) {
+ throw new IOException(e);
+ }
+ }
+ if (inArray.peek()) {
+ end();
+ }
+ return true;
+ }
+
+ private void end()
+ throws IOException {
+ try {
+ streamWriter.writeEndElement();
+ } catch (XMLStreamException e) {
+ throw new IOException(e);
+ }
+ }
+
+ @Override
+ public boolean endObjectEntry()
+ throws org.json.simple.parser.ParseException, IOException {
+ end();
+ return true;
+ }
+
+ @Override
+ public boolean endObject() throws org.json.simple.parser.ParseException,
+ IOException {
+ inArray.pop();
+ if (inArray.peek()) {
+ end();
+ }
+ return true;
+ }
+
+ @Override
+ public void endJSON() throws org.json.simple.parser.ParseException,
+ IOException {
+ end();
+ try {
+ streamWriter.writeEndDocument();
+ } catch (XMLStreamException e) {
+ throw new IOException(e);
+ }
+ }
+
+ @Override
+ public boolean endArray() throws org.json.simple.parser.ParseException,
+ IOException {
+ inArray.pop();
+ return true;
+ }
+ }
+
private static final String P_OUTPUT_VALIDATE_STRUCTURE = "com.ctc.wstx.outputValidateStructure"; //$NON-NLS-1$
public static ClobType xslTransform(CommandContext context, Object xml, Object styleSheet) throws Exception {
@@ -496,5 +634,72 @@
CharsetUtils.toHex(cb, (byte)chr);
return cb.append("_").flip().toString(); //$NON-NLS-1$
}
+
+ public static SQLXML jsonToXml(CommandContext context, final String rootName, final Blob json) throws TeiidComponentException, TeiidProcessingException, SQLException, IOException {
+ InputStream is = json.getBinaryStream();
+ PushbackInputStream pStream = new PushbackInputStream(is, 4);
+ byte[] encoding = new byte[3];
+ int read = pStream.read(encoding);
+ pStream.unread(encoding, 0, read);
+ Charset charset = UTF_8;
+ if (read > 2) {
+ if (encoding[0] == 0) {
+ if (encoding[1] == 0) {
+ charset = UTF_32BE;
+ } else {
+ charset = UTF_16BE;
+ }
+ } else if (encoding[1] == 0) {
+ if (encoding[2] == 0) {
+ charset = UTF_32LE;
+ } else {
+ charset = UTF_16LE;
+ }
+ }
+ }
+ Reader r = new InputStreamReader(pStream, charset);
+ return jsonToXml(context, rootName, r);
+ }
+ public static SQLXML jsonToXml(CommandContext context, final String rootName, final Clob json) throws TeiidComponentException, TeiidProcessingException, SQLException {
+ return jsonToXml(context, rootName, json.getCharacterStream());
+ }
+
+ private static SQLXML jsonToXml(CommandContext context,
+ final String rootName, final Reader r) throws TeiidComponentException,
+ TeiidProcessingException {
+ XMLType result = new XMLType(XMLUtil.saveToBufferManager(context.getBufferManager(), new XMLTranslator() {
+
+ @Override
+ public void translate(Writer writer) throws TransformerException,
+ IOException {
+ try {
+ JSONParser parser = new JSONParser();
+ XMLOutputFactory factory = getOutputFactory();
+ final XMLStreamWriter streamWriter = factory.createXMLStreamWriter(writer);
+
+ parser.parse(r, new JsonToXmlContentHandler(escapeName(rootName, true), streamWriter));
+
+ streamWriter.flush(); //woodstox needs a flush rather than a close
+ } catch (XMLStreamException e) {
+ throw new TransformerException(e);
+ } catch (ParseException e) {
+ throw new TransformerException(e);
+ } finally {
+ try {
+ r.close();
+ } catch (IOException e) {
+
+ }
+ }
+ }
+ }));
+ result.setType(Type.DOCUMENT);
+ return result;
+ }
+
+ public static void main(String[] args) {
+ System.out.println(Charset.availableCharsets());
+ }
+
}
Modified: trunk/engine/src/main/resources/org/teiid/query/i18n.properties
===================================================================
--- trunk/engine/src/main/resources/org/teiid/query/i18n.properties 2010-10-25 16:31:58 UTC (rev 2678)
+++ trunk/engine/src/main/resources/org/teiid/query/i18n.properties 2010-10-25 16:56:38 UTC (rev 2679)
@@ -593,6 +593,10 @@
SystemSource.xmlpi_param1=Target
SystemSource.xmlpi_param2=Content
SystemSource.xmlpi_result=XML result
+SystemSource.jsonToXml_description=Create an XML document representing the given JSON.
+SystemSource.jsonToXml_param1=Root element name
+SystemSource.jsonToXml_param2=JSON
+SystemSource.jsonToXml_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/org/teiid/query/function/source/TestXMLSystemFunctions.java
===================================================================
--- trunk/engine/src/test/java/org/teiid/query/function/source/TestXMLSystemFunctions.java 2010-10-25 16:31:58 UTC (rev 2678)
+++ trunk/engine/src/test/java/org/teiid/query/function/source/TestXMLSystemFunctions.java 2010-10-25 16:56:38 UTC (rev 2679)
@@ -26,19 +26,29 @@
import java.io.File;
import java.io.IOException;
+import java.nio.charset.Charset;
+import java.sql.SQLException;
+import java.sql.SQLXML;
import java.util.TimeZone;
+import javax.sql.rowset.serial.SerialBlob;
+import javax.sql.rowset.serial.SerialClob;
+import javax.sql.rowset.serial.SerialException;
+
import net.sf.saxon.trans.XPathException;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.Test;
+import org.teiid.common.buffer.BufferManagerFactory;
+import org.teiid.core.TeiidComponentException;
import org.teiid.core.TeiidProcessingException;
import org.teiid.core.types.SQLXMLImpl;
import org.teiid.core.types.XMLType;
import org.teiid.core.util.ObjectConverterUtil;
import org.teiid.core.util.UnitTestUtil;
import org.teiid.query.unittest.TimestampUtil;
+import org.teiid.query.util.CommandContext;
@SuppressWarnings("nls")
public class TestXMLSystemFunctions {
@@ -182,6 +192,32 @@
assertEquals("_u000A_", XMLSystemFunctions.escapeName(new String(new char[] {10}), true));
}
+ @Test public void testJsonToXml() throws Exception {
+ String json = "[0,{\"1\":{\"2\":{\"3\":{\"4\":[5,{\"6\":7}]}}}}]";
+ String expected = "<?xml version=\"1.0\" ?><Array><Array>0</Array><Array><_u0031_><_u0032_><_u0033_><_u0034_><_u0034_>5</_u0034_><_u0034_><_u0036_>7</_u0036_></_u0034_></_u0034_></_u0033_></_u0032_></_u0031_></Array></Array>";
+ helpTestJson(json, "Array", expected);
+ }
+
+ private void helpTestJson(String json, String rootName, String expected)
+ throws SQLException, TeiidComponentException,
+ TeiidProcessingException, SerialException, IOException {
+ CommandContext cc = new CommandContext();
+ cc.setBufferManager(BufferManagerFactory.getStandaloneBufferManager());
+ SQLXML xml = XMLSystemFunctions.jsonToXml(cc, rootName, new SerialClob(json.toCharArray()));
+ assertEquals(expected, xml.getString());
+ xml = XMLSystemFunctions.jsonToXml(cc, rootName, new SerialBlob(json.getBytes(Charset.forName("UTF-8"))));
+ assertEquals(expected, xml.getString());
+ xml = XMLSystemFunctions.jsonToXml(cc, rootName, new SerialBlob(json.getBytes(Charset.forName("UTF-32BE"))));
+ assertEquals(expected, xml.getString());
+ }
+
+ @Test public void testJsonToXml1() throws Exception {
+ String json = "{ \"firstName\": \"John\", \"lastName\": \"Smith\", \"age\": 25, \"address\": { \"streetAddress\": \"21 2nd Street\", \"city\": \"New York\", \"state\": \"NY\", "+
+ "\"postalCode\": \"10021\" }, \"phoneNumber\": [ { \"type\": \"home\", \"number\": \"212 555-1234\" }, { \"type\": \"fax\", \"number\": \"646 555-4567\" } ] }";
+ String expected = "<?xml version=\"1.0\" ?><Person><firstName>John</firstName><lastName>Smith</lastName><age>25</age><address><streetAddress>21 2nd Street</streetAddress><city>New York</city><state>NY</state><postalCode>10021</postalCode></address><phoneNumber><phoneNumber><type>home</type><number>212 555-1234</number></phoneNumber><number><type>fax</type><number>646 555-4567</number></number></phoneNumber></Person>";
+ helpTestJson(json, "Person", expected);
+ }
+
@BeforeClass static public void setUpOnce() {
TimeZone.setDefault(TimeZone.getTimeZone("GMT-6:00"));
}
Modified: trunk/pom.xml
===================================================================
--- trunk/pom.xml 2010-10-25 16:31:58 UTC (rev 2678)
+++ trunk/pom.xml 2010-10-25 16:56:38 UTC (rev 2679)
@@ -456,6 +456,11 @@
<artifactId>ant</artifactId>
<version>${ant.version}</version>
</dependency>
+ <dependency>
+ <groupId>com.googlecode.json-simple</groupId>
+ <artifactId>json-simple</artifactId>
+ <version>1.1</version>
+ </dependency>
</dependencies>
</dependencyManagement>
<modules>
15 years, 6 months
teiid SVN: r2678 - in branches/7.1.x/connectors/translator-jdbc/src: test/java/org/teiid/translator/jdbc/oracle and 1 other directory.
by teiid-commits@lists.jboss.org
Author: shawkins
Date: 2010-10-25 12:31:58 -0400 (Mon, 25 Oct 2010)
New Revision: 2678
Modified:
branches/7.1.x/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/oracle/OracleExecutionFactory.java
branches/7.1.x/connectors/translator-jdbc/src/test/java/org/teiid/translator/jdbc/oracle/TestOracleConvertModifier.java
Log:
TEIID-1320 update to the oracle timestamp to string logic
Modified: branches/7.1.x/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/oracle/OracleExecutionFactory.java
===================================================================
--- branches/7.1.x/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/oracle/OracleExecutionFactory.java 2010-10-22 21:42:45 UTC (rev 2677)
+++ branches/7.1.x/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/oracle/OracleExecutionFactory.java 2010-10-25 16:31:58 UTC (rev 2678)
@@ -150,11 +150,9 @@
//if column and type is date, just use date format
Expression ex = function.getParameters().get(0);
String format = TIMESTAMP_FORMAT;
- if (ex instanceof ColumnReference) {
- if ("date".equals(((ColumnReference)ex).getMetadataObject().getNativeType())) { //$NON-NLS-1$
- format = DATETIME_FORMAT;
- }
- } else if (!(ex instanceof Function) && !(ex instanceof Literal)) {
+ if (ex instanceof ColumnReference && "date".equalsIgnoreCase(((ColumnReference)ex).getMetadataObject().getNativeType())) { //$NON-NLS-1$
+ format = DATETIME_FORMAT;
+ } else if (!(ex instanceof Literal) && !(ex instanceof Function)) {
//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);
}
Modified: branches/7.1.x/connectors/translator-jdbc/src/test/java/org/teiid/translator/jdbc/oracle/TestOracleConvertModifier.java
===================================================================
--- branches/7.1.x/connectors/translator-jdbc/src/test/java/org/teiid/translator/jdbc/oracle/TestOracleConvertModifier.java 2010-10-22 21:42:45 UTC (rev 2677)
+++ branches/7.1.x/connectors/translator-jdbc/src/test/java/org/teiid/translator/jdbc/oracle/TestOracleConvertModifier.java 2010-10-25 16:31:58 UTC (rev 2678)
@@ -34,6 +34,7 @@
import org.teiid.language.Expression;
import org.teiid.language.Function;
import org.teiid.language.LanguageFactory;
+import org.teiid.metadata.Column;
import org.teiid.query.unittest.TimestampUtil;
import org.teiid.translator.TypeFacility;
import org.teiid.translator.jdbc.SQLConversionVisitor;
@@ -41,6 +42,7 @@
/**
*/
+@SuppressWarnings("nls")
public class TestOracleConvertModifier {
private static final LanguageFactory LANG_FACTORY = new LanguageFactory();
@@ -500,6 +502,13 @@
Timestamp ts = TimestampUtil.createTimestamp(103, 10, 1, 12, 5, 2, 10000000);
helpTest(LANG_FACTORY.createLiteral(ts, Timestamp.class), "string", "to_char({ts '2003-11-01 12:05:02.01'}, 'YYYY-MM-DD HH24:MI:SS.FF')"); //$NON-NLS-1$ //$NON-NLS-2$
}
+
+ @Test public void testTimestampToString1() throws Exception {
+ Column column = new Column();
+ column.setNativeType("DATE");
+ column.setNameInSource("dt");
+ helpTest(LANG_FACTORY.createColumnReference("dt", LANG_FACTORY.createNamedTable("x", null, null), column, Timestamp.class), "string", "to_char(x.dt, 'YYYY-MM-DD HH24:MI:SS')"); //$NON-NLS-1$ //$NON-NLS-2$
+ }
@Test public void testTimestampToDate() throws Exception {
Timestamp ts = TimestampUtil.createTimestamp(103, 10, 1, 12, 5, 2, 10000000);
15 years, 6 months
teiid SVN: r2677 - in branches/7.1.x/connectors/translator-jdbc/src: test/java/org/teiid/translator/jdbc/postgresql and 1 other directory.
by teiid-commits@lists.jboss.org
Author: shawkins
Date: 2010-10-22 17:42:45 -0400 (Fri, 22 Oct 2010)
New Revision: 2677
Modified:
branches/7.1.x/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/postgresql/PostgreSQLExecutionFactory.java
branches/7.1.x/connectors/translator-jdbc/src/test/java/org/teiid/translator/jdbc/postgresql/TestPostgreSQLTranslator.java
Log:
TEIID-1319 updating the format string for timestamp to string
Modified: branches/7.1.x/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/postgresql/PostgreSQLExecutionFactory.java
===================================================================
--- branches/7.1.x/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/postgresql/PostgreSQLExecutionFactory.java 2010-10-22 21:40:32 UTC (rev 2676)
+++ branches/7.1.x/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/postgresql/PostgreSQLExecutionFactory.java 2010-10-22 21:42:45 UTC (rev 2677)
@@ -140,7 +140,7 @@
});
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.UF")); //$NON-NLS-1$ //$NON-NLS-2$
+ convertModifier.addConvert(FunctionModifier.TIMESTAMP, FunctionModifier.STRING, new ConvertModifier.FormatModifier("to_char", "YYYY-MM-DD HH24:MI:SS.US")); //$NON-NLS-1$ //$NON-NLS-2$
convertModifier.addConvert(FunctionModifier.BOOLEAN, FunctionModifier.STRING, new FunctionModifier() {
@Override
public List<?> translate(Function function) {
Modified: branches/7.1.x/connectors/translator-jdbc/src/test/java/org/teiid/translator/jdbc/postgresql/TestPostgreSQLTranslator.java
===================================================================
--- branches/7.1.x/connectors/translator-jdbc/src/test/java/org/teiid/translator/jdbc/postgresql/TestPostgreSQLTranslator.java 2010-10-22 21:40:32 UTC (rev 2676)
+++ branches/7.1.x/connectors/translator-jdbc/src/test/java/org/teiid/translator/jdbc/postgresql/TestPostgreSQLTranslator.java 2010-10-22 21:42:45 UTC (rev 2677)
@@ -158,7 +158,7 @@
}
@Test public void testConversion13() throws Exception {
String input = "SELECT convert(convert(PART_WEIGHT, timestamp), string) FROM PARTS"; //$NON-NLS-1$
- String output = "SELECT to_char(cast(PARTS.PART_WEIGHT AS timestamp), 'YYYY-MM-DD HH24:MI:SS.UF') FROM PARTS"; //$NON-NLS-1$
+ String output = "SELECT to_char(cast(PARTS.PART_WEIGHT AS timestamp), 'YYYY-MM-DD HH24:MI:SS.US') FROM PARTS"; //$NON-NLS-1$
helpTestVisitor(getTestVDB(),
input,
15 years, 6 months
teiid SVN: r2676 - in branches/7.1.x/engine/src: test/java/org/teiid/query/optimizer and 1 other directories.
by teiid-commits@lists.jboss.org
Author: shawkins
Date: 2010-10-22 17:40:32 -0400 (Fri, 22 Oct 2010)
New Revision: 2676
Modified:
branches/7.1.x/engine/src/main/java/org/teiid/query/optimizer/relational/rules/RuleCollapseSource.java
branches/7.1.x/engine/src/main/java/org/teiid/query/optimizer/relational/rules/RulePushLimit.java
branches/7.1.x/engine/src/test/java/org/teiid/query/optimizer/TestLimit.java
branches/7.1.x/engine/src/test/java/org/teiid/query/processor/TestProcessor.java
Log:
TEIID-1317 ensuring that limit expressions get evaluated prior to pushdown
Modified: branches/7.1.x/engine/src/main/java/org/teiid/query/optimizer/relational/rules/RuleCollapseSource.java
===================================================================
--- branches/7.1.x/engine/src/main/java/org/teiid/query/optimizer/relational/rules/RuleCollapseSource.java 2010-10-22 16:24:31 UTC (rev 2675)
+++ branches/7.1.x/engine/src/main/java/org/teiid/query/optimizer/relational/rules/RuleCollapseSource.java 2010-10-22 21:40:32 UTC (rev 2676)
@@ -39,6 +39,7 @@
import org.teiid.query.optimizer.relational.RuleStack;
import org.teiid.query.optimizer.relational.plantree.NodeConstants;
import org.teiid.query.optimizer.relational.plantree.NodeEditor;
+import org.teiid.query.optimizer.relational.plantree.NodeFactory;
import org.teiid.query.optimizer.relational.plantree.PlanNode;
import org.teiid.query.optimizer.relational.plantree.NodeConstants.Info;
import org.teiid.query.processor.ProcessorPlan;
@@ -378,24 +379,20 @@
private void processLimit(PlanNode node,
QueryCommand query, QueryMetadataInterface metadata) {
+
Expression limit = (Expression)node.getProperty(NodeConstants.Info.MAX_TUPLE_LIMIT);
- if (limit != null) {
- if (query.getLimit() != null) {
- Expression oldlimit = query.getLimit().getRowLimit();
- query.getLimit().setRowLimit(RulePushLimit.getMinValue(limit, oldlimit));
- } else {
- query.setLimit(new Limit(null, limit));
- }
- }
Expression offset = (Expression)node.getProperty(NodeConstants.Info.OFFSET_TUPLE_COUNT);
- if (offset != null) {
- if (query.getLimit() != null) {
- Expression oldoffset = query.getLimit().getOffset();
- query.getLimit().setOffset(RulePushLimit.getSum(offset, oldoffset, metadata.getFunctionLibrary()));
- } else {
- query.setLimit(new Limit(offset, null));
- }
+
+ PlanNode limitNode = NodeFactory.getNewNode(NodeConstants.Types.TUPLE_LIMIT);
+ Expression childLimit = null;
+ Expression childOffset = null;
+ if (query.getLimit() != null) {
+ childLimit = query.getLimit().getRowLimit();
+ childOffset = query.getLimit().getOffset();
}
+ RulePushLimit.combineLimits(limitNode, metadata, limit, offset, childLimit, childOffset);
+
+ query.setLimit(new Limit((Expression)limitNode.getProperty(NodeConstants.Info.OFFSET_TUPLE_COUNT), (Expression)limitNode.getProperty(NodeConstants.Info.MAX_TUPLE_LIMIT)));
}
/**
Modified: branches/7.1.x/engine/src/main/java/org/teiid/query/optimizer/relational/rules/RulePushLimit.java
===================================================================
--- branches/7.1.x/engine/src/main/java/org/teiid/query/optimizer/relational/rules/RulePushLimit.java 2010-10-22 16:24:31 UTC (rev 2675)
+++ branches/7.1.x/engine/src/main/java/org/teiid/query/optimizer/relational/rules/RulePushLimit.java 2010-10-22 21:40:32 UTC (rev 2676)
@@ -26,11 +26,16 @@
import java.util.LinkedList;
import java.util.List;
+import org.teiid.api.exception.query.ExpressionEvaluationException;
import org.teiid.api.exception.query.QueryMetadataException;
import org.teiid.api.exception.query.QueryPlannerException;
+import org.teiid.common.buffer.BlockedException;
import org.teiid.core.TeiidComponentException;
+import org.teiid.core.TeiidException;
+import org.teiid.core.TeiidRuntimeException;
import org.teiid.core.types.DataTypeManager;
import org.teiid.query.analysis.AnalysisRecord;
+import org.teiid.query.eval.Evaluator;
import org.teiid.query.function.FunctionLibrary;
import org.teiid.query.metadata.QueryMetadataInterface;
import org.teiid.query.optimizer.capabilities.CapabilitiesFinder;
@@ -47,7 +52,9 @@
import org.teiid.query.sql.symbol.Expression;
import org.teiid.query.sql.symbol.Function;
import org.teiid.query.sql.symbol.SearchedCaseExpression;
+import org.teiid.query.sql.visitor.EvaluatableVisitor;
import org.teiid.query.util.CommandContext;
+import org.teiid.translator.SourceSystemFunctions;
/**
@@ -116,18 +123,19 @@
return false;
}
- switch (child.getType()) {
+ Expression parentLimit = (Expression)limitNode.getProperty(NodeConstants.Info.MAX_TUPLE_LIMIT);
+ Expression parentOffset = (Expression)limitNode.getProperty(NodeConstants.Info.OFFSET_TUPLE_COUNT);
+ switch (child.getType()) {
case NodeConstants.Types.TUPLE_LIMIT:
{
+
//combine the limits
- Expression minLimit = getMinValue((Expression)limitNode.getProperty(NodeConstants.Info.MAX_TUPLE_LIMIT), (Expression)child.getProperty(NodeConstants.Info.MAX_TUPLE_LIMIT));
- Expression offSet = getSum((Expression)limitNode.getProperty(NodeConstants.Info.OFFSET_TUPLE_COUNT), (Expression)child.getProperty(NodeConstants.Info.OFFSET_TUPLE_COUNT), metadata.getFunctionLibrary());
+ Expression childLimit = (Expression)child.getProperty(NodeConstants.Info.MAX_TUPLE_LIMIT);
+ Expression childOffset = (Expression)child.getProperty(NodeConstants.Info.OFFSET_TUPLE_COUNT);
+
+ combineLimits(limitNode, metadata, parentLimit, parentOffset, childLimit, childOffset);
NodeEditor.removeChildNode(limitNode, child);
-
- limitNode.setProperty(NodeConstants.Info.MAX_TUPLE_LIMIT, minLimit);
- limitNode.setProperty(NodeConstants.Info.OFFSET_TUPLE_COUNT, offSet);
-
limitNodes.remove(child);
return canPushLimit(rootNode, limitNode, limitNodes, metadata, capFinder);
@@ -141,9 +149,7 @@
List<PlanNode> grandChildren = new LinkedList<PlanNode>(child.getChildren());
for (PlanNode grandChild : grandChildren) {
PlanNode newLimit = NodeFactory.getNewNode(NodeConstants.Types.TUPLE_LIMIT);
- Expression limit = (Expression)limitNode.getProperty(NodeConstants.Info.MAX_TUPLE_LIMIT);
- Expression offset = (Expression)limitNode.getProperty(NodeConstants.Info.OFFSET_TUPLE_COUNT);
- newLimit.setProperty(NodeConstants.Info.MAX_TUPLE_LIMIT, getSum(limit, offset, metadata.getFunctionLibrary()));
+ newLimit.setProperty(NodeConstants.Info.MAX_TUPLE_LIMIT, op(SourceSystemFunctions.ADD_OP, parentLimit, parentOffset, metadata.getFunctionLibrary()));
grandChild.addAsParent(newLimit);
limitNodes.add(newLimit);
}
@@ -171,6 +177,28 @@
}
}
}
+
+ static void combineLimits(PlanNode limitNode,
+ QueryMetadataInterface metadata, Expression parentLimit,
+ Expression parentOffset, Expression childLimit,
+ Expression childOffset) {
+ Expression minLimit = null;
+ Expression offSet = null;
+
+ if (childLimit == null) {
+ minLimit = parentLimit;
+ offSet = op(SourceSystemFunctions.ADD_OP, childOffset, parentOffset, metadata.getFunctionLibrary());
+ } else {
+ minLimit = getMinValue(parentLimit, op(SourceSystemFunctions.SUBTRACT_OP, childLimit, parentOffset, metadata.getFunctionLibrary()));
+ offSet = childOffset;
+ if (offSet == null) {
+ offSet = parentOffset;
+ }
+ }
+
+ limitNode.setProperty(NodeConstants.Info.MAX_TUPLE_LIMIT, minLimit);
+ limitNode.setProperty(NodeConstants.Info.OFFSET_TUPLE_COUNT, offSet);
+ }
static PlanNode raiseAccessOverLimit(PlanNode rootNode,
PlanNode accessNode,
@@ -206,7 +234,7 @@
// since we're pushing underneath the offset, we want enough rows to satisfy both the limit and the row offset
- pushedLimit.setProperty(NodeConstants.Info.MAX_TUPLE_LIMIT, getSum(limit, offset, metadata.getFunctionLibrary()));
+ pushedLimit.setProperty(NodeConstants.Info.MAX_TUPLE_LIMIT, op(SourceSystemFunctions.ADD_OP, limit, offset, metadata.getFunctionLibrary()));
if (accessNode.getChildCount() == 0) {
accessNode.addFirstChild(pushedLimit);
@@ -221,11 +249,7 @@
return RuleRaiseAccess.performRaise(rootNode, accessNode, parentNode);
}
- /**
- * @param limitNode
- * @param child
- */
- static Expression getSum(Expression expr1, Expression expr2, FunctionLibrary functionLibrary) {
+ static Expression op(String op, Expression expr1, Expression expr2, FunctionLibrary functionLibrary) {
if (expr1 == null) {
return expr2;
}
@@ -233,15 +257,29 @@
return expr1;
}
- Function newExpr = new Function("+", new Expression[] {expr1, expr2}); //$NON-NLS-1$
- newExpr.setFunctionDescriptor(functionLibrary.findFunction("+", new Class[] {DataTypeManager.DefaultDataClasses.INTEGER, DataTypeManager.DefaultDataClasses.INTEGER})); //$NON-NLS-1$
+ Function newExpr = new Function(op, new Expression[] {expr1, expr2});
+ newExpr.setFunctionDescriptor(functionLibrary.findFunction(op, new Class[] {DataTypeManager.DefaultDataClasses.INTEGER, DataTypeManager.DefaultDataClasses.INTEGER}));
newExpr.setType(newExpr.getFunctionDescriptor().getReturnType());
+ return evaluateIfPossible(newExpr);
+ }
+
+ private static Expression evaluateIfPossible(Expression newExpr) {
+ if (EvaluatableVisitor.isFullyEvaluatable(newExpr, true)) {
+ try {
+ return new Constant(Evaluator.evaluate(newExpr), newExpr.getType());
+ } catch (TeiidException e) {
+ throw new TeiidRuntimeException(e, "Unexpected Exception"); //$NON-NLS-1$
+ }
+ }
return newExpr;
- }
+ }
/**
* @param limitNode
* @param child
+ * @throws TeiidComponentException
+ * @throws BlockedException
+ * @throws ExpressionEvaluationException
*/
static Expression getMinValue(Expression expr1, Expression expr2) {
if (expr1 == null) {
@@ -254,7 +292,8 @@
Criteria crit = new CompareCriteria(expr1, CompareCriteria.LT, expr2);
SearchedCaseExpression sce = new SearchedCaseExpression(Arrays.asList(new Object[] {crit}), Arrays.asList(new Object[] {expr1}));
sce.setElseExpression(expr2);
- return sce;
+ sce.setType(expr1.getType());
+ return evaluateIfPossible(sce);
}
/**
Modified: branches/7.1.x/engine/src/test/java/org/teiid/query/optimizer/TestLimit.java
===================================================================
--- branches/7.1.x/engine/src/test/java/org/teiid/query/optimizer/TestLimit.java 2010-10-22 16:24:31 UTC (rev 2675)
+++ branches/7.1.x/engine/src/test/java/org/teiid/query/optimizer/TestLimit.java 2010-10-22 21:40:32 UTC (rev 2676)
@@ -268,7 +268,7 @@
String sql = "SELECT * FROM pm1.g1 limit 50, 100";//$NON-NLS-1$
String[] expectedSql = new String[] {
- "SELECT pm1.g1.e1, pm1.g1.e2, pm1.g1.e3, pm1.g1.e4 FROM pm1.g1 LIMIT (100 + 50)" //$NON-NLS-1$
+ "SELECT pm1.g1.e1, pm1.g1.e2, pm1.g1.e3, pm1.g1.e4 FROM pm1.g1 LIMIT 150" //$NON-NLS-1$
};
ProcessorPlan plan = TestOptimizer.helpPlan(sql, FakeMetadataFactory.example1Cached(),
null, capFinder, expectedSql, TestOptimizer.ComparisonMode.EXACT_COMMAND_STRING);
@@ -535,7 +535,7 @@
String sql = "SELECT * FROM pm1.g1 UNION SELECT * FROM PM1.g2 LIMIT 50, 100";//$NON-NLS-1$
String[] expectedSql = new String[] {
- "SELECT PM1.g2.e1 AS c_0, PM1.g2.e2 AS c_1, PM1.g2.e3 AS c_2, PM1.g2.e4 AS c_3 FROM PM1.g2 LIMIT (100 + 50)", "SELECT pm1.g1.e1 AS c_0, pm1.g1.e2 AS c_1, pm1.g1.e3 AS c_2, pm1.g1.e4 AS c_3 FROM pm1.g1 LIMIT (100 + 50)" //$NON-NLS-1$ //$NON-NLS-2$
+ "SELECT PM1.g2.e1 AS c_0, PM1.g2.e2 AS c_1, PM1.g2.e3 AS c_2, PM1.g2.e4 AS c_3 FROM PM1.g2 LIMIT 150", "SELECT pm1.g1.e1 AS c_0, pm1.g1.e2 AS c_1, pm1.g1.e3 AS c_2, pm1.g1.e4 AS c_3 FROM pm1.g1 LIMIT 150" //$NON-NLS-1$ //$NON-NLS-2$
};
ProcessorPlan plan = TestOptimizer.helpPlan(sql, FakeMetadataFactory.example1Cached(),
null, capFinder, expectedSql, TestOptimizer.ComparisonMode.EXACT_COMMAND_STRING);
@@ -603,7 +603,7 @@
String sql = "SELECT * from (SELECT pm1.g1.e1 FROM pm1.g1 LIMIT 10, 100) x LIMIT 20, 75";//$NON-NLS-1$
String[] expectedSql = new String[] {
- "SELECT pm1.g1.e1 AS c_0 FROM pm1.g1 LIMIT CASE WHEN (75 + (20 + 10)) < (100 + 10) THEN (75 + (20 + 10)) ELSE (100 + 10) END" //$NON-NLS-1$
+ "SELECT pm1.g1.e1 AS c_0 FROM pm1.g1 LIMIT 105" //$NON-NLS-1$
};
ProcessorPlan plan = TestOptimizer.helpPlan(sql, FakeMetadataFactory.example1Cached(),
null, capFinder, expectedSql, TestOptimizer.ComparisonMode.EXACT_COMMAND_STRING);
@@ -636,9 +636,9 @@
// pm1 model supports order by
capFinder.addCapabilities("pm1", caps); //$NON-NLS-1$
- String sql = "SELECT * from (SELECT pm1.g1.e1 FROM pm1.g1 LIMIT 10, 100) x LIMIT 20, 75";//$NON-NLS-1$
+ String sql = "SELECT * from (SELECT pm1.g1.e1 FROM pm1.g1 LIMIT 10, 100) x LIMIT 40, 75";//$NON-NLS-1$
String[] expectedSql = new String[] {
- "SELECT pm1.g1.e1 AS c_0 FROM pm1.g1 LIMIT (20 + 10), CASE WHEN 75 < 100 THEN 75 ELSE 100 END" //$NON-NLS-1$
+ "SELECT pm1.g1.e1 AS c_0 FROM pm1.g1 LIMIT 10, 60" //$NON-NLS-1$
};
ProcessorPlan plan = TestOptimizer.helpPlan(sql, FakeMetadataFactory.example1Cached(),
null, capFinder, expectedSql, TestOptimizer.ComparisonMode.EXACT_COMMAND_STRING);
Modified: branches/7.1.x/engine/src/test/java/org/teiid/query/processor/TestProcessor.java
===================================================================
--- branches/7.1.x/engine/src/test/java/org/teiid/query/processor/TestProcessor.java 2010-10-22 16:24:31 UTC (rev 2675)
+++ branches/7.1.x/engine/src/test/java/org/teiid/query/processor/TestProcessor.java 2010-10-22 21:40:32 UTC (rev 2676)
@@ -68,7 +68,6 @@
import org.teiid.query.analysis.AnalysisRecord;
import org.teiid.query.function.FunctionLibrary;
import org.teiid.query.function.FunctionTree;
-import org.teiid.query.function.SystemFunctionManager;
import org.teiid.query.function.UDFSource;
import org.teiid.query.mapping.relational.QueryNode;
import org.teiid.query.metadata.QueryMetadataInterface;
@@ -7338,7 +7337,7 @@
FakeDataManager dataManager = new FakeDataManager();
sampleData2(dataManager);
- ProcessorPlan plan = TestOptimizer.helpPlan(sql, FakeMetadataFactory.example1Cached(), null, capFinder, new String[] {"SELECT pm1.g1.e1 FROM pm1.g1 LIMIT (5 + 1)"}, TestOptimizer.ComparisonMode.EXACT_COMMAND_STRING); //$NON-NLS-1$
+ ProcessorPlan plan = TestOptimizer.helpPlan(sql, FakeMetadataFactory.example1Cached(), null, capFinder, new String[] {"SELECT pm1.g1.e1 FROM pm1.g1 LIMIT 6"}, TestOptimizer.ComparisonMode.EXACT_COMMAND_STRING); //$NON-NLS-1$
helpProcess(plan, dataManager, expected);
}
15 years, 6 months
teiid SVN: r2675 - in branches/7.1.x/engine/src/main/java/org/teiid/query: processor/relational and 1 other directories.
by teiid-commits@lists.jboss.org
Author: shawkins
Date: 2010-10-22 12:24:31 -0400 (Fri, 22 Oct 2010)
New Revision: 2675
Modified:
branches/7.1.x/engine/src/main/java/org/teiid/query/eval/Evaluator.java
branches/7.1.x/engine/src/main/java/org/teiid/query/processor/relational/XMLTableNode.java
branches/7.1.x/engine/src/main/java/org/teiid/query/xquery/saxon/SaxonXQueryExpression.java
Log:
ensuring that xquery evaluation closes all sources it creates.
Modified: branches/7.1.x/engine/src/main/java/org/teiid/query/eval/Evaluator.java
===================================================================
--- branches/7.1.x/engine/src/main/java/org/teiid/query/eval/Evaluator.java 2010-10-22 14:45:09 UTC (rev 2674)
+++ branches/7.1.x/engine/src/main/java/org/teiid/query/eval/Evaluator.java 2010-10-22 16:24:31 UTC (rev 2675)
@@ -41,7 +41,6 @@
import java.util.regex.Pattern;
import java.util.regex.PatternSyntaxException;
-import net.sf.saxon.om.SequenceIterator;
import net.sf.saxon.trans.XPathException;
import org.teiid.api.exception.query.ExpressionEvaluationException;
@@ -110,6 +109,7 @@
import org.teiid.query.sql.util.ValueIteratorSource;
import org.teiid.query.util.CommandContext;
import org.teiid.query.xquery.saxon.SaxonXQueryExpression;
+import org.teiid.query.xquery.saxon.SaxonXQueryExpression.Result;
import org.teiid.translator.WSConnection.Util;
public class Evaluator {
@@ -761,13 +761,18 @@
if (xmlQuery.getEmptyOnEmpty() != null) {
emptyOnEmpty = xmlQuery.getEmptyOnEmpty();
}
+ Result result = null;
try {
- SequenceIterator iter = evaluateXQuery(xmlQuery.getXQueryExpression(), xmlQuery.getPassing(), tuple);
- return xmlQuery.getXQueryExpression().createXMLType(iter, this.context.getBufferManager(), emptyOnEmpty);
+ result = evaluateXQuery(xmlQuery.getXQueryExpression(), xmlQuery.getPassing(), tuple);
+ return xmlQuery.getXQueryExpression().createXMLType(result.iter, this.context.getBufferManager(), 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$
+ } finally {
+ if (result != null) {
+ result.close();
+ }
}
}
@@ -837,7 +842,7 @@
}
}
- public SequenceIterator evaluateXQuery(SaxonXQueryExpression xquery, List<DerivedColumn> cols, List<?> tuple)
+ public Result evaluateXQuery(SaxonXQueryExpression xquery, List<DerivedColumn> cols, List<?> tuple)
throws BlockedException, TeiidComponentException, TeiidProcessingException {
HashMap<String, Object> parameters = new HashMap<String, Object>();
Object contextItem = null;
Modified: branches/7.1.x/engine/src/main/java/org/teiid/query/processor/relational/XMLTableNode.java
===================================================================
--- branches/7.1.x/engine/src/main/java/org/teiid/query/processor/relational/XMLTableNode.java 2010-10-22 14:45:09 UTC (rev 2674)
+++ branches/7.1.x/engine/src/main/java/org/teiid/query/processor/relational/XMLTableNode.java 2010-10-22 16:24:31 UTC (rev 2675)
@@ -50,6 +50,7 @@
import org.teiid.query.function.FunctionDescriptor;
import org.teiid.query.sql.lang.XMLTable;
import org.teiid.query.sql.lang.XMLTable.XMLColumn;
+import org.teiid.query.xquery.saxon.SaxonXQueryExpression.Result;
/**
* Handles xml table processing.
@@ -69,7 +70,7 @@
private XMLTable table;
private List<XMLColumn> projectedColumns;
- private SequenceIterator result;
+ private Result result;
private int rowCount = 0;
private Item item;
@@ -130,7 +131,7 @@
TeiidComponentException, TeiidProcessingException {
if (item == null) {
try {
- item = result.next();
+ item = result.iter.next();
} catch (XPathException e) {
throw new TeiidProcessingException(e, QueryPlugin.Util.getString("XMLTableNode.error", e.getMessage())); //$NON-NLS-1$
}
Modified: branches/7.1.x/engine/src/main/java/org/teiid/query/xquery/saxon/SaxonXQueryExpression.java
===================================================================
--- branches/7.1.x/engine/src/main/java/org/teiid/query/xquery/saxon/SaxonXQueryExpression.java 2010-10-22 14:45:09 UTC (rev 2674)
+++ branches/7.1.x/engine/src/main/java/org/teiid/query/xquery/saxon/SaxonXQueryExpression.java 2010-10-22 16:24:31 UTC (rev 2675)
@@ -28,6 +28,7 @@
import java.util.Arrays;
import java.util.HashSet;
import java.util.Iterator;
+import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Properties;
@@ -88,10 +89,27 @@
import org.teiid.query.sql.symbol.DerivedColumn;
import org.teiid.query.sql.symbol.XMLNamespaces;
import org.teiid.query.sql.symbol.XMLNamespaces.NamespaceItem;
+import org.teiid.translator.WSConnection.Util;
@SuppressWarnings("serial")
public class SaxonXQueryExpression {
+ public static class Result {
+ public SequenceIterator iter;
+ public List<Source> sources = new LinkedList<Source>();
+
+ public void close() {
+ for (Source source : sources) {
+ Util.closeSource(source);
+ }
+ if (iter != null) {
+ iter.close();
+ }
+ sources.clear();
+ iter = null;
+ }
+ }
+
private static final Expression DUMMY_EXPRESSION = new Expression() {
@Override
public ItemType getItemType(TypeHierarchy th) {
@@ -133,7 +151,7 @@
private net.sf.saxon.query.XQueryExpression xQuery;
private Configuration config = new Configuration();
private PathMapRoot contextRoot;
-
+
public SaxonXQueryExpression(String xQueryString, XMLNamespaces namespaces, List<DerivedColumn> passing, List<XMLTable.XMLColumn> columns)
throws QueryResolverException {
config.setErrorListener(ERROR_LISTENER);
@@ -354,47 +372,55 @@
xmlColumn.setPathExpression(exp);
}
}
-
- public SequenceIterator evaluateXQuery(Object context, Map<String, Object> parameterValues) throws TeiidProcessingException {
+
+ public Result evaluateXQuery(Object context, Map<String, Object> parameterValues) throws TeiidProcessingException {
DynamicQueryContext dynamicContext = new DynamicQueryContext(config);
-
+
+ Result result = new Result();
try {
- for (Map.Entry<String, Object> entry : parameterValues.entrySet()) {
- Object value = entry.getValue();
- if(value instanceof SQLXML) {
- value = XMLSystemFunctions.convertToSource(value);
- } else if (value instanceof java.util.Date) {
- java.util.Date d = (java.util.Date)value;
- value = XMLSystemFunctions.convertToAtomicValue(value);
+ try {
+ for (Map.Entry<String, Object> entry : parameterValues.entrySet()) {
+ Object value = entry.getValue();
+ if(value instanceof SQLXML) {
+ value = XMLSystemFunctions.convertToSource(value);
+ result.sources.add((Source)value);
+ } else if (value instanceof java.util.Date) {
+ value = XMLSystemFunctions.convertToAtomicValue(value);
+ }
+ dynamicContext.setParameter(entry.getKey(), value);
+ }
+ } catch (TransformerException e) {
+ throw new TeiidProcessingException(e);
+ }
+ if (context != null) {
+ Source source = XMLSystemFunctions.convertToSource(context);
+ result.sources.add(source);
+ if (contextRoot != null) {
+ //create our own filter as this logic is not provided in the free saxon
+ ProxyReceiver filter = new PathMapFilter(contextRoot);
+ AugmentedSource sourceInput = AugmentedSource.makeAugmentedSource(source);
+ sourceInput.addFilter(filter);
+ source = sourceInput;
}
- dynamicContext.setParameter(entry.getKey(), value);
+ DocumentInfo doc;
+ try {
+ doc = config.buildDocument(source);
+ } catch (XPathException e) {
+ throw new TeiidProcessingException(e, QueryPlugin.Util.getString("SaxonXQueryExpression.bad_context")); //$NON-NLS-1$
+ }
+ dynamicContext.setContextItem(doc);
}
- } catch (TransformerException e) {
- throw new TeiidProcessingException(e);
+ try {
+ result.iter = xQuery.iterator(dynamicContext);
+ return result;
+ } catch (TransformerException e) {
+ throw new TeiidProcessingException(e, QueryPlugin.Util.getString("SaxonXQueryExpression.bad_xquery")); //$NON-NLS-1$
+ }
+ } finally {
+ if (result.iter == null) {
+ result.close();
+ }
}
-
- if (context != null) {
- Source source = XMLSystemFunctions.convertToSource(context);
- if (contextRoot != null) {
- //create our own filter as this logic is not provided in the free saxon
- ProxyReceiver filter = new PathMapFilter(contextRoot);
- AugmentedSource sourceInput = AugmentedSource.makeAugmentedSource(source);
- sourceInput.addFilter(filter);
- source = sourceInput;
- }
- DocumentInfo doc;
- try {
- doc = config.buildDocument(source);
- } catch (XPathException e) {
- throw new TeiidProcessingException(e, QueryPlugin.Util.getString("SaxonXQueryExpression.bad_context")); //$NON-NLS-1$
- }
- dynamicContext.setContextItem(doc);
- }
- try {
- return xQuery.iterator(dynamicContext);
- } catch (TransformerException e) {
- throw new TeiidProcessingException(e, QueryPlugin.Util.getString("SaxonXQueryExpression.bad_xquery")); //$NON-NLS-1$
- }
}
public XMLType createXMLType(final SequenceIterator iter, BufferManager bufferManager, boolean emptyOnEmpty) throws XPathException, TeiidComponentException, TeiidProcessingException {
15 years, 6 months
teiid SVN: r2674 - in branches/7.1.x: engine/src/main/java/org/teiid/query/metadata and 2 other directories.
by teiid-commits@lists.jboss.org
Author: shawkins
Date: 2010-10-22 10:45:09 -0400 (Fri, 22 Oct 2010)
New Revision: 2674
Modified:
branches/7.1.x/build/kits/jboss-container/teiid-releasenotes.html
branches/7.1.x/engine/src/main/java/org/teiid/query/metadata/TransformationMetadata.java
branches/7.1.x/engine/src/main/resources/org/teiid/query/i18n.properties
branches/7.1.x/engine/src/test/java/org/teiid/query/metadata/TestTransformationMetadata.java
Log:
TEIID-1315 fix for parent relative paths for getting schemas. also minor corrections to release notes and an i18n message
Modified: branches/7.1.x/build/kits/jboss-container/teiid-releasenotes.html
===================================================================
--- branches/7.1.x/build/kits/jboss-container/teiid-releasenotes.html 2010-10-21 21:05:20 UTC (rev 2673)
+++ branches/7.1.x/build/kits/jboss-container/teiid-releasenotes.html 2010-10-22 14:45:09 UTC (rev 2674)
@@ -53,7 +53,7 @@
<li>Model visibility no longer restricts access to tables and procedures. Setting visible to false will only hide entries from system tables. Data roles should be used to restrict data access.
<li>Admin API "getWorkManagerStats" methods renamed to "getWorkerPoolStats". Also, "setRuntimeProperty" and "getProcesses" methods were removed.
<li>By default the "ENV" system function is now turned off. To enable it, edit the teiid-jboss-beans.xml configuration file.
- <li>The use of VARIABLES.ROWCOUNT is now reserved. Use a different
+ <li>The use of VARIABLES.ROWCOUNT is now reserved.
<li>Direct assignments in virtual procedures using stored procedures (e.g. var = EXEC foo()) are only valid if the procedure has a return parameter and no result set.
</ul>
<h4>from 7.0</h4>
Modified: branches/7.1.x/engine/src/main/java/org/teiid/query/metadata/TransformationMetadata.java
===================================================================
--- branches/7.1.x/engine/src/main/java/org/teiid/query/metadata/TransformationMetadata.java 2010-10-21 21:05:20 UTC (rev 2673)
+++ branches/7.1.x/engine/src/main/java/org/teiid/query/metadata/TransformationMetadata.java 2010-10-22 14:45:09 UTC (rev 2674)
@@ -783,10 +783,22 @@
path = path.replace(File.separatorChar, '/');
}
for (String string : schemaPaths) {
- SQLXMLImpl schema = getVDBResourceAsSQLXML(string);
-
+ String parentPath = path;
+ boolean relative = false;
+ while (string.startsWith("../")) { //$NON-NLS-1$
+ relative = true;
+ string = string.substring(3);
+ parentPath = new File(parentPath).getParent();
+ }
+ SQLXMLImpl schema = null;
+ if (!relative) {
+ schema = getVDBResourceAsSQLXML(string);
+ }
if (schema == null) {
- schema = getVDBResourceAsSQLXML(path + '/' + string);
+ if (!parentPath.endsWith("/")) { //$NON-NLS-1$
+ parentPath += "/"; //$NON-NLS-1$
+ }
+ schema = getVDBResourceAsSQLXML(parentPath + string);
}
if (schema == null) {
Modified: branches/7.1.x/engine/src/main/resources/org/teiid/query/i18n.properties
===================================================================
--- branches/7.1.x/engine/src/main/resources/org/teiid/query/i18n.properties 2010-10-21 21:05:20 UTC (rev 2673)
+++ branches/7.1.x/engine/src/main/resources/org/teiid/query/i18n.properties 2010-10-22 14:45:09 UTC (rev 2674)
@@ -871,4 +871,4 @@
RequestWorkItem.cache_nondeterministic=Caching command '{0}'' at a session level, but less deterministic functions were evaluated.
not_found_cache=Results not found in cache
failed_to_unwrap_connection=Failed to unwrap the source connection.
-connection_factory_not_found=Failed to the Connection Factory with JNDI name {0}. Please check the name for spelling or deploy the Connection Factory with specified name.
\ No newline at end of file
+connection_factory_not_found=Failed to find the Connection Factory with JNDI name {0}. Please check the name or deploy the Connection Factory with specified name.
\ No newline at end of file
Modified: branches/7.1.x/engine/src/test/java/org/teiid/query/metadata/TestTransformationMetadata.java
===================================================================
--- branches/7.1.x/engine/src/test/java/org/teiid/query/metadata/TestTransformationMetadata.java 2010-10-21 21:05:20 UTC (rev 2673)
+++ branches/7.1.x/engine/src/test/java/org/teiid/query/metadata/TestTransformationMetadata.java 2010-10-22 14:45:09 UTC (rev 2674)
@@ -31,7 +31,9 @@
import java.util.Map;
import java.util.Properties;
+import org.jboss.virtual.VirtualFile;
import org.junit.Test;
+import org.mockito.Mockito;
import org.teiid.adminapi.Model;
import org.teiid.adminapi.impl.ModelMetaData;
import org.teiid.adminapi.impl.VDBMetaData;
@@ -42,6 +44,7 @@
import org.teiid.metadata.Table;
import org.teiid.query.metadata.CompositeMetadataStore;
import org.teiid.query.metadata.TransformationMetadata;
+import org.teiid.query.metadata.TransformationMetadata.Resource;
import org.teiid.query.unittest.FakeMetadataFactory;
import org.teiid.translator.TranslatorException;
@@ -71,6 +74,14 @@
MetadataFactory mf1 = new MetadataFactory("x1", datatypes, new Properties()); //$NON-NLS-1$
mf1.addProcedure("y"); //$NON-NLS-1$
+
+ Table table = mf1.addTable("doc");
+ table.setSchemaPaths(Arrays.asList("../../x.xsd"));
+ table.setResourcePath("/a/b/doc.xmi");
+
+ HashMap<String, Resource> resources = new HashMap<String, Resource>();
+ resources.put("/x.xsd", new Resource(Mockito.mock(VirtualFile.class), true));
+
CompositeMetadataStore cms = new CompositeMetadataStore(Arrays.asList(mf.getMetadataStore(), mf1.getMetadataStore()));
VDBMetaData vdb = new VDBMetaData();
@@ -79,8 +90,9 @@
vdb.addModel(buildModel("x"));
vdb.addModel(buildModel("x1"));
+ vdb.addModel(buildModel("y"));
- return new TransformationMetadata(vdb, cms, null, null, FakeMetadataFactory.SFM.getSystemFunctions());
+ return new TransformationMetadata(vdb, cms, resources, null, FakeMetadataFactory.SFM.getSystemFunctions());
}
ModelMetaData buildModel(String name) {
@@ -131,4 +143,9 @@
tm.getElementID("x.FoO.coL");
}
+ @Test public void testRelativeSchemas() throws Exception {
+ TransformationMetadata tm = exampleTransformationMetadata();
+ assertEquals(1, tm.getXMLSchemas(tm.getGroupID("x1.doc")).size());
+ }
+
}
15 years, 6 months
teiid SVN: r2673 - in branches/7.1.x: engine/src/test/java/org/teiid/query/processor and 1 other directories.
by teiid-commits@lists.jboss.org
Author: shawkins
Date: 2010-10-21 17:05:20 -0400 (Thu, 21 Oct 2010)
New Revision: 2673
Added:
branches/7.1.x/engine/src/test/resources/encoding.xml
Modified:
branches/7.1.x/common-core/src/main/java/org/teiid/core/types/SQLXMLImpl.java
branches/7.1.x/engine/src/test/java/org/teiid/query/processor/TestSQLXMLProcessing.java
Log:
TEIID-1316 fix for picking up the encoding correctly from the document
Modified: branches/7.1.x/common-core/src/main/java/org/teiid/core/types/SQLXMLImpl.java
===================================================================
--- branches/7.1.x/common-core/src/main/java/org/teiid/core/types/SQLXMLImpl.java 2010-10-21 18:49:17 UTC (rev 2672)
+++ branches/7.1.x/common-core/src/main/java/org/teiid/core/types/SQLXMLImpl.java 2010-10-21 21:05:20 UTC (rev 2673)
@@ -89,14 +89,17 @@
if (cs != null) {
return cs;
}
+ String enc = null;
try {
- String enc = XMLType.getEncoding(this.getBinaryStream());
- if (enc != null) {
- setEncoding(enc);
- }
+ enc = XMLType.getEncoding(this.getBinaryStream());
} catch (SQLException e) {
}
- return Streamable.CHARSET;
+ if (enc != null) {
+ setEncoding(enc);
+ } else {
+ super.setCharset(Streamable.CHARSET);
+ }
+ return super.getCharset();
}
@SuppressWarnings("unchecked")
Modified: branches/7.1.x/engine/src/test/java/org/teiid/query/processor/TestSQLXMLProcessing.java
===================================================================
--- branches/7.1.x/engine/src/test/java/org/teiid/query/processor/TestSQLXMLProcessing.java 2010-10-21 18:49:17 UTC (rev 2672)
+++ branches/7.1.x/engine/src/test/java/org/teiid/query/processor/TestSQLXMLProcessing.java 2010-10-21 21:05:20 UTC (rev 2673)
@@ -25,6 +25,8 @@
import static org.teiid.query.processor.TestProcessor.*;
import java.io.FileInputStream;
+import java.io.InputStreamReader;
+import java.nio.charset.Charset;
import java.sql.Timestamp;
import java.util.Arrays;
import java.util.List;
@@ -349,6 +351,16 @@
processPreparedStatement(sql, expected, dataManager, new DefaultCapabilitiesFinder(), FakeMetadataFactory.example1Cached(), Arrays.asList(blobFromFile("udf.xmi")));
}
+ @Test public void testXmlParseBlobWithEncoding() throws Exception {
+ String sql = "select xmlparse(document cast(? as blob)) x"; //$NON-NLS-1$
+
+ List[] expected = new List[] {
+ Arrays.asList(ObjectConverterUtil.convertToString(new InputStreamReader(new FileInputStream(UnitTestUtil.getTestDataFile("encoding.xml")), Charset.forName("ISO-8859-1")))),
+ };
+
+ processPreparedStatement(sql, expected, dataManager, new DefaultCapabilitiesFinder(), FakeMetadataFactory.example1Cached(), Arrays.asList(blobFromFile("encoding.xml")));
+ }
+
@Test public void testXmlTableTypes() throws Exception {
String sql = "select * from xmltable('/a' passing xmlparse(document '<a>2000-01-01T01:01:00.2-06:00</a>') columns x timestamp path 'xs:dateTime(./text())', y timestamp path '.') as x"; //$NON-NLS-1$
Timestamp ts = TimestampUtil.createTimestamp(100, 0, 1, 1, 1, 0, 200000000);
Added: branches/7.1.x/engine/src/test/resources/encoding.xml
===================================================================
--- branches/7.1.x/engine/src/test/resources/encoding.xml (rev 0)
+++ branches/7.1.x/engine/src/test/resources/encoding.xml 2010-10-21 21:05:20 UTC (rev 2673)
@@ -0,0 +1,2 @@
+<?xml version="1.0" encoding="ISO-8859-1"?>
+<name>���</name>
Property changes on: branches/7.1.x/engine/src/test/resources/encoding.xml
___________________________________________________________________
Name: svn:mime-type
+ text/plain
15 years, 6 months
teiid SVN: r2672 - branches/7.1.x/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc.
by teiid-commits@lists.jboss.org
Author: shawkins
Date: 2010-10-21 14:49:17 -0400 (Thu, 21 Oct 2010)
New Revision: 2672
Modified:
branches/7.1.x/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/JDBCExecutionFactory.java
Log:
TEIID-1314 fix to address bigdecimal truncation with jConnect 6
Modified: branches/7.1.x/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/JDBCExecutionFactory.java
===================================================================
--- branches/7.1.x/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/JDBCExecutionFactory.java 2010-10-21 18:43:02 UTC (rev 2671)
+++ branches/7.1.x/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/JDBCExecutionFactory.java 2010-10-21 18:49:17 UTC (rev 2672)
@@ -817,6 +817,11 @@
stmt.setTimestamp(i,(java.sql.Timestamp)param, getDatabaseCalendar());
return;
}
+ //not all drivers handle the setObject call with BigDecimal correctly (namely jConnect 6.05)
+ if (TypeFacility.RUNTIME_TYPES.BIG_DECIMAL.equals(paramType)) {
+ stmt.setBigDecimal(i, (BigDecimal)param);
+ return;
+ }
//convert these the following to jdbc safe values
if (TypeFacility.RUNTIME_TYPES.BIG_INTEGER.equals(paramType)) {
param = new BigDecimal((BigInteger)param);
@@ -824,7 +829,8 @@
param = new Double(((Float)param).doubleValue());
} else if (TypeFacility.RUNTIME_TYPES.CHAR.equals(paramType)) {
param = ((Character)param).toString();
- }
+ }
+
stmt.setObject(i, param, type);
}
15 years, 6 months
teiid SVN: r2671 - in trunk/engine/src: test/java/org/teiid/query/processor and 1 other directory.
by teiid-commits@lists.jboss.org
Author: rareddy
Date: 2010-10-21 14:43:02 -0400 (Thu, 21 Oct 2010)
New Revision: 2671
Modified:
trunk/engine/src/main/java/org/teiid/query/processor/relational/NestedTableJoinStrategy.java
trunk/engine/src/test/java/org/teiid/query/processor/TestTextTable.java
Log:
TEIID-1313: avoid the duplicate row the batch boundaries with nested table join
Modified: trunk/engine/src/main/java/org/teiid/query/processor/relational/NestedTableJoinStrategy.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/processor/relational/NestedTableJoinStrategy.java 2010-10-21 18:18:56 UTC (rev 2670)
+++ trunk/engine/src/main/java/org/teiid/query/processor/relational/NestedTableJoinStrategy.java 2010-10-21 18:43:02 UTC (rev 2671)
@@ -126,12 +126,14 @@
List<?> outputTuple = outputTuple(this.leftSource.getCurrentTuple(), this.rightSource.getCurrentTuple());
- if (this.joinNode.matchesCriteria(outputTuple)) {
- joinNode.addBatchRow(outputTuple);
- outerMatched = true;
- }
+ boolean matches = this.joinNode.matchesCriteria(outputTuple);
rightSource.saveNext();
+
+ if (matches) {
+ outerMatched = true;
+ joinNode.addBatchRow(outputTuple);
+ }
}
if (!outerMatched && this.joinNode.getJoinType() == JoinType.JOIN_LEFT_OUTER) {
Modified: trunk/engine/src/test/java/org/teiid/query/processor/TestTextTable.java
===================================================================
--- trunk/engine/src/test/java/org/teiid/query/processor/TestTextTable.java 2010-10-21 18:18:56 UTC (rev 2670)
+++ trunk/engine/src/test/java/org/teiid/query/processor/TestTextTable.java 2010-10-21 18:43:02 UTC (rev 2671)
@@ -198,7 +198,19 @@
process(sql, expected);
}
- public static void process(String sql, List[] expectedResults) throws Exception {
+ @Test public void testTextTableMultiBatch() throws Exception {
+ String sql = "select x.* from (select * from pm1.g1 where e1 = 'c') y, texttable(e1 || '\n' || e2 || '\n' || e3 COLUMNS x string) x";
+
+ List[] expected = new List[] {
+ Arrays.asList("c"),
+ Arrays.asList("1"),
+ Arrays.asList("true"),
+ };
+
+ process(sql, expected);
+ }
+
+ public static void process(String sql, List[] expectedResults) throws Exception {
FakeDataManager dataManager = new FakeDataManager();
sampleData1(dataManager);
ProcessorPlan plan = helpGetPlan(helpParse(sql), FakeMetadataFactory.example1Cached());
15 years, 6 months
teiid SVN: r2670 - in branches/7.1.x/engine/src: test/java/org/teiid/query/processor and 1 other directory.
by teiid-commits@lists.jboss.org
Author: rareddy
Date: 2010-10-21 14:18:56 -0400 (Thu, 21 Oct 2010)
New Revision: 2670
Modified:
branches/7.1.x/engine/src/main/java/org/teiid/query/processor/relational/NestedTableJoinStrategy.java
branches/7.1.x/engine/src/test/java/org/teiid/query/processor/TestTextTable.java
Log:
TEIID-1313: avoid the duplicate row the batch boundaries with nested table join
Modified: branches/7.1.x/engine/src/main/java/org/teiid/query/processor/relational/NestedTableJoinStrategy.java
===================================================================
--- branches/7.1.x/engine/src/main/java/org/teiid/query/processor/relational/NestedTableJoinStrategy.java 2010-10-21 15:33:12 UTC (rev 2669)
+++ branches/7.1.x/engine/src/main/java/org/teiid/query/processor/relational/NestedTableJoinStrategy.java 2010-10-21 18:18:56 UTC (rev 2670)
@@ -126,12 +126,14 @@
List<?> outputTuple = outputTuple(this.leftSource.getCurrentTuple(), this.rightSource.getCurrentTuple());
- if (this.joinNode.matchesCriteria(outputTuple)) {
- joinNode.addBatchRow(outputTuple);
- outerMatched = true;
- }
+ boolean matches = this.joinNode.matchesCriteria(outputTuple);
rightSource.saveNext();
+
+ if (matches) {
+ outerMatched = true;
+ joinNode.addBatchRow(outputTuple);
+ }
}
if (!outerMatched && this.joinNode.getJoinType() == JoinType.JOIN_LEFT_OUTER) {
Modified: branches/7.1.x/engine/src/test/java/org/teiid/query/processor/TestTextTable.java
===================================================================
--- branches/7.1.x/engine/src/test/java/org/teiid/query/processor/TestTextTable.java 2010-10-21 15:33:12 UTC (rev 2669)
+++ branches/7.1.x/engine/src/test/java/org/teiid/query/processor/TestTextTable.java 2010-10-21 18:18:56 UTC (rev 2670)
@@ -198,7 +198,19 @@
process(sql, expected);
}
- public static void process(String sql, List[] expectedResults) throws Exception {
+ @Test public void testTextTableMultiBatch() throws Exception {
+ String sql = "select x.* from (select * from pm1.g1 where e1 = 'c') y, texttable(e1 || '\n' || e2 || '\n' || e3 COLUMNS x string) x";
+
+ List[] expected = new List[] {
+ Arrays.asList("c"),
+ Arrays.asList("1"),
+ Arrays.asList("true"),
+ };
+
+ process(sql, expected);
+ }
+
+ public static void process(String sql, List[] expectedResults) throws Exception {
FakeDataManager dataManager = new FakeDataManager();
sampleData1(dataManager);
ProcessorPlan plan = helpGetPlan(helpParse(sql), FakeMetadataFactory.example1Cached());
15 years, 6 months