-
Notifications
You must be signed in to change notification settings - Fork 141
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Complete rework on serialization and deserialization. (#1498)
Signed-off-by: Yury-Fridlyand <[email protected]>
- Loading branch information
1 parent
b9cb0d0
commit 9a1a17c
Showing
45 changed files
with
607 additions
and
685 deletions.
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 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 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
70 changes: 70 additions & 0 deletions
70
core/src/main/java/org/opensearch/sql/planner/SerializablePlan.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,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 org.apache.commons.lang3.NotImplementedException; | ||
import org.opensearch.sql.executor.pagination.PlanSerializer; | ||
|
||
/** | ||
* 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 PlanSerializer.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; | ||
} | ||
} |
Oops, something went wrong.