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 8 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
13 changes: 13 additions & 0 deletions
13
core/src/main/java/org/opensearch/sql/exception/NoCursorException.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,13 @@ | ||
| /* | ||
| * Copyright OpenSearch Contributors | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| package org.opensearch.sql.exception; | ||
|
|
||
| /** | ||
| * This should be thrown on serialization of a PhysicalPlan tree if paging is finished. | ||
| * Processing of such exception should outcome of responding no cursor to the user. | ||
| */ | ||
| public class NoCursorException extends RuntimeException { | ||
| } |
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
71 changes: 71 additions & 0 deletions
71
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,71 @@ | ||
| /* | ||
| * 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.ObjectInputStream; | ||
| import java.io.ObjectOutput; | ||
| import org.apache.commons.lang3.NotImplementedException; | ||
| import org.opensearch.sql.executor.pagination.PaginatedPlanCache; | ||
|
|
||
| /** | ||
| * All subtypes of PhysicalPlan which needs to be serialized (in cursor, for pagination feature) | ||
| * should follow one of the following options. | ||
| * <ul> | ||
| * <li>Both: | ||
| * <ul> | ||
| * <li>Override both methods from {@link Externalizable}.</li> | ||
| * <li>Define a public no-arg constructor.</li> | ||
| * </ul> | ||
| * </li> | ||
| * <li> | ||
| * Overwrite {@link #getPlanForSerialization} to return | ||
| * another instance of {@link SerializablePlan}. | ||
| * </li> | ||
| * </ul> | ||
| */ | ||
| public interface SerializablePlan extends Externalizable { | ||
|
|
||
| /** | ||
| * Argument is an instance of {@link PaginatedPlanCache.CursorDeserializationStream}. | ||
| */ | ||
| @Override | ||
| default void readExternal(ObjectInput in) throws IOException, ClassNotFoundException { | ||
| throw new NotImplementedException(String.format("`readExternal` is not implemented in %s", | ||
| getClass().getSimpleName())); | ||
| } | ||
|
|
||
| /** | ||
| * Each plan which has as a child plan should do. | ||
| * <pre>{@code | ||
| * out.writeObject(input.getPlanForSerialization()); | ||
| * }</pre> | ||
| */ | ||
| @Override | ||
| default void writeExternal(ObjectOutput out) throws IOException { | ||
| throw new NotImplementedException(String.format("`readExternal` is not implemented in %s", | ||
| getClass().getSimpleName())); | ||
| } | ||
|
|
||
| /** | ||
| * 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 | ||
| * <pre> | ||
| * A -> this | ||
| * `- B -> child | ||
| * `- C -> this | ||
| * </pre> | ||
| * 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. | ||
| */ | ||
| default SerializablePlan getPlanForSerialization() { | ||
| return this; | ||
| } | ||
| } |
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When can
ClassCastExceptionbe thrown?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We are always trying to convert a plan tree to a cursor in
opensearch-project-sql/opensearch/src/main/java/org/opensearch/sql/opensearch/executor/OpenSearchExecutionEngine.java
Line 55 in 10ba1d6
If tree contains a plan which doesn't implement
SerializablePlan, there would be aClassCastExceptionsomewhere, e.g. inopensearch-project-sql/opensearch/src/main/java/org/opensearch/sql/opensearch/executor/protector/ResourceMonitorPlan.java
Lines 93 to 96 in 10ba1d6
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't serialize
PaginateOperator(to reduce cursor size), so I can't checkplan instanceof PaginateOperatorhere as it was before.opensearch-project-sql/core/src/main/java/org/opensearch/sql/planner/physical/PaginateOperator.java
Lines 69 to 73 in 0ff3390
That means I have to do another protection here. The incoming tree could be
ProjectOperator -> ResourceMonitorPlan -> PrometheusIndexScanorProjectOperator -> ValuesOperator.