-
Notifications
You must be signed in to change notification settings - Fork 66
add: UPPER
, LOWER
and TRIM
support for CHAR/VARCHAR
types
#1839
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 10 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
1e08443
work around string functions support for char/varchar
XuechunHHH b82d886
Dynamic type resolve for upper/lower
XuechunHHH 52cc57d
add trim
XuechunHHH 58c346b
Merge branch 'main' into add--string-fn-support-on-char
XuechunHHH 769b46a
formalize concat
XuechunHHH aea18f8
add trim
XuechunHHH 6333695
update CHANGELOG
XuechunHHH a03a903
update tests names
XuechunHHH 37fe13c
formalize acc. sql2023
XuechunHHH 5a958c8
update changelog
XuechunHHH 489a0f6
update like predicate
XuechunHHH 290c439
update casttableptype; update javadoc; add blob(len) syntax support
XuechunHHH File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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
52 changes: 52 additions & 0 deletions
52
partiql-planner/src/test/kotlin/org/partiql/planner/internal/typer/functions/ConcatTest.kt
This file contains hidden or 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,52 @@ | ||
package org.partiql.planner.internal.typer.functions | ||
|
||
import org.junit.jupiter.api.Test | ||
import org.junit.jupiter.api.assertThrows | ||
import org.partiql.spi.errors.PRuntimeException | ||
|
||
// Basic concat tests are covered in OpConcatTest.kt | ||
class ConcatTest { | ||
private val maxInt = Int.MAX_VALUE | ||
|
||
@Test | ||
fun `concat with VARCHAR overflow throws exception`() { | ||
assertThrows<PRuntimeException> { | ||
FnTestUtils.getQueryResultType("CAST('some string' AS VARCHAR($maxInt)) || CAST('a' AS VARCHAR(1))") | ||
} | ||
} | ||
|
||
@Test | ||
fun `concat with CHAR overflow throws exception`() { | ||
assertThrows<PRuntimeException> { | ||
FnTestUtils.getQueryResultType("CAST('some string' AS CHAR($maxInt)) || CAST('a' AS CHAR(1))") | ||
} | ||
} | ||
|
||
@Test | ||
fun `concat with CLOB overflow throws exception`() { | ||
assertThrows<PRuntimeException> { | ||
FnTestUtils.getQueryResultType("CAST('some string' AS CLOB($maxInt)) || CAST('a' AS CLOB(1))") | ||
} | ||
} | ||
|
||
@Test | ||
fun `concat with VARCHAR and CHAR overflow throws exception`() { | ||
assertThrows<PRuntimeException> { | ||
FnTestUtils.getQueryResultType("CAST('some string' AS VARCHAR($maxInt)) || CAST('a' AS CHAR(1))") | ||
} | ||
} | ||
|
||
@Test | ||
fun `concat with CLOB and CHAR overflow throws exception`() { | ||
assertThrows<PRuntimeException> { | ||
FnTestUtils.getQueryResultType("CAST('some string' AS CLOB($maxInt)) || CAST('a' AS CHAR(1))") | ||
} | ||
} | ||
|
||
@Test | ||
fun `concat with CLOB and VARCHAR overflow throws exception`() { | ||
assertThrows<PRuntimeException> { | ||
FnTestUtils.getQueryResultType("CAST('some string' AS CLOB($maxInt)) || CAST('a' AS VARCHAR(1))") | ||
} | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
partiql-planner/src/test/kotlin/org/partiql/planner/internal/typer/functions/FnTestUtils.kt
This file contains hidden or 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,30 @@ | ||
package org.partiql.planner.internal.typer.functions | ||
|
||
import org.partiql.parser.PartiQLParser | ||
import org.partiql.plan.Action | ||
import org.partiql.planner.PartiQLPlanner | ||
import org.partiql.planner.internal.TestCatalog | ||
import org.partiql.spi.catalog.Session | ||
import org.partiql.spi.types.PType | ||
|
||
object FnTestUtils { | ||
/** | ||
* Helper function to parse, plan, and extract the result type from a PartiQL query. | ||
*/ | ||
fun getQueryResultType(query: String): PType { | ||
val session = Session.builder() | ||
.catalog("default") | ||
.catalogs( | ||
TestCatalog.builder() | ||
.name("default") | ||
.build() | ||
) | ||
.build() | ||
val parseResult = PartiQLParser.standard().parse(query) | ||
val ast = parseResult.statements[0] | ||
val planner = PartiQLPlanner.builder().build() | ||
val result = planner.plan(ast, session) | ||
val queryAction = result.plan.action as Action.Query | ||
return queryAction.rex.type.pType | ||
} | ||
} |
44 changes: 44 additions & 0 deletions
44
partiql-planner/src/test/kotlin/org/partiql/planner/internal/typer/functions/LowerTest.kt
This file contains hidden or 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,44 @@ | ||
package org.partiql.planner.internal.typer.functions | ||
|
||
import org.junit.jupiter.api.Test | ||
import org.junit.jupiter.api.assertThrows | ||
import org.partiql.spi.errors.PRuntimeException | ||
import org.partiql.spi.types.PType | ||
import kotlin.test.assertEquals | ||
|
||
class LowerTest { | ||
|
||
@Test | ||
fun `lower preserves CHAR length and type`() { | ||
val actualType = FnTestUtils.getQueryResultType("LOWER(CAST('HELLO' AS CHAR(5)))") | ||
assertEquals(PType.CHAR, actualType.code()) | ||
assertEquals(5, actualType.length) | ||
} | ||
|
||
@Test | ||
fun `lower preserves VARCHAR length and type`() { | ||
val actualType = FnTestUtils.getQueryResultType("LOWER(CAST('HELLO ' AS VARCHAR(10)))") | ||
assertEquals(PType.VARCHAR, actualType.code()) | ||
assertEquals(10, actualType.length) | ||
} | ||
|
||
@Test | ||
fun `lower preserves CLOB length and type`() { | ||
val actualType = FnTestUtils.getQueryResultType("LOWER(CAST(' HELLO' AS CLOB(20)))") | ||
assertEquals(PType.CLOB, actualType.code()) | ||
assertEquals(20, actualType.length) | ||
} | ||
|
||
@Test | ||
fun `lower preserves STRING type`() { | ||
val actualType = FnTestUtils.getQueryResultType("LOWER('HELLO')") | ||
assertEquals(PType.STRING, actualType.code()) | ||
} | ||
|
||
@Test | ||
fun `lower with unsupported type throws exception`() { | ||
assertThrows<PRuntimeException> { | ||
FnTestUtils.getQueryResultType("LOWER(42)") | ||
} | ||
} | ||
} |
44 changes: 44 additions & 0 deletions
44
partiql-planner/src/test/kotlin/org/partiql/planner/internal/typer/functions/TrimTest.kt
This file contains hidden or 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,44 @@ | ||
package org.partiql.planner.internal.typer.functions | ||
|
||
import org.junit.jupiter.api.Test | ||
import org.junit.jupiter.api.assertThrows | ||
import org.partiql.spi.errors.PRuntimeException | ||
import org.partiql.spi.types.PType | ||
import kotlin.test.assertEquals | ||
|
||
class TrimTest { | ||
|
||
@Test | ||
fun `trim preserves CHAR length and returns VARCHAR type`() { | ||
val actualType = FnTestUtils.getQueryResultType("TRIM(CAST(' HELLO ' AS CHAR(9)))") | ||
assertEquals(PType.VARCHAR, actualType.code()) | ||
XuechunHHH marked this conversation as resolved.
Show resolved
Hide resolved
|
||
assertEquals(9, actualType.length) | ||
lucaxchen marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
@Test | ||
fun `trim preserves VARCHAR length and type`() { | ||
val actualType = FnTestUtils.getQueryResultType("TRIM(CAST(' HELLO ' AS VARCHAR(15)))") | ||
assertEquals(PType.VARCHAR, actualType.code()) | ||
assertEquals(15, actualType.length) | ||
} | ||
|
||
@Test | ||
fun `trim preserves CLOB length and type`() { | ||
val actualType = FnTestUtils.getQueryResultType("TRIM(CAST(' HELLO ' AS CLOB(20)))") | ||
assertEquals(PType.CLOB, actualType.code()) | ||
assertEquals(20, actualType.length) | ||
} | ||
|
||
@Test | ||
fun `trim preserves STRING type`() { | ||
val actualType = FnTestUtils.getQueryResultType("TRIM(' HELLO ')") | ||
assertEquals(PType.STRING, actualType.code()) | ||
} | ||
|
||
@Test | ||
fun `trim with unsupported type throws exception`() { | ||
assertThrows<PRuntimeException> { | ||
FnTestUtils.getQueryResultType("TRIM(42)") | ||
} | ||
} | ||
} |
44 changes: 44 additions & 0 deletions
44
partiql-planner/src/test/kotlin/org/partiql/planner/internal/typer/functions/UpperTest.kt
This file contains hidden or 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,44 @@ | ||
package org.partiql.planner.internal.typer.functions | ||
|
||
import org.junit.jupiter.api.Test | ||
import org.junit.jupiter.api.assertThrows | ||
import org.partiql.spi.errors.PRuntimeException | ||
import org.partiql.spi.types.PType | ||
import kotlin.test.assertEquals | ||
|
||
class UpperTest { | ||
|
||
@Test | ||
fun `upper preserves CHAR length and type`() { | ||
val actualType = FnTestUtils.getQueryResultType("UPPER(CAST('hello' AS CHAR(5)))") | ||
assertEquals(PType.CHAR, actualType.code()) | ||
assertEquals(5, actualType.length) | ||
} | ||
|
||
@Test | ||
fun `upper preserves VARCHAR length and type`() { | ||
val actualType = FnTestUtils.getQueryResultType("UPPER(CAST('hello ' AS VARCHAR(10)))") | ||
assertEquals(PType.VARCHAR, actualType.code()) | ||
assertEquals(10, actualType.length) | ||
} | ||
|
||
@Test | ||
fun `upper preserves CLOB length and type`() { | ||
val actualType = FnTestUtils.getQueryResultType("UPPER(CAST(' hello' AS CLOB(20)))") | ||
assertEquals(PType.CLOB, actualType.code()) | ||
assertEquals(20, actualType.length) | ||
} | ||
|
||
@Test | ||
fun `upper preserves STRING type`() { | ||
val actualType = FnTestUtils.getQueryResultType("UPPER(' hello ')") | ||
assertEquals(PType.STRING, actualType.code()) | ||
} | ||
|
||
@Test | ||
fun `upper with unsupported type throws exception`() { | ||
assertThrows<PRuntimeException> { | ||
FnTestUtils.getQueryResultType("UPPER(42)") | ||
} | ||
} | ||
} |
This file contains hidden or 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 hidden or 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 hidden or 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: 1 addition & 0 deletions
1
partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/FnBitLength.kt
This file contains hidden or 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 hidden or 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.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.