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](partitionkey) serialize expr in PartitionKey via gson #37277

Merged
merged 4 commits into from
Jul 5, 2024
Merged
Changes from 1 commit
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
Prev Previous commit
Next Next commit
fix
  • Loading branch information
dataroaring committed Jul 4, 2024
commit 226229f67ce4facfde23410c7cadbac6b52942e9
Original file line number Diff line number Diff line change
Expand Up @@ -528,6 +528,7 @@ public JsonElement serialize(PartitionKey partitionKey, java.lang.reflect.Type r
typeAndKey.add(context.serialize(keys.get(i)));
jsonArray.add(typeAndKey);
}

return jsonArray;
}

Expand All @@ -541,10 +542,35 @@ public PartitionKey deserialize(JsonElement json, java.lang.reflect.Type typeOfT

JsonArray jsonArray = json.getAsJsonArray();
for (int i = 0; i < jsonArray.size(); i++) {
partitionKey.types.add(context.deserialize(jsonArray.get(i).getAsJsonArray().get(0),
PrimitiveType.class));
partitionKey.keys.add(context.deserialize(jsonArray.get(i).getAsJsonArray().get(1),
Expr.class));
PrimitiveType type = null;
type = context.deserialize(jsonArray.get(i).getAsJsonArray().get(0), PrimitiveType.class);
LiteralExpr key = context.deserialize(jsonArray.get(i).getAsJsonArray().get(1), Expr.class);

if (key instanceof NullLiteral) {
key = NullLiteral.create(Type.fromPrimitiveType(type));
partitionKey.types.add(type);
partitionKey.keys.add(key);
continue;
}
if (key instanceof MaxLiteral) {
key = MaxLiteral.MAX_VALUE;
}
if (type != PrimitiveType.DATETIMEV2) {
key.setType(Type.fromPrimitiveType(type));
}
if (type.isDateV2Type()) {
try {
key.checkValueValid();
} catch (AnalysisException e) {
LOG.warn("Value {} for partition key [type = {}] is invalid! This is a bug exists "
+ "in Doris 1.2.0 and fixed since Doris 1.2.1. You should create this table "
+ "again using Doris 1.2.1+ .", key.getStringValue(), type);
((DateLiteral) key).setMinValue();
}
}

partitionKey.types.add(type);
partitionKey.keys.add(key);
}
return partitionKey;
}
Expand Down
Loading