Author: shawkins
Date: 2012-03-02 12:35:05 -0500 (Fri, 02 Mar 2012)
New Revision: 3908
Modified:
branches/7.7.x/api/src/main/java/org/teiid/translator/SourceSystemFunctions.java
branches/7.7.x/engine/src/main/java/org/teiid/dqp/internal/process/CachedFinder.java
branches/7.7.x/engine/src/main/java/org/teiid/query/function/FunctionDescriptor.java
branches/7.7.x/engine/src/main/java/org/teiid/query/function/FunctionMethods.java
branches/7.7.x/engine/src/main/java/org/teiid/query/processor/xml/AddNodeInstruction.java
branches/7.7.x/engine/src/main/java/org/teiid/query/processor/xml/XMLValueTranslator.java
branches/7.7.x/engine/src/main/java/org/teiid/query/rewriter/QueryRewriter.java
branches/7.7.x/engine/src/main/java/org/teiid/query/util/CommandContext.java
branches/7.7.x/engine/src/test/java/org/teiid/query/function/TestFunction.java
branches/7.7.x/engine/src/test/java/org/teiid/query/processor/xml/TestXMLValueTranslator.java
branches/7.7.x/engine/src/test/java/org/teiid/query/rewriter/TestQueryRewriter.java
Log:
TEIID-499 consolidating numeric parse/format functions for easier pushdown support. also
caching date/number formats for reuse and changed the cached finder to not actually cache
the capabilities - since we can rely on the connector manager to do that and we do not
have a concept of user level capabilities.
Modified:
branches/7.7.x/api/src/main/java/org/teiid/translator/SourceSystemFunctions.java
===================================================================
---
branches/7.7.x/api/src/main/java/org/teiid/translator/SourceSystemFunctions.java 2012-03-02
17:21:18 UTC (rev 3907)
+++
branches/7.7.x/api/src/main/java/org/teiid/translator/SourceSystemFunctions.java 2012-03-02
17:35:05 UTC (rev 3908)
@@ -77,20 +77,25 @@
public static final String DEGREES = "degrees"; //$NON-NLS-1$
public static final String EXP = "exp"; //$NON-NLS-1$
public static final String FLOOR = "floor"; //$NON-NLS-1$
- public static final String FORMATINTEGER = "formatinteger"; //$NON-NLS-1$
- public static final String FORMATLONG = "formatlong"; //$NON-NLS-1$
- public static final String FORMATDOUBLE = "formatdouble"; //$NON-NLS-1$
- public static final String FORMATFLOAT = "formatfloat"; //$NON-NLS-1$
- public static final String FORMATBIGINTEGER = "formatbiginteger";
//$NON-NLS-1$
+
+ @Deprecated public static final String FORMATINTEGER = "formatinteger";
//$NON-NLS-1$
+ @Deprecated public static final String FORMATLONG = "formatlong";
//$NON-NLS-1$
+ @Deprecated public static final String FORMATDOUBLE = "formatdouble";
//$NON-NLS-1$
+ @Deprecated public static final String FORMATFLOAT = "formatfloat";
//$NON-NLS-1$
+ @Deprecated public static final String FORMATBIGINTEGER = "formatbiginteger";
//$NON-NLS-1$
+
public static final String FORMATBIGDECIMAL = "formatbigdecimal";
//$NON-NLS-1$
+
public static final String LOG = "log"; //$NON-NLS-1$
public static final String LOG10 = "log10"; //$NON-NLS-1$
public static final String MOD = "mod"; //$NON-NLS-1$
- public static final String PARSEINTEGER = "parseinteger"; //$NON-NLS-1$
- public static final String PARSELONG = "parselong"; //$NON-NLS-1$
- public static final String PARSEDOUBLE = "parsedouble"; //$NON-NLS-1$
- public static final String PARSEFLOAT = "parsefloat"; //$NON-NLS-1$
- public static final String PARSEBIGINTEGER = "parsebiginteger"; //$NON-NLS-1$
+
+ @Deprecated public static final String PARSEINTEGER = "parseinteger";
//$NON-NLS-1$
+ @Deprecated public static final String PARSELONG = "parselong"; //$NON-NLS-1$
+ @Deprecated public static final String PARSEDOUBLE = "parsedouble";
//$NON-NLS-1$
+ @Deprecated public static final String PARSEFLOAT = "parsefloat";
//$NON-NLS-1$
+ @Deprecated public static final String PARSEBIGINTEGER = "parsebiginteger";
//$NON-NLS-1$
+
public static final String PARSEBIGDECIMAL = "parsebigdecimal"; //$NON-NLS-1$
public static final String PI = "pi"; //$NON-NLS-1$
public static final String POWER = "power"; //$NON-NLS-1$
Modified:
branches/7.7.x/engine/src/main/java/org/teiid/dqp/internal/process/CachedFinder.java
===================================================================
---
branches/7.7.x/engine/src/main/java/org/teiid/dqp/internal/process/CachedFinder.java 2012-03-02
17:21:18 UTC (rev 3907)
+++
branches/7.7.x/engine/src/main/java/org/teiid/dqp/internal/process/CachedFinder.java 2012-03-02
17:35:05 UTC (rev 3908)
@@ -40,6 +40,9 @@
/**
+ * This class is misnamed. Since connector managers are in process and cache their own
+ * capabilities, there is no need to cache again here. Also we want to pick up any
+ * changes if a source has it's translator modified.
*/
public class CachedFinder implements CapabilitiesFinder {
@@ -95,7 +98,6 @@
throw new TeiidRuntimeException("No sources were given for the model "
+ modelName); //$NON-NLS-1$
}
- userCache.put(modelName, caps);
return caps;
}
Modified:
branches/7.7.x/engine/src/main/java/org/teiid/query/function/FunctionDescriptor.java
===================================================================
---
branches/7.7.x/engine/src/main/java/org/teiid/query/function/FunctionDescriptor.java 2012-03-02
17:21:18 UTC (rev 3907)
+++
branches/7.7.x/engine/src/main/java/org/teiid/query/function/FunctionDescriptor.java 2012-03-02
17:35:05 UTC (rev 3908)
@@ -171,7 +171,7 @@
public Object invokeFunction(Object[] values) throws FunctionExecutionException {
if (!isNullDependent()) {
- for (int i = 0; i < values.length; i++) {
+ for (int i = requiresContext?1:0; i < values.length; i++) {
if (values[i] == null) {
return null;
}
Modified:
branches/7.7.x/engine/src/main/java/org/teiid/query/function/FunctionMethods.java
===================================================================
---
branches/7.7.x/engine/src/main/java/org/teiid/query/function/FunctionMethods.java 2012-03-02
17:21:18 UTC (rev 3907)
+++
branches/7.7.x/engine/src/main/java/org/teiid/query/function/FunctionMethods.java 2012-03-02
17:35:05 UTC (rev 3908)
@@ -1052,10 +1052,10 @@
}
// ================== Format date/time/timestamp TO String ==================
- public static String format(Date date, String format)
+ public static String format(CommandContext context, Date date, String format)
throws FunctionExecutionException {
try {
- SimpleDateFormat sdf = new SimpleDateFormat(format);
+ SimpleDateFormat sdf = CommandContext.getDateFormat(context, format);
return sdf.format(date);
} catch (IllegalArgumentException iae) {
throw new FunctionExecutionException("ERR.015.001.0042",
QueryPlugin.Util.getString("ERR.015.001.0042" , //$NON-NLS-1$ //$NON-NLS-2$
@@ -1064,9 +1064,9 @@
}
// ================== Parse String TO date/time/timestamp ==================
- private static Date parseDateHelper(String date, String format)
+ private static Date parseDateHelper(CommandContext context, String date, String format)
throws FunctionExecutionException {
- DateFormat df = new SimpleDateFormat(format);
+ DateFormat df = CommandContext.getDateFormat(context, format);
try {
return df.parse(date);
} catch (ParseException e) {
@@ -1075,16 +1075,16 @@
}
}
- public static Timestamp parseTimestamp(String timestamp, String format)
+ public static Timestamp parseTimestamp(CommandContext context, String timestamp, String
format)
throws FunctionExecutionException {
- return new Timestamp(parseDateHelper(timestamp, format).getTime());
+ return new Timestamp(parseDateHelper(context, timestamp, format).getTime());
}
// ================== Format number TO String ==================
- public static String format(Number number, String format)
+ public static String format(CommandContext context, Number number, String format)
throws FunctionExecutionException {
try {
- DecimalFormat df = new DecimalFormat(format);
+ DecimalFormat df = CommandContext.getDecimalFormat(context, format);
return df.format(number);
} catch (IllegalArgumentException iae) {
throw new FunctionExecutionException("ERR.015.001.0042",
QueryPlugin.Util.getString("ERR.015.001.0042" , //$NON-NLS-1$ //$NON-NLS-2$
@@ -1093,49 +1093,41 @@
}
// ================== Parse String TO numbers ==================
- public static Object parseInteger(String number, String format)
+ public static Object parseInteger(CommandContext context, String number, String format)
throws FunctionExecutionException {
- Number intNum = parseNumberHelper(number, format);
+ Number intNum = parseBigDecimal(context, number, format);
return new Integer(intNum.intValue());
}
- public static Object parseLong(String number, String format)
+ public static Object parseLong(CommandContext context, String number, String format)
throws FunctionExecutionException {
- Number longNum = parseNumberHelper(number, format);
+ Number longNum = parseBigDecimal(context, number, format);
return new Long(longNum.longValue());
}
- public static Object parseDouble(String number, String format)
+ public static Object parseDouble(CommandContext context, String number, String format)
throws FunctionExecutionException {
- Number doubleNum = parseNumberHelper(number, format);
+ Number doubleNum = parseBigDecimal(context, number, format);
return new Double(doubleNum.doubleValue());
}
- public static Object parseFloat(String number, String format)
+ public static Object parseFloat(CommandContext context, String number, String format)
throws FunctionExecutionException {
- Number longNum = parseNumberHelper(number, format);
+ Number longNum = parseBigDecimal(context, number, format);
return new Float(longNum.floatValue());
}
- public static Object parseBigInteger(String number, String format)
+ public static Object parseBigInteger(CommandContext context, String number, String
format)
throws FunctionExecutionException {
- Number bigIntegerNum = parseNumberHelper(number, format);
+ Number bigIntegerNum = parseBigDecimal(context, number, format);
return new BigInteger(bigIntegerNum.toString());
}
- public static Object parseBigDecimal(String number, String format)
+ public static BigDecimal parseBigDecimal(CommandContext context, String number, String
format)
throws FunctionExecutionException {
- Number bigDecimalNum = parseNumberHelper(number, format);
- return new BigDecimal(bigDecimalNum.toString());
- }
-
- // ============== Helper Function for format/parse numbers ==================
-
- private static Number parseNumberHelper(String number, String format)
- throws FunctionExecutionException {
- DecimalFormat df= new DecimalFormat(format);
+ DecimalFormat df= CommandContext.getDecimalFormat(context, format);
try {
- return df.parse(number);
+ return (BigDecimal) df.parse(number);
} catch (ParseException e) {
throw new FunctionExecutionException("ERR.015.001.0043",
QueryPlugin.Util.getString("ERR.015.001.0043" , //$NON-NLS-1$ //$NON-NLS-2$
number,format));
Modified:
branches/7.7.x/engine/src/main/java/org/teiid/query/processor/xml/AddNodeInstruction.java
===================================================================
---
branches/7.7.x/engine/src/main/java/org/teiid/query/processor/xml/AddNodeInstruction.java 2012-03-02
17:21:18 UTC (rev 3907)
+++
branches/7.7.x/engine/src/main/java/org/teiid/query/processor/xml/AddNodeInstruction.java 2012-03-02
17:35:05 UTC (rev 3908)
@@ -22,12 +22,7 @@
package org.teiid.query.processor.xml;
-import static org.teiid.query.analysis.AnalysisRecord.PROP_DATA_COL;
-import static org.teiid.query.analysis.AnalysisRecord.PROP_DEFAULT;
-import static org.teiid.query.analysis.AnalysisRecord.PROP_NAMESPACE;
-import static org.teiid.query.analysis.AnalysisRecord.PROP_NAMESPACE_DECL;
-import static org.teiid.query.analysis.AnalysisRecord.PROP_OPTIONAL;
-import static org.teiid.query.analysis.AnalysisRecord.PROP_TAG;
+import static org.teiid.query.analysis.AnalysisRecord.*;
import java.util.ArrayList;
import java.util.Enumeration;
@@ -115,7 +110,7 @@
}
} else {
Object value = context.getVariableContext().getValue(symbol);
- String valueStr = XMLValueTranslator.translateToXMLValue(value,
descriptor.getRuntimeType(), descriptor.getDocBuiltInType());
+ String valueStr = XMLValueTranslator.translateToXMLValue(value,
descriptor.getRuntimeType(), descriptor.getDocBuiltInType(), env.getProcessorContext());
if (valueStr != null){
if(isElement) {
Modified:
branches/7.7.x/engine/src/main/java/org/teiid/query/processor/xml/XMLValueTranslator.java
===================================================================
---
branches/7.7.x/engine/src/main/java/org/teiid/query/processor/xml/XMLValueTranslator.java 2012-03-02
17:21:18 UTC (rev 3907)
+++
branches/7.7.x/engine/src/main/java/org/teiid/query/processor/xml/XMLValueTranslator.java 2012-03-02
17:35:05 UTC (rev 3908)
@@ -37,6 +37,7 @@
import org.teiid.core.types.TransformationException;
import org.teiid.query.function.FunctionMethods;
import org.teiid.query.function.source.XMLSystemFunctions;
+import org.teiid.query.util.CommandContext;
@@ -105,7 +106,7 @@
* @throws TransformationException
* @since 5.0
*/
- public static String translateToXMLValue(Object value, Class<?> runtimeType,
String builtInType) throws FunctionExecutionException, TransformationException {
+ public static String translateToXMLValue(Object value, Class<?> runtimeType,
String builtInType, CommandContext context) throws FunctionExecutionException,
TransformationException {
if (value == null) {
return null;
}
@@ -141,10 +142,10 @@
valueStr = bigIntegerTogMonth((BigInteger)value);
break;
case GMONTHDAY_CODE:
- valueStr = FunctionMethods.format((Timestamp)value,
GMONTHDAY_FORMAT);
+ valueStr = FunctionMethods.format(context, (Timestamp)value,
GMONTHDAY_FORMAT);
break;
case GYEAR_CODE:
- valueStr = FunctionMethods.format((BigInteger)value, GYEAR_FORMAT);
+ valueStr = FunctionMethods.format(context, (BigInteger)value,
GYEAR_FORMAT);
break;
case GYEARMONTH_CODE:
DateTimeValue dtv;
Modified: branches/7.7.x/engine/src/main/java/org/teiid/query/rewriter/QueryRewriter.java
===================================================================
---
branches/7.7.x/engine/src/main/java/org/teiid/query/rewriter/QueryRewriter.java 2012-03-02
17:21:18 UTC (rev 3907)
+++
branches/7.7.x/engine/src/main/java/org/teiid/query/rewriter/QueryRewriter.java 2012-03-02
17:35:05 UTC (rev 3908)
@@ -1637,7 +1637,7 @@
return getSimpliedCriteria(crit, leftExpr, crit.getOperator() !=
CompareCriteria.EQ, true);
}
Constant other = ResolverUtil.convertConstant(leftExprTypeName,
DataTypeManager.getDataTypeName(rightConstant.getType()), result);
- if (other == null ||
((Comparable)rightConstant.getValue()).compareTo(other.getValue()) != 0) {
+ if (other == null || rightConstant.compareTo(other) != 0) {
return getSimpliedCriteria(crit, leftExpr, crit.getOperator() !=
CompareCriteria.EQ, true);
}
@@ -1770,8 +1770,8 @@
}
Object value = ((Constant)rightExpr).getValue();
try {
- Object result = descriptor.invokeFunction(new Object[]
{((Constant)rightExpr).getValue(), format});
- result = leftFunction.getFunctionDescriptor().invokeFunction(new Object[] { result,
format } );
+ Object result = descriptor.invokeFunction(new Object[] {context,
((Constant)rightExpr).getValue(), format});
+ result = leftFunction.getFunctionDescriptor().invokeFunction(new Object[] {context,
result, format } );
if (((Comparable)value).compareTo(result) != 0) {
return getSimpliedCriteria(crit, leftExpr, crit.getOperator() !=
CompareCriteria.EQ, true);
}
@@ -1917,7 +1917,7 @@
// Passed all the checks, so build the optimized version
try {
- Timestamp ts = FunctionMethods.parseTimestamp(timestampValue, dateFormat +
timeFormat);
+ Timestamp ts = FunctionMethods.parseTimestamp(this.context, timestampValue,
dateFormat + timeFormat);
Constant dateConstant = new Constant(TimestampWithTimezone.createDate(ts));
CompareCriteria dateCompare = new
CompareCriteria(formatDateFunction.getArgs()[0], CompareCriteria.EQ, dateConstant);
@@ -2238,6 +2238,29 @@
function.setFunctionDescriptor(descriptor);
}
+ if(functionLowerName.startsWith("parse")) { //$NON-NLS-1$
+ String type = functionLowerName.substring(5);
+ if (PARSE_FORMAT_TYPES.contains(type) &&
Number.class.isAssignableFrom(function.getType()) &&
!type.equals(DataTypeManager.DefaultDataTypes.BIG_DECIMAL)) {
+ Function result = new Function(SourceSystemFunctions.PARSEBIGDECIMAL,
function.getArgs());
+ FunctionDescriptor descriptor =
+ funcLibrary.findFunction(SourceSystemFunctions.PARSEBIGDECIMAL, new Class[] {
DataTypeManager.DefaultDataClasses.STRING, DataTypeManager.DefaultDataClasses.STRING });
+ result.setFunctionDescriptor(descriptor);
+ result.setType(DataTypeManager.DefaultDataClasses.BIG_DECIMAL);
+ return rewriteFunction(ResolverUtil.getConversion(result,
DataTypeManager.DefaultDataTypes.BIG_DECIMAL,
DataTypeManager.getDataTypeName(function.getType()), false,
metadata.getFunctionLibrary()));
+ }
+ } else if(functionLowerName.startsWith("format")) { //$NON-NLS-1$
+ String type = functionLowerName.substring(6);
+ if (PARSE_FORMAT_TYPES.contains(type) &&
Number.class.isAssignableFrom(function.getArg(0).getType()) &&
!type.equals(DataTypeManager.DefaultDataTypes.BIG_DECIMAL)) {
+ Function bigDecimalParam = ResolverUtil.getConversion(function.getArg(0),
DataTypeManager.getDataTypeName(function.getArg(0).getType()),
DataTypeManager.DefaultDataTypes.BIG_DECIMAL, false, metadata.getFunctionLibrary());
+ Function result = new Function(SourceSystemFunctions.FORMATBIGDECIMAL, new
Expression[] {bigDecimalParam, function.getArg(1)});
+ FunctionDescriptor descriptor =
+ funcLibrary.findFunction(SourceSystemFunctions.FORMATBIGDECIMAL, new Class[] {
DataTypeManager.DefaultDataClasses.BIG_DECIMAL, DataTypeManager.DefaultDataClasses.STRING
});
+ result.setFunctionDescriptor(descriptor);
+ result.setType(DataTypeManager.DefaultDataClasses.STRING);
+ return rewriteFunction(result);
+ }
+ }
+
Integer code = FUNCTION_MAP.get(functionLowerName);
if (code != null) {
switch (code) {
Modified: branches/7.7.x/engine/src/main/java/org/teiid/query/util/CommandContext.java
===================================================================
---
branches/7.7.x/engine/src/main/java/org/teiid/query/util/CommandContext.java 2012-03-02
17:21:18 UTC (rev 3907)
+++
branches/7.7.x/engine/src/main/java/org/teiid/query/util/CommandContext.java 2012-03-02
17:35:05 UTC (rev 3908)
@@ -23,6 +23,8 @@
package org.teiid.query.util;
import java.io.Serializable;
+import java.text.DecimalFormat;
+import java.text.SimpleDateFormat;
import java.util.Collections;
import java.util.HashSet;
import java.util.LinkedList;
@@ -44,6 +46,7 @@
import org.teiid.core.TeiidComponentException;
import org.teiid.core.util.ArgCheck;
import org.teiid.core.util.ExecutorUtils;
+import org.teiid.core.util.LRUCache;
import org.teiid.dqp.internal.process.DQPWorkContext;
import org.teiid.dqp.internal.process.PreparedPlan;
import org.teiid.dqp.internal.process.SessionAwareCache;
@@ -138,6 +141,8 @@
private TransactionService transactionService;
private SourceHint sourceHint;
private Executor executor = ExecutorUtils.getDirectExecutor();
+ private LRUCache<String, DecimalFormat> decimalFormatCache;
+ private LRUCache<String, SimpleDateFormat> dateFormatCache;
}
private GlobalState globalState = new GlobalState();
@@ -650,4 +655,41 @@
this.globalState.executor = e;
}
+ public static DecimalFormat getDecimalFormat(CommandContext context, String format) {
+ DecimalFormat result = null;
+ if (context != null) {
+ if (context.globalState.decimalFormatCache == null) {
+ context.globalState.decimalFormatCache = new LRUCache<String,
DecimalFormat>(32);
+ } else {
+ result = context.globalState.decimalFormatCache.get(format);
+ }
+ }
+ if (result == null) {
+ result = new DecimalFormat(format); //TODO: could be locale sensitive
+ result.setParseBigDecimal(true);
+ if (context != null) {
+ context.globalState.decimalFormatCache.put(format, result);
+ }
+ }
+ return result;
+ }
+
+ public static SimpleDateFormat getDateFormat(CommandContext context, String format) {
+ SimpleDateFormat result = null;
+ if (context != null) {
+ if (context.globalState.dateFormatCache == null) {
+ context.globalState.dateFormatCache = new LRUCache<String,
SimpleDateFormat>(32);
+ } else {
+ result = context.globalState.dateFormatCache.get(format);
+ }
+ }
+ if (result == null) {
+ result = new SimpleDateFormat(format); //TODO: could be locale sensitive
+ if (context != null) {
+ context.globalState.dateFormatCache.put(format, result);
+ }
+ }
+ return result;
+ }
+
}
Modified: branches/7.7.x/engine/src/test/java/org/teiid/query/function/TestFunction.java
===================================================================
---
branches/7.7.x/engine/src/test/java/org/teiid/query/function/TestFunction.java 2012-03-02
17:21:18 UTC (rev 3907)
+++
branches/7.7.x/engine/src/test/java/org/teiid/query/function/TestFunction.java 2012-03-02
17:35:05 UTC (rev 3908)
@@ -189,7 +189,7 @@
}
public static void helpTestParseTimestamp(String tsStr, String format, String
expected) throws FunctionExecutionException {
- Object actual = FunctionMethods.parseTimestamp(tsStr, format);
+ Object actual = FunctionMethods.parseTimestamp(new CommandContext(), tsStr,
format);
assertEquals("parseTimestamp(" + tsStr + ", " + format +
") failed", expected.toString(), //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
new Constant(actual).toString());
}
@@ -1138,15 +1138,15 @@
}
@Test(expected=FunctionExecutionException.class) public void testParseIntStrictness()
throws Exception {
- FunctionMethods.parseInteger("a 1 a", "#"); //$NON-NLS-1$
//$NON-NLS-2$
+ FunctionMethods.parseBigDecimal(new CommandContext(), "a 1 a",
"#"); //$NON-NLS-1$ //$NON-NLS-2$
}
@Test public void testParseDateStrictness() throws Exception {
- assertEquals(TimestampUtil.createTimestamp(108, 0, 1, 0, 0, 0, 0),
FunctionMethods.parseTimestamp(" 2007-13-01", "yyyy-MM"));
//$NON-NLS-1$ //$NON-NLS-2$
+ assertEquals(TimestampUtil.createTimestamp(108, 0, 1, 0, 0, 0, 0),
FunctionMethods.parseTimestamp(new CommandContext(), " 2007-13-01",
"yyyy-MM")); //$NON-NLS-1$ //$NON-NLS-2$
}
@Test public void testParseTimeWhitespace() throws Exception {
- assertEquals(TimestampUtil.createTime(15, 0, 0),
FunctionMethods.parseTimestamp(" 15:00:00 ", "HH:mm:ss"));
//$NON-NLS-1$ //$NON-NLS-2$
+ assertEquals(TimestampUtil.createTime(15, 0, 0), FunctionMethods.parseTimestamp(new
CommandContext(), " 15:00:00 ", "HH:mm:ss")); //$NON-NLS-1$
//$NON-NLS-2$
}
@Test public void testMod() {
Modified:
branches/7.7.x/engine/src/test/java/org/teiid/query/processor/xml/TestXMLValueTranslator.java
===================================================================
---
branches/7.7.x/engine/src/test/java/org/teiid/query/processor/xml/TestXMLValueTranslator.java 2012-03-02
17:21:18 UTC (rev 3907)
+++
branches/7.7.x/engine/src/test/java/org/teiid/query/processor/xml/TestXMLValueTranslator.java 2012-03-02
17:35:05 UTC (rev 3908)
@@ -34,6 +34,7 @@
import org.teiid.core.types.DataTypeManager;
import org.teiid.core.util.TimestampWithTimezone;
import org.teiid.query.unittest.TimestampUtil;
+import org.teiid.query.util.CommandContext;
public class TestXMLValueTranslator {
@@ -49,54 +50,54 @@
@Test public void test24HourDateTimeTranslation() throws Exception {
Timestamp ts = TimestampUtil.createTimestamp(100, 0, 2, 14, 14, 5, 6000);
- String value = XMLValueTranslator.translateToXMLValue(ts,
DataTypeManager.DefaultDataClasses.TIMESTAMP, XMLValueTranslator.DATETIME);
+ String value = XMLValueTranslator.translateToXMLValue(ts,
DataTypeManager.DefaultDataClasses.TIMESTAMP, XMLValueTranslator.DATETIME, new
CommandContext());
assertEquals("2000-01-02T20:14:05.000006Z", value); //$NON-NLS-1$
}
@Test public void testDateTimeTranslation() throws Exception {
Timestamp ts = TimestampUtil.createTimestamp(100, 0, 2, 3, 4, 5, 6);
- String value = XMLValueTranslator.translateToXMLValue(ts,
DataTypeManager.DefaultDataClasses.TIMESTAMP, XMLValueTranslator.DATETIME);
+ String value = XMLValueTranslator.translateToXMLValue(ts,
DataTypeManager.DefaultDataClasses.TIMESTAMP, XMLValueTranslator.DATETIME, new
CommandContext());
assertEquals("2000-01-02T09:04:05Z", value); //$NON-NLS-1$
ts.setNanos(6000);
- value = XMLValueTranslator.translateToXMLValue(ts,
DataTypeManager.DefaultDataClasses.TIMESTAMP, XMLValueTranslator.DATETIME);
+ value = XMLValueTranslator.translateToXMLValue(ts,
DataTypeManager.DefaultDataClasses.TIMESTAMP, XMLValueTranslator.DATETIME, new
CommandContext());
assertEquals("2000-01-02T09:04:05.000006Z", value); //$NON-NLS-1$
ts.setNanos(0);
- value = XMLValueTranslator.translateToXMLValue(ts,
DataTypeManager.DefaultDataClasses.TIMESTAMP, XMLValueTranslator.DATETIME);
+ value = XMLValueTranslator.translateToXMLValue(ts,
DataTypeManager.DefaultDataClasses.TIMESTAMP, XMLValueTranslator.DATETIME, new
CommandContext());
assertEquals("2000-01-02T09:04:05Z", value); //$NON-NLS-1$
ts = TimestampUtil.createTimestamp(-2000, 0, 2, 3, 4, 5, 6);
- value = XMLValueTranslator.translateToXMLValue(ts,
DataTypeManager.DefaultDataClasses.TIMESTAMP, XMLValueTranslator.DATETIME);
+ value = XMLValueTranslator.translateToXMLValue(ts,
DataTypeManager.DefaultDataClasses.TIMESTAMP, XMLValueTranslator.DATETIME, new
CommandContext());
assertEquals("-0102-12-30T09:04:05Z", value); //$NON-NLS-1$
}
@Test public void testgYearTranslation() throws Exception {
- String value = XMLValueTranslator.translateToXMLValue(new
BigInteger("5"), DataTypeManager.DefaultDataClasses.BIG_INTEGER,
XMLValueTranslator.GYEAR); //$NON-NLS-1$
+ String value = XMLValueTranslator.translateToXMLValue(new
BigInteger("5"), DataTypeManager.DefaultDataClasses.BIG_INTEGER,
XMLValueTranslator.GYEAR, new CommandContext()); //$NON-NLS-1$
assertEquals("0005", value); //$NON-NLS-1$
- value = XMLValueTranslator.translateToXMLValue(new
BigInteger("-10000"), DataTypeManager.DefaultDataClasses.BIG_INTEGER,
XMLValueTranslator.GYEAR); //$NON-NLS-1$
+ value = XMLValueTranslator.translateToXMLValue(new
BigInteger("-10000"), DataTypeManager.DefaultDataClasses.BIG_INTEGER,
XMLValueTranslator.GYEAR, new CommandContext()); //$NON-NLS-1$
assertEquals("-10000", value); //$NON-NLS-1$
}
@Test public void testgYearMonthTranslation() throws Exception {
Timestamp ts = TimestampUtil.createTimestamp(100, 0, 4, 6, 8, 10, 12);
- String value = XMLValueTranslator.translateToXMLValue(ts,
DataTypeManager.DefaultDataClasses.TIMESTAMP, XMLValueTranslator.GYEARMONTH);
+ String value = XMLValueTranslator.translateToXMLValue(ts,
DataTypeManager.DefaultDataClasses.TIMESTAMP, XMLValueTranslator.GYEARMONTH, new
CommandContext());
assertEquals("2000-01Z", value); //$NON-NLS-1$
ts = TimestampUtil.createTimestamp(-30000, 0, 4, 6, 8, 10, 12);
- value = XMLValueTranslator.translateToXMLValue(ts,
DataTypeManager.DefaultDataClasses.TIMESTAMP, XMLValueTranslator.GYEARMONTH);
+ value = XMLValueTranslator.translateToXMLValue(ts,
DataTypeManager.DefaultDataClasses.TIMESTAMP, XMLValueTranslator.GYEARMONTH, new
CommandContext());
assertEquals("-28102-06Z", value); //$NON-NLS-1$
}
@Test public void testDefaultTranslation() throws Exception {
- String value = XMLValueTranslator.translateToXMLValue("",
DataTypeManager.DefaultDataClasses.STRING, XMLValueTranslator.STRING); //$NON-NLS-1$
+ String value = XMLValueTranslator.translateToXMLValue("",
DataTypeManager.DefaultDataClasses.STRING, XMLValueTranslator.STRING, new
CommandContext()); //$NON-NLS-1$
assertNull(value);
}
Modified:
branches/7.7.x/engine/src/test/java/org/teiid/query/rewriter/TestQueryRewriter.java
===================================================================
---
branches/7.7.x/engine/src/test/java/org/teiid/query/rewriter/TestQueryRewriter.java 2012-03-02
17:21:18 UTC (rev 3907)
+++
branches/7.7.x/engine/src/test/java/org/teiid/query/rewriter/TestQueryRewriter.java 2012-03-02
17:35:05 UTC (rev 3908)
@@ -56,19 +56,7 @@
import org.teiid.query.parser.QueryParser;
import org.teiid.query.resolver.QueryResolver;
import org.teiid.query.resolver.util.ResolverVisitor;
-import org.teiid.query.sql.lang.Command;
-import org.teiid.query.sql.lang.CompareCriteria;
-import org.teiid.query.sql.lang.CompoundCriteria;
-import org.teiid.query.sql.lang.Criteria;
-import org.teiid.query.sql.lang.IsNullCriteria;
-import org.teiid.query.sql.lang.MatchCriteria;
-import org.teiid.query.sql.lang.ProcedureContainer;
-import org.teiid.query.sql.lang.Query;
-import org.teiid.query.sql.lang.QueryCommand;
-import org.teiid.query.sql.lang.SPParameter;
-import org.teiid.query.sql.lang.SetCriteria;
-import org.teiid.query.sql.lang.SetQuery;
-import org.teiid.query.sql.lang.StoredProcedure;
+import org.teiid.query.sql.lang.*;
import org.teiid.query.sql.proc.CreateUpdateProcedureCommand;
import org.teiid.query.sql.symbol.Constant;
import org.teiid.query.sql.symbol.ElementSymbol;
@@ -561,9 +549,9 @@
"pm1.g1.e2 = 1234" ); //$NON-NLS-1$
}
- @Test public void testRewriteCrit_formatInteger1() {
+ @Test public void testRewriteCrit_formatInteger1() throws QueryMetadataException,
TeiidComponentException, TeiidProcessingException {
helpTestRewriteCriteria("formatInteger(pm1.g1.e2, '#5') =
'105'", //$NON-NLS-1$
- "formatInteger(pm1.g1.e2, '#5') =
'105'" ); //$NON-NLS-1$
+ "formatbigdecimal(convert(pm1.g1.e2, bigdecimal),
'#5') = '105'", true ); //$NON-NLS-1$
}
@Ignore(value="Cannot deterime if the format is narrowing")