-
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.
Adds CURRENT_USER and CURRENT_DATE to transpiler (#1228)
- Loading branch information
Showing
18 changed files
with
181 additions
and
18 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
1 change: 0 additions & 1 deletion
1
...tiql-transpiler/src/main/kotlin/org/partiql/transpiler/targets/redshift/RedshiftTarget.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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -277,6 +277,7 @@ expr::[ | |
session_attribute::{ | ||
attribute: [ | ||
CURRENT_USER, | ||
CURRENT_DATE, | ||
], | ||
}, | ||
|
||
|
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
85 changes: 85 additions & 0 deletions
85
partiql-parser/src/test/kotlin/org/partiql/parser/impl/PartiQLParserSessionAttributeTests.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,85 @@ | ||
package org.partiql.parser.impl | ||
|
||
import org.junit.jupiter.api.Test | ||
import org.partiql.ast.AstNode | ||
import org.partiql.ast.Expr | ||
import org.partiql.ast.builder.AstFactory | ||
import org.partiql.value.PartiQLValueExperimental | ||
import org.partiql.value.int64Value | ||
import kotlin.test.assertEquals | ||
|
||
@OptIn(PartiQLValueExperimental::class) | ||
class PartiQLParserSessionAttributeTests { | ||
|
||
private val parser = PartiQLParserDefault() | ||
|
||
private fun query(body: AstFactory.() -> Expr) = AstFactory.create { | ||
statementQuery(this.body()) | ||
} | ||
|
||
@Test | ||
fun currentUserUpperCase() = assertExpression( | ||
"CURRENT_USER", | ||
query { | ||
exprSessionAttribute(Expr.SessionAttribute.Attribute.CURRENT_USER) | ||
} | ||
) | ||
|
||
@Test | ||
fun currentUserMixedCase() = assertExpression( | ||
"CURRENT_user", | ||
query { | ||
exprSessionAttribute(Expr.SessionAttribute.Attribute.CURRENT_USER) | ||
} | ||
) | ||
|
||
@Test | ||
fun currentUserLowerCase() = assertExpression( | ||
"current_user", | ||
query { | ||
exprSessionAttribute(Expr.SessionAttribute.Attribute.CURRENT_USER) | ||
} | ||
) | ||
|
||
@Test | ||
fun currentUserEquals() = assertExpression( | ||
"1 = current_user", | ||
query { | ||
exprBinary( | ||
op = Expr.Binary.Op.EQ, | ||
lhs = exprLit(int64Value(1)), | ||
rhs = exprSessionAttribute(Expr.SessionAttribute.Attribute.CURRENT_USER) | ||
) | ||
} | ||
) | ||
|
||
@Test | ||
fun currentDateUpperCase() = assertExpression( | ||
"CURRENT_DATE", | ||
query { | ||
exprSessionAttribute(Expr.SessionAttribute.Attribute.CURRENT_DATE) | ||
} | ||
) | ||
|
||
@Test | ||
fun currentDateMixedCase() = assertExpression( | ||
"CURRENT_date", | ||
query { | ||
exprSessionAttribute(Expr.SessionAttribute.Attribute.CURRENT_DATE) | ||
} | ||
) | ||
|
||
@Test | ||
fun currentDateLowerCase() = assertExpression( | ||
"current_date", | ||
query { | ||
exprSessionAttribute(Expr.SessionAttribute.Attribute.CURRENT_DATE) | ||
} | ||
) | ||
|
||
private fun assertExpression(input: String, expected: AstNode) { | ||
val result = parser.parse(input) | ||
val actual = result.root | ||
assertEquals(expected, actual) | ||
} | ||
} |
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 |
---|---|---|
|
@@ -182,7 +182,9 @@ rex::{ | |
], | ||
}, | ||
|
||
err::{}, | ||
err::{ | ||
message: string, | ||
}, | ||
], | ||
} | ||
|
||
|
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