Skip to content

Commit 6aa7ece

Browse files
committed
minor improvements
1 parent ece6678 commit 6aa7ece

File tree

2 files changed

+14
-12
lines changed

2 files changed

+14
-12
lines changed

fluss-client/src/main/java/org/apache/fluss/client/converter/ConverterCommons.java

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@
2929
import java.util.Map;
3030
import java.util.Set;
3131

32+
import static org.apache.fluss.client.converter.RowToPojoConverter.charLengthExceptionMessage;
33+
3234
/**
3335
* Internal shared utilities for POJO and Fluss InternalRow conversions.
3436
*
@@ -108,13 +110,9 @@ static void validateCompatibility(DataType fieldType, PojoType.Property prop) {
108110
}
109111

110112
static BinaryString toBinaryStringForText(Object v, String fieldName, DataTypeRoot root) {
111-
final String s =
112-
(v instanceof Character) ? String.valueOf((Character) v) : String.valueOf(v);
113+
final String s = String.valueOf(v);
113114
if (root == DataTypeRoot.CHAR && s.length() != 1) {
114-
throw new IllegalArgumentException(
115-
String.format(
116-
"Field %s expects exactly one character for CHAR type, got length %d.",
117-
fieldName, s.length()));
115+
throw new IllegalArgumentException(charLengthExceptionMessage(fieldName, s.length()));
118116
}
119117
return BinaryString.fromString(s);
120118
}

fluss-client/src/main/java/org/apache/fluss/client/converter/RowToPojoConverter.java

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -184,13 +184,10 @@ private static RowToField createRowReader(DataType fieldType, PojoType.Property
184184
private static Object convertTextValue(
185185
DataType fieldType, PojoType.Property prop, BinaryString s) {
186186
String v = s.toString();
187-
String formattedMessage =
188-
String.format(
189-
"Field %s expects exactly one character for CHAR type, got length %d.",
190-
prop.name, v.length());
191187
if (prop.type == String.class) {
192188
if (fieldType.getTypeRoot() == DataTypeRoot.CHAR && v.length() != 1) {
193-
throw new IllegalArgumentException(formattedMessage);
189+
throw new IllegalArgumentException(
190+
charLengthExceptionMessage(prop.name, v.length()));
194191
}
195192
return v;
196193
} else if (prop.type == Character.class) {
@@ -201,7 +198,8 @@ private static Object convertTextValue(
201198
prop.name));
202199
}
203200
if (fieldType.getTypeRoot() == DataTypeRoot.CHAR && v.length() != 1) {
204-
throw new IllegalArgumentException(formattedMessage);
201+
throw new IllegalArgumentException(
202+
charLengthExceptionMessage(prop.name, v.length()));
205203
}
206204
return v.charAt(0);
207205
}
@@ -211,6 +209,12 @@ private static Object convertTextValue(
211209
prop.name));
212210
}
213211

212+
public static String charLengthExceptionMessage(String fieldName, int length) {
213+
return String.format(
214+
"Field %s expects exactly one character for CHAR type, got length %d.",
215+
fieldName, length);
216+
}
217+
214218
/**
215219
* Converts a DECIMAL value from an InternalRow into a BigDecimal using the column's precision
216220
* and scale. The row position is assumed non-null (caller checks), so this never returns null.

0 commit comments

Comments
 (0)