forked from apache/flink
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FLINK-26055][table] Use FlinkVersion rather than version string from…
… core in persisted plan This closes apache#18755.
- Loading branch information
1 parent
54cedcb
commit 009d255
Showing
10 changed files
with
217 additions
and
12 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
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
48 changes: 48 additions & 0 deletions
48
...va/org/apache/flink/table/planner/plan/nodes/exec/serde/FlinkVersionJsonDeserializer.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,48 @@ | ||
/* | ||
* 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:https://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.flink.table.planner.plan.nodes.exec.serde; | ||
|
||
import org.apache.flink.FlinkVersion; | ||
import org.apache.flink.table.api.ValidationException; | ||
|
||
import org.apache.flink.shaded.jackson2.com.fasterxml.jackson.core.JsonParser; | ||
import org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.DeserializationContext; | ||
import org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.deser.std.StdDeserializer; | ||
|
||
import java.io.IOException; | ||
|
||
/** JSON deserializer for {@link FlinkVersion}. */ | ||
public class FlinkVersionJsonDeserializer extends StdDeserializer<FlinkVersion> { | ||
private static final long serialVersionUID = 1L; | ||
|
||
public FlinkVersionJsonDeserializer() { | ||
super(FlinkVersion.class); | ||
} | ||
|
||
@Override | ||
public FlinkVersion deserialize(JsonParser jsonParser, DeserializationContext ctx) | ||
throws IOException { | ||
String codeString = jsonParser.getValueAsString(); | ||
return FlinkVersion.byCode(codeString) | ||
.orElseThrow( | ||
() -> | ||
new ValidationException( | ||
"Unknown Flink version '" + codeString + "'")); | ||
} | ||
} |
45 changes: 45 additions & 0 deletions
45
...java/org/apache/flink/table/planner/plan/nodes/exec/serde/FlinkVersionJsonSerializer.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,45 @@ | ||
/* | ||
* 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:https://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.flink.table.planner.plan.nodes.exec.serde; | ||
|
||
import org.apache.flink.FlinkVersion; | ||
|
||
import org.apache.flink.shaded.jackson2.com.fasterxml.jackson.core.JsonGenerator; | ||
import org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.SerializerProvider; | ||
import org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.ser.std.StdSerializer; | ||
|
||
import java.io.IOException; | ||
|
||
/** JSON serializer for {@link FlinkVersion}. */ | ||
public class FlinkVersionJsonSerializer extends StdSerializer<FlinkVersion> { | ||
private static final long serialVersionUID = 1L; | ||
|
||
public FlinkVersionJsonSerializer() { | ||
super(FlinkVersion.class); | ||
} | ||
|
||
@Override | ||
public void serialize( | ||
FlinkVersion flinkVersion, | ||
JsonGenerator jsonGenerator, | ||
SerializerProvider serializerProvider) | ||
throws IOException { | ||
jsonGenerator.writeString(flinkVersion.toString()); | ||
} | ||
} |
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
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
53 changes: 53 additions & 0 deletions
53
.../java/org/apache/flink/table/planner/plan/nodes/exec/serde/FlinkVersionJsonSerdeTest.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,53 @@ | ||
/* | ||
* 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:https://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.flink.table.planner.plan.nodes.exec.serde; | ||
|
||
import org.apache.flink.FlinkVersion; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.parallel.Execution; | ||
import org.junit.jupiter.params.ParameterizedTest; | ||
import org.junit.jupiter.params.provider.EnumSource; | ||
|
||
import java.io.IOException; | ||
|
||
import static org.apache.flink.table.planner.plan.nodes.exec.serde.JsonSerdeTestUtil.configuredSerdeContext; | ||
import static org.apache.flink.table.planner.plan.nodes.exec.serde.JsonSerdeTestUtil.testJsonRoundTrip; | ||
import static org.apache.flink.table.planner.plan.nodes.exec.serde.JsonSerdeTestUtil.toJson; | ||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.junit.jupiter.api.parallel.ExecutionMode.CONCURRENT; | ||
|
||
/** Tests for {@link FlinkVersion} serialization and deserialization. */ | ||
@Execution(CONCURRENT) | ||
final class FlinkVersionJsonSerdeTest { | ||
|
||
@ParameterizedTest | ||
@EnumSource(FlinkVersion.class) | ||
void testFlinkVersions(FlinkVersion flinkVersion) throws IOException { | ||
testJsonRoundTrip(flinkVersion, FlinkVersion.class); | ||
} | ||
|
||
@Test | ||
void testManualString() throws IOException { | ||
final String flinkVersion = "1.15"; | ||
|
||
assertThat(toJson(configuredSerdeContext(), FlinkVersion.v1_15)) | ||
.isEqualTo(JsonSerdeUtil.getObjectMapper().writeValueAsString(flinkVersion)); | ||
} | ||
} |
46 changes: 46 additions & 0 deletions
46
...flink-table-planner/src/test/java/org/apache/flink/table/planner/utils/JsonTestUtils.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,46 @@ | ||
/* | ||
* 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:https://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.flink.table.planner.utils; | ||
|
||
import org.apache.flink.FlinkVersion; | ||
import org.apache.flink.table.planner.plan.nodes.exec.serde.JsonSerdeUtil; | ||
|
||
import org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.JsonNode; | ||
import org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.node.ObjectNode; | ||
|
||
import java.io.IOException; | ||
|
||
/** This class contains a collection of generic utilities to deal with JSON in tests. */ | ||
public final class JsonTestUtils { | ||
|
||
private JsonTestUtils() {} | ||
|
||
public static JsonNode readFromResource(String path) throws IOException { | ||
return JsonSerdeUtil.getObjectMapper().readTree(JsonTestUtils.class.getResource(path)); | ||
} | ||
|
||
public static JsonNode setFlinkVersion(JsonNode target, FlinkVersion flinkVersion) { | ||
return ((ObjectNode) target) | ||
.set("flinkVersion", JsonSerdeUtil.getObjectMapper().valueToTree(flinkVersion)); | ||
} | ||
|
||
public static JsonNode clearFlinkVersion(JsonNode target) { | ||
return ((ObjectNode) target).remove("flinkVersion"); | ||
} | ||
} |