Skip to content

Commit

Permalink
[fix](paimon)fix type convert for paimon (#28774)
Browse files Browse the repository at this point in the history
fix type convert for paimon
  • Loading branch information
wuwenchi authored Dec 22, 2023
1 parent fb52e11 commit f38e11e
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,17 @@
import org.apache.paimon.data.InternalArray;
import org.apache.paimon.data.InternalMap;
import org.apache.paimon.data.InternalRow;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.math.BigDecimal;
import java.math.BigInteger;
import java.time.Instant;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.ZoneOffset;
import java.util.List;

public class PaimonColumnValue implements ColumnValue {
private static final Logger LOG = LoggerFactory.getLogger(PaimonColumnValue.class);
private int idx;
private DataGetters record;
private ColumnType dorisType;
Expand Down Expand Up @@ -118,13 +119,12 @@ public byte[] getStringAsBytes() {

@Override
public LocalDate getDate() {
return LocalDate.ofEpochDay(record.getLong(idx));
return LocalDate.ofEpochDay(record.getInt(idx));
}

@Override
public LocalDateTime getDateTime() {
return Instant.ofEpochMilli(record.getTimestamp(idx, 3)
.getMillisecond()).atZone(ZoneOffset.ofHours(0)).toLocalDateTime();
return record.getTimestamp(idx, dorisType.getPrecision()).toLocalDateTime();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,16 @@ public PaimonColumnType visit(VarBinaryType varBinaryType) {

@Override
public PaimonColumnType visit(DecimalType decimalType) {
return new PaimonColumnType(Type.DECIMAL128, decimalType.getPrecision(), decimalType.getScale());
int precision = decimalType.getPrecision();
Type type;
if (precision <= ColumnType.MAX_DECIMAL32_PRECISION) {
type = Type.DECIMAL32;
} else if (precision <= ColumnType.MAX_DECIMAL64_PRECISION) {
type = Type.DECIMAL64;
} else {
type = Type.DECIMAL128;
}
return new PaimonColumnType(type, decimalType.getPrecision(), decimalType.getScale());
}

@Override
Expand Down
Loading

0 comments on commit f38e11e

Please sign in to comment.