Skip to content

Commit

Permalink
Fix oracle incorrect char padding
Browse files Browse the repository at this point in the history
  • Loading branch information
brandboat authored and findepi committed Apr 20, 2021
1 parent c682a1d commit c6111d2
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
import io.trino.spi.connector.JoinCondition;
import io.trino.spi.connector.SchemaTableName;
import io.trino.spi.type.CharType;
import io.trino.spi.type.Chars;
import io.trino.spi.type.DecimalType;
import io.trino.spi.type.Decimals;
import io.trino.spi.type.Type;
Expand Down Expand Up @@ -306,7 +305,7 @@ else if (precision > Decimals.MAX_PRECISION || actualPrecision <= 0) {
return Optional.of(ColumnMapping.sliceMapping(
charType,
charReadFunction(charType),
oracleCharWriteFunction(charType),
oracleCharWriteFunction(),
FULL_PUSHDOWN));

case OracleTypes.VARCHAR:
Expand Down Expand Up @@ -420,11 +419,10 @@ public static DoubleWriteFunction oracleDoubleWriteFunction()
return ((statement, index, value) -> ((OraclePreparedStatement) statement).setBinaryDouble(index, value));
}

private SliceWriteFunction oracleCharWriteFunction(CharType charType)
private SliceWriteFunction oracleCharWriteFunction()
{
return (statement, index, value) -> {
statement.setString(index, Chars.padSpaces(value, charType).toStringUtf8());
};
return (statement, index, value) ->
((OraclePreparedStatement) statement).setFixedCHAR(index, value.toStringUtf8());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -366,6 +366,11 @@ public void testCharUnicodeReadMapping()
unicodeTests(charDataType(CHAR), codePoints(), MAX_CHAR_ON_READ),
unicodeTests(charDataType(BYTE), utf8Bytes(), MAX_CHAR_ON_READ),
unicodeTests(ncharDataType(), String::length, MAX_NCHAR));

SqlDataTypeTest.create()
.addRoundTrip(format("char(%d char)", MAX_CHAR_ON_READ), "'攻殻機動隊'",
createCharType(MAX_CHAR_ON_READ), format("CAST('攻殻機動隊' AS char(%d))", MAX_CHAR_ON_READ))
.execute(getQueryRunner(), oracleCreateAndInsert("read_char_unicode"));
}

private static DataTypeTest unicodeTests(IntFunction<DataType<String>> typeConstructor, ToIntFunction<String> stringLength, int maxSize)
Expand Down

0 comments on commit c6111d2

Please sign in to comment.