Author: jolee
Date: 2012-07-24 10:02:03 -0400 (Tue, 24 Jul 2012)
New Revision: 4261
Modified:
branches/7.4.x/engine/src/main/java/org/teiid/query/processor/relational/XMLTableNode.java
branches/7.4.x/engine/src/test/java/org/teiid/query/processor/TestSQLXMLProcessing.java
Log:
TEIID-2112 backport: using the local timezone for saxon calendarvalues, consistent
handling of local timezone on xsd:date, xsd:datetime, and xsd:time values that have no
timezone specified.
Modified:
branches/7.4.x/engine/src/main/java/org/teiid/query/processor/relational/XMLTableNode.java
===================================================================
---
branches/7.4.x/engine/src/main/java/org/teiid/query/processor/relational/XMLTableNode.java 2012-07-24
01:39:54 UTC (rev 4260)
+++
branches/7.4.x/engine/src/main/java/org/teiid/query/processor/relational/XMLTableNode.java 2012-07-24
14:02:03 UTC (rev 4261)
@@ -23,10 +23,14 @@
package org.teiid.query.processor.relational;
import java.util.ArrayList;
+import java.util.Calendar;
+import java.util.Collection;
import java.util.Collections;
+import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
+import java.util.TimeZone;
import net.sf.saxon.om.Item;
import net.sf.saxon.om.NodeInfo;
@@ -37,6 +41,7 @@
import net.sf.saxon.type.BuiltInAtomicType;
import net.sf.saxon.type.ConversionResult;
import net.sf.saxon.value.AtomicValue;
+import net.sf.saxon.value.CalendarValue;
import net.sf.saxon.value.StringValue;
import net.sf.saxon.value.Value;
@@ -51,6 +56,7 @@
import org.teiid.core.TeiidRuntimeException;
import org.teiid.core.types.DataTypeManager;
import org.teiid.core.types.XMLType;
+import org.teiid.core.util.TimestampWithTimezone;
import org.teiid.query.QueryPlugin;
import org.teiid.query.function.FunctionDescriptor;
import org.teiid.query.sql.lang.XMLTable;
@@ -222,14 +228,14 @@
}
Object value = colItem;
if (value instanceof AtomicValue) {
- value = Value.convertToJava(colItem);
+ value = getValue((AtomicValue)colItem);
} else if (value instanceof Item) {
Item i = (Item)value;
BuiltInAtomicType bat = typeMapping.get(proColumn.getSymbol().getType());
if (bat != null) {
ConversionResult cr = StringValue.convertStringToBuiltInType(i.getStringValueCS(),
bat, null);
value = cr.asAtomic();
- value = Value.convertToJava((AtomicValue)value);
+ value = getValue((AtomicValue)value);
if (value instanceof Item) {
value = ((Item)value).getStringValue();
}
@@ -247,6 +253,19 @@
item = null;
return tuple;
}
+
+ private Object getValue(AtomicValue value) throws XPathException {
+ if (value instanceof CalendarValue) {
+ CalendarValue cv = (CalendarValue)value;
+ if (!cv.hasTimezone()) {
+ Calendar cal = cv.getCalendar();
+ Date d = cal.getTime();
+ cal.setTimeZone(getContext().getServerTimeZone());
+ return TimestampWithTimezone.createTimestamp(d,
TimeZone.getTimeZone("GMT"), cal);
+ }
+ }
+ return Value.convertToJava(value);
+ }
@Override
public boolean hasFinalBuffer() {
Modified:
branches/7.4.x/engine/src/test/java/org/teiid/query/processor/TestSQLXMLProcessing.java
===================================================================
---
branches/7.4.x/engine/src/test/java/org/teiid/query/processor/TestSQLXMLProcessing.java 2012-07-24
01:39:54 UTC (rev 4260)
+++
branches/7.4.x/engine/src/test/java/org/teiid/query/processor/TestSQLXMLProcessing.java 2012-07-24
14:02:03 UTC (rev 4261)
@@ -193,6 +193,16 @@
process(sql, expected);
}
+ @Test public void testXmlTableDateTime() throws Exception {
+ String sql = "select * from xmltable('/a' passing convert('<a
dt=\"2011-11-17T07:38:49\" dtz=\"2011-11-17T07:38:49Z\"
t=\"13:23:14\" d=\"2010-04-05\" />', xml) columns x timestamp
path '@dt', x1 timestamp path '@dtz', y date path '@d', z time
path '@t') as x"; //$NON-NLS-1$
+
+ List<?>[] expected = new List<?>[] {
+ Arrays.asList(TimestampUtil.createTimestamp(111, 10, 17, 7, 38, 49, 0),
TimestampUtil.createTimestamp(111, 10, 17, 1, 38, 49, 0), TimestampUtil.createDate(110, 3,
5), TimestampUtil.createTime(13, 23, 14))
+ };
+
+ process(sql, expected);
+ }
+
@Test public void testXmlTableInView() throws Exception {
String sql = "select * from g1"; //$NON-NLS-1$