forked from opensearch-project/sql
-
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.
Add table write operator and builder (opensearch-project#1094)
* Add table write operator and builder Signed-off-by: Chen Dai <[email protected]> * Add UT for all new classes Signed-off-by: Chen Dai <[email protected]> * Rename child field Signed-off-by: Chen Dai <[email protected]> * Add columns field Signed-off-by: Chen Dai <[email protected]> * Update javadoc to prepare PR Signed-off-by: Chen Dai <[email protected]> Signed-off-by: Chen Dai <[email protected]>
- Loading branch information
1 parent
eb595c7
commit ecdd4b8
Showing
16 changed files
with
360 additions
and
1 deletion.
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
42 changes: 42 additions & 0 deletions
42
core/src/main/java/org/opensearch/sql/planner/logical/LogicalWrite.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,42 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package org.opensearch.sql.planner.logical; | ||
|
||
import java.util.Collections; | ||
import java.util.List; | ||
import lombok.EqualsAndHashCode; | ||
import lombok.Getter; | ||
import lombok.ToString; | ||
import org.opensearch.sql.storage.Table; | ||
|
||
/** | ||
* Logical operator for insert statement. | ||
*/ | ||
@EqualsAndHashCode(callSuper = true) | ||
@Getter | ||
@ToString | ||
public class LogicalWrite extends LogicalPlan { | ||
|
||
/** Table that handles the write operation. */ | ||
private final Table table; | ||
|
||
/** Optional column name list specified in insert statement. */ | ||
private final List<String> columns; | ||
|
||
/** | ||
* Construct a logical write with given child node, table and column name list. | ||
*/ | ||
public LogicalWrite(LogicalPlan child, Table table, List<String> columns) { | ||
super(Collections.singletonList(child)); | ||
this.table = table; | ||
this.columns = columns; | ||
} | ||
|
||
@Override | ||
public <R, C> R accept(LogicalPlanNodeVisitor<R, C> visitor, C context) { | ||
return visitor.visitWrite(this, context); | ||
} | ||
} |
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
...rc/main/java/org/opensearch/sql/planner/optimizer/rule/write/CreateTableWriteBuilder.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 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package org.opensearch.sql.planner.optimizer.rule.write; | ||
|
||
import static org.opensearch.sql.planner.optimizer.pattern.Patterns.writeTable; | ||
|
||
import com.facebook.presto.matching.Capture; | ||
import com.facebook.presto.matching.Captures; | ||
import com.facebook.presto.matching.Pattern; | ||
import lombok.Getter; | ||
import lombok.experimental.Accessors; | ||
import org.opensearch.sql.planner.logical.LogicalPlan; | ||
import org.opensearch.sql.planner.logical.LogicalWrite; | ||
import org.opensearch.sql.planner.optimizer.Rule; | ||
import org.opensearch.sql.storage.Table; | ||
import org.opensearch.sql.storage.write.TableWriteBuilder; | ||
|
||
/** | ||
* Rule that replaces logical write operator with {@link TableWriteBuilder} for later optimization | ||
* and transforming to physical operator. | ||
*/ | ||
public class CreateTableWriteBuilder implements Rule<LogicalWrite> { | ||
|
||
/** Capture the table inside matched logical relation operator. */ | ||
private final Capture<Table> capture; | ||
|
||
/** Pattern that matches logical relation operator. */ | ||
@Accessors(fluent = true) | ||
@Getter | ||
private final Pattern<LogicalWrite> pattern; | ||
|
||
/** | ||
* Construct create table write builder rule. | ||
*/ | ||
public CreateTableWriteBuilder() { | ||
this.capture = Capture.newCapture(); | ||
this.pattern = Pattern.typeOf(LogicalWrite.class) | ||
.with(writeTable().capturedAs(capture)); | ||
} | ||
|
||
@Override | ||
public LogicalPlan apply(LogicalWrite plan, Captures captures) { | ||
return captures.get(capture).createWriteBuilder(plan); | ||
} | ||
} |
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
40 changes: 40 additions & 0 deletions
40
core/src/main/java/org/opensearch/sql/storage/write/TableWriteBuilder.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,40 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package org.opensearch.sql.storage.write; | ||
|
||
import java.util.Collections; | ||
import org.opensearch.sql.planner.logical.LogicalPlan; | ||
import org.opensearch.sql.planner.logical.LogicalPlanNodeVisitor; | ||
import org.opensearch.sql.planner.physical.PhysicalPlan; | ||
|
||
/** | ||
* A {@link TableWriteBuilder} represents transition state between logical planning and physical | ||
* planning for table write operator. The concrete implementation class gets involved in the logical | ||
* optimization through this abstraction and thus transform to specific {@link TableWriteOperator} | ||
* in a certain storage engine. | ||
*/ | ||
public abstract class TableWriteBuilder extends LogicalPlan { | ||
|
||
/** | ||
* Construct table write builder with child node. | ||
*/ | ||
public TableWriteBuilder(LogicalPlan child) { | ||
super(Collections.singletonList(child)); | ||
} | ||
|
||
/** | ||
* Build table write operator with given child node. | ||
* | ||
* @param child child operator node | ||
* @return table write operator | ||
*/ | ||
public abstract TableWriteOperator build(PhysicalPlan child); | ||
|
||
@Override | ||
public <R, C> R accept(LogicalPlanNodeVisitor<R, C> visitor, C context) { | ||
return visitor.visitTableWriteBuilder(this, context); | ||
} | ||
} |
41 changes: 41 additions & 0 deletions
41
core/src/main/java/org/opensearch/sql/storage/write/TableWriteOperator.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,41 @@ | ||
/* | ||
* Copyright OpenSearch Contributors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package org.opensearch.sql.storage.write; | ||
|
||
import java.util.Collections; | ||
import java.util.List; | ||
import lombok.RequiredArgsConstructor; | ||
import org.opensearch.sql.planner.physical.PhysicalPlan; | ||
import org.opensearch.sql.planner.physical.PhysicalPlanNodeVisitor; | ||
|
||
/** | ||
* {@link TableWriteOperator} is the abstraction for data source to implement different physical | ||
* write operator on a data source. This is also to avoid "polluting" physical plan visitor by | ||
* concrete table scan implementation. | ||
*/ | ||
@RequiredArgsConstructor | ||
public abstract class TableWriteOperator extends PhysicalPlan { | ||
|
||
/** Input physical node. */ | ||
protected final PhysicalPlan input; | ||
|
||
@Override | ||
public <R, C> R accept(PhysicalPlanNodeVisitor<R, C> visitor, C context) { | ||
return visitor.visitTableWrite(this, context); | ||
} | ||
|
||
@Override | ||
public List<PhysicalPlan> getChild() { | ||
return Collections.singletonList(input); | ||
} | ||
|
||
/** | ||
* Explain the execution plan. | ||
* | ||
* @return explain output | ||
*/ | ||
public abstract String explain(); | ||
} |
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
Oops, something went wrong.