Skip to content

Commit 31e6c2c

Browse files
authored
[Fix-4075][metadata] Fix the errors when querying the data of numeric and date types in Paimon (#4152)
1 parent 2a31ef0 commit 31e6c2c

File tree

2 files changed

+16
-8
lines changed

2 files changed

+16
-8
lines changed

dinky-metadata/dinky-metadata-paimon/src/main/java/org/dinky/metadata/convert/PaimonTypeConvert.java

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,11 @@
2929
import org.apache.paimon.data.InternalRow;
3030
import org.apache.paimon.types.DataField;
3131
import org.apache.paimon.types.DataTypeRoot;
32+
import org.apache.paimon.types.DecimalType;
33+
import org.apache.paimon.types.TimestampType;
3234

3335
import java.time.LocalDate;
36+
import java.time.LocalTime;
3437
import java.util.Optional;
3538

3639
/**
@@ -63,7 +66,7 @@ public PaimonTypeConvert() {
6366
register("int", ColumnType.INT, ColumnType.INTEGER);
6467
}
6568

66-
public static Object SafeGetRowData(DataField fieldType, InternalRow row, int ordinal) {
69+
public static Object getRowDataSafe(DataField fieldType, InternalRow row, int ordinal) {
6770
if (row.isNullAt(ordinal)) {
6871
return null;
6972
}
@@ -73,12 +76,14 @@ public static Object SafeGetRowData(DataField fieldType, InternalRow row, int or
7376
case VARCHAR:
7477
return row.getString(ordinal).toString();
7578
case BOOLEAN:
76-
return row.getBoolean(ordinal);
79+
return String.valueOf(row.getBoolean(ordinal));
7780
case BINARY:
7881
case VARBINARY:
7982
return "<Binary Type>";
80-
// case DECIMAL:
81-
// return "<DECIMAL Type>";
83+
case DECIMAL:
84+
DecimalType decimalType = (DecimalType) fieldType.type();
85+
return row.getDecimal(ordinal, decimalType.getPrecision(), decimalType.getScale())
86+
.toString();
8287
case TINYINT:
8388
case SMALLINT:
8489
case INTEGER:
@@ -90,12 +95,15 @@ public static Object SafeGetRowData(DataField fieldType, InternalRow row, int or
9095
case DOUBLE:
9196
return row.getDouble(ordinal);
9297
case DATE:
93-
int timeInt = row.getInt(ordinal);
94-
return LocalDate.of(1970, 1, 1).plusDays(timeInt);
98+
int dateInt = row.getInt(ordinal);
99+
return LocalDate.of(1970, 1, 1).plusDays(dateInt);
95100
case TIME_WITHOUT_TIME_ZONE:
101+
int timeInt = row.getInt(ordinal);
102+
return LocalTime.ofSecondOfDay(timeInt / 1000);
96103
case TIMESTAMP_WITHOUT_TIME_ZONE:
97104
case TIMESTAMP_WITH_LOCAL_TIME_ZONE:
98-
return row.getTimestamp(ordinal, 3).toLocalDateTime();
105+
TimestampType timestampType = (TimestampType) fieldType.type();
106+
return row.getTimestamp(ordinal, timestampType.getPrecision()).toLocalDateTime();
99107
case ARRAY:
100108
case MULTISET:
101109
return row.getArray(ordinal).toString();

dinky-metadata/dinky-metadata-paimon/src/main/java/org/dinky/metadata/driver/PaimonDriver.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ public JdbcSelectResult query(QueryData queryData) {
9999
LinkedHashMap<String, Object> rowList = new LinkedHashMap<>();
100100
for (int i = 0; i < row.getFieldCount(); i++) {
101101
String name = fieldTypes.get(i).name();
102-
Object data = PaimonTypeConvert.SafeGetRowData(fieldTypes.get(i), row, i);
102+
Object data = PaimonTypeConvert.getRowDataSafe(fieldTypes.get(i), row, i);
103103
rowList.put(name, data);
104104
}
105105
datas.add(rowList);

0 commit comments

Comments
 (0)