Author: shawkins
Date: 2009-10-01 10:46:23 -0400 (Thu, 01 Oct 2009)
New Revision: 1511
Added:
trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/h2/
trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/h2/H2Capabilities.java
trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/h2/H2Translator.java
trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/hsql/
trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/hsql/AddDiffModifier.java
trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/hsql/HsqlCapabilities.java
trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/hsql/HsqlTranslator.java
trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/h2/
trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/h2/TestH2Translator.java
trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/translator/TestEscapeSyntaxModifier.java
Removed:
trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/extension/impl/TestEscapeSyntaxModifier.java
Modified:
trunk/connector-api/src/main/java/org/teiid/connector/api/SourceSystemFunctions.java
trunk/connectors/connector-jdbc/src/main/resources/connector-jdbc.xml
trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/derby/TestDerbySQLTranslator.java
trunk/documentation/reference/src/main/docbook/en-US/content/scalar_functions.xml
trunk/engine/src/main/java/com/metamatrix/query/function/FunctionLibrary.java
trunk/engine/src/main/java/com/metamatrix/query/function/FunctionMethods.java
trunk/engine/src/main/java/com/metamatrix/query/function/source/SystemSource.java
trunk/engine/src/main/java/com/metamatrix/query/resolver/util/ResolverUtil.java
trunk/engine/src/main/java/com/metamatrix/query/rewriter/QueryRewriter.java
trunk/engine/src/test/java/com/metamatrix/query/function/TestFunction.java
trunk/engine/src/test/java/com/metamatrix/query/function/TestFunctionLibrary.java
trunk/engine/src/test/java/com/metamatrix/query/rewriter/TestQueryRewriter.java
Log:
TEIID-822 TEIID-868 adding h2 and hsqldb translators, also simplifying datetime functions
inline with what sources typically support.
Modified:
trunk/connector-api/src/main/java/org/teiid/connector/api/SourceSystemFunctions.java
===================================================================
---
trunk/connector-api/src/main/java/org/teiid/connector/api/SourceSystemFunctions.java 2009-10-01
13:56:55 UTC (rev 1510)
+++
trunk/connector-api/src/main/java/org/teiid/connector/api/SourceSystemFunctions.java 2009-10-01
14:46:23 UTC (rev 1511)
@@ -110,8 +110,6 @@
public static final String DAYOFMONTH = "dayofmonth"; //$NON-NLS-1$
public static final String DAYOFWEEK = "dayofweek"; //$NON-NLS-1$
public static final String DAYOFYEAR = "dayofyear"; //$NON-NLS-1$
- public static final String FORMATDATE = "formatdate"; //$NON-NLS-1$
- public static final String FORMATTIME = "formattime"; //$NON-NLS-1$
public static final String FORMATTIMESTAMP = "formattimestamp"; //$NON-NLS-1$
public static final String HOUR = "hour"; //$NON-NLS-1$
public static final String MINUTE = "minute"; //$NON-NLS-1$
@@ -119,8 +117,6 @@
public static final String MONTH = "month"; //$NON-NLS-1$
public static final String MONTHNAME = "monthname"; //$NON-NLS-1$
public static final String NOW = "now"; //$NON-NLS-1$
- public static final String PARSEDATE = "parsedate"; //$NON-NLS-1$
- public static final String PARSETIME = "parsetime"; //$NON-NLS-1$
public static final String PARSETIMESTAMP = "parsetimestamp"; //$NON-NLS-1$
public static final String QUARTER = "quarter"; //$NON-NLS-1$
public static final String SECOND = "second"; //$NON-NLS-1$
Added:
trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/h2/H2Capabilities.java
===================================================================
---
trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/h2/H2Capabilities.java
(rev 0)
+++
trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/h2/H2Capabilities.java 2009-10-01
14:46:23 UTC (rev 1511)
@@ -0,0 +1,137 @@
+/*
+ * 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.connector.jdbc.h2;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.teiid.connector.api.SourceSystemFunctions;
+import org.teiid.connector.jdbc.JDBCCapabilities;
+
+public class H2Capabilities extends JDBCCapabilities {
+
+ public List<String> getSupportedFunctions() {
+ List<String> supportedFunctions = new ArrayList<String>();
+ supportedFunctions.addAll(super.getSupportedFunctions());
+
+ supportedFunctions.add(SourceSystemFunctions.ABS);
+ supportedFunctions.add(SourceSystemFunctions.ACOS);
+ supportedFunctions.add(SourceSystemFunctions.ASIN);
+ supportedFunctions.add(SourceSystemFunctions.ATAN);
+ supportedFunctions.add(SourceSystemFunctions.ATAN2);
+ supportedFunctions.add(SourceSystemFunctions.BITAND);
+ //supportedFunctions.add(SourceSystemFunctions.BITNOT);
+ supportedFunctions.add(SourceSystemFunctions.BITOR);
+ supportedFunctions.add(SourceSystemFunctions.BITXOR);
+ supportedFunctions.add(SourceSystemFunctions.CEILING);
+ supportedFunctions.add(SourceSystemFunctions.COS);
+ supportedFunctions.add(SourceSystemFunctions.COT);
+ supportedFunctions.add(SourceSystemFunctions.DEGREES);
+ supportedFunctions.add(SourceSystemFunctions.EXP);
+ supportedFunctions.add(SourceSystemFunctions.FLOOR);
+ supportedFunctions.add(SourceSystemFunctions.LOG);
+ supportedFunctions.add(SourceSystemFunctions.LOG10);
+ supportedFunctions.add(SourceSystemFunctions.MOD);
+ supportedFunctions.add(SourceSystemFunctions.PI);
+ supportedFunctions.add(SourceSystemFunctions.POWER);
+ supportedFunctions.add(SourceSystemFunctions.RADIANS);
+ supportedFunctions.add(SourceSystemFunctions.ROUND);
+ supportedFunctions.add(SourceSystemFunctions.SIGN);
+ supportedFunctions.add(SourceSystemFunctions.SIN);
+ supportedFunctions.add(SourceSystemFunctions.SQRT);
+ supportedFunctions.add(SourceSystemFunctions.TAN);
+
+ supportedFunctions.add(SourceSystemFunctions.ASCII);
+ supportedFunctions.add(SourceSystemFunctions.CHAR);
+ supportedFunctions.add(SourceSystemFunctions.CONCAT);
+ supportedFunctions.add(SourceSystemFunctions.INSERT);
+ supportedFunctions.add(SourceSystemFunctions.LCASE);
+ supportedFunctions.add(SourceSystemFunctions.LEFT);
+ supportedFunctions.add(SourceSystemFunctions.LENGTH);
+ supportedFunctions.add(SourceSystemFunctions.LOCATE);
+ supportedFunctions.add(SourceSystemFunctions.LPAD);
+ supportedFunctions.add(SourceSystemFunctions.LTRIM);
+ supportedFunctions.add(SourceSystemFunctions.REPEAT);
+ supportedFunctions.add(SourceSystemFunctions.REPLACE);
+ supportedFunctions.add(SourceSystemFunctions.RIGHT);
+ supportedFunctions.add(SourceSystemFunctions.RPAD);
+ supportedFunctions.add(SourceSystemFunctions.RTRIM);
+ supportedFunctions.add(SourceSystemFunctions.SUBSTRING);
+ supportedFunctions.add(SourceSystemFunctions.UCASE);
+
+ supportedFunctions.add(SourceSystemFunctions.DAYNAME);
+ supportedFunctions.add(SourceSystemFunctions.DAYOFMONTH);
+ supportedFunctions.add(SourceSystemFunctions.DAYOFWEEK);
+ supportedFunctions.add(SourceSystemFunctions.DAYOFYEAR);
+
+ supportedFunctions.add(SourceSystemFunctions.FORMATDATE);
+ supportedFunctions.add(SourceSystemFunctions.FORMATTIME);
+ supportedFunctions.add(SourceSystemFunctions.FORMATTIMESTAMP);
+ supportedFunctions.add(SourceSystemFunctions.HOUR);
+ supportedFunctions.add(SourceSystemFunctions.MINUTE);
+ supportedFunctions.add(SourceSystemFunctions.MONTH);
+ supportedFunctions.add(SourceSystemFunctions.MONTHNAME);
+
+ supportedFunctions.add(SourceSystemFunctions.PARSEDATE);
+ supportedFunctions.add(SourceSystemFunctions.PARSETIME);
+ supportedFunctions.add(SourceSystemFunctions.PARSETIMESTAMP);
+ supportedFunctions.add(SourceSystemFunctions.QUARTER);
+ supportedFunctions.add(SourceSystemFunctions.SECOND);
+ supportedFunctions.add(SourceSystemFunctions.TIMESTAMPADD);
+ supportedFunctions.add(SourceSystemFunctions.TIMESTAMPDIFF);
+ //supportedFunctions.add(SourceSystemFunctions.TIMESTAMPCREATE);
+ supportedFunctions.add(SourceSystemFunctions.WEEK);
+ supportedFunctions.add(SourceSystemFunctions.YEAR);
+
+ supportedFunctions.add(SourceSystemFunctions.CONVERT);
+ supportedFunctions.add(SourceSystemFunctions.IFNULL);
+ supportedFunctions.add(SourceSystemFunctions.COALESCE);
+ return supportedFunctions;
+ }
+
+ @Override
+ public boolean supportsInlineViews() {
+ return true;
+ }
+
+ @Override
+ public boolean supportsRowLimit() {
+ return true;
+ }
+
+ @Override
+ public boolean supportsRowOffset() {
+ return true;
+ }
+
+ @Override
+ public boolean supportsExcept() {
+ return true;
+ }
+
+ @Override
+ public boolean supportsIntersect() {
+ return true;
+ }
+
+}
Property changes on:
trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/h2/H2Capabilities.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added:
trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/h2/H2Translator.java
===================================================================
---
trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/h2/H2Translator.java
(rev 0)
+++
trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/h2/H2Translator.java 2009-10-01
14:46:23 UTC (rev 1511)
@@ -0,0 +1,96 @@
+/*
+ * 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.connector.jdbc.h2;
+
+import java.sql.Date;
+import java.sql.Time;
+import java.sql.Timestamp;
+
+import org.teiid.connector.api.ConnectorCapabilities;
+import org.teiid.connector.api.ConnectorEnvironment;
+import org.teiid.connector.api.ConnectorException;
+import org.teiid.connector.api.SourceSystemFunctions;
+import org.teiid.connector.jdbc.hsql.AddDiffModifier;
+import org.teiid.connector.jdbc.oracle.ConcatFunctionModifier;
+import org.teiid.connector.jdbc.translator.AliasModifier;
+import org.teiid.connector.jdbc.translator.ConvertModifier;
+import org.teiid.connector.jdbc.translator.FunctionModifier;
+import org.teiid.connector.jdbc.translator.ModFunctionModifier;
+import org.teiid.connector.jdbc.translator.Translator;
+
+public class H2Translator extends Translator {
+
+ @Override
+ public void initialize(ConnectorEnvironment env) throws ConnectorException {
+ super.initialize(env);
+ registerFunctionModifier(SourceSystemFunctions.PARSETIMESTAMP, new
AliasModifier("parsedatetime")); //$NON-NLS-1$
+ registerFunctionModifier(SourceSystemFunctions.FORMATTIMESTAMP, new
AliasModifier("formatdatetime")); //$NON-NLS-1$
+ registerFunctionModifier(SourceSystemFunctions.DAYOFMONTH, new
AliasModifier("day_of_month")); //$NON-NLS-1$
+ registerFunctionModifier(SourceSystemFunctions.DAYOFWEEK, new
AliasModifier("day_of_week")); //$NON-NLS-1$
+ registerFunctionModifier(SourceSystemFunctions.DAYOFYEAR, new
AliasModifier("day_of_year")); //$NON-NLS-1$
+ registerFunctionModifier(SourceSystemFunctions.MOD, new
ModFunctionModifier(SourceSystemFunctions.MOD, getLanguageFactory()));
+ //TODO: this behavior is configurable in h2 starting with 1.1.119
+ registerFunctionModifier(SourceSystemFunctions.CONCAT, new
ConcatFunctionModifier(getLanguageFactory()));
+
+ registerFunctionModifier(SourceSystemFunctions.TIMESTAMPADD, new AddDiffModifier(true,
getLanguageFactory()));
+ registerFunctionModifier(SourceSystemFunctions.TIMESTAMPDIFF, new
AddDiffModifier(false, getLanguageFactory()));
+
+ ConvertModifier convert = new ConvertModifier();
+ convert.addTypeMapping("boolean", FunctionModifier.BOOLEAN); //$NON-NLS-1$
+ convert.addTypeMapping("tinyint", FunctionModifier.BYTE); //$NON-NLS-1$
+ convert.addTypeMapping("smallint", FunctionModifier.SHORT); //$NON-NLS-1$
+ convert.addTypeMapping("int", FunctionModifier.INTEGER); //$NON-NLS-1$
+ convert.addTypeMapping("bigint", FunctionModifier.LONG); //$NON-NLS-1$
+ convert.addTypeMapping("real", FunctionModifier.FLOAT); //$NON-NLS-1$
+ convert.addTypeMapping("double", FunctionModifier.DOUBLE); //$NON-NLS-1$
+ convert.addTypeMapping("decimal", FunctionModifier.BIGDECIMAL);
//$NON-NLS-1$
+ convert.addTypeMapping("decimal(38,0)", FunctionModifier.BIGINTEGER);
//$NON-NLS-1$
+ convert.addTypeMapping("date", FunctionModifier.DATE); //$NON-NLS-1$
+ convert.addTypeMapping("time", FunctionModifier.TIME); //$NON-NLS-1$
+ convert.addTypeMapping("timestamp", FunctionModifier.TIMESTAMP);
//$NON-NLS-1$
+ convert.addTypeMapping("char(1)", FunctionModifier.CHAR); //$NON-NLS-1$
+ convert.addTypeMapping("varchar", FunctionModifier.STRING); //$NON-NLS-1$
+ registerFunctionModifier(SourceSystemFunctions.CONVERT, convert);
+ }
+
+ @Override
+ public String translateLiteralDate(Date dateValue) {
+ return "DATE '" + formatDateValue(dateValue) + "'";
//$NON-NLS-1$//$NON-NLS-2$
+ }
+
+ @Override
+ public String translateLiteralTime(Time timeValue) {
+ return "TIME '" + formatDateValue(timeValue) + "'";
//$NON-NLS-1$//$NON-NLS-2$
+ }
+
+ @Override
+ public String translateLiteralTimestamp(Timestamp timestampValue) {
+ return "TIMESTAMP '" + formatDateValue(timestampValue) +
"'"; //$NON-NLS-1$//$NON-NLS-2$
+ }
+
+ @Override
+ public Class<? extends ConnectorCapabilities> getDefaultCapabilities() {
+ return H2Capabilities.class;
+ }
+
+}
Property changes on:
trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/h2/H2Translator.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added:
trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/hsql/AddDiffModifier.java
===================================================================
---
trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/hsql/AddDiffModifier.java
(rev 0)
+++
trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/hsql/AddDiffModifier.java 2009-10-01
14:46:23 UTC (rev 1511)
@@ -0,0 +1,101 @@
+/*
+ * 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.connector.jdbc.hsql;
+
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import org.teiid.connector.api.TypeFacility;
+import org.teiid.connector.jdbc.translator.ExtractFunctionModifier;
+import org.teiid.connector.jdbc.translator.FunctionModifier;
+import org.teiid.connector.language.IExpression;
+import org.teiid.connector.language.IFunction;
+import org.teiid.connector.language.ILanguageFactory;
+import org.teiid.connector.language.ILiteral;
+import org.teiid.connector.visitor.util.SQLReservedWords;
+
+public class AddDiffModifier extends FunctionModifier {
+
+ private static Map<String, String> INTERVAL_MAP = new HashMap<String,
String>();
+
+ static {
+ INTERVAL_MAP.put(SQLReservedWords.SQL_TSI_DAY, ExtractFunctionModifier.DAY);
+ INTERVAL_MAP.put(SQLReservedWords.SQL_TSI_HOUR, ExtractFunctionModifier.HOUR);
+ INTERVAL_MAP.put(SQLReservedWords.SQL_TSI_MINUTE, ExtractFunctionModifier.MINUTE);
+ INTERVAL_MAP.put(SQLReservedWords.SQL_TSI_MONTH, ExtractFunctionModifier.MONTH);
+ INTERVAL_MAP.put(SQLReservedWords.SQL_TSI_SECOND, ExtractFunctionModifier.SECOND);
+ INTERVAL_MAP.put(SQLReservedWords.SQL_TSI_YEAR, ExtractFunctionModifier.YEAR);
+ }
+
+ private boolean add;
+ private ILanguageFactory factory;
+
+ public AddDiffModifier(boolean add, ILanguageFactory factory) {
+ this.add = add;
+ this.factory = factory;
+ }
+
+ @Override
+ public List<?> translate(IFunction function) {
+ if (add) {
+ function.setName("dateadd"); //$NON-NLS-1$
+ } else {
+ function.setName("datediff"); //$NON-NLS-1$
+ }
+ ILiteral intervalType = (ILiteral)function.getParameters().get(0);
+ String interval = ((String)intervalType.getValue()).toUpperCase();
+ String newInterval = INTERVAL_MAP.get(interval);
+ if (newInterval != null) {
+ intervalType.setValue(newInterval);
+ return null;
+ }
+ if (add) {
+ if (interval.equals(SQLReservedWords.SQL_TSI_FRAC_SECOND)) {
+ intervalType.setValue("MILLISECOND"); //$NON-NLS-1$
+ IExpression[] args = new IExpression[] {function.getParameters().get(1),
factory.createLiteral(1000000, TypeFacility.RUNTIME_TYPES.INTEGER)};
+ function.getParameters().set(1, factory.createFunction("/", args,
TypeFacility.RUNTIME_TYPES.INTEGER)); //$NON-NLS-1$
+ } else if (interval.equals(SQLReservedWords.SQL_TSI_QUARTER)) {
+ intervalType.setValue(ExtractFunctionModifier.DAY);
+ IExpression[] args = new IExpression[] {function.getParameters().get(1),
factory.createLiteral(91, TypeFacility.RUNTIME_TYPES.INTEGER)};
+ function.getParameters().set(1, factory.createFunction("*", args,
TypeFacility.RUNTIME_TYPES.INTEGER)); //$NON-NLS-1$
+ } else {
+ intervalType.setValue(ExtractFunctionModifier.DAY);
+ IExpression[] args = new IExpression[] {function.getParameters().get(1),
factory.createLiteral(7, TypeFacility.RUNTIME_TYPES.INTEGER)};
+ function.getParameters().set(1, factory.createFunction("*", args,
TypeFacility.RUNTIME_TYPES.INTEGER)); //$NON-NLS-1$
+ }
+ return null;
+ }
+ if (interval.equals(SQLReservedWords.SQL_TSI_FRAC_SECOND)) {
+ intervalType.setValue("MILLISECOND"); //$NON-NLS-1$
+ return Arrays.asList(function, " * 1000000"); //$NON-NLS-1$
+ } else if (interval.equals(SQLReservedWords.SQL_TSI_QUARTER)) {
+ intervalType.setValue(ExtractFunctionModifier.DAY);
+ return Arrays.asList(function, " / 91"); //$NON-NLS-1$
+ }
+ intervalType.setValue(ExtractFunctionModifier.DAY);
+ return Arrays.asList(function, " / 7"); //$NON-NLS-1$
+ }
+
+}
\ No newline at end of file
Property changes on:
trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/hsql/AddDiffModifier.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added:
trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/hsql/HsqlCapabilities.java
===================================================================
---
trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/hsql/HsqlCapabilities.java
(rev 0)
+++
trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/hsql/HsqlCapabilities.java 2009-10-01
14:46:23 UTC (rev 1511)
@@ -0,0 +1,133 @@
+/*
+ * 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.connector.jdbc.hsql;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.teiid.connector.api.SourceSystemFunctions;
+import org.teiid.connector.jdbc.JDBCCapabilities;
+
+public class HsqlCapabilities extends JDBCCapabilities {
+
+ public List<String> getSupportedFunctions() {
+ List<String> supportedFunctions = new ArrayList<String>();
+ supportedFunctions.addAll(super.getSupportedFunctions());
+
+ supportedFunctions.add(SourceSystemFunctions.ABS);
+ supportedFunctions.add(SourceSystemFunctions.ACOS);
+ supportedFunctions.add(SourceSystemFunctions.ASIN);
+ supportedFunctions.add(SourceSystemFunctions.ATAN);
+ supportedFunctions.add(SourceSystemFunctions.ATAN2);
+ supportedFunctions.add(SourceSystemFunctions.BITAND);
+ //supportedFunctions.add(SourceSystemFunctions.BITNOT);
+ supportedFunctions.add(SourceSystemFunctions.BITOR);
+ //supportedFunctions.add(SourceSystemFunctions.BITXOR);
+ supportedFunctions.add(SourceSystemFunctions.CEILING);
+ supportedFunctions.add(SourceSystemFunctions.COS);
+ supportedFunctions.add(SourceSystemFunctions.COT);
+ supportedFunctions.add(SourceSystemFunctions.DEGREES);
+ supportedFunctions.add(SourceSystemFunctions.EXP);
+ supportedFunctions.add(SourceSystemFunctions.FLOOR);
+ supportedFunctions.add(SourceSystemFunctions.LOG);
+ supportedFunctions.add(SourceSystemFunctions.LOG10);
+ supportedFunctions.add(SourceSystemFunctions.MOD);
+ supportedFunctions.add(SourceSystemFunctions.PI);
+ supportedFunctions.add(SourceSystemFunctions.POWER);
+ supportedFunctions.add(SourceSystemFunctions.RADIANS);
+ supportedFunctions.add(SourceSystemFunctions.ROUND);
+ supportedFunctions.add(SourceSystemFunctions.SIGN);
+ supportedFunctions.add(SourceSystemFunctions.SIN);
+ supportedFunctions.add(SourceSystemFunctions.SQRT);
+ supportedFunctions.add(SourceSystemFunctions.TAN);
+
+ supportedFunctions.add(SourceSystemFunctions.ASCII);
+ supportedFunctions.add(SourceSystemFunctions.CHAR);
+ supportedFunctions.add(SourceSystemFunctions.CONCAT);
+ supportedFunctions.add(SourceSystemFunctions.INSERT);
+ supportedFunctions.add(SourceSystemFunctions.LCASE);
+ supportedFunctions.add(SourceSystemFunctions.LEFT);
+ supportedFunctions.add(SourceSystemFunctions.LENGTH);
+ supportedFunctions.add(SourceSystemFunctions.LOCATE);
+ supportedFunctions.add(SourceSystemFunctions.LPAD);
+ supportedFunctions.add(SourceSystemFunctions.LTRIM);
+ supportedFunctions.add(SourceSystemFunctions.REPEAT);
+ supportedFunctions.add(SourceSystemFunctions.REPLACE);
+ supportedFunctions.add(SourceSystemFunctions.RIGHT);
+ supportedFunctions.add(SourceSystemFunctions.RPAD);
+ supportedFunctions.add(SourceSystemFunctions.RTRIM);
+ supportedFunctions.add(SourceSystemFunctions.SUBSTRING);
+ supportedFunctions.add(SourceSystemFunctions.UCASE);
+
+ supportedFunctions.add(SourceSystemFunctions.DAYNAME);
+ supportedFunctions.add(SourceSystemFunctions.DAYOFMONTH);
+ supportedFunctions.add(SourceSystemFunctions.DAYOFWEEK);
+ supportedFunctions.add(SourceSystemFunctions.DAYOFYEAR);
+
+ //supportedFunctions.add(SourceSystemFunctions.FORMATDATE);
+ //supportedFunctions.add(SourceSystemFunctions.FORMATTIME);
+ //supportedFunctions.add(SourceSystemFunctions.FORMATTIMESTAMP);
+ supportedFunctions.add(SourceSystemFunctions.HOUR);
+ supportedFunctions.add(SourceSystemFunctions.MINUTE);
+ supportedFunctions.add(SourceSystemFunctions.MONTH);
+ supportedFunctions.add(SourceSystemFunctions.MONTHNAME);
+
+ //supportedFunctions.add(SourceSystemFunctions.PARSEDATE);
+ //supportedFunctions.add(SourceSystemFunctions.PARSETIME);
+ //supportedFunctions.add(SourceSystemFunctions.PARSETIMESTAMP);
+ supportedFunctions.add(SourceSystemFunctions.QUARTER);
+ supportedFunctions.add(SourceSystemFunctions.SECOND);
+ supportedFunctions.add(SourceSystemFunctions.TIMESTAMPADD);
+ supportedFunctions.add(SourceSystemFunctions.TIMESTAMPDIFF);
+ supportedFunctions.add(SourceSystemFunctions.WEEK);
+ supportedFunctions.add(SourceSystemFunctions.YEAR);
+
+ supportedFunctions.add(SourceSystemFunctions.CONVERT);
+ supportedFunctions.add(SourceSystemFunctions.IFNULL);
+ supportedFunctions.add(SourceSystemFunctions.COALESCE);
+ return supportedFunctions;
+ }
+
+ public boolean supportsInlineViews() {
+ return true;
+ }
+
+ public boolean supportsRowLimit() {
+ return true;
+ }
+
+ public boolean supportsRowOffset() {
+ return true;
+ }
+
+ @Override
+ public boolean supportsExcept() {
+ return true;
+ }
+
+ @Override
+ public boolean supportsIntersect() {
+ return true;
+ }
+
+}
Property changes on:
trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/hsql/HsqlCapabilities.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Added:
trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/hsql/HsqlTranslator.java
===================================================================
---
trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/hsql/HsqlTranslator.java
(rev 0)
+++
trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/hsql/HsqlTranslator.java 2009-10-01
14:46:23 UTC (rev 1511)
@@ -0,0 +1,83 @@
+/*
+ * 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.connector.jdbc.hsql;
+
+import java.sql.Date;
+import java.sql.Time;
+import java.sql.Timestamp;
+
+import org.teiid.connector.api.ConnectorCapabilities;
+import org.teiid.connector.api.ConnectorEnvironment;
+import org.teiid.connector.api.ConnectorException;
+import org.teiid.connector.api.SourceSystemFunctions;
+import org.teiid.connector.jdbc.translator.ConvertModifier;
+import org.teiid.connector.jdbc.translator.FunctionModifier;
+import org.teiid.connector.jdbc.translator.Translator;
+
+public class HsqlTranslator extends Translator {
+
+ @Override
+ public void initialize(ConnectorEnvironment env) throws ConnectorException {
+ super.initialize(env);
+ registerFunctionModifier(SourceSystemFunctions.TIMESTAMPADD, new AddDiffModifier(true,
getLanguageFactory()));
+ registerFunctionModifier(SourceSystemFunctions.TIMESTAMPDIFF, new
AddDiffModifier(false, getLanguageFactory()));
+
+ ConvertModifier convert = new ConvertModifier();
+ convert.addTypeMapping("boolean", FunctionModifier.BOOLEAN); //$NON-NLS-1$
+ convert.addTypeMapping("tinyint", FunctionModifier.BYTE); //$NON-NLS-1$
+ convert.addTypeMapping("smallint", FunctionModifier.SHORT); //$NON-NLS-1$
+ convert.addTypeMapping("int", FunctionModifier.INTEGER); //$NON-NLS-1$
+ convert.addTypeMapping("bigint", FunctionModifier.LONG); //$NON-NLS-1$
+ convert.addTypeMapping("real", FunctionModifier.FLOAT); //$NON-NLS-1$
+ convert.addTypeMapping("double", FunctionModifier.DOUBLE); //$NON-NLS-1$
+ convert.addTypeMapping("decimal", FunctionModifier.BIGDECIMAL);
//$NON-NLS-1$
+ convert.addTypeMapping("decimal(38,0)", FunctionModifier.BIGINTEGER);
//$NON-NLS-1$
+ convert.addTypeMapping("date", FunctionModifier.DATE); //$NON-NLS-1$
+ convert.addTypeMapping("time", FunctionModifier.TIME); //$NON-NLS-1$
+ convert.addTypeMapping("timestamp", FunctionModifier.TIMESTAMP);
//$NON-NLS-1$
+ convert.addTypeMapping("char(1)", FunctionModifier.CHAR); //$NON-NLS-1$
+ convert.addTypeMapping("varchar", FunctionModifier.STRING); //$NON-NLS-1$
+ registerFunctionModifier(SourceSystemFunctions.CONVERT, convert);
+ }
+
+ @Override
+ public String translateLiteralDate(Date dateValue) {
+ return "DATE '" + formatDateValue(dateValue) + "'";
//$NON-NLS-1$//$NON-NLS-2$
+ }
+
+ @Override
+ public String translateLiteralTime(Time timeValue) {
+ return "TIME '" + formatDateValue(timeValue) + "'";
//$NON-NLS-1$//$NON-NLS-2$
+ }
+
+ @Override
+ public String translateLiteralTimestamp(Timestamp timestampValue) {
+ return "TIMESTAMP '" + formatDateValue(timestampValue) +
"'"; //$NON-NLS-1$//$NON-NLS-2$
+ }
+
+ @Override
+ public Class<? extends ConnectorCapabilities> getDefaultCapabilities() {
+ return HsqlCapabilities.class;
+ }
+
+}
Property changes on:
trunk/connectors/connector-jdbc/src/main/java/org/teiid/connector/jdbc/hsql/HsqlTranslator.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Modified: trunk/connectors/connector-jdbc/src/main/resources/connector-jdbc.xml
===================================================================
--- trunk/connectors/connector-jdbc/src/main/resources/connector-jdbc.xml 2009-10-01
13:56:55 UTC (rev 1510)
+++ trunk/connectors/connector-jdbc/src/main/resources/connector-jdbc.xml 2009-10-01
14:46:23 UTC (rev 1511)
@@ -134,6 +134,16 @@
<PropertyDefinition Name="ConnectionSource"
DisplayName="Connection Source Class" ShortDescription="Driver, DataSource,
or XADataSource class name" DefaultValue="sun.jdbc.odbc.JdbcOdbcDriver"
IsRequired="true" />
<PropertyDefinition Name="URL" DisplayName="JDBC URL"
ShortDescription="" DefaultValue="jdbc:odbc:Driver={MicroSoft Excel Driver
(*.xls)};DBQ=<filePathToExcelFile>" IsRequired="true"
/>
</ComponentType>
+ <ComponentType Name="H2 1 Connector" ComponentTypeCode="2"
Deployable="true" Deprecated="false" Monitorable="false"
SuperComponentType="JDBC Connector" ParentComponentType="Connectors"
LastChangedBy="ConfigurationStartup"
CreatedBy="ConfigurationStartup">
+ <PropertyDefinition Name="ConnectionSource"
DisplayName="Connection Source Class" ShortDescription="Driver, DataSource,
or XADataSource class name" DefaultValue="org.h2.Driver"
IsRequired="true" />
+ <PropertyDefinition Name="URL" DisplayName="JDBC URL"
ShortDescription=""
DefaultValue="jdbc:h2://<server>:<9092>/<db-name>"
IsRequired="true" PropertyType="String" IsMasked="false"
/>
+ <PropertyDefinition Name="ExtensionTranslationClass"
DisplayName="Extension SQL Translation Class" ShortDescription=""
DefaultValue="org.teiid.connector.jdbc.h2.H2Translator"
PropertyType="String" IsExpert="true" IsMasked="false"
/>
+ </ComponentType>
+ <ComponentType Name="HSQLDB 1 Connector"
ComponentTypeCode="2" Deployable="true" Deprecated="false"
Monitorable="false" SuperComponentType="JDBC Connector"
ParentComponentType="Connectors" LastChangedBy="ConfigurationStartup"
CreatedBy="ConfigurationStartup">
+ <PropertyDefinition Name="ConnectionSource"
DisplayName="Connection Source Class" ShortDescription="Driver, DataSource,
or XADataSource class name" DefaultValue="org.hsqldb.jdbcDriver"
IsRequired="true" />
+ <PropertyDefinition Name="URL" DisplayName="JDBC URL"
ShortDescription=""
DefaultValue="jdbc:hsqldb:hsql://<server>:<1476>"
IsRequired="true" PropertyType="String" IsMasked="false"
/>
+ <PropertyDefinition Name="ExtensionTranslationClass"
DisplayName="Extension SQL Translation Class" ShortDescription=""
DefaultValue="org.teiid.connector.jdbc.h2.H2Translator"
PropertyType="String" IsExpert="true" IsMasked="false"
/>
+ </ComponentType>
<!--
<ComponentType Name="Datadirect DB2 8 Connector"
ComponentTypeCode="2" Deployable="true" Deprecated="false"
Monitorable="false" SuperComponentType="JDBC Connector"
ParentComponentType="Connectors" LastChangedBy="ConfigurationStartup"
LastChangedDate="2008-10-31T10:26:19.928-06:00"
CreatedBy="ConfigurationStartup"
CreationDate="2008-10-31T10:26:19.928-06:00">
<PropertyDefinition Name="ConnectionSource"
DisplayName="Connection Source Class" ShortDescription="Driver, DataSource,
or XADataSource class name"
DefaultValue="com.metamatrix.jdbcx.db2.DB2DataSource"
IsRequired="true" />
Modified:
trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/derby/TestDerbySQLTranslator.java
===================================================================
---
trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/derby/TestDerbySQLTranslator.java 2009-10-01
13:56:55 UTC (rev 1510)
+++
trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/derby/TestDerbySQLTranslator.java 2009-10-01
14:46:23 UTC (rev 1511)
@@ -22,22 +22,14 @@
package org.teiid.connector.jdbc.derby;
-import static org.junit.Assert.assertEquals;
-
import java.util.Properties;
import org.junit.BeforeClass;
import org.junit.Test;
import org.teiid.connector.api.ConnectorException;
-import org.teiid.connector.api.ExecutionContext;
import org.teiid.connector.jdbc.MetadataFactory;
-import org.teiid.connector.jdbc.translator.TranslatedCommand;
-import org.teiid.connector.language.ICommand;
import com.metamatrix.cdk.api.EnvironmentUtility;
-import com.metamatrix.cdk.api.TranslationUtility;
-import com.metamatrix.cdk.unittest.FakeTranslationFactory;
-import com.metamatrix.core.util.UnitTestUtil;
/**
*/
@@ -51,31 +43,12 @@
TRANSLATOR.initialize(EnvironmentUtility.createEnvironment(new Properties(),
false));
}
- public String getTestVDB() {
- return UnitTestUtil.getTestDataPath() + "/PartsSupplier.vdb";
//$NON-NLS-1$
- }
-
- public void helpTestVisitor(TranslationUtility util, String input, String
expectedOutput) throws ConnectorException {
- // Convert from sql to objects
- ICommand obj = util.parseCommand(input);
-
- ExecutionContext context =
EnvironmentUtility.createSecurityContext("user"); //$NON-NLS-1$
-
- TranslatedCommand tc = new TranslatedCommand(context, TRANSLATOR);
- tc.translateCommand(obj);
-
- assertEquals("Did not get correct sql", expectedOutput, tc.getSql());
//$NON-NLS-1$
- }
-
@Test
public void testConcat_useLiteral() throws Exception {
String input = "select concat(stringnum,'_xx') from
BQT1.Smalla"; //$NON-NLS-1$
String output = "SELECT {fn concat(SmallA.StringNum, '_xx')} FROM
SmallA"; //$NON-NLS-1$
- helpTestVisitor(FakeTranslationFactory.getInstance().getBQTTranslationUtility(),
- input,
- output);
-
+ MetadataFactory.helpTestVisitor(MetadataFactory.BQT_VDB, input, output,
TRANSLATOR);
}
@Test
@@ -83,9 +56,7 @@
String input = "select concat(stringnum, stringnum) from BQT1.Smalla";
//$NON-NLS-1$
String output = "SELECT {fn concat(SmallA.StringNum, SmallA.StringNum)} FROM
SmallA"; //$NON-NLS-1$
- helpTestVisitor(FakeTranslationFactory.getInstance().getBQTTranslationUtility(),
- input,
- output);
+ MetadataFactory.helpTestVisitor(MetadataFactory.BQT_VDB, input, output,
TRANSLATOR);
}
@Test
@@ -93,10 +64,7 @@
String input = "select concat2(stringnum,'_xx') from
BQT1.Smalla"; //$NON-NLS-1$
String output = "SELECT {fn concat(coalesce(SmallA.StringNum, ''),
'_xx')} FROM SmallA"; //$NON-NLS-1$
- helpTestVisitor(FakeTranslationFactory.getInstance().getBQTTranslationUtility(),
- input,
- output);
-
+ MetadataFactory.helpTestVisitor(MetadataFactory.BQT_VDB, input, output,
TRANSLATOR);
}
@Test
@@ -104,9 +72,7 @@
String input = "select concat2(stringnum, stringnum) from BQT1.Smalla";
//$NON-NLS-1$
String output = "SELECT CASE WHEN SmallA.StringNum IS NULL THEN NULL ELSE
{fn concat(coalesce(SmallA.StringNum, ''), coalesce(SmallA.StringNum,
''))} END FROM SmallA"; //$NON-NLS-1$
- helpTestVisitor(FakeTranslationFactory.getInstance().getBQTTranslationUtility(),
- input,
- output);
+ MetadataFactory.helpTestVisitor(MetadataFactory.BQT_VDB, input, output,
TRANSLATOR);
}
}
Deleted:
trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/extension/impl/TestEscapeSyntaxModifier.java
===================================================================
---
trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/extension/impl/TestEscapeSyntaxModifier.java 2009-10-01
13:56:55 UTC (rev 1510)
+++
trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/extension/impl/TestEscapeSyntaxModifier.java 2009-10-01
14:46:23 UTC (rev 1511)
@@ -1,79 +0,0 @@
-/*
- * 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.connector.jdbc.extension.impl;
-
-import java.sql.Timestamp;
-import java.util.Arrays;
-import java.util.List;
-
-import org.teiid.connector.jdbc.translator.EscapeSyntaxModifier;
-import org.teiid.connector.language.IFunction;
-import org.teiid.connector.language.ILiteral;
-import org.teiid.connector.visitor.util.SQLReservedWords;
-
-import junit.framework.TestCase;
-
-import com.metamatrix.cdk.CommandBuilder;
-import com.metamatrix.query.unittest.TimestampUtil;
-
-/**
- */
-public class TestEscapeSyntaxModifier extends TestCase {
-
- /**
- * Constructor for TestDropFunctionModifier.
- * @param name
- */
- public TestEscapeSyntaxModifier(String name) {
- super(name);
- }
-
- public void testEscape() {
- ILiteral arg1 =
CommandBuilder.getLanuageFactory().createLiteral("arg1", String.class);
//$NON-NLS-1$
- ILiteral arg2 =
CommandBuilder.getLanuageFactory().createLiteral("arg2",
String.class);//$NON-NLS-1$
- IFunction func =
CommandBuilder.getLanuageFactory().createFunction("concat", Arrays.asList( arg1,
arg2), Integer.class); //$NON-NLS-1$
-
- helpTest(func, "{fn concat('arg1', 'arg2')}");
- }
-
- public void testTimestampAdd() {
- ILiteral arg1 =
CommandBuilder.getLanuageFactory().createLiteral(SQLReservedWords.SQL_TSI_HOUR,
String.class); //$NON-NLS-1$
- ILiteral arg2 =
CommandBuilder.getLanuageFactory().createLiteral(Integer.valueOf(1),
Integer.class);//$NON-NLS-1$
- ILiteral arg3 =
CommandBuilder.getLanuageFactory().createLiteral(TimestampUtil.createTimestamp(0, 0, 0, 0,
0, 0, 0), Timestamp.class);//$NON-NLS-1$
- IFunction func =
CommandBuilder.getLanuageFactory().createFunction("timestampadd", Arrays.asList(
arg1, arg2, arg3), Timestamp.class); //$NON-NLS-1$
-
- helpTest(func, "{fn timestampadd(SQL_TSI_HOUR, 1, {ts'1899-12-31
00:00:00.0'})}");
- }
-
- private void helpTest(IFunction func, String expected) {
- EscapeSyntaxModifier mod = new EscapeSyntaxModifier();
-
- List parts = mod.translate(func);
- StringBuffer sb = new StringBuffer();
- for (Object object : parts) {
- sb.append(object);
- }
- assertEquals(expected, sb.toString());
- }
-
-}
Added:
trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/h2/TestH2Translator.java
===================================================================
---
trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/h2/TestH2Translator.java
(rev 0)
+++
trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/h2/TestH2Translator.java 2009-10-01
14:46:23 UTC (rev 1511)
@@ -0,0 +1,66 @@
+/*
+ * 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.connector.jdbc.h2;
+
+import java.util.Properties;
+
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.teiid.connector.api.ConnectorException;
+import org.teiid.connector.jdbc.MetadataFactory;
+
+import com.metamatrix.cdk.api.EnvironmentUtility;
+
+public class TestH2Translator {
+
+ private static H2Translator TRANSLATOR;
+
+ @BeforeClass
+ public static void setUp() throws ConnectorException {
+ TRANSLATOR = new H2Translator();
+ TRANSLATOR.initialize(EnvironmentUtility.createEnvironment(new Properties(),
false));
+ }
+
+ @Test public void testTimestampDiff() throws Exception {
+ String input = "select timestampdiff(SQL_TSI_FRAC_SECOND, timestampvalue,
{d'1970-01-01'}) from BQT1.Smalla"; //$NON-NLS-1$
+ String output = "SELECT datediff('MILLISECOND',
SmallA.TimestampValue, TIMESTAMP '1970-01-01 00:00:00.0') * 1000000 FROM
SmallA"; //$NON-NLS-1$
+
+ MetadataFactory.helpTestVisitor(MetadataFactory.BQT_VDB, input, output,
TRANSLATOR);
+ }
+
+ @Test public void testTimestampAdd() throws Exception {
+ String input = "select timestampadd(SQL_TSI_FRAC_SECOND, 2, datevalue) from
BQT1.Smalla"; //$NON-NLS-1$
+ String output = "SELECT cast(dateadd('MILLISECOND', (2 / 1000000),
cast(SmallA.DateValue AS timestamp)) AS date) FROM SmallA"; //$NON-NLS-1$
+
+ MetadataFactory.helpTestVisitor(MetadataFactory.BQT_VDB, input, output,
TRANSLATOR);
+ }
+
+ @Test public void testTimestampAdd1() throws Exception {
+ String input = "select timestampadd(SQL_TSI_HOUR, intnum, {t'00:00:00'})
from BQT1.Smalla"; //$NON-NLS-1$
+ String output = "SELECT cast(dateadd('HOUR', SmallA.IntNum,
TIMESTAMP '1970-01-01 00:00:00.0') AS time) FROM SmallA"; //$NON-NLS-1$
+
+ MetadataFactory.helpTestVisitor(MetadataFactory.BQT_VDB, input, output,
TRANSLATOR);
+ }
+
+
+}
Property changes on:
trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/h2/TestH2Translator.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Copied:
trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/translator/TestEscapeSyntaxModifier.java
(from rev 1501,
trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/extension/impl/TestEscapeSyntaxModifier.java)
===================================================================
---
trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/translator/TestEscapeSyntaxModifier.java
(rev 0)
+++
trunk/connectors/connector-jdbc/src/test/java/org/teiid/connector/jdbc/translator/TestEscapeSyntaxModifier.java 2009-10-01
14:46:23 UTC (rev 1511)
@@ -0,0 +1,79 @@
+/*
+ * 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.connector.jdbc.translator;
+
+import java.sql.Timestamp;
+import java.util.Arrays;
+import java.util.List;
+
+import org.teiid.connector.jdbc.translator.EscapeSyntaxModifier;
+import org.teiid.connector.language.IFunction;
+import org.teiid.connector.language.ILiteral;
+import org.teiid.connector.visitor.util.SQLReservedWords;
+
+import junit.framework.TestCase;
+
+import com.metamatrix.cdk.CommandBuilder;
+import com.metamatrix.query.unittest.TimestampUtil;
+
+/**
+ */
+public class TestEscapeSyntaxModifier extends TestCase {
+
+ /**
+ * Constructor for TestDropFunctionModifier.
+ * @param name
+ */
+ public TestEscapeSyntaxModifier(String name) {
+ super(name);
+ }
+
+ public void testEscape() {
+ ILiteral arg1 =
CommandBuilder.getLanuageFactory().createLiteral("arg1", String.class);
//$NON-NLS-1$
+ ILiteral arg2 =
CommandBuilder.getLanuageFactory().createLiteral("arg2",
String.class);//$NON-NLS-1$
+ IFunction func =
CommandBuilder.getLanuageFactory().createFunction("concat", Arrays.asList( arg1,
arg2), Integer.class); //$NON-NLS-1$
+
+ helpTest(func, "{fn concat('arg1', 'arg2')}");
+ }
+
+ public void testTimestampAdd() {
+ ILiteral arg1 =
CommandBuilder.getLanuageFactory().createLiteral(SQLReservedWords.SQL_TSI_HOUR,
String.class);
+ ILiteral arg2 =
CommandBuilder.getLanuageFactory().createLiteral(Integer.valueOf(1), Integer.class);
+ ILiteral arg3 =
CommandBuilder.getLanuageFactory().createLiteral(TimestampUtil.createTimestamp(0, 0, 0, 0,
0, 0, 0), Timestamp.class);
+ IFunction func =
CommandBuilder.getLanuageFactory().createFunction("timestampadd", Arrays.asList(
arg1, arg2, arg3), Timestamp.class); //$NON-NLS-1$
+
+ helpTest(func, "{fn timestampadd(SQL_TSI_HOUR, 1, {ts'1899-12-31
00:00:00.0'})}");
+ }
+
+ private void helpTest(IFunction func, String expected) {
+ EscapeSyntaxModifier mod = new EscapeSyntaxModifier();
+
+ List parts = mod.translate(func);
+ StringBuffer sb = new StringBuffer();
+ for (Object object : parts) {
+ sb.append(object);
+ }
+ assertEquals(expected, sb.toString());
+ }
+
+}
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 2009-10-01
13:56:55 UTC (rev 1510)
+++
trunk/documentation/reference/src/main/docbook/en-US/content/scalar_functions.xml 2009-10-01
14:46:23 UTC (rev 1511)
@@ -1343,8 +1343,7 @@
(endTime > startTime), a positive number will be returned. If
(endTime < startTime), a negative number will be returned. Calculations are
approximate and may be less accurate over longer time spans.</para>
</entry>
<entry>
- <para>Interval in {string}; startTime, endTime in {date,
- time, timestamp}, returns a long.</para>
+ <para>Interval in {string}; startTime, endTime in {timestamp},
returns a long.</para>
</entry>
</row>
<row>
Modified: trunk/engine/src/main/java/com/metamatrix/query/function/FunctionLibrary.java
===================================================================
---
trunk/engine/src/main/java/com/metamatrix/query/function/FunctionLibrary.java 2009-10-01
13:56:55 UTC (rev 1510)
+++
trunk/engine/src/main/java/com/metamatrix/query/function/FunctionLibrary.java 2009-10-01
14:46:23 UTC (rev 1511)
@@ -82,6 +82,11 @@
public static final String FROM_UNIXTIME = "from_unixtime"; //$NON-NLS-1$
public static final String TIMESTAMPADD = "timestampadd"; //$NON-NLS-1$
+ public static final String PARSETIME = "parsetime"; //$NON-NLS-1$
+ public static final String PARSEDATE = "parsedate"; //$NON-NLS-1$
+ public static final String FORMATTIME = "formattime"; //$NON-NLS-1$
+ public static final String FORMATDATE = "formatdate"; //$NON-NLS-1$
+
public static final String NULLIF = "nullif"; //$NON-NLS-1$
public static final String COALESCE = "coalesce"; //$NON-NLS-1$
Modified: trunk/engine/src/main/java/com/metamatrix/query/function/FunctionMethods.java
===================================================================
---
trunk/engine/src/main/java/com/metamatrix/query/function/FunctionMethods.java 2009-10-01
13:56:55 UTC (rev 1510)
+++
trunk/engine/src/main/java/com/metamatrix/query/function/FunctionMethods.java 2009-10-01
14:46:23 UTC (rev 1511)
@@ -479,23 +479,6 @@
return ts;
}
- public static Object timestampAdd(String intervalType, Integer count, java.sql.Date
timestamp) {
- Calendar cal = TimestampWithTimezone.getCalendar();
- // Note: if dates are different, for example, days are different, the times
- // are still different even they may have the same hours, minutes and seconds.
- cal.setTime(timestamp);
- addField(intervalType, count, cal);
- return TimestampWithTimezone.createDate(cal.getTime());
- }
-
- public static Object timestampAdd(String intervalType, Integer count, Time timestamp) {
- Calendar cal = TimestampWithTimezone.getCalendar();
- cal.setTime(timestamp);
- addField(intervalType, count, cal);
- return TimestampWithTimezone.createTime(cal.getTime());
- }
-
-
/** Helper method for timestampAdd method
* @param interval Integer
* @param count Integer
@@ -527,10 +510,6 @@
// ================== Function = timestampdiff =====================
- public static Object timestampDiff(String intervalType, Time timestamp1, Time
timestamp2) {
- return timestampDiff(intervalType, new Timestamp(timestamp1.getTime()), new
Timestamp(timestamp2.getTime()));
- }
-
/**
* This method truncates (ignores) figures
* @param interval
@@ -1055,16 +1034,6 @@
}
}
- public static Date parseDate(String date, String format)
- throws FunctionExecutionException {
- return TimestampWithTimezone.createDate(parseDateHelper(date, format));
- }
-
- public static Time parseTime(String time, String format)
- throws FunctionExecutionException {
- return TimestampWithTimezone.createTime(parseDateHelper(time, format));
- }
-
public static Timestamp parseTimestamp(String timestamp, String format)
throws FunctionExecutionException {
return new Timestamp(parseDateHelper(timestamp, format).getTime());
Modified:
trunk/engine/src/main/java/com/metamatrix/query/function/source/SystemSource.java
===================================================================
---
trunk/engine/src/main/java/com/metamatrix/query/function/source/SystemSource.java 2009-10-01
13:56:55 UTC (rev 1510)
+++
trunk/engine/src/main/java/com/metamatrix/query/function/source/SystemSource.java 2009-10-01
14:46:23 UTC (rev 1511)
@@ -160,17 +160,11 @@
addIfNullFunctions();
// format
- addFormatTimeFunction(SourceSystemFunctions.FORMATTIME,
QueryPlugin.Util.getString("SystemSource.Formattime_desc"), "format",
QueryPlugin.Util.getString("SystemSource.Formattime_result_desc"));
//$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- addFormatDateFunction(SourceSystemFunctions.FORMATDATE,
QueryPlugin.Util.getString("SystemSource.Formatdate_desc"), "format",
QueryPlugin.Util.getString("SystemSource.Formatdate_result_desc"));
//$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- addFormatTimestampFunction(SourceSystemFunctions.FORMATTIMESTAMP,
QueryPlugin.Util.getString("SystemSource.Formattimestamp_desc"),
"format",
QueryPlugin.Util.getString("SystemSource.Formattimestamp_result_desc"));
//$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
-
+ addFormatTimestampFunction();
addFormatNumberFunctions();
// parse
- addParseTimeFunction(SourceSystemFunctions.PARSETIME,
QueryPlugin.Util.getString("SystemSource.Parsetime_desc"),
"parseTime",
QueryPlugin.Util.getString("SystemSource.Parsetime_result_desc")); //$NON-NLS-1$
//$NON-NLS-2$ //$NON-NLS-3$
- addParseDateFunction(SourceSystemFunctions.PARSEDATE,
QueryPlugin.Util.getString("SystemSource.Parsedate_desc"),
"parseDate",
QueryPlugin.Util.getString("SystemSource.Parsedate_result_desc")); //$NON-NLS-1$
//$NON-NLS-2$ //$NON-NLS-3$
- addParseTimestampFunction(SourceSystemFunctions.PARSETIMESTAMP,
QueryPlugin.Util.getString("SystemSource.Parsetimestamp_desc"),
"parseTimestamp",
QueryPlugin.Util.getString("SystemSource.Parsetimestamp_result_desc"));
//$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
-
+ addParseTimestampFunction();
addParseNumberFunctions();
// xml functions
@@ -396,14 +390,14 @@
private void addTimestampAddFunction() {
functions.add(
- new FunctionMethod(SourceSystemFunctions.TIMESTAMPADD,
QueryPlugin.Util.getString("SystemSource.Timestampadd_d_desc"), DATETIME,
FUNCTION_CLASS, "timestampAdd", //$NON-NLS-1$ //$NON-NLS-2$
+ new FunctionMethod(SourceSystemFunctions.TIMESTAMPADD,
QueryPlugin.Util.getString("SystemSource.Timestampadd_d_desc"), DATETIME,
FunctionMethod.SYNTHETIC, null, null, //$NON-NLS-1$
new FunctionParameter[] {
new FunctionParameter("interval", DataTypeManager.DefaultDataTypes.STRING,
QueryPlugin.Util.getString("SystemSource.Timestampadd_d_arg1")), //$NON-NLS-1$
//$NON-NLS-2$
new FunctionParameter("count", DataTypeManager.DefaultDataTypes.INTEGER,
QueryPlugin.Util.getString("SystemSource.Timestampadd_d_arg2")), //$NON-NLS-1$
//$NON-NLS-2$
new FunctionParameter("timestamp", DataTypeManager.DefaultDataTypes.DATE,
QueryPlugin.Util.getString("SystemSource.Timestampadd_d_arg3"))}, //$NON-NLS-1$
//$NON-NLS-2$
new FunctionParameter("result", DataTypeManager.DefaultDataTypes.DATE,
QueryPlugin.Util.getString("SystemSource.Timestampadd_d_result_desc")) ) );
//$NON-NLS-1$ //$NON-NLS-2$
functions.add(
- new FunctionMethod(SourceSystemFunctions.TIMESTAMPADD,
QueryPlugin.Util.getString("SystemSource.Timestampadd_t_desc"), DATETIME,
FUNCTION_CLASS, "timestampAdd", //$NON-NLS-1$ //$NON-NLS-2$
+ new FunctionMethod(SourceSystemFunctions.TIMESTAMPADD,
QueryPlugin.Util.getString("SystemSource.Timestampadd_t_desc"), DATETIME,
FunctionMethod.SYNTHETIC, null, null, //$NON-NLS-1$
new FunctionParameter[] {
new FunctionParameter("interval", DataTypeManager.DefaultDataTypes.STRING,
QueryPlugin.Util.getString("SystemSource.Timestampadd_t_arg1")), //$NON-NLS-1$
//$NON-NLS-2$
new FunctionParameter("count", DataTypeManager.DefaultDataTypes.INTEGER,
QueryPlugin.Util.getString("SystemSource.Timestampadd_t_arg2")), //$NON-NLS-1$
//$NON-NLS-2$
@@ -420,13 +414,6 @@
private void addTimestampDiffFunction() {
functions.add(
- new FunctionMethod(SourceSystemFunctions.TIMESTAMPDIFF,
QueryPlugin.Util.getString("SystemSource.Timestampdiff_t_desc"), DATETIME,
FUNCTION_CLASS, "timestampDiff", //$NON-NLS-1$ //$NON-NLS-2$
- new FunctionParameter[] {
- new FunctionParameter("interval",
DataTypeManager.DefaultDataTypes.STRING,
QueryPlugin.Util.getString("SystemSource.Timestampdiff_t_arg1")), //$NON-NLS-1$
//$NON-NLS-2$
- new FunctionParameter("time1",
DataTypeManager.DefaultDataTypes.TIME,
QueryPlugin.Util.getString("SystemSource.Timestampdiff_t_arg2")), //$NON-NLS-1$
//$NON-NLS-2$
- new FunctionParameter("time2",
DataTypeManager.DefaultDataTypes.TIME,
QueryPlugin.Util.getString("SystemSource.Timestampdiff_t_arg3"))}, //$NON-NLS-1$
//$NON-NLS-2$
- new FunctionParameter("result",
DataTypeManager.DefaultDataTypes.LONG,
QueryPlugin.Util.getString("SystemSource.Timestampdiff_t_result_desc")) ) );
//$NON-NLS-1$ //$NON-NLS-2$
- functions.add(
new FunctionMethod(SourceSystemFunctions.TIMESTAMPDIFF,
QueryPlugin.Util.getString("SystemSource.Timestampdiff_ts_desc"), DATETIME,
FUNCTION_CLASS, "timestampDiff", //$NON-NLS-1$ //$NON-NLS-2$
new FunctionParameter[] {
new FunctionParameter("interval",
DataTypeManager.DefaultDataTypes.STRING,
QueryPlugin.Util.getString("SystemSource.Timestampdiff_ts_arg1")),
//$NON-NLS-1$ //$NON-NLS-2$
@@ -805,59 +792,47 @@
nvl.setNullDependent(true);
functions.add(nvl);
}
-
- private void addFormatTimeFunction(String functionName, String description, String
methodName, String resultDesc) {
+
+ private void addFormatTimestampFunction() {
functions.add(
- new FunctionMethod(functionName, description,CONVERSION, FUNCTION_CLASS, methodName,
+ new FunctionMethod(SourceSystemFunctions.FORMATTIMESTAMP,
QueryPlugin.Util.getString("SystemSource.Formattimestamp_desc"),CONVERSION,
FUNCTION_CLASS, "format", //$NON-NLS-1$ //$NON-NLS-2$
new FunctionParameter[] {
- new FunctionParameter("time", DataTypeManager.DefaultDataTypes.TIME,
QueryPlugin.Util.getString("SystemSource.Formattime_arg1")), //$NON-NLS-1$
//$NON-NLS-2$
- new FunctionParameter("format", DataTypeManager.DefaultDataTypes.STRING,
QueryPlugin.Util.getString("SystemSource.Formattime_arg2")) }, //$NON-NLS-1$
//$NON-NLS-2$
- new FunctionParameter("result", DataTypeManager.DefaultDataTypes.STRING,
resultDesc) ) ); //$NON-NLS-1$
- }
-
- private void addFormatDateFunction(String functionName, String description, String
methodName, String resultDesc) {
- functions.add(
- new FunctionMethod(functionName, description,CONVERSION, FUNCTION_CLASS, methodName,
- new FunctionParameter[] {
- new FunctionParameter("date", DataTypeManager.DefaultDataTypes.DATE,
QueryPlugin.Util.getString("SystemSource.Formatdate_arg1")), //$NON-NLS-1$
//$NON-NLS-2$
- new FunctionParameter("format", DataTypeManager.DefaultDataTypes.STRING,
QueryPlugin.Util.getString("SystemSource.Formatdate_arg2")) }, //$NON-NLS-1$
//$NON-NLS-2$
- new FunctionParameter("result", DataTypeManager.DefaultDataTypes.STRING,
resultDesc) ) ); //$NON-NLS-1$
- }
-
- private void addFormatTimestampFunction(String functionName, String description, String
methodName, String resultDesc) {
- functions.add(
- new FunctionMethod(functionName, description,CONVERSION, FUNCTION_CLASS, methodName,
- new FunctionParameter[] {
new FunctionParameter("timestamp",
DataTypeManager.DefaultDataTypes.TIMESTAMP,
QueryPlugin.Util.getString("SystemSource.Formattimestamp_arg1")), //$NON-NLS-1$
//$NON-NLS-2$
new FunctionParameter("format", DataTypeManager.DefaultDataTypes.STRING,
QueryPlugin.Util.getString("SystemSource.Formattimestamp_arg2")) },
//$NON-NLS-1$ //$NON-NLS-2$
- new FunctionParameter("result", DataTypeManager.DefaultDataTypes.STRING,
resultDesc) ) ); //$NON-NLS-1$
- }
-
- private void addParseTimeFunction(String functionName, String description, String
methodName, String resultDesc) {
+ new FunctionParameter("result", DataTypeManager.DefaultDataTypes.STRING,
QueryPlugin.Util.getString("SystemSource.Formattimestamp_result_desc")) ) );
//$NON-NLS-1$ //$NON-NLS-2$
functions.add(
- new FunctionMethod(functionName, description,CONVERSION, FUNCTION_CLASS, methodName,
- new FunctionParameter[] {
- new FunctionParameter("time", DataTypeManager.DefaultDataTypes.STRING,
QueryPlugin.Util.getString("SystemSource.Parsetime_arg1")), //$NON-NLS-1$
//$NON-NLS-2$
- new FunctionParameter("format", DataTypeManager.DefaultDataTypes.STRING,
QueryPlugin.Util.getString("SystemSource.Parsetime_arg2")) }, //$NON-NLS-1$
//$NON-NLS-2$
- new FunctionParameter("result", DataTypeManager.DefaultDataTypes.TIME,
resultDesc) ) ); //$NON-NLS-1$
- }
-
- private void addParseDateFunction(String functionName, String description, String
methodName, String resultDesc) {
+ new FunctionMethod(SourceSystemFunctions.FORMATDATE,
QueryPlugin.Util.getString("SystemSource.Formatdate_desc"),CONVERSION,
FunctionMethod.SYNTHETIC, null, null, //$NON-NLS-1$
+ new FunctionParameter[] {
+ new FunctionParameter("date", DataTypeManager.DefaultDataTypes.DATE,
QueryPlugin.Util.getString("SystemSource.Formatdate_arg1")), //$NON-NLS-1$
//$NON-NLS-2$
+ new FunctionParameter("format", DataTypeManager.DefaultDataTypes.STRING,
QueryPlugin.Util.getString("SystemSource.Formatdate_arg2")) }, //$NON-NLS-1$
//$NON-NLS-2$
+ new FunctionParameter("result", DataTypeManager.DefaultDataTypes.STRING,
QueryPlugin.Util.getString("SystemSource.Formatdate_result_desc")) ) );
//$NON-NLS-1$ //$NON-NLS-2$
functions.add(
- new FunctionMethod(functionName, description,CONVERSION, FUNCTION_CLASS, methodName,
- new FunctionParameter[] {
- new FunctionParameter("date", DataTypeManager.DefaultDataTypes.STRING,
QueryPlugin.Util.getString("SystemSource.Parsedate_arg1")), //$NON-NLS-1$
//$NON-NLS-2$
- new FunctionParameter("format", DataTypeManager.DefaultDataTypes.STRING,
QueryPlugin.Util.getString("SystemSource.Parsedate_arg2")) }, //$NON-NLS-1$
//$NON-NLS-2$
- new FunctionParameter("result", DataTypeManager.DefaultDataTypes.DATE,
resultDesc) ) ); //$NON-NLS-1$
+ new FunctionMethod(SourceSystemFunctions.FORMATTIME,
QueryPlugin.Util.getString("SystemSource.Formattime_desc"),CONVERSION,
FunctionMethod.SYNTHETIC, null, null, //$NON-NLS-1$
+ new FunctionParameter[] {
+ new FunctionParameter("time", DataTypeManager.DefaultDataTypes.TIME,
QueryPlugin.Util.getString("SystemSource.Formattime_arg1")), //$NON-NLS-1$
//$NON-NLS-2$
+ new FunctionParameter("format", DataTypeManager.DefaultDataTypes.STRING,
QueryPlugin.Util.getString("SystemSource.Formattime_arg2")) }, //$NON-NLS-1$
//$NON-NLS-2$
+ new FunctionParameter("result", DataTypeManager.DefaultDataTypes.STRING,
QueryPlugin.Util.getString("SystemSource.Formattime_result_desc")) ) );
//$NON-NLS-1$ //$NON-NLS-2$
}
-
- private void addParseTimestampFunction(String functionName, String description, String
methodName, String resultDesc) {
+
+ private void addParseTimestampFunction() {
functions.add(
- new FunctionMethod(functionName, description,CONVERSION, FUNCTION_CLASS, methodName,
+ new FunctionMethod(SourceSystemFunctions.PARSETIMESTAMP,
QueryPlugin.Util.getString("SystemSource.Parsetimestamp_desc"),CONVERSION,
FUNCTION_CLASS, "parseTimestamp", //$NON-NLS-1$ //$NON-NLS-2$
new FunctionParameter[] {
new FunctionParameter("timestamp",
DataTypeManager.DefaultDataTypes.STRING,
QueryPlugin.Util.getString("SystemSource.Parsetimestamp_arg1")), //$NON-NLS-1$
//$NON-NLS-2$
new FunctionParameter("format", DataTypeManager.DefaultDataTypes.STRING,
QueryPlugin.Util.getString("SystemSource.Parsetimestamp_arg2")) }, //$NON-NLS-1$
//$NON-NLS-2$
- new FunctionParameter("result", DataTypeManager.DefaultDataTypes.TIMESTAMP,
resultDesc) ) ); //$NON-NLS-1$
+ new FunctionParameter("result", DataTypeManager.DefaultDataTypes.TIMESTAMP,
QueryPlugin.Util.getString("SystemSource.Parsetimestamp_result_desc")) ) );
//$NON-NLS-1$ //$NON-NLS-2$
+ functions.add(
+ new FunctionMethod(SourceSystemFunctions.PARSETIME,
QueryPlugin.Util.getString("SystemSource.Parsetime_desc"),CONVERSION,
FunctionMethod.SYNTHETIC, null, null, //$NON-NLS-1$
+ new FunctionParameter[] {
+ new FunctionParameter("time", DataTypeManager.DefaultDataTypes.STRING,
QueryPlugin.Util.getString("SystemSource.Parsetime_arg1")), //$NON-NLS-1$
//$NON-NLS-2$
+ new FunctionParameter("format", DataTypeManager.DefaultDataTypes.STRING,
QueryPlugin.Util.getString("SystemSource.Parsetime_arg2")) }, //$NON-NLS-1$
//$NON-NLS-2$
+ new FunctionParameter("result", DataTypeManager.DefaultDataTypes.TIME,
QueryPlugin.Util.getString("SystemSource.Parsetime_result_desc")) ) );
//$NON-NLS-1$ //$NON-NLS-2$
+ functions.add(
+ new FunctionMethod(SourceSystemFunctions.PARSEDATE,
QueryPlugin.Util.getString("SystemSource.Parsedate_desc"),CONVERSION,
FunctionMethod.SYNTHETIC, null, null, //$NON-NLS-1$
+ new FunctionParameter[] {
+ new FunctionParameter("date", DataTypeManager.DefaultDataTypes.STRING,
QueryPlugin.Util.getString("SystemSource.Parsedate_arg1")), //$NON-NLS-1$
//$NON-NLS-2$
+ new FunctionParameter("format", DataTypeManager.DefaultDataTypes.STRING,
QueryPlugin.Util.getString("SystemSource.Parsedate_arg2")) }, //$NON-NLS-1$
//$NON-NLS-2$
+ new FunctionParameter("result", DataTypeManager.DefaultDataTypes.DATE,
QueryPlugin.Util.getString("SystemSource.Parsedate_result_desc")) ) );
//$NON-NLS-1$ //$NON-NLS-2$
}
private void addFormatNumberFunction(String functionName, String description, String
methodName, String inputParam, String dataType, String resultDesc) {
Modified: trunk/engine/src/main/java/com/metamatrix/query/resolver/util/ResolverUtil.java
===================================================================
---
trunk/engine/src/main/java/com/metamatrix/query/resolver/util/ResolverUtil.java 2009-10-01
13:56:55 UTC (rev 1510)
+++
trunk/engine/src/main/java/com/metamatrix/query/resolver/util/ResolverUtil.java 2009-10-01
14:46:23 UTC (rev 1511)
@@ -205,7 +205,7 @@
if(canImplicitlyConvert(sourceTypeName, targetTypeName)
|| (sourceExpression instanceof Constant &&
convertConstant(sourceTypeName, targetTypeName, (Constant)sourceExpression) != null)) {
- return getConversion(sourceExpression, sourceTypeName, targetTypeName);
+ return getConversion(sourceExpression, sourceTypeName, targetTypeName,
true);
}
//Expression is wrong type and can't convert
@@ -250,9 +250,10 @@
return null;
}
- private static Expression getConversion(Expression sourceExpression,
+ public static Function getConversion(Expression sourceExpression,
String sourceTypeName,
- String targetTypeName) {
+ String targetTypeName,
+ boolean implicit) {
Class<?> srcType = DataTypeManager.getDataTypeClass(sourceTypeName);
FunctionLibrary library = FunctionLibraryManager.getFunctionLibrary();
@@ -261,7 +262,9 @@
Function conversion = new Function(fd.getName(), new Expression[] {
sourceExpression, new Constant(targetTypeName) });
conversion.setType(DataTypeManager.getDataTypeClass(targetTypeName));
conversion.setFunctionDescriptor(fd);
- conversion.makeImplicit();
+ if (implicit) {
+ conversion.makeImplicit();
+ }
return conversion;
}
Modified: trunk/engine/src/main/java/com/metamatrix/query/rewriter/QueryRewriter.java
===================================================================
--- trunk/engine/src/main/java/com/metamatrix/query/rewriter/QueryRewriter.java 2009-10-01
13:56:55 UTC (rev 1510)
+++ trunk/engine/src/main/java/com/metamatrix/query/rewriter/QueryRewriter.java 2009-10-01
14:46:23 UTC (rev 1511)
@@ -2014,92 +2014,140 @@
}
return expression;
}
-
+
+ private static Map<String, Integer> FUNCTION_MAP = new HashMap<String,
Integer>();
+
+ static {
+ FUNCTION_MAP.put(FunctionLibrary.SPACE.toLowerCase(), 0);
+ FUNCTION_MAP.put(FunctionLibrary.FROM_UNIXTIME.toLowerCase(), 1);
+ FUNCTION_MAP.put(FunctionLibrary.NULLIF.toLowerCase(), 2);
+ FUNCTION_MAP.put(FunctionLibrary.COALESCE.toLowerCase(), 3);
+ FUNCTION_MAP.put(FunctionLibrary.CONCAT2.toLowerCase(), 4);
+ FUNCTION_MAP.put(FunctionLibrary.TIMESTAMPADD.toLowerCase(), 5);
+ FUNCTION_MAP.put(FunctionLibrary.PARSEDATE.toLowerCase(), 6);
+ FUNCTION_MAP.put(FunctionLibrary.PARSETIME.toLowerCase(), 7);
+ FUNCTION_MAP.put(FunctionLibrary.FORMATDATE.toLowerCase(), 8);
+ FUNCTION_MAP.put(FunctionLibrary.FORMATTIME.toLowerCase(), 9);
+ }
+
private Expression rewriteFunction(Function function) throws QueryValidatorException {
//rewrite alias functions
- String actualName =ALIASED_FUNCTIONS.get(function.getName().toLowerCase());
+ String functionLowerName = function.getName().toLowerCase();
+ String actualName =ALIASED_FUNCTIONS.get(functionLowerName);
if (actualName != null) {
function.setName(actualName);
}
- //space(x) => repeat(' ', x)
- if (function.getName().equalsIgnoreCase(FunctionLibrary.SPACE)) {
- Function result = new Function(SourceSystemFunctions.REPEAT,
- new Expression[] {new Constant(" "), function.getArg(0)}); //$NON-NLS-1$
- //resolve the function
- FunctionDescriptor descriptor =
-
FunctionLibraryManager.getFunctionLibrary().findFunction(SourceSystemFunctions.REPEAT,
new Class[] { DataTypeManager.DefaultDataClasses.STRING,
DataTypeManager.DefaultDataClasses.INTEGER});
- result.setFunctionDescriptor(descriptor);
- result.setType(DataTypeManager.DefaultDataClasses.STRING);
- return rewriteFunction(result);
- }
-
- //from_unixtime(a) => timestampadd(SQL_TSI_SECOND, a, new Timestamp(0))
- if (function.getName().equalsIgnoreCase(FunctionLibrary.FROM_UNIXTIME)) {
- Function result = new Function(FunctionLibrary.TIMESTAMPADD,
- new Expression[] {new Constant(ReservedWords.SQL_TSI_SECOND), function.getArg(0),
new Constant(new Timestamp(0)) });
- //resolve the function
- FunctionDescriptor descriptor =
-
FunctionLibraryManager.getFunctionLibrary().findFunction(FunctionLibrary.TIMESTAMPADD,
new Class[] { DataTypeManager.DefaultDataClasses.STRING,
DataTypeManager.DefaultDataClasses.INTEGER, DataTypeManager.DefaultDataClasses.TIMESTAMP
});
- result.setFunctionDescriptor(descriptor);
- result.setType(DataTypeManager.DefaultDataClasses.TIMESTAMP);
- return rewriteFunction(result);
- }
-
- //rewrite nullif(a, b) => case when (a = b) then null else a
- if (function.getName().equalsIgnoreCase(FunctionLibrary.NULLIF)) {
- List when = Arrays.asList(new Criteria[] {new CompareCriteria(function.getArg(0),
CompareCriteria.EQ, function.getArg(1))});
- Constant nullConstant = new Constant(null, function.getType());
- List then = Arrays.asList(new Expression[] {nullConstant});
- SearchedCaseExpression caseExpr = new SearchedCaseExpression(when, then);
- caseExpr.setElseExpression(function.getArg(0));
- caseExpr.setType(function.getType());
- return rewriteExpressionDirect(caseExpr);
- }
-
- if (function.getName().equalsIgnoreCase(FunctionLibrary.COALESCE)) {
- Expression[] args = function.getArgs();
- if (args.length == 2) {
- Function result = new Function(SourceSystemFunctions.IFNULL,
- new Expression[] {function.getArg(0), function.getArg(1) });
+ Integer code = FUNCTION_MAP.get(functionLowerName);
+ if (code != null) {
+ switch (code) {
+ case 0: { //space(x) => repeat(' ', x)
+ Function result = new Function(SourceSystemFunctions.REPEAT,
+ new Expression[] {new Constant(" "), function.getArg(0)}); //$NON-NLS-1$
//resolve the function
FunctionDescriptor descriptor =
-
FunctionLibraryManager.getFunctionLibrary().findFunction(SourceSystemFunctions.IFNULL,
new Class[] { function.getType(), function.getType() });
+
FunctionLibraryManager.getFunctionLibrary().findFunction(SourceSystemFunctions.REPEAT,
new Class[] { DataTypeManager.DefaultDataClasses.STRING,
DataTypeManager.DefaultDataClasses.INTEGER});
result.setFunctionDescriptor(descriptor);
- result.setType(function.getType());
- return rewriteFunction(result);
+ result.setType(DataTypeManager.DefaultDataClasses.STRING);
+ function = result;
+ break;
}
- }
-
- //rewrite concat2 - CONCAT2(a, b) ==> CASE WHEN (a is NULL AND b is NULL) THEN NULL
ELSE CONCAT( NVL(a, ''), NVL(b, '') )
- if (function.getName().equalsIgnoreCase(FunctionLibrary.CONCAT2)) {
- Expression[] args = function.getArgs();
- Function[] newArgs = new Function[args.length];
+ case 1: {//from_unixtime(a) => timestampadd(SQL_TSI_SECOND, a, new Timestamp(0))
+ Function result = new Function(FunctionLibrary.TIMESTAMPADD,
+ new Expression[] {new Constant(ReservedWords.SQL_TSI_SECOND), function.getArg(0),
new Constant(new Timestamp(0)) });
+ //resolve the function
+ FunctionDescriptor descriptor =
+
FunctionLibraryManager.getFunctionLibrary().findFunction(FunctionLibrary.TIMESTAMPADD,
new Class[] { DataTypeManager.DefaultDataClasses.STRING,
DataTypeManager.DefaultDataClasses.INTEGER, DataTypeManager.DefaultDataClasses.TIMESTAMP
});
+ result.setFunctionDescriptor(descriptor);
+ result.setType(DataTypeManager.DefaultDataClasses.TIMESTAMP);
+ function = result;
+ break;
+ }
+ case 2: { //rewrite nullif(a, b) => case when (a = b) then null else a
+ List when = Arrays.asList(new Criteria[] {new CompareCriteria(function.getArg(0),
CompareCriteria.EQ, function.getArg(1))});
+ Constant nullConstant = new Constant(null, function.getType());
+ List then = Arrays.asList(new Expression[] {nullConstant});
+ SearchedCaseExpression caseExpr = new SearchedCaseExpression(when, then);
+ caseExpr.setElseExpression(function.getArg(0));
+ caseExpr.setType(function.getType());
+ return rewriteExpressionDirect(caseExpr);
+ }
+ case 3: {
+ Expression[] args = function.getArgs();
+ if (args.length == 2) {
+ Function result = new Function(SourceSystemFunctions.IFNULL,
+ new Expression[] {function.getArg(0), function.getArg(1) });
+ //resolve the function
+ FunctionDescriptor descriptor =
+
FunctionLibraryManager.getFunctionLibrary().findFunction(SourceSystemFunctions.IFNULL,
new Class[] { function.getType(), function.getType() });
+ result.setFunctionDescriptor(descriptor);
+ result.setType(function.getType());
+ function = result;
+ }
+ break;
+ }
+ case 4: { //rewrite concat2 - CONCAT2(a, b) ==> CASE WHEN (a is NULL AND b is NULL)
THEN NULL ELSE CONCAT( NVL(a, ''), NVL(b, '') )
+ Expression[] args = function.getArgs();
+ Function[] newArgs = new Function[args.length];
- for(int i=0; i<args.length; i++) {
- newArgs[i] = new Function(SourceSystemFunctions.IFNULL, new Expression[] {args[i],
new Constant("")}); //$NON-NLS-1$
- newArgs[i].setType(args[i].getType());
- Assertion.assertTrue(args[i].getType() ==
DataTypeManager.DefaultDataClasses.STRING);
- FunctionDescriptor descriptor =
-
FunctionLibraryManager.getFunctionLibrary().findFunction(SourceSystemFunctions.IFNULL,
new Class[] { args[i].getType(), DataTypeManager.DefaultDataClasses.STRING });
- newArgs[i].setFunctionDescriptor(descriptor);
+ for(int i=0; i<args.length; i++) {
+ newArgs[i] = new Function(SourceSystemFunctions.IFNULL, new Expression[] {args[i],
new Constant("")}); //$NON-NLS-1$
+ newArgs[i].setType(args[i].getType());
+ Assertion.assertTrue(args[i].getType() ==
DataTypeManager.DefaultDataClasses.STRING);
+ FunctionDescriptor descriptor =
+
FunctionLibraryManager.getFunctionLibrary().findFunction(SourceSystemFunctions.IFNULL,
new Class[] { args[i].getType(), DataTypeManager.DefaultDataClasses.STRING });
+ newArgs[i].setFunctionDescriptor(descriptor);
+ }
+
+ Function concat = new Function(SourceSystemFunctions.CONCAT, newArgs);
+ concat.setType(DataTypeManager.DefaultDataClasses.STRING);
+ FunctionDescriptor descriptor =
+
FunctionLibraryManager.getFunctionLibrary().findFunction(SourceSystemFunctions.CONCAT,
new Class[] { DataTypeManager.DefaultDataClasses.STRING,
DataTypeManager.DefaultDataClasses.STRING });
+ concat.setFunctionDescriptor(descriptor);
+
+ List when = Arrays.asList(new Criteria[] {new CompoundCriteria(CompoundCriteria.AND,
new IsNullCriteria(args[0]), new IsNullCriteria(args[1]))});
+ Constant nullConstant = new Constant(null,
DataTypeManager.DefaultDataClasses.STRING);
+ List then = Arrays.asList(new Expression[] {nullConstant});
+ SearchedCaseExpression caseExpr = new SearchedCaseExpression(when, then);
+ caseExpr.setElseExpression(concat);
+ caseExpr.setType(DataTypeManager.DefaultDataClasses.STRING);
+ return rewriteExpressionDirect(caseExpr);
}
-
- Function concat = new Function(SourceSystemFunctions.CONCAT, newArgs);
- concat.setType(DataTypeManager.DefaultDataClasses.STRING);
- FunctionDescriptor descriptor =
-
FunctionLibraryManager.getFunctionLibrary().findFunction(SourceSystemFunctions.CONCAT,
new Class[] { DataTypeManager.DefaultDataClasses.STRING,
DataTypeManager.DefaultDataClasses.STRING });
- concat.setFunctionDescriptor(descriptor);
-
- List when = Arrays.asList(new Criteria[] {new CompoundCriteria(CompoundCriteria.AND,
new IsNullCriteria(args[0]), new IsNullCriteria(args[1]))});
- Constant nullConstant = new Constant(null,
DataTypeManager.DefaultDataClasses.STRING);
- List then = Arrays.asList(new Expression[] {nullConstant});
- SearchedCaseExpression caseExpr = new SearchedCaseExpression(when, then);
- caseExpr.setElseExpression(concat);
- caseExpr.setType(DataTypeManager.DefaultDataClasses.STRING);
- return rewriteExpressionDirect(caseExpr);
+ case 5: {
+ if (function.getType() != DataTypeManager.DefaultDataClasses.TIMESTAMP) {
+ FunctionDescriptor descriptor =
+
FunctionLibraryManager.getFunctionLibrary().findFunction(SourceSystemFunctions.TIMESTAMPADD,
new Class[] { DataTypeManager.DefaultDataClasses.STRING,
DataTypeManager.DefaultDataClasses.INTEGER, DataTypeManager.DefaultDataClasses.TIMESTAMP
});
+ function.setFunctionDescriptor(descriptor);
+ Class<?> type = function.getType();
+ function.setType(DataTypeManager.DefaultDataClasses.TIMESTAMP);
+ function.getArgs()[2] = ResolverUtil.getConversion(function.getArg(2),
DataTypeManager.getDataTypeName(type), DataTypeManager.DefaultDataTypes.TIMESTAMP,
false);
+ function = ResolverUtil.getConversion(function,
DataTypeManager.DefaultDataTypes.TIMESTAMP, DataTypeManager.getDataTypeName(type),
false);
+ }
+ break;
+ }
+ case 6:
+ case 7: {
+ FunctionDescriptor descriptor =
+
FunctionLibraryManager.getFunctionLibrary().findFunction(SourceSystemFunctions.PARSETIMESTAMP,
new Class[] { DataTypeManager.DefaultDataClasses.STRING,
DataTypeManager.DefaultDataClasses.STRING });
+ function.setName(SourceSystemFunctions.PARSETIMESTAMP);
+ function.setFunctionDescriptor(descriptor);
+ Class<?> type = function.getType();
+ function.setType(DataTypeManager.DefaultDataClasses.TIMESTAMP);
+ function = ResolverUtil.getConversion(function,
DataTypeManager.DefaultDataTypes.TIMESTAMP, DataTypeManager.getDataTypeName(type),
false);
+ break;
+ }
+ case 8:
+ case 9: {
+ FunctionDescriptor descriptor =
+
FunctionLibraryManager.getFunctionLibrary().findFunction(SourceSystemFunctions.FORMATTIMESTAMP,
new Class[] { DataTypeManager.DefaultDataClasses.TIMESTAMP,
DataTypeManager.DefaultDataClasses.STRING });
+ function.setName(SourceSystemFunctions.FORMATTIMESTAMP);
+ function.setFunctionDescriptor(descriptor);
+ function.getArgs()[0] = ResolverUtil.getConversion(function.getArg(0),
DataTypeManager.getDataTypeName(function.getArg(0).getType()),
DataTypeManager.DefaultDataTypes.TIMESTAMP, false);
+ break;
+ }
+ }
}
-
+
Expression[] args = function.getArgs();
Expression[] newArgs = new Expression[args.length];
Modified: trunk/engine/src/test/java/com/metamatrix/query/function/TestFunction.java
===================================================================
--- trunk/engine/src/test/java/com/metamatrix/query/function/TestFunction.java 2009-10-01
13:56:55 UTC (rev 1510)
+++ trunk/engine/src/test/java/com/metamatrix/query/function/TestFunction.java 2009-10-01
14:46:23 UTC (rev 1511)
@@ -188,18 +188,6 @@
expected2, actual2);
}
- public static void helpTestTimestampDiff(String intervalType, Time timeStamp1, Time
timeStamp2, Long expected) {
- Object actual = FunctionMethods.timestampDiff(intervalType, timeStamp1,
timeStamp2);
- assertEquals("timestampDiff(" + intervalType + ", " +
timeStamp1 + ", " + timeStamp2 + ") failed", //$NON-NLS-1$
//$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
- expected, actual);
-
- // test reverse - should be
- Long expected2 = new Long(0 - expected.longValue());
- Object actual2 = FunctionMethods.timestampDiff(intervalType, timeStamp2,
timeStamp1);
- assertEquals("timestampDiff(" + intervalType + ", " +
timeStamp2 + ", " + timeStamp1 + ") failed", //$NON-NLS-1$
//$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
- expected2, actual2);
- }
-
public static void helpTestParseTimestamp(String tsStr, String format, String
expected) throws FunctionExecutionException {
Object actual = FunctionMethods.parseTimestamp(tsStr, format);
assertEquals("parseTimestamp(" + tsStr + ", " + format +
") failed", expected.toString(), //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
@@ -856,18 +844,10 @@
helpTestTimestampCreate(TimestampUtil.createDate(103, 11, 1),
TimestampUtil.createTime(23, 59, 59), "2003-12-01 23:59:59.0"); //$NON-NLS-1$
}
- @Test public void testTimestampAdd1() throws Exception {
- assertEquals(TimestampUtil.createDate(103, 11, 4),
FunctionMethods.timestampAdd(ReservedWords.SQL_TSI_DAY, 3, TimestampUtil.createDate(103,
11, 1)));
- }
-
@Test public void testTimestampAdd2() throws Exception {
assertEquals(TimestampUtil.createTimestamp(103, 11, 1, 18, 20, 30, 0),
FunctionMethods.timestampAdd(ReservedWords.SQL_TSI_HOUR, 3,
TimestampUtil.createTimestamp(103, 11, 1, 15, 20, 30, 0)));
}
- @Test public void testTimestampAdd3() throws Exception {
- assertEquals(TimestampUtil.createTime(11, 50, 30),
FunctionMethods.timestampAdd(ReservedWords.SQL_TSI_MINUTE, 90,
TimestampUtil.createTime(10, 20, 30)));
- }
-
@Test public void testTimestampDiffTimeStamp_FracSec_1() throws Exception {
helpTestTimestampDiff(ReservedWords.SQL_TSI_FRAC_SECOND,
TimestampUtil.createTimestamp((2001-1900), 5, 21, 3, 9, 35,
1),
@@ -1034,19 +1014,17 @@
new Long(29));
}
- @Test public void testTimestampDiffTime_Hour_1() throws Exception {
- helpTestTimestampDiff(ReservedWords.SQL_TSI_HOUR,
- TimestampUtil.createTime(3, 4, 45),
- TimestampUtil.createTime(5, 5, 36),
- new Long(2));
- }
+ @Test public void testTimestampDiffTime_Hour_1() throws Exception {
+ helpTestTimestampDiff(ReservedWords.SQL_TSI_HOUR, new Timestamp(
+ TimestampUtil.createTime(3, 4, 45).getTime()), new Timestamp(
+ TimestampUtil.createTime(5, 5, 36).getTime()), new Long(2));
+ }
- @Test public void testTimestampDiffTime_Hour_2() throws Exception {
- helpTestTimestampDiff(ReservedWords.SQL_TSI_HOUR,
- TimestampUtil.createTime(5, 0, 30),
- TimestampUtil.createTime(3, 0, 31),
- new Long(-1));
- }
+ @Test public void testTimestampDiffTime_Hour_2() throws Exception {
+ helpTestTimestampDiff(ReservedWords.SQL_TSI_HOUR, new Timestamp(
+ TimestampUtil.createTime(5, 0, 30).getTime()), new Timestamp(
+ TimestampUtil.createTime(3, 0, 31).getTime()), new Long(-1));
+ }
@Test public void testParseTimestamp1() throws Exception {
helpTestParseTimestamp("1993-04-24 3:59:59 PM", "yyyy-MM-dd
hh:mm:ss aa", "{ts'1993-04-24 15:59:59.0'}"); //$NON-NLS-1$
//$NON-NLS-2$ //$NON-NLS-3$
@@ -1158,16 +1136,16 @@
assertEquals(systemProperty+"_lowercase", FunctionMethods.env(context,
systemProperty.toUpperCase())); //$NON-NLS-1$
}
- public void testParseIntStrictness() throws Exception {
- assertEquals(Integer.valueOf(1), FunctionMethods.parseInteger("a 1 a",
"#")); //$NON-NLS-1$ //$NON-NLS-2$
+ @Test(expected=FunctionExecutionException.class) public void testParseIntStrictness()
throws Exception {
+ FunctionMethods.parseInteger("a 1 a", "#"); //$NON-NLS-1$
//$NON-NLS-2$
}
- public void testParseDateStrictness() throws Exception {
- assertEquals(TimestampUtil.createDate(2007, 1, 1), FunctionMethods.parseDate("
2007-13-01", "yyyy-MM")); //$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$
}
@Test public void testParseTimeWhitespace() throws Exception {
- assertEquals(TimestampUtil.createTime(15, 0, 0), FunctionMethods.parseTime("
15:00:00 ", "HH:mm:ss")); //$NON-NLS-1$ //$NON-NLS-2$
+ assertEquals(TimestampUtil.createTime(15, 0, 0),
FunctionMethods.parseTimestamp(" 15:00:00 ", "HH:mm:ss"));
//$NON-NLS-1$ //$NON-NLS-2$
}
@Test public void testMod() {
Modified:
trunk/engine/src/test/java/com/metamatrix/query/function/TestFunctionLibrary.java
===================================================================
---
trunk/engine/src/test/java/com/metamatrix/query/function/TestFunctionLibrary.java 2009-10-01
13:56:55 UTC (rev 1510)
+++
trunk/engine/src/test/java/com/metamatrix/query/function/TestFunctionLibrary.java 2009-10-01
14:46:23 UTC (rev 1511)
@@ -22,6 +22,8 @@
package com.metamatrix.query.function;
+import static org.junit.Assert.*;
+
import java.math.BigDecimal;
import java.math.BigInteger;
import java.sql.Date;
@@ -32,7 +34,6 @@
import java.util.Properties;
import java.util.TimeZone;
-import static org.junit.Assert.*;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
@@ -789,45 +790,6 @@
helpCreateDescriptor("env", new Class[] {T_STRING}));
//$NON-NLS-1$
}
- @Test public void testInvokeFormatTime1() {
- helpInvokeMethod("formatTime", new Object[]
{TimestampUtil.createTime(3,5,12), new String("h:mm a") }, "3:05
AM"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- }
-
- @Test public void testInvokeFormatTime2() {
- helpInvokeMethod("formatTime", new Object[] {TimestampUtil.createTime(13,
5,12), new String("K:mm a, z") }, "1:05 PM, GMT-06:00");
//$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- }
-
- @Test public void testInvokeFormatTime3() {
- helpInvokeMethod("formatTime", new Object[] {TimestampUtil.createTime(13,
5,12), new String("HH:mm:ss z") }, "13:05:12 GMT-06:00");
//$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- }
-
- @Test public void testInvokeFormatTime4() {
- TimestampWithTimezone.resetCalendar(TimeZone.getTimeZone("America/Chicago"));
//$NON-NLS-1$
- helpInvokeMethod("formatTime", new Object[] {TimestampUtil.createTime(13,
5,12), new String("hh a, zzzz") }, "01 PM, Central Standard Time");
//$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- }
-
- @Test public void testInvokeFormatTimeFail() {
- helpInvokeMethodFail("formatTime", new Object[] {TimestampUtil.createTime(13,
5,12), new String("hh i, www") }, //$NON-NLS-1$ //$NON-NLS-2$
- new FunctionExecutionException("")); //$NON-NLS-1$
- }
-
- @Test public void testInvokeFormatDate1() {
- helpInvokeMethod("formatDate", new Object[] {TimestampUtil.createDate(103, 2,
5), new String("yyyy.MM.dd G") }, "2003.03.05 AD"); //$NON-NLS-1$
//$NON-NLS-2$ //$NON-NLS-3$
- }
-
- @Test public void testInvokeFormatDate2() {
- helpInvokeMethod("formatDate", new Object[] {TimestampUtil.createDate(103, 2,
5), new String("EEE, MMM d, '' yy") }, "Wed, Mar 5, '
03"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- }
-
- @Test public void testInvokeFormatDate3() {
- helpInvokeMethod("formatDate", new Object[] {new Date(12345678), new
String("yyyy.MMMMM.dd GGG hh:mm aaa") }, "1969.December.31 AD 09:25
PM"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- }
-
- @Test public void testInvokeFormatDateFail() {
- helpInvokeMethodFail("formatTime", new Object[]
{TimestampUtil.createTime(103, 2, 5), new String("yyyy.i.www") }, //$NON-NLS-1$
//$NON-NLS-2$
- new FunctionExecutionException("")); //$NON-NLS-1$
- }
-
@Test public void testInvokeFormatTimestamp1() {
helpInvokeMethod("formatTimestamp", new Object[]
{TimestampUtil.createTimestamp(103, 2, 5, 3, 4, 12, 255), new String("mm/dd/yy h:mm
a") }, "04/05/03 3:04 AM"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
}
@@ -845,22 +807,6 @@
new FunctionExecutionException("")); //$NON-NLS-1$
}
- @Test public void testInvokeParseTime1() {
- helpInvokeMethod("parseTime", new Object[] {new String("3:12 PM"),
new String("h:mm a") }, TimestampUtil.createTime(15, 12, 0)); //$NON-NLS-1$
//$NON-NLS-2$ //$NON-NLS-3$
- }
-
- @Test public void testInvokeParseTime2() {
- helpInvokeMethod("parseTime", new Object[] {new String("03:12:23
CST"), new String("hh:mm:ss z") }, TimestampUtil.createTime(3, 12, 23));
//$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- }
-
- @Test public void testInvokeParseDate1() {
- helpInvokeMethod("parseDate", new Object[] {new String("03/05/03"),
new String("MM/dd/yy") }, TimestampUtil.createDate(103, 2, 5)); //$NON-NLS-1$
//$NON-NLS-2$ //$NON-NLS-3$
- }
-
- @Test public void testInvokeParseDate2() {
- helpInvokeMethod("parseDate", new Object[] {new
String("05-Mar-03"), new String("dd-MMM-yy") },
TimestampUtil.createDate(103, 2, 5)); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
- }
-
@Test public void testInvokeParseTimestamp1() {
helpInvokeMethod("parseTimestamp", new Object[] {new String("05 Mar 2003
03:12:23 CST"), new String("dd MMM yyyy HH:mm:ss z") },
TimestampUtil.createTimestamp(103, 2, 5, 3, 12, 23, 0)); //$NON-NLS-1$ //$NON-NLS-2$
//$NON-NLS-3$
}
@@ -1062,75 +1008,63 @@
new Integer(5), new String("cat")}, new String("Downtocat"));
//$NON-NLS-1$ //$NON-NLS-2$
}
- /** date + day --> count=28, inteval=day, result should be 2003-6-12 */
- @Test public void testInvokeTimestampAddDate1() {
- helpInvokeMethod("timestampAdd", new Object[] {ReservedWords.SQL_TSI_DAY,
//$NON-NLS-1$
- new Integer(28), TimestampUtil.createDate(103, 4, 15)}, TimestampUtil.createDate(103,
5, 12));
- }
-
@Test public void testInvokeTimestampAddDate_ignore_case() {
helpInvokeMethod("timestampAdd", new Object[] {"sql_TSI_day",
//$NON-NLS-1$ //$NON-NLS-2$
- new Integer(28), TimestampUtil.createDate(103, 4, 15)},
TimestampUtil.createDate(103, 5, 12));
+ new Integer(28), new Timestamp(TimestampUtil.createDate(103, 4,
15).getTime())}, new Timestamp(TimestampUtil.createDate(103, 5, 12).getTime()));
}
- /** date + day --> count=-28, inteval=day, result should be 2003-4-17 */
- @Test public void testInvokeTimestampAddDate1a() {
- helpInvokeMethod("timestampAdd", new Object[] {ReservedWords.SQL_TSI_DAY,
//$NON-NLS-1$
- new Integer(-28), TimestampUtil.createDate(103, 4, 15)}, TimestampUtil.createDate(103,
3, 17));
- }
-
/** date + month --> count=18, inteval=month, result should be 2004-11-15 */
@Test public void testInvokeTimestampAddDate2() {
helpInvokeMethod("timestampAdd", new Object[] {ReservedWords.SQL_TSI_MONTH,
//$NON-NLS-1$
- new Integer(18), TimestampUtil.createDate(103, 4, 15)}, TimestampUtil.createDate(104,
10, 15));
+ new Integer(18), new Timestamp(TimestampUtil.createDate(103, 4, 15).getTime())}, new
Timestamp(TimestampUtil.createDate(104, 10, 15).getTime()));
}
/** date + month --> count=-18, inteval=month, result should be 2001-11-15 */
@Test public void testInvokeTimestampAddDate2a() {
helpInvokeMethod("timestampAdd", new Object[] {ReservedWords.SQL_TSI_MONTH,
//$NON-NLS-1$
- new Integer(-18), TimestampUtil.createDate(103, 4, 15)}, TimestampUtil.createDate(101,
10, 15));
+ new Integer(-18), new Timestamp(TimestampUtil.createDate(103, 4, 15).getTime())}, new
Timestamp(TimestampUtil.createDate(101, 10, 15).getTime()));
}
/** date + week --> count=6, inteval=week, result should be 2003-04-03 */
@Test public void testInvokeTimestampAddDate3() {
helpInvokeMethod("timestampAdd", new Object[] {ReservedWords.SQL_TSI_WEEK,
//$NON-NLS-1$
- new Integer(-6), TimestampUtil.createDate(103, 4, 15)}, TimestampUtil.createDate(103,
3, 3));
+ new Integer(-6), new Timestamp(TimestampUtil.createDate(103, 4, 15).getTime())}, new
Timestamp(TimestampUtil.createDate(103, 3, 3).getTime()));
}
/** date + quarter --> count=3, inteval=quarter, result should be 2004-2-15 */
@Test public void testInvokeTimestampAddDate4() {
helpInvokeMethod("timestampAdd", new Object[] {ReservedWords.SQL_TSI_QUARTER,
//$NON-NLS-1$
- new Integer(3), TimestampUtil.createDate(103, 4, 15)}, TimestampUtil.createDate(104,
1, 15));
+ new Integer(3), new Timestamp(TimestampUtil.createDate(103, 4, 15).getTime())}, new
Timestamp(TimestampUtil.createDate(104, 1, 15).getTime()));
}
/** date + year --> count=-1, inteval=year, result should be 2002-5-15 */
@Test public void testInvokeTimestampAddDate5() {
helpInvokeMethod("timestampAdd", new Object[] {ReservedWords.SQL_TSI_YEAR,
//$NON-NLS-1$
- new Integer(-1), TimestampUtil.createDate(103, 4, 15)}, TimestampUtil.createDate(102,
4, 15));
+ new Integer(-1), new Timestamp(TimestampUtil.createDate(103, 4, 15).getTime())}, new
Timestamp(TimestampUtil.createDate(102, 4, 15).getTime()));
}
/** time + minute --> count=23, inteval=3, result should be 03:32:12 */
@Test public void testInvokeTimestampAddTime1() {
helpInvokeMethod("timestampAdd", new Object[] {ReservedWords.SQL_TSI_MINUTE,
//$NON-NLS-1$
- new Integer(23), TimestampUtil.createTime(3, 9, 12)}, TimestampUtil.createTime(3, 32,
12));
+ new Integer(23), new Timestamp(TimestampUtil.createTime(3, 9, 12).getTime())}, new
Timestamp(TimestampUtil.createTime(3, 32, 12).getTime()));
}
/** time + hour --> count=21, inteval=4, result should be 00:09:12 and overflow */
@Test public void testInvokeTimestampAddTime2() {
helpInvokeMethod("timestampAdd", new Object[] {ReservedWords.SQL_TSI_HOUR,
//$NON-NLS-1$
- new Integer(21), TimestampUtil.createTime(3, 9, 12)}, TimestampUtil.createTime(0, 9,
12));
+ new Integer(21), new Timestamp(TimestampUtil.createTime(3, 9, 12).getTime())},
TimestampUtil.createTimestamp(70, 0, 2, 0, 9, 12, 0));
}
/** time + hour --> count=2, inteval=4, result should be 01:12:12*/
@Test public void testInvokeTimestampAddTime3() {
helpInvokeMethod("timestampAdd", new Object[] {ReservedWords.SQL_TSI_HOUR,
//$NON-NLS-1$
- new Integer(2), TimestampUtil.createTime(23, 12, 12)}, TimestampUtil.createTime(1, 12,
12));
+ new Integer(2), new Timestamp(TimestampUtil.createTime(23, 12, 12).getTime())},
TimestampUtil.createTimestamp(70, 0, 2, 1, 12, 12, 0));
}
/** time + second --> count=23, inteval=2, result should be 03:10:01 */
@Test public void testInvokeTimestampAddTime4() {
helpInvokeMethod("timestampAdd", new Object[] {ReservedWords.SQL_TSI_SECOND,
//$NON-NLS-1$
- new Integer(49), TimestampUtil.createTime(3, 9, 12)}, TimestampUtil.createTime(3, 10,
1));
+ new Integer(49), new Timestamp(TimestampUtil.createTime(3, 9, 12).getTime())}, new
Timestamp(TimestampUtil.createTime(3, 10, 1).getTime()));
}
/** timestamp + second --> count=23, inteval=2, result should be 2003-05-15
03:09:35.100 */
@@ -1159,13 +1093,13 @@
/** time --> interval=hour, time1 = 03:04:45, time2= 05:05:36 return = 2 */
@Test public void testInvokeTimestampDiffTime1() {
helpInvokeMethod("timestampDiff", new Object[] {ReservedWords.SQL_TSI_HOUR,
//$NON-NLS-1$
- TimestampUtil.createTime(3, 4, 45), TimestampUtil.createTime(5, 5, 36) },
+ new Timestamp(TimestampUtil.createTime(3, 4, 45).getTime()), new
Timestamp(TimestampUtil.createTime(5, 5, 36).getTime()) },
new Long(2));
}
@Test public void testInvokeTimestampDiffTime1_ignorecase() {
helpInvokeMethod("timestampDiff", new Object[]
{"SQL_tsi_HOUR", //$NON-NLS-1$ //$NON-NLS-2$
- TimestampUtil.createTime(3, 4, 45), TimestampUtil.createTime(5, 5, 36) },
+ new Timestamp(TimestampUtil.createTime(3, 4, 45).getTime()), new
Timestamp(TimestampUtil.createTime(5, 5, 36).getTime()) },
new Long(2));
}
Modified: trunk/engine/src/test/java/com/metamatrix/query/rewriter/TestQueryRewriter.java
===================================================================
---
trunk/engine/src/test/java/com/metamatrix/query/rewriter/TestQueryRewriter.java 2009-10-01
13:56:55 UTC (rev 1510)
+++
trunk/engine/src/test/java/com/metamatrix/query/rewriter/TestQueryRewriter.java 2009-10-01
14:46:23 UTC (rev 1511)
@@ -120,8 +120,7 @@
actual = QueryRewriter.rewriteCriteria(origCrit, null, null, null);
assertEquals("Did not rewrite correctly: ", expectedCrit, actual);
//$NON-NLS-1$
} catch(QueryValidatorException e) {
- e.printStackTrace();
- fail("Exception during rewriting (" + e.getClass().getName() +
"): " + e.getMessage()); //$NON-NLS-1$ //$NON-NLS-2$
+ throw new RuntimeException(e);
}
return actual;
}
@@ -402,7 +401,8 @@
helpTestRewriteCriteria("PARSEDATE(pm3.g1.e1, 'yyyyMM') =
{d'2003-05-01'}", //$NON-NLS-1$
"pm3.g1.e1 = '200305'" );
//$NON-NLS-1$
}
-
+
+ @Ignore(value="we're no longer considering parsedate directly")
@Test public void testRewriteCrit_parseDate2() {
helpTestRewriteCriteria("PARSEDATE(pm3.g1.e1, 'yyyyMM') =
{d'2003-05-02'}", //$NON-NLS-1$
"1 = 0" ); //$NON-NLS-1$
@@ -1526,7 +1526,7 @@
@Test public void testRewriteRecursive() {
Command c = helpTestRewriteCommand("SELECT e2 FROM vm1.g33",
"SELECT e2 FROM vm1.g33"); //$NON-NLS-1$ //$NON-NLS-2$
- Command innerCommand = (Command) c.getSubCommands().get(0);
+ Command innerCommand = c.getSubCommands().get(0);
assertEquals("Inner command not rewritten", "SELECT e2 FROM pm1.g1
WHERE e2 = 2", innerCommand.toString()); //$NON-NLS-1$ //$NON-NLS-2$
@@ -2286,4 +2286,22 @@
helpTestRewriteCriteria(original,
parseCriteria("convert(BQT1.SmallA.TimestampValue, time) in ({t'10:00:00'},
{t'11:00:00'})", FakeMetadataFactory.exampleBQTCached()),
FakeMetadataFactory.exampleBQTCached()); //$NON-NLS-1$
}
+ @Test public void testRewriteParseDate() {
+ String original = "parsedate(BQT1.SmallA.stringkey, 'yymmdd') =
{d'1970-01-01'}"; //$NON-NLS-1$
+ FakeMetadataFacade metadata = FakeMetadataFactory.exampleBQTCached();
+ helpTestRewriteCriteria(original,
parseCriteria("convert(parsetimestamp(BQT1.SmallA.stringkey, 'yymmdd'), date)
= {d'1970-01-01'}", metadata), metadata); //$NON-NLS-1$
+ }
+
+ @Test public void testRewriteFormatTime() {
+ String original = "formattime(BQT1.SmallA.timevalue, 'hh:mm') =
'08:02'"; //$NON-NLS-1$
+ FakeMetadataFacade metadata = FakeMetadataFactory.exampleBQTCached();
+ helpTestRewriteCriteria(original,
parseCriteria("formattimestamp(convert(BQT1.SmallA.timevalue, timestamp),
'hh:mm') = '08:02'", metadata), metadata); //$NON-NLS-1$
+ }
+
+ @Test public void testRewriteTimestampAdd() {
+ String original = "timestampadd(SQL_TSI_SECOND, 1, BQT1.SmallA.timevalue) =
{t'08:02:00'}"; //$NON-NLS-1$
+ FakeMetadataFacade metadata = FakeMetadataFactory.exampleBQTCached();
+ helpTestRewriteCriteria(original,
parseCriteria("convert(timestampadd(SQL_TSI_SECOND, 1, convert(BQT1.SmallA.timevalue,
timestamp)), time) = {t'08:02:00'}", metadata), metadata); //$NON-NLS-1$
+ }
+
}