-
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 1 commit
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
91 changes: 91 additions & 0 deletions
91
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,91 @@ | ||
package org.partiql.planner.internal.typer.functions | ||
|
||
import org.junit.jupiter.api.Test | ||
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 | ||
import kotlin.test.assertEquals | ||
|
||
class TrimTest { | ||
|
||
@Test | ||
fun `trim preserves CHAR length`() { | ||
val session = Session.builder() | ||
.catalog("default") | ||
.catalogs( | ||
TestCatalog.builder() | ||
.name("default") | ||
.build() | ||
) | ||
.build() | ||
val parseResult = PartiQLParser.standard().parse("TRIM(CAST(' HELLO ' AS CHAR(9)))") | ||
val ast = parseResult.statements[0] | ||
val planner = PartiQLPlanner.builder().build() | ||
val result = planner.plan(ast, session) | ||
val query = result.plan.action as Action.Query | ||
val actualType = query.rex.type.pType | ||
assertEquals(PType.CHAR, actualType.code()) | ||
assertEquals(9, actualType.length) | ||
lucaxchen marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
@Test | ||
fun `trim preserves VARCHAR length`() { | ||
val session = Session.builder() | ||
.catalog("default") | ||
.catalogs( | ||
TestCatalog.builder() | ||
.name("default") | ||
.build() | ||
) | ||
.build() | ||
val parseResult = PartiQLParser.standard().parse("TRIM(CAST(' HELLO ' AS VARCHAR(15)))") | ||
val ast = parseResult.statements[0] | ||
val planner = PartiQLPlanner.builder().build() | ||
val result = planner.plan(ast, session) | ||
val query = result.plan.action as Action.Query | ||
val actualType = query.rex.type.pType | ||
assertEquals(PType.VARCHAR, actualType.code()) | ||
assertEquals(15, actualType.length) | ||
} | ||
|
||
@Test | ||
fun `trim preserves CLOB type`() { | ||
val session = Session.builder() | ||
.catalog("default") | ||
.catalogs( | ||
TestCatalog.builder() | ||
.name("default") | ||
.build() | ||
) | ||
.build() | ||
val parseResult = PartiQLParser.standard().parse("TRIM(CAST(' HELLO ' AS CLOB))") | ||
val ast = parseResult.statements[0] | ||
val planner = PartiQLPlanner.builder().build() | ||
val result = planner.plan(ast, session) | ||
val query = result.plan.action as Action.Query | ||
val actualType = query.rex.type.pType | ||
assertEquals(PType.CLOB, actualType.code()) | ||
} | ||
|
||
@Test | ||
fun `trim preserves STRING type`() { | ||
val session = Session.builder() | ||
.catalog("default") | ||
.catalogs( | ||
TestCatalog.builder() | ||
.name("default") | ||
.build() | ||
) | ||
.build() | ||
val parseResult = PartiQLParser.standard().parse("TRIM(' HELLO ')") | ||
val ast = parseResult.statements[0] | ||
val planner = PartiQLPlanner.builder().build() | ||
val result = planner.plan(ast, session) | ||
val query = result.plan.action as Action.Query | ||
val actualType = query.rex.type.pType | ||
assertEquals(PType.STRING, actualType.code()) | ||
} | ||
} |
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.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
self-review: Since the length handling should also be done at planning time, add the real function support instead of only siganatures.