twalthr commented on a change in pull request #17811:
URL: https://github.com/apache/flink/pull/17811#discussion_r758354073
##########
File path:
flink-table/flink-table-api-java/src/main/java/org/apache/flink/table/api/config/ExecutionConfigOptions.java
##########
@@ -421,9 +422,9 @@ public InlineElement getDescription() {
text(
"Don't apply any trimming, and instead "
Review comment:
`Don't apply any trimming and padding`
##########
File path:
flink-table/flink-table-planner/src/main/java/org/apache/flink/table/planner/plan/nodes/exec/common/CommonExecSink.java
##########
@@ -225,15 +226,19 @@ public DynamicTableSinkSpec getTableSinkSpec() {
/**
* Returns a List of Tuples, each Tuple holds 2 integers, the char field
idx and its precision.
*/
- private List<Tuple2<Integer, Integer>> getCharFieldIndices(RowType
physicalType) {
- final List<Tuple2<Integer, Integer>> charFieldsAndLengths = new
ArrayList<>();
+ private List<Tuple3<Integer, Integer, Boolean>>
getCharFieldIndices(RowType physicalType) {
+ final List<Tuple3<Integer, Integer, Boolean>> charFieldsAndLengths =
new ArrayList<>();
Review comment:
Tuples are not very convenient for code readability. Also the method
name `getCharFieldIndices` is not useful for what the function is doing. Can't
we introduce a little POJO with default scoped members and an assigning
constructor?
##########
File path:
flink-table/flink-table-runtime/src/main/java/org/apache/flink/table/runtime/operators/sink/ConstraintEnforcer.java
##########
@@ -227,22 +243,34 @@ public void processElement(StreamRecord<RowData> element)
throws Exception {
final RowData rowData = element.getValue();
- boolean trimmed = false;
+ boolean trimmedOrPadded = false;
for (int i = 0; i < charFieldIndices.length; i++) {
final int fieldIdx = charFieldIndices[i];
final int precision = charFieldPrecisions[i];
final BinaryStringData stringData = (BinaryStringData)
rowData.getString(fieldIdx);
+ final int sourceStrLength = stringData.numChars();
- if (stringData.numChars() > precision) {
- if (!trimmed) {
+ if (charFieldShouldPad.get(i) && sourceStrLength < precision) {
+ if (!trimmedOrPadded) {
+ reusableRowData.setRow(rowData);
+ }
+ byte[] newString = new byte[precision];
Review comment:
attention: bytes length != string precision
JVM uses UTF-16, planner runtime uses UTF-8
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]