Skip to content

Commit

Permalink
TEIID-2422 adding workarounds to directly call source timestampdiff
Browse files Browse the repository at this point in the history
functions
  • Loading branch information
shawkins committed Aug 13, 2013
1 parent de4442e commit c751552
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 3 deletions.
Expand Up @@ -35,6 +35,7 @@
import org.teiid.translator.SourceSystemFunctions;
import org.teiid.translator.Translator;
import org.teiid.translator.TranslatorException;
import org.teiid.translator.TypeFacility;
import org.teiid.translator.jdbc.AliasModifier;
import org.teiid.translator.jdbc.ConvertModifier;
import org.teiid.translator.jdbc.FunctionModifier;
Expand Down Expand Up @@ -79,6 +80,7 @@ public void start() throws TranslatorException {
convert.addTypeMapping("char(1)", FunctionModifier.CHAR); //$NON-NLS-1$
convert.addTypeMapping("varchar", FunctionModifier.STRING); //$NON-NLS-1$
registerFunctionModifier(SourceSystemFunctions.CONVERT, convert);
addPushDownFunction("h2", "timestampdiff", TypeFacility.RUNTIME_NAMES.INTEGER, TypeFacility.RUNTIME_NAMES.STRING, TypeFacility.RUNTIME_NAMES.TIMESTAMP, TypeFacility.RUNTIME_NAMES.TIMESTAMP); //$NON-NLS-1$ //$NON-NLS-2$
}

@Override
Expand Down
Expand Up @@ -9,13 +9,21 @@
import java.util.List;

import org.teiid.translator.Translator;
import org.teiid.translator.TranslatorException;
import org.teiid.translator.TypeFacility;
import org.teiid.translator.jdbc.JDBCExecutionFactory;

/**
* Capabilities compatible with MM 5.5.x
*/
@Translator(name="metamatrix", description="A translator for MetaMatrix 5.5 or later")
public class MetaMatrixExecutionFactory extends JDBCExecutionFactory {

@Override
public void start() throws TranslatorException {
super.start();
addPushDownFunction("mm", "timestampdiff", TypeFacility.RUNTIME_NAMES.INTEGER, TypeFacility.RUNTIME_NAMES.STRING, TypeFacility.RUNTIME_NAMES.TIMESTAMP, TypeFacility.RUNTIME_NAMES.TIMESTAMP); //$NON-NLS-1$ //$NON-NLS-2$
}

public List<String> getSupportedFunctions() {
List<String> supportedFunctions = new ArrayList<String>();
Expand Down
Expand Up @@ -68,7 +68,9 @@ public List<?> translate(Function function) {
}
});

registerFunctionModifier(SourceSystemFunctions.TIMESTAMPDIFF, new FunctionModifier() {
addPushDownFunction("mysql", "timestampdiff", TypeFacility.RUNTIME_NAMES.INTEGER, TypeFacility.RUNTIME_NAMES.STRING, TypeFacility.RUNTIME_NAMES.TIMESTAMP, TypeFacility.RUNTIME_NAMES.TIMESTAMP); //$NON-NLS-1$ //$NON-NLS-2$

registerFunctionModifier(SourceSystemFunctions.TIMESTAMPDIFF, new FunctionModifier() {

@Override
public List<?> translate(Function function) {
Expand Down
Expand Up @@ -38,7 +38,7 @@ public static void setUp() throws TranslatorException {
}

@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 input = "select h2.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$

TranslationHelper.helpTestVisitor(TranslationHelper.BQT_VDB, input, output, TRANSLATOR);
Expand Down
Expand Up @@ -49,7 +49,7 @@ public class TestMySQL5Translator {


@Test public void testTimestampFunctions() throws Exception {
String input = "SELECT timestampdiff(SQL_TSI_FRAC_SECOND, timestampvalue, {d '1970-01-01'}), timestampdiff(SQL_TSI_HOUR, timestampvalue, {d '1970-01-01'}), timestampadd(SQL_TSI_FRAC_SECOND, 2000, MediumA.TimestampValue) FROM BQT1.MediumA"; //$NON-NLS-1$
String input = "SELECT mysql.timestampdiff('SQL_TSI_FRAC_SECOND', timestampvalue, {d '1970-01-01'}), mysql.timestampdiff('SQL_TSI_HOUR', timestampvalue, {d '1970-01-01'}), timestampadd(SQL_TSI_FRAC_SECOND, 2000, MediumA.TimestampValue) FROM BQT1.MediumA"; //$NON-NLS-1$
String output = "SELECT timestampdiff(MICROSECOND, MediumA.TimestampValue, {ts '1970-01-01 00:00:00.0'}) * 1000, timestampdiff(SQL_TSI_HOUR, MediumA.TimestampValue, {ts '1970-01-01 00:00:00.0'}), timestampadd(MICROSECOND, (2000 / 1000), MediumA.TimestampValue) FROM MediumA"; //$NON-NLS-1$

TranslationHelper.helpTestVisitor(TranslationHelper.BQT_VDB,
Expand Down

0 comments on commit c751552

Please sign in to comment.