Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
Zouxxyy committed Jan 15, 2024
1 parent 24152d4 commit 516d289
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 15 deletions.
26 changes: 15 additions & 11 deletions paimon-core/src/main/java/org/apache/paimon/stats/ColStats.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,10 @@
* <li>avgLen: average column length
* <li>maxLen: max column length
* </ul>
*
* @param <T> col internal data type
*/
public class ColStats<T extends Comparable<T>> {
public class ColStats<T> {

private static final String FIELD_DISTINCT_COUNT = "distinctCount";
private static final String FIELD_MIN = "min";
Expand All @@ -62,13 +64,13 @@ public class ColStats<T extends Comparable<T>> {
@JsonProperty(FIELD_MIN)
private @Nullable String serializedMin;

private @Nullable T min;
private @Nullable Comparable<T> min;

@JsonInclude(JsonInclude.Include.NON_NULL)
@JsonProperty(FIELD_MAX)
private @Nullable String serializedMax;

private @Nullable T max;
private @Nullable Comparable<T> max;

@JsonInclude(JsonInclude.Include.NON_NULL)
@JsonProperty(FIELD_NULL_COUNT)
Expand Down Expand Up @@ -100,8 +102,8 @@ public ColStats(

public ColStats(
@Nullable Long distinctCount,
@Nullable T min,
@Nullable T max,
@Nullable Comparable<T> min,
@Nullable Comparable<T> max,
@Nullable Long nullCount,
@Nullable Long avgLen,
@Nullable Long maxLen) {
Expand All @@ -117,11 +119,11 @@ public OptionalLong distinctCount() {
return OptionalUtils.ofNullable(distinctCount);
}

public Optional<T> min() {
public Optional<Comparable<T>> min() {
return Optional.ofNullable(min);
}

public Optional<T> max() {
public Optional<Comparable<T>> max() {
return Optional.ofNullable(max);
}

Expand All @@ -137,26 +139,28 @@ public OptionalLong maxLen() {
return OptionalUtils.ofNullable(maxLen);
}

@SuppressWarnings("unchecked")
public void serializeFieldsToString(DataType dataType) {
if ((min != null && serializedMin == null) || (max != null && serializedMax == null)) {
Serializer<T> serializer = InternalSerializers.create(dataType);
if (min != null && serializedMin == null) {
serializedMin = serializer.serializeToString(min);
serializedMin = serializer.serializeToString((T) min);
}
if (max != null && serializedMax == null) {
serializedMax = serializer.serializeToString(max);
serializedMax = serializer.serializeToString((T) max);
}
}
}

@SuppressWarnings("unchecked")
public void deserializeFieldsFromString(DataType dataType) {
if ((serializedMin != null && min == null) || (serializedMax != null && max == null)) {
Serializer<T> serializer = InternalSerializers.create(dataType);
if (serializedMin != null && min == null) {
min = serializer.deserializeFromString(serializedMin);
min = (Comparable<T>) serializer.deserializeFromString(serializedMin);
}
if (serializedMax != null && max == null) {
max = serializer.deserializeFromString(serializedMax);
max = (Comparable<T>) serializer.deserializeFromString(serializedMax);
}
}
}
Expand Down
11 changes: 9 additions & 2 deletions paimon-core/src/main/java/org/apache/paimon/stats/Stats.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
*/
public class Stats {

// SnapshotId that stats belongs to
private static final String FIELD_SNAPSHOT_ID = "snapshotId";
private static final String FIELD_MERGED_RECORD_COUNT = "mergedRecordCount";
private static final String FIELD_MERGED_RECORD_SIZE = "mergedRecordSize";
Expand Down Expand Up @@ -109,7 +110,10 @@ public void serializeFieldsToString(TableSchema schema) {
schema.fields().stream()
.filter(field -> field.name().equals(colName))
.findFirst()
.get()
.orElseThrow(
() ->
new IllegalStateException(
"Unable to obtain the latest schema"))
.type();
colStats.serializeFieldsToString(type);
}
Expand All @@ -129,7 +133,10 @@ public void deserializeFieldsFromString(TableSchema schema) {
schema.fields().stream()
.filter(field -> field.name().equals(colName))
.findFirst()
.get()
.orElseThrow(
() ->
new IllegalStateException(
"Unable to obtain the latest schema"))
.type();
colStats.deserializeFieldsFromString(type);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@ public String writeStats(Stats stats) {
schemaManager
.latest()
.orElseThrow(
() -> new IllegalStateException("Latest schema cannot be found")));
() ->
new IllegalStateException(
"Unable to obtain the latest schema")));
return statsFile.write(stats);
}

Expand All @@ -60,7 +62,7 @@ public String writeStats(Stats stats) {
public Optional<Stats> readStats() {
Long latestSnapshotId = snapshotManager.latestSnapshotId();
if (latestSnapshotId == null) {
throw new IllegalStateException("Latest snapshot cannot be found");
throw new IllegalStateException("Unable to obtain the latest schema");
}
return readStats(latestSnapshotId);
}
Expand Down

0 comments on commit 516d289

Please sign in to comment.