-
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.
- Loading branch information
Showing
13 changed files
with
167 additions
and
14 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
39 changes: 39 additions & 0 deletions
39
partiql-planner/src/main/kotlin/org/partiql/planner/internal/IdentifierManager.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,39 @@ | ||
package org.partiql.planner.internal | ||
|
||
import org.partiql.ast.Binder | ||
import org.partiql.ast.Identifier | ||
import org.partiql.ast.binder | ||
import org.partiql.ast.identifierSymbol | ||
|
||
internal class IdentifierManager( | ||
val casePreservation: Boolean, | ||
val rValue: RValue | ||
) { | ||
fun normalizeBinder(binder: Binder): Binder = | ||
when (binder.caseSensitivity) { | ||
Binder.CaseSensitivity.SENSITIVE -> binder | ||
Binder.CaseSensitivity.INSENSITIVE -> { | ||
if (casePreservation) { | ||
binder(binder.symbol, Binder.CaseSensitivity.SENSITIVE) | ||
} | ||
// This is a conscious decision | ||
// Even though the case preservation is off, we still need a way to store the binder | ||
// To make this compatible with the current implementation, | ||
// the decision here is: we normalize by preserving case. | ||
else { | ||
binder(binder.symbol, Binder.CaseSensitivity.SENSITIVE) | ||
} | ||
} | ||
} | ||
|
||
fun normalizeRvalue(id: Identifier.Symbol): Identifier.Symbol = | ||
when (id.caseSensitivity) { | ||
Identifier.CaseSensitivity.SENSITIVE -> id | ||
Identifier.CaseSensitivity.INSENSITIVE -> when (rValue) { | ||
RValue.FOLDING_UP -> identifierSymbol(id.symbol.uppercase(), Identifier.CaseSensitivity.SENSITIVE) | ||
RValue.FOLDING_DOWN -> identifierSymbol(id.symbol.lowercase(), Identifier.CaseSensitivity.SENSITIVE) | ||
RValue.SENSITIVE -> identifierSymbol(id.symbol, Identifier.CaseSensitivity.SENSITIVE) | ||
RValue.INSENSITIVE -> identifierSymbol(id.symbol, Identifier.CaseSensitivity.INSENSITIVE) | ||
} | ||
} | ||
} |
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
41 changes: 41 additions & 0 deletions
41
...iql-planner/src/main/kotlin/org/partiql/planner/internal/astPasses/NormalizeIdentifier.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,41 @@ | ||
package org.partiql.planner.internal.astPasses | ||
|
||
import org.partiql.ast.Binder | ||
import org.partiql.ast.Identifier | ||
import org.partiql.ast.Statement | ||
import org.partiql.ast.normalize.AstPass | ||
import org.partiql.ast.util.AstRewriter | ||
import org.partiql.planner.internal.IdentifierManager | ||
import org.partiql.planner.internal.RValue | ||
|
||
/** | ||
* Case Preservation: | ||
* - If on, turn case-insensitive binder to case-sensitive binder, with symbol preserve the original case | ||
* - If off, normalize the binder. | ||
* - The normalization function in the spec perhaps will end up being implementation defined. | ||
* - Therefore, for now we normalize by preserving case. | ||
* - This is to stay consistent with the current behavior, and reduce one moving element during testing.... | ||
* | ||
* Identifier Normalization: | ||
* - Determines the normalization for identifier (variable look up) | ||
* - Folding down: Using lower case text to look up | ||
* - Folding up: Using upper case text to look up. | ||
* - Case Sensitive: Using original text to look up | ||
* - Case Insensitive: Matching behavior, string comparison with case ignored. | ||
*/ | ||
internal class NormalizeIdentifier( | ||
casePreservation: Boolean, | ||
rValue: RValue | ||
) : AstPass { | ||
|
||
val identifierManager = IdentifierManager(casePreservation, rValue) | ||
override fun apply(statement: Statement): Statement = Visitor(identifierManager).visitStatement(statement, Unit) as Statement | ||
|
||
private class Visitor(val identifierManager: IdentifierManager) : AstRewriter<Unit>() { | ||
|
||
override fun visitIdentifierSymbol(node: Identifier.Symbol, ctx: Unit) = | ||
identifierManager.normalizeRvalue(node) | ||
|
||
override fun visitBinder(node: Binder, ctx: Unit) = identifierManager.normalizeBinder(node) | ||
} | ||
} |
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