-
Notifications
You must be signed in to change notification settings - Fork 62
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[v1] Add v1 ast -> plan conversion; hook up w/ existing code (#1631)
- Loading branch information
Showing
20 changed files
with
1,977 additions
and
39 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
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
2 changes: 1 addition & 1 deletion
2
partiql-planner/src/main/kotlin/org/partiql/planner/PartiQLPlanner.kt
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
75 changes: 75 additions & 0 deletions
75
partiql-planner/src/main/kotlin/org/partiql/planner/internal/transforms/V1AstToPlan.kt
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,75 @@ | ||
/* | ||
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"). | ||
* You may not use this file except in compliance with the License. | ||
* A copy of the License is located at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* or in the "license" file accompanying this file. This file 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.partiql.planner.internal.transforms | ||
|
||
import org.partiql.ast.v1.AstNode | ||
import org.partiql.ast.v1.AstVisitor | ||
import org.partiql.ast.v1.Query | ||
import org.partiql.ast.v1.expr.ExprQuerySet | ||
import org.partiql.planner.internal.Env | ||
import org.partiql.planner.internal.ir.statementQuery | ||
import org.partiql.spi.catalog.Identifier | ||
import org.partiql.ast.v1.Identifier as AstIdentifier | ||
import org.partiql.ast.v1.IdentifierChain as AstIdentifierChain | ||
import org.partiql.ast.v1.Statement as AstStatement | ||
import org.partiql.planner.internal.ir.Statement as PlanStatement | ||
|
||
/** | ||
* Simple translation from AST to an unresolved algebraic IR. | ||
*/ | ||
internal object V1AstToPlan { | ||
|
||
// statement.toPlan() | ||
@JvmStatic | ||
fun apply(statement: AstStatement, env: Env): PlanStatement = statement.accept(ToPlanStatement, env) | ||
|
||
@Suppress("PARAMETER_NAME_CHANGED_ON_OVERRIDE") | ||
private object ToPlanStatement : AstVisitor<PlanStatement, Env>() { | ||
|
||
override fun defaultReturn(node: AstNode, env: Env) = throw IllegalArgumentException("Unsupported statement") | ||
|
||
override fun visitQuery(node: Query, env: Env): PlanStatement { | ||
val rex = when (val expr = node.expr) { | ||
is ExprQuerySet -> V1RelConverter.apply(expr, env) | ||
else -> V1RexConverter.apply(expr, env) | ||
} | ||
return statementQuery(rex) | ||
} | ||
} | ||
|
||
// --- Helpers -------------------- | ||
|
||
fun convert(identifier: AstIdentifierChain): Identifier { | ||
val parts = mutableListOf<Identifier.Part>() | ||
parts.add(part(identifier.root)) | ||
var curStep = identifier.next | ||
while (curStep != null) { | ||
parts.add(part(curStep.root)) | ||
curStep = curStep.next | ||
} | ||
return Identifier.of(parts) | ||
} | ||
|
||
fun convert(identifier: AstIdentifier): Identifier { | ||
return Identifier.of(part(identifier)) | ||
} | ||
|
||
fun part(identifier: AstIdentifier): Identifier.Part = when (identifier.isDelimited) { | ||
true -> Identifier.Part.delimited(identifier.symbol) | ||
false -> Identifier.Part.regular(identifier.symbol) | ||
} | ||
} |
Oops, something went wrong.