Skip to content

Commit 70a4170

Browse files
committed
[Fix-4075] Fix the errors when querying the data of numeric and date types in Paimon
1 parent 0481223 commit 70a4170

File tree

2 files changed

+17
-8
lines changed

2 files changed

+17
-8
lines changed

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

Lines changed: 16 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,14 +76,17 @@ 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:
89+
return row.getShort(ordinal);
8490
case INTEGER:
8591
return row.getInt(ordinal);
8692
case BIGINT:
@@ -90,12 +96,15 @@ public static Object SafeGetRowData(DataField fieldType, InternalRow row, int or
9096
case DOUBLE:
9197
return row.getDouble(ordinal);
9298
case DATE:
93-
int timeInt = row.getInt(ordinal);
94-
return LocalDate.of(1970, 1, 1).plusDays(timeInt);
99+
int dateInt = row.getInt(ordinal);
100+
return LocalDate.of(1970, 1, 1).plusDays(dateInt);
95101
case TIME_WITHOUT_TIME_ZONE:
102+
int timeInt = row.getInt(ordinal);
103+
return LocalTime.ofSecondOfDay(timeInt / 1000);
96104
case TIMESTAMP_WITHOUT_TIME_ZONE:
97105
case TIMESTAMP_WITH_LOCAL_TIME_ZONE:
98-
return row.getTimestamp(ordinal, 3).toLocalDateTime();
106+
TimestampType timestampType = (TimestampType) fieldType.type();
107+
return row.getTimestamp(ordinal, timestampType.getPrecision()).toLocalDateTime();
99108
case ARRAY:
100109
case MULTISET:
101110
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)