Skip to content

Commit

Permalink
[Fix-4075] Fix the errors when querying the data of numeric and date …
Browse files Browse the repository at this point in the history
…types in Paimon
  • Loading branch information
aiwenmo committed Feb 7, 2025
1 parent 0481223 commit 70a4170
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,11 @@
import org.apache.paimon.data.InternalRow;
import org.apache.paimon.types.DataField;
import org.apache.paimon.types.DataTypeRoot;
import org.apache.paimon.types.DecimalType;
import org.apache.paimon.types.TimestampType;

import java.time.LocalDate;
import java.time.LocalTime;
import java.util.Optional;

/**
Expand Down Expand Up @@ -63,7 +66,7 @@ public PaimonTypeConvert() {
register("int", ColumnType.INT, ColumnType.INTEGER);
}

public static Object SafeGetRowData(DataField fieldType, InternalRow row, int ordinal) {
public static Object getRowDataSafe(DataField fieldType, InternalRow row, int ordinal) {
if (row.isNullAt(ordinal)) {
return null;
}
Expand All @@ -73,14 +76,17 @@ public static Object SafeGetRowData(DataField fieldType, InternalRow row, int or
case VARCHAR:
return row.getString(ordinal).toString();
case BOOLEAN:
return row.getBoolean(ordinal);
return String.valueOf(row.getBoolean(ordinal));
case BINARY:
case VARBINARY:
return "<Binary Type>";
// case DECIMAL:
// return "<DECIMAL Type>";
case DECIMAL:
DecimalType decimalType = (DecimalType) fieldType.type();
return row.getDecimal(ordinal, decimalType.getPrecision(), decimalType.getScale())
.toString();
case TINYINT:
case SMALLINT:
return row.getShort(ordinal);
case INTEGER:
return row.getInt(ordinal);
case BIGINT:
Expand All @@ -90,12 +96,15 @@ public static Object SafeGetRowData(DataField fieldType, InternalRow row, int or
case DOUBLE:
return row.getDouble(ordinal);
case DATE:
int timeInt = row.getInt(ordinal);
return LocalDate.of(1970, 1, 1).plusDays(timeInt);
int dateInt = row.getInt(ordinal);
return LocalDate.of(1970, 1, 1).plusDays(dateInt);
case TIME_WITHOUT_TIME_ZONE:
int timeInt = row.getInt(ordinal);
return LocalTime.ofSecondOfDay(timeInt / 1000);
case TIMESTAMP_WITHOUT_TIME_ZONE:
case TIMESTAMP_WITH_LOCAL_TIME_ZONE:
return row.getTimestamp(ordinal, 3).toLocalDateTime();
TimestampType timestampType = (TimestampType) fieldType.type();
return row.getTimestamp(ordinal, timestampType.getPrecision()).toLocalDateTime();
case ARRAY:
case MULTISET:
return row.getArray(ordinal).toString();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ public JdbcSelectResult query(QueryData queryData) {
LinkedHashMap<String, Object> rowList = new LinkedHashMap<>();
for (int i = 0; i < row.getFieldCount(); i++) {
String name = fieldTypes.get(i).name();
Object data = PaimonTypeConvert.SafeGetRowData(fieldTypes.get(i), row, i);
Object data = PaimonTypeConvert.getRowDataSafe(fieldTypes.get(i), row, i);
rowList.put(name, data);
}
datas.add(rowList);
Expand Down

0 comments on commit 70a4170

Please sign in to comment.