forked from apache/doris
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[fix](gson) Fix Expr deserialize compatibility
Since GsonBuilder.create() adds all registered factories to GSON in reverse order, and ExprAdapterFactory is registered before the RuntimeTypeAdapterFactory for Expr, ExprAdapterFactory will not be executed. This PR adjusts their registration order. Now, it will first check in ExprAdapterFactory whether to use the pre-134 deserialize method, and then attempt to use the RuntimeTypeAdapterFactory for Expr.class.
- Loading branch information
Showing
3 changed files
with
74 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
fe/fe-core/src/test/java/org/apache/doris/persist/ExprTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
// Licensed to the Apache Software Foundation (ASF) under one | ||
// or more contributor license agreements. See the NOTICE file | ||
// distributed with this work for additional information | ||
// regarding copyright ownership. The ASF licenses this file | ||
// to you under the Apache License, Version 2.0 (the | ||
// "License"); you may not use this file except in compliance | ||
// with the License. You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, | ||
// software distributed under the License is distributed on an | ||
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
// KIND, either express or implied. See the License for the | ||
// specific language governing permissions and limitations | ||
// under the License. | ||
|
||
package org.apache.doris.persist; | ||
|
||
import org.apache.doris.analysis.Expr; | ||
import org.apache.doris.common.FeMetaVersion; | ||
import org.apache.doris.meta.MetaContext; | ||
import org.apache.doris.persist.gson.GsonUtils; | ||
import org.apache.doris.persist.gson.GsonUtils134; | ||
|
||
import com.google.gson.annotations.SerializedName; | ||
import org.apache.logging.log4j.LogManager; | ||
import org.apache.logging.log4j.Logger; | ||
import org.junit.Test; | ||
|
||
public class ExprTest { | ||
private static final Logger LOG = LogManager.getLogger(ExprTest.class); | ||
|
||
private static class ExprWrapper { | ||
@SerializedName("expr") | ||
private Expr expr; | ||
} | ||
|
||
@Test | ||
public void testExprDeserializeCompatibility() { | ||
LOG.info("run testDeserializeExprWithMetaVersion134 test"); | ||
|
||
String serializedString = "{\"expr\":{\"expr\": \"AAAADAAAAAAKZGF0ZV90cnVuYwAAAQAAAAIAAAABAAAAAANkYXkAAAAIAAAABW1vbnRoAAA\\u003d\"}}"; | ||
|
||
MetaContext ctx = new MetaContext(); | ||
ctx.setMetaVersion(FeMetaVersion.VERSION_129); | ||
ctx.setThreadLocalInfo(); | ||
GsonUtils134.GSON.fromJson(serializedString, ExprWrapper.class); | ||
GsonUtils.GSON.fromJson(serializedString, ExprWrapper.class); | ||
MetaContext.remove(); | ||
} | ||
} |