[teiid-commits] teiid SVN: r4260 - in trunk/engine/src: test/java/org/teiid/query/processor and 1 other directory.

teiid-commits at lists.jboss.org teiid-commits at lists.jboss.org
Mon Jul 23 21:39:54 EDT 2012


Author: shawkins
Date: 2012-07-23 21:39:54 -0400 (Mon, 23 Jul 2012)
New Revision: 4260

Modified:
   trunk/engine/src/main/java/org/teiid/query/processor/relational/XMLTableNode.java
   trunk/engine/src/test/java/org/teiid/query/processor/TestSQLXMLProcessing.java
Log:
TEIID-2112 using the local timezone for saxon calendarvalues

Modified: trunk/engine/src/main/java/org/teiid/query/processor/relational/XMLTableNode.java
===================================================================
--- trunk/engine/src/main/java/org/teiid/query/processor/relational/XMLTableNode.java	2012-07-23 02:05:25 UTC (rev 4259)
+++ trunk/engine/src/main/java/org/teiid/query/processor/relational/XMLTableNode.java	2012-07-24 01:39:54 UTC (rev 4260)
@@ -23,11 +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;
@@ -38,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;
 
@@ -52,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.eval.Evaluator;
 import org.teiid.query.function.FunctionDescriptor;
@@ -281,14 +286,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();
 							}
@@ -306,6 +311,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: trunk/engine/src/test/java/org/teiid/query/processor/TestSQLXMLProcessing.java
===================================================================
--- trunk/engine/src/test/java/org/teiid/query/processor/TestSQLXMLProcessing.java	2012-07-23 02:05:25 UTC (rev 4259)
+++ trunk/engine/src/test/java/org/teiid/query/processor/TestSQLXMLProcessing.java	2012-07-24 01:39:54 UTC (rev 4260)
@@ -194,6 +194,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 testXmlTablePassingSubquery() throws Exception {
         String sql = "select * from xmltable('/a/b' passing (SELECT xmlelement(name a, xmlAgg(xmlelement(name b, e1))) from pm1.g1) columns val string path '/.') as x"; //$NON-NLS-1$
         



More information about the teiid-commits mailing list