Skip to content

Commit

Permalink
TEIID-5441 adding explicit precision/scale to decimal casts
Browse files Browse the repository at this point in the history
  • Loading branch information
shawkins committed Aug 10, 2018
1 parent 6b09517 commit 1d31e69
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,8 @@ protected Object convertToken(String group) {

private Version postGisVersion = Version.DEFAULT_VERSION;
private boolean projSupported = false;

protected ConvertModifier convertModifier;

public PostgreSQLExecutionFactory() {
setMaxDependentInPredicates(1);
Expand Down Expand Up @@ -246,8 +248,7 @@ public List<?> translate(Function function) {
}
});

//add in type conversion
ConvertModifier convertModifier = new ConvertModifier();
convertModifier = new ConvertModifier();
convertModifier.addTypeMapping("boolean", FunctionModifier.BOOLEAN); //$NON-NLS-1$
convertModifier.addTypeMapping("smallint", FunctionModifier.BYTE, FunctionModifier.SHORT); //$NON-NLS-1$
convertModifier.addTypeMapping(INTEGER_TYPE, FunctionModifier.INTEGER);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import org.teiid.translator.Translator;
import org.teiid.translator.TranslatorException;
import org.teiid.translator.TypeFacility;
import org.teiid.translator.jdbc.FunctionModifier;
import org.teiid.translator.jdbc.postgresql.PostgreSQLExecutionFactory;


Expand All @@ -43,6 +44,8 @@ public void start() throws TranslatorException {
getFunctionModifiers().remove(SourceSystemFunctions.SUBSTRING); //redshift doesn't use substr
//to_timestamp is not supported
this.parseModifier.setPrefix("TO_DATE("); //$NON-NLS-1$
//redshift needs explicit precision/scale
this.convertModifier.addTypeMapping("decimal(38, 19)", FunctionModifier.BIGDECIMAL); //$NON-NLS-1$
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@

import org.junit.BeforeClass;
import org.junit.Test;
import org.teiid.translator.ExecutionFactory.Format;
import org.teiid.translator.TranslatorException;
import org.teiid.translator.jdbc.TranslationHelper;

Expand Down Expand Up @@ -52,6 +51,13 @@ public static void setUp() throws TranslatorException {
TranslationHelper.helpTestVisitor(TranslationHelper.BQT_VDB, input, output, TRANSLATOR);
}

@Test public void testBigDecimalCast() throws Exception {
String input = "SELECT cast(floatnum as bigdecimal) FROM bqt1.SmallA";
String output = "SELECT cast(SmallA.FloatNum AS decimal(38, 19)) FROM SmallA";

TranslationHelper.helpTestVisitor(TranslationHelper.BQT_VDB, input, output, TRANSLATOR);
}

@Test public void testTimezoneFormat() throws Exception {
assertFalse(TRANSLATOR.supportsFormatLiteral("hh:MM:ss Z", Format.DATE));
}
Expand Down

0 comments on commit 1d31e69

Please sign in to comment.