teiid SVN: r3909 - in trunk: test-integration/common/src/test/java/org/teiid/jdbc and 1 other directory.
by teiid-commits@lists.jboss.org
Author: shawkins
Date: 2012-03-02 21:23:45 -0500 (Fri, 02 Mar 2012)
New Revision: 3909
Modified:
trunk/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/JDBCMetdataProcessor.java
trunk/test-integration/common/src/test/java/org/teiid/jdbc/TestDymamicImportedMetaData.java
Log:
TEIID-1959 added excludeTables and excludeProcedures
Modified: trunk/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/JDBCMetdataProcessor.java
===================================================================
--- trunk/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/JDBCMetdataProcessor.java 2012-03-02 17:35:05 UTC (rev 3908)
+++ trunk/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/JDBCMetdataProcessor.java 2012-03-03 02:23:45 UTC (rev 3909)
@@ -33,6 +33,7 @@
import java.util.Map;
import java.util.Set;
import java.util.TreeMap;
+import java.util.regex.Pattern;
import org.teiid.core.util.StringUtil;
import org.teiid.logging.LogConstants;
@@ -90,6 +91,9 @@
private Set<String> unsignedTypes = new HashSet<String>();
private String quoteString;
+ private Pattern excludeTables;
+ private Pattern excludeProcedures;
+
public void getConnectorMetadata(Connection conn, MetadataFactory metadataFactory)
throws SQLException, TranslatorException {
DatabaseMetaData metadata = conn.getMetaData();
@@ -149,6 +153,9 @@
}
}
String fullProcedureName = getFullyQualifiedName(procedureCatalog, procedureSchema, procedureName);
+ if (excludeProcedures != null && excludeProcedures.matcher(fullProcedureName).matches()) {
+ continue;
+ }
Procedure procedure = metadataFactory.addProcedure(useFullSchemaName?fullProcedureName:procedureName);
procedure.setNameInSource(getFullyQualifiedName(procedureCatalog, procedureSchema, nameInSource, true));
ResultSet columns = metadata.getProcedureColumns(catalog, procedureSchema, procedureName, null);
@@ -209,6 +216,9 @@
String tableSchema = tables.getString(2);
String tableName = tables.getString(3);
String fullName = getFullyQualifiedName(tableCatalog, tableSchema, tableName);
+ if (excludeTables != null && excludeTables.matcher(fullName).matches()) {
+ continue;
+ }
Table table = metadataFactory.addTable(useFullSchemaName?fullName:tableName);
table.setNameInSource(getFullyQualifiedName(tableCatalog, tableSchema, tableName, true));
table.setSupportsUpdate(true);
@@ -486,4 +496,12 @@
this.useCatalogName = useCatalog;
}
+ public void setExcludeProcedures(String excludeProcedures) {
+ this.excludeProcedures = Pattern.compile(excludeProcedures, Pattern.DOTALL | Pattern.CASE_INSENSITIVE);
+ }
+
+ public void setExcludeTables(String excludeTables) {
+ this.excludeTables = Pattern.compile(excludeTables, Pattern.DOTALL | Pattern.CASE_INSENSITIVE);
+ }
+
}
Modified: trunk/test-integration/common/src/test/java/org/teiid/jdbc/TestDymamicImportedMetaData.java
===================================================================
--- trunk/test-integration/common/src/test/java/org/teiid/jdbc/TestDymamicImportedMetaData.java 2012-03-02 17:35:05 UTC (rev 3908)
+++ trunk/test-integration/common/src/test/java/org/teiid/jdbc/TestDymamicImportedMetaData.java 2012-03-03 02:23:45 UTC (rev 3909)
@@ -28,6 +28,8 @@
import java.util.LinkedHashMap;
import java.util.Properties;
+import org.junit.After;
+import org.junit.Before;
import org.junit.Test;
import org.teiid.core.types.DataTypeManager;
import org.teiid.core.util.UnitTestUtil;
@@ -47,6 +49,16 @@
@SuppressWarnings("nls")
public class TestDymamicImportedMetaData {
+ FakeServer server;
+
+ @Before public void setup() {
+ server = new FakeServer();
+ }
+
+ @After public void teardown() {
+ server.stop();
+ }
+
private MetadataFactory getMetadata(Properties importProperties, Connection conn)
throws TranslatorException {
MetadataFactory mf = createMetadataFactory("test", importProperties);
@@ -63,7 +75,6 @@
}
@Test public void testProcImport() throws Exception {
- FakeServer server = new FakeServer();
server.deployVDB("vdb", UnitTestUtil.getTestDataPath() + "/TestCase3473/test.vdb");
Connection conn = server.createConnection("jdbc:teiid:vdb"); //$NON-NLS-1$
@@ -71,11 +82,25 @@
importProperties.setProperty("importer.importProcedures", Boolean.TRUE.toString());
MetadataFactory mf = getMetadata(importProperties, conn);
Procedure p = mf.getMetadataStore().getSchemas().get("TEST").getProcedures().get("VDB.SYS.GETXMLSCHEMAS");
+ assertEquals(29, mf.getMetadataStore().getSchemas().get("TEST").getTables().size());
+ assertEquals(8, mf.getMetadataStore().getSchemas().get("TEST").getProcedures().size());
assertEquals(1, p.getResultSet().getColumns().size());
}
+ @Test public void testExcludes() throws Exception {
+ server.deployVDB("vdb", UnitTestUtil.getTestDataPath() + "/TestCase3473/test.vdb");
+ Connection conn = server.createConnection("jdbc:teiid:vdb"); //$NON-NLS-1$
+
+ Properties importProperties = new Properties();
+ importProperties.setProperty("importer.importProcedures", Boolean.TRUE.toString());
+ importProperties.setProperty("importer.excludeTables", "VDB\\.SYS\\..*");
+ importProperties.setProperty("importer.excludeProcedures", "VDB\\..*");
+ MetadataFactory mf = getMetadata(importProperties, conn);
+ assertEquals(18, mf.getMetadataStore().getSchemas().get("TEST").getTables().size());
+ assertEquals(0, mf.getMetadataStore().getSchemas().get("TEST").getProcedures().size());
+ }
+
@Test public void testDuplicateException() throws Exception {
- FakeServer server = new FakeServer();
MetadataFactory mf = createMetadataFactory("x", new Properties());
MetadataFactory mf1 = createMetadataFactory("y", new Properties());
@@ -107,7 +132,6 @@
}
@Test public void testUseCatalog() throws Exception {
- FakeServer server = new FakeServer();
MetadataFactory mf = createMetadataFactory("x", new Properties());
Table dup = mf.addTable("dup");
12 years, 10 months
teiid SVN: r3908 - in branches/7.7.x: engine/src/main/java/org/teiid/dqp/internal/process and 7 other directories.
by teiid-commits@lists.jboss.org
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")
12 years, 10 months
teiid SVN: r3907 - branches/7.7.x/connectors/connector-file/src/test/java/org/teiid/resource/adapter/file.
by teiid-commits@lists.jboss.org
Author: shawkins
Date: 2012-03-02 12:21:18 -0500 (Fri, 02 Mar 2012)
New Revision: 3907
Modified:
branches/7.7.x/connectors/connector-file/src/test/java/org/teiid/resource/adapter/file/TestFileConnection.java
Log:
corrections for windows builds
Modified: branches/7.7.x/connectors/connector-file/src/test/java/org/teiid/resource/adapter/file/TestFileConnection.java
===================================================================
--- branches/7.7.x/connectors/connector-file/src/test/java/org/teiid/resource/adapter/file/TestFileConnection.java 2012-03-01 02:28:49 UTC (rev 3906)
+++ branches/7.7.x/connectors/connector-file/src/test/java/org/teiid/resource/adapter/file/TestFileConnection.java 2012-03-02 17:21:18 UTC (rev 3907)
@@ -42,9 +42,9 @@
BasicConnectionFactory bcf = fmcf.createConnectionFactory();
FileConnection fc = (FileConnection)bcf.getConnection();
File f = fc.getFile("x");
- assertEquals("foo/y", f.getPath());
+ assertEquals("foo" + File.separator + "y", f.getPath());
f = fc.getFile("n");
- assertEquals("foo/n", f.getPath());
+ assertEquals("foo" + File.separator + "n", f.getPath());
}
@Test(expected=ResourceException.class) public void testParentPaths() throws Exception {
@@ -53,7 +53,7 @@
fmcf.setAllowParentPaths(false);
BasicConnectionFactory bcf = fmcf.createConnectionFactory();
FileConnection fc = (FileConnection)bcf.getConnection();
- fc.getFile("../x");
+ fc.getFile(".." + File.separator + "x");
}
@Test public void testParentPaths1() throws Exception {
@@ -62,7 +62,7 @@
fmcf.setAllowParentPaths(true);
BasicConnectionFactory bcf = fmcf.createConnectionFactory();
FileConnection fc = (FileConnection)bcf.getConnection();
- fc.getFile("../x");
+ fc.getFile(".." + File.separator + "x");
}
}
12 years, 10 months
teiid SVN: r3906 - in branches/7.7.x: connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/postgresql and 2 other directories.
by teiid-commits@lists.jboss.org
Author: shawkins
Date: 2012-02-29 21:28:49 -0500 (Wed, 29 Feb 2012)
New Revision: 3906
Added:
branches/7.7.x/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/postgresql/GreenplumExecutionFactory.java
Modified:
branches/7.7.x/build/kits/jboss-container/teiid-releasenotes.html
branches/7.7.x/connectors/translator-jdbc/src/main/resources/META-INF/jboss-beans.xml
branches/7.7.x/documentation/reference/src/main/docbook/en-US/content/translators.xml
Log:
TEIID-1953 adding a greenplum translator
Modified: branches/7.7.x/build/kits/jboss-container/teiid-releasenotes.html
===================================================================
--- branches/7.7.x/build/kits/jboss-container/teiid-releasenotes.html 2012-02-29 22:59:27 UTC (rev 3905)
+++ branches/7.7.x/build/kits/jboss-container/teiid-releasenotes.html 2012-03-01 02:28:49 UTC (rev 3906)
@@ -27,6 +27,7 @@
<H2><A NAME="Highlights"></A>Highlights</H2>
<UL>
<LI><B>Excel JDBC Translator</B> - for use with Excel using the JDBC-ODBC bridge.
+ <LI><B>Greenplum Translator</B> - for use with the Greenplum database.
<LI><B>Salesforce Aggregates</B> - salesforce pushdown queries now support GROUP BY, HAVING, and the standard aggregate functions.
<LI><B>Comparable LOBs</B> - the system property org.teiid.comparableLobs can be set to use CLOB and BLOB values in comparison/sorting/grouping operations.
<LI><B>Padded String Comparison</B> - the system property org.teiid.padSpace can be set to effectively right pad strings to the same length for comparison.
Added: branches/7.7.x/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/postgresql/GreenplumExecutionFactory.java
===================================================================
--- branches/7.7.x/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/postgresql/GreenplumExecutionFactory.java (rev 0)
+++ branches/7.7.x/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/postgresql/GreenplumExecutionFactory.java 2012-03-01 02:28:49 UTC (rev 3906)
@@ -0,0 +1,38 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * See the COPYRIGHT.txt file distributed with this work for information
+ * regarding copyright ownership. Some portions may be licensed
+ * to Red Hat, Inc. under one or more contributor license agreements.
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA.
+ */
+
+package org.teiid.translator.jdbc.postgresql;
+
+import org.teiid.translator.Translator;
+
+/**
+ * Translator for Greenplum.
+ */
+@Translator(name="greenplum", description="A translator for the Greenplum Database")
+public class GreenplumExecutionFactory extends PostgreSQLExecutionFactory {
+
+ @Override
+ public boolean supportsCorrelatedSubqueries() {
+ return false;
+ }
+
+}
Property changes on: branches/7.7.x/connectors/translator-jdbc/src/main/java/org/teiid/translator/jdbc/postgresql/GreenplumExecutionFactory.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Modified: branches/7.7.x/connectors/translator-jdbc/src/main/resources/META-INF/jboss-beans.xml
===================================================================
--- branches/7.7.x/connectors/translator-jdbc/src/main/resources/META-INF/jboss-beans.xml 2012-02-29 22:59:27 UTC (rev 3905)
+++ branches/7.7.x/connectors/translator-jdbc/src/main/resources/META-INF/jboss-beans.xml 2012-03-01 02:28:49 UTC (rev 3906)
@@ -209,6 +209,22 @@
</constructor>
</bean>
+ <!-- Greenplum -->
+ <bean name="translator-greenplum-template" class="org.teiid.templates.TranslatorDeploymentTemplate">
+ <property name="info"><inject bean="translator-greenplum" /> </property>
+ <property name="managedObjectFactory"> <inject bean="ManagedObjectFactory" /> </property>
+ </bean>
+
+ <bean name="translator-greenplum" class="org.teiid.templates.TranslatorTemplateInfo">
+ <constructor factoryMethod="createTemplateInfo">
+ <factory bean="TranslatorDeploymentTemplateInfoFactory" />
+ <parameter class="java.lang.Class">org.teiid.templates.TranslatorTemplateInfo</parameter>
+ <parameter class="java.lang.Class">org.teiid.translator.jdbc.postgresql.GreenplumExecutionFactory</parameter>
+ <parameter class="java.lang.String">translator-greenplum</parameter>
+ <parameter class="java.lang.String">Greenplum</parameter>
+ </constructor>
+ </bean>
+
<!-- SQL SERVER -->
<bean name="translator-sqlserver-template" class="org.teiid.templates.TranslatorDeploymentTemplate">
<property name="info"><inject bean="translator-sqlserver" /> </property>
Modified: branches/7.7.x/documentation/reference/src/main/docbook/en-US/content/translators.xml
===================================================================
--- branches/7.7.x/documentation/reference/src/main/docbook/en-US/content/translators.xml 2012-02-29 22:59:27 UTC (rev 3905)
+++ branches/7.7.x/documentation/reference/src/main/docbook/en-US/content/translators.xml 2012-03-01 02:28:49 UTC (rev 3906)
@@ -262,6 +262,11 @@
<para>
<emphasis>excel-odbc</emphasis> - for use with Excel 2003 or later via a JDBC-ODBC bridge.
</para>
+ </listitem>
+ <listitem>
+ <para>
+ <emphasis>greenplum</emphasis> - for use with the Greenplum database.
+ </para>
</listitem>
<listitem>
<para>
12 years, 10 months