Skip to content

Commit

Permalink
[improve] some improve for package (apache#242)
Browse files Browse the repository at this point in the history
1. Modify the serialization method to be static to facilitate external use.
2. Modify the catalog’s type mapping to synchronize and unify it with the entire library.
  • Loading branch information
JNSimba authored Nov 23, 2023
1 parent 43e9bf3 commit 1e2965d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ public String visit(CharType charType) {
@Override
public String visit(VarCharType varCharType) {
int length = varCharType.getLength();
return length > 65533 ? STRING : String.format("%s(%s)", VARCHAR, length);
return length * 4 > 65533 ? STRING : String.format("%s(%s)", VARCHAR, length * 4);
}

@Override
Expand All @@ -143,7 +143,7 @@ public String visit(DecimalType decimalType) {
int precision = decimalType.getPrecision();
int scale = decimalType.getScale();
return precision <= 38
? String.format("%s(%s,%s)", DorisType.DECIMAL_V3, precision, scale >= 0 ? scale : 0)
? String.format("%s(%s,%s)", DorisType.DECIMAL_V3, precision, Math.max(scale, 0))
: DorisType.STRING;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,11 +123,11 @@ public Object convertExternal(RowData rowData, int index) {
* Create a nullable runtime {@link DeserializationConverter} from given {@link
* LogicalType}.
*/
protected DeserializationConverter createNullableInternalConverter(LogicalType type) {
public DeserializationConverter createNullableInternalConverter(LogicalType type) {
return wrapIntoNullableInternalConverter(createInternalConverter(type));
}

protected DeserializationConverter wrapIntoNullableInternalConverter(
public DeserializationConverter wrapIntoNullableInternalConverter(
DeserializationConverter deserializationConverter) {
return val -> {
if (val == null) {
Expand All @@ -138,11 +138,11 @@ protected DeserializationConverter wrapIntoNullableInternalConverter(
};
}

protected SerializationConverter createNullableExternalConverter(LogicalType type) {
public static SerializationConverter createNullableExternalConverter(LogicalType type) {
return wrapIntoNullableExternalConverter(createExternalConverter(type));
}

protected SerializationConverter wrapIntoNullableExternalConverter(SerializationConverter serializationConverter) {
public static SerializationConverter wrapIntoNullableExternalConverter(SerializationConverter serializationConverter) {
return (index, val) -> {
if (val == null || val.isNullAt(index)) {
return null;
Expand All @@ -154,7 +154,7 @@ protected SerializationConverter wrapIntoNullableExternalConverter(Serialization

/** Runtime converter to convert doris field to {@link RowData} type object. */
@FunctionalInterface
interface DeserializationConverter extends Serializable {
public interface DeserializationConverter extends Serializable {
/**
* Convert a doris field object of {@link RowBatch } to the data structure object.
*
Expand All @@ -167,11 +167,11 @@ interface DeserializationConverter extends Serializable {
* Runtime converter to convert {@link RowData} type object to doris field.
*/
@FunctionalInterface
interface SerializationConverter extends Serializable {
public interface SerializationConverter extends Serializable {
Object serialize(int index, RowData field);
}

protected DeserializationConverter createInternalConverter(LogicalType type) {
public DeserializationConverter createInternalConverter(LogicalType type) {
switch (type.getTypeRoot()) {
case NULL:
return val -> null;
Expand Down Expand Up @@ -230,7 +230,7 @@ protected DeserializationConverter createInternalConverter(LogicalType type) {
}
}

protected SerializationConverter createExternalConverter(LogicalType type) {
public static SerializationConverter createExternalConverter(LogicalType type) {
switch (type.getTypeRoot()) {
case NULL:
return ((index, val) -> null);
Expand Down Expand Up @@ -327,7 +327,7 @@ private RowData convertRowData(Map<String, ?> row, LogicalType type) {
return rowData;
}

private List<Object> convertArrayData(ArrayData array, LogicalType type){
private static List<Object> convertArrayData(ArrayData array, LogicalType type){
if(array instanceof GenericArrayData){
return Arrays.asList(((GenericArrayData)array).toObjectArray());
}
Expand All @@ -345,7 +345,7 @@ private List<Object> convertArrayData(ArrayData array, LogicalType type){
throw new UnsupportedOperationException("Unsupported array data: " + array.getClass());
}

private Object convertMapData(MapData map, LogicalType type) {
private static Object convertMapData(MapData map, LogicalType type) {
Map<Object, Object> result = new HashMap<>();
if (map instanceof GenericMapData) {
GenericMapData gMap = (GenericMapData)map;
Expand Down Expand Up @@ -377,7 +377,7 @@ private Object convertMapData(MapData map, LogicalType type) {
throw new UnsupportedOperationException("Unsupported map data: " + map.getClass());
}

private Object convertRowData(RowData val, int index, LogicalType type) {
private static Object convertRowData(RowData val, int index, LogicalType type) {
RowType rowType = (RowType)type;
Map<String, Object> value = new HashMap<>();
RowData row = val.getRow(index, rowType.getFieldCount());
Expand All @@ -392,7 +392,7 @@ private Object convertRowData(RowData val, int index, LogicalType type) {
return value;
}

private String writeValueAsString(Object object){
private static String writeValueAsString(Object object){
try {
return objectMapper.writeValueAsString(object);
} catch (JsonProcessingException e) {
Expand Down

0 comments on commit 1e2965d

Please sign in to comment.