Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Fix-4075][metadata] Fix the errors when querying the data of numeric and date types in Paimon #4152

Merged
merged 1 commit into from
Jan 15, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,12 +76,14 @@ 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:
case INTEGER:
Expand All @@ -90,12 +95,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
Loading