Skip to content

Commit

Permalink
TEIID-4395 supporting clob conversion to string
Browse files Browse the repository at this point in the history
  • Loading branch information
shawkins committed Aug 19, 2016
1 parent 44bba23 commit 4a40a5e
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
import org.teiid.translator.TranslatorException;
import org.teiid.translator.TranslatorProperty;
import org.teiid.translator.TypeFacility;
import org.teiid.translator.TypeFacility.RUNTIME_CODES;
import org.teiid.translator.jdbc.*;


Expand Down Expand Up @@ -225,6 +226,7 @@ public List<?> translate(Function function) {
convertModifier.addConvert(FunctionModifier.STRING, FunctionModifier.DATE, new ConvertModifier.FormatModifier("to_date", DATE_FORMAT)); //$NON-NLS-1$
convertModifier.addConvert(FunctionModifier.STRING, FunctionModifier.TIME, new ConvertModifier.FormatModifier("to_date", TIME_FORMAT)); //$NON-NLS-1$
convertModifier.addConvert(FunctionModifier.STRING, FunctionModifier.TIMESTAMP, new ConvertModifier.FormatModifier("to_timestamp", TIMESTAMP_FORMAT)); //$NON-NLS-1$
convertModifier.addConvert(FunctionModifier.CLOB, FunctionModifier.STRING, new TemplateFunctionModifier("DBMS_LOB.substr(", 0, ", 4000)")); //$NON-NLS-1$ //$NON-NLS-2$
convertModifier.addTypeConversion(new ConvertModifier.FormatModifier("to_char"), FunctionModifier.STRING); //$NON-NLS-1$
//NOTE: numeric handling in Oracle is split only between integral vs. floating/decimal types
convertModifier.addTypeConversion(new ConvertModifier.FormatModifier("to_number"), //$NON-NLS-1$
Expand Down Expand Up @@ -1114,4 +1116,12 @@ public String translateLiteralBinaryType(BinaryType obj) {
public boolean supportsSubqueryInOn() {
return false; //even oracle 12 still has issues if a with clause is also in the source query
}

public boolean supportsConvert(int fromType, int toType) {
//allow conversion from clob to string
if (fromType == RUNTIME_CODES.OBJECT || fromType == RUNTIME_CODES.XML || fromType == RUNTIME_CODES.BLOB || toType == RUNTIME_CODES.CLOB || toType == RUNTIME_CODES.XML || toType == RUNTIME_CODES.BLOB) {
return false;
}
return true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

package org.teiid.translator.jdbc.oracle;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.*;

import java.math.BigDecimal;
import java.math.BigInteger;
Expand All @@ -31,6 +31,8 @@

import org.junit.BeforeClass;
import org.junit.Test;
import org.teiid.core.types.DataTypeManager;
import org.teiid.language.ColumnReference;
import org.teiid.language.Expression;
import org.teiid.language.Function;
import org.teiid.language.LanguageFactory;
Expand Down Expand Up @@ -518,6 +520,11 @@ public void helpTest(Expression srcExpression, String tgtType, String expectedEx
@Test public void testTimestampToTime() throws Exception {
Timestamp ts = TimestampUtil.createTimestamp(103, 10, 1, 12, 5, 2, 10000000);
helpTest(LANG_FACTORY.createLiteral(ts, Timestamp.class), "time", "case when {ts '2003-11-01 12:05:02.01'} is null then null else to_date('1970-01-01 ' || to_char({ts '2003-11-01 12:05:02.01'}, 'HH24:MI:SS'), 'YYYY-MM-DD HH24:MI:SS') end"); //$NON-NLS-1$ //$NON-NLS-2$
}
}

@Test public void testClobToString() throws Exception {
assertTrue(TRANSLATOR.supportsConvert(TypeFacility.RUNTIME_CODES.CLOB, TypeFacility.RUNTIME_CODES.STRING));
helpTest(new ColumnReference(null, "x", null, DataTypeManager.DefaultDataClasses.CLOB), "string", "DBMS_LOB.substr(x, 4000)"); //$NON-NLS-1$ //$NON-NLS-2$
}

}

0 comments on commit 4a40a5e

Please sign in to comment.