forked from opensearch-project/sql
-
Notifications
You must be signed in to change notification settings - Fork 0
Rework on serialization and deserialization #252
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
Closed
Closed
Changes from 7 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
ef44600
Step 1.
Yury-Fridlyand 93a82ad
Minor cleanup.
Yury-Fridlyand ecc1c9a
Optimize serialization of `ProjectOperator`.
Yury-Fridlyand 430323c
Minor cleaning and commenting.
Yury-Fridlyand 8350d9c
Move `ExpressionSerializer` back to `:opensearch`.
Yury-Fridlyand 67ce92d
Add tests.
Yury-Fridlyand 490af96
Address PR feedback.
Yury-Fridlyand 10ba1d6
Complete rework on serialization and deserialization.
Yury-Fridlyand 0ff3390
Minor fix for serialization.
Yury-Fridlyand File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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
70 changes: 70 additions & 0 deletions
70
core/src/main/java/org/opensearch/sql/planner/SerializablePlan.java
This file contains hidden or 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,70 @@ | ||
| /* | ||
| * Copyright OpenSearch Contributors | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| package org.opensearch.sql.planner; | ||
|
|
||
| import java.io.Externalizable; | ||
| import java.io.IOException; | ||
| import java.io.ObjectInput; | ||
| import java.io.ObjectOutput; | ||
| import java.io.Serializable; | ||
| import org.apache.commons.lang3.NotImplementedException; | ||
| import org.opensearch.sql.storage.StorageEngine; | ||
|
|
||
| /** | ||
| * All instances of PhysicalPlan which needs to be serialized (in cursor feature) should | ||
| * override all given here methods. | ||
| * This class can't implement Externalizable, because deserialization of Externalizable objects | ||
| * works the following way: | ||
| * 1. A new object created with no-arg constructor (no PhysicalPlan has it) | ||
| * 2. Object loads data from the stream. | ||
| * {@link Externalizable} interface was split into two pars: serialization is kept with | ||
| * {@link #writeExternal}, but deserialization is provided by {@link PlanLoader}. | ||
| */ | ||
| public abstract class SerializablePlan { | ||
|
|
||
| // Copied from Externalizable | ||
| /** | ||
| * Each plan which supports serialization should dump itself into the stream and go recursive. | ||
| * It is good to create and dump a {@link PlanLoader} here as well. See usage samples. | ||
| * <pre>{@code | ||
| * out.writeSomething(data); | ||
| * for (var plan : getChild()) { | ||
| * plan.getPlanForSerialization().writeExternal(out); | ||
| * } | ||
| * }</pre> | ||
| */ | ||
| public boolean writeExternal(ObjectOutput out) throws IOException { | ||
| throw new NotImplementedException(); | ||
| } | ||
|
|
||
| /** | ||
| * Override to return child or delegated plan, so parent plan should skip this one | ||
| * for serialization, but it should try to serialize grandchild plan. | ||
| * Imagine plan structure like this | ||
| * A -> this | ||
| * `- B -> child | ||
| * `- C -> this | ||
| * In that case only plans A and C should be attempted to serialize. | ||
| * It is needed to skip a `ResourceMonitorPlan` instance only, actually. | ||
| * @return Next plan for serialization. | ||
| */ | ||
| public SerializablePlan getPlanForSerialization() { | ||
| return this; | ||
| } | ||
|
|
||
| /** | ||
| * Each plan should serialize an instance of this function. | ||
| * The function deserializes and creates a new instance of that plan type. | ||
| * A loader of a plan X could be defined only in scope of X, because only X | ||
| * knows how to create a new X. | ||
| * Deserialization should match with serialization given in {@link #writeExternal}. | ||
| */ | ||
| @FunctionalInterface | ||
| public interface PlanLoader extends Serializable { | ||
| SerializablePlan apply(ObjectInput in, StorageEngine engine) | ||
| throws IOException, ClassNotFoundException; | ||
| } | ||
Yury-Fridlyand marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.