-
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
base: main
Are you sure you want to change the base?
Conversation
CROSS-COMMIT-REPORT-PARTIQLCORE ❌
Testing DetailsResult Details
New Tests AddedThe complete list can be found in GitHub CI summary, either from Step Summary or in the Artifact. Now FAILING Tests ❌The complete list can be found in GitHub CI summary, either from Step Summary or in the Artifact. Now Passing TestsThe following 2 test(s) were previously FAILING in BASE but are now PASSING in TARGET. Before merging, confirm they are intended to pass: Click here to see
CROSS-COMMIT-REPORT-PARTIQLEXTENDED ✅
Testing DetailsResult Details
New Tests AddedThe complete list can be found in GitHub CI summary, either from Step Summary or in the Artifact. |
The cross-commit report failure stems from the update of conformance test submodule. Run the conformance test locally, the failing and passing tests are exactly the same as the main branch. |
partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/FnLower.kt
Outdated
Show resolved
Hide resolved
partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/FnLower.kt
Outdated
Show resolved
Hide resolved
CHAR/VARCHAR
UPPER
, LOWER
and TRIM
support for CHAR/VARCHAR
types
CHANGELOG.md
Outdated
## [Unreleased](https://TODO.com) - YYYY-MM-DD | ||
|
||
### Added | ||
- `UPPER`, `LOWER`, `TRIM` function support for `CHAR/VARCHAR` types |
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.
partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/FnConcat.kt
Show resolved
Hide resolved
partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/FnConcat.kt
Outdated
Show resolved
Hide resolved
partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/FnConcat.kt
Show resolved
Hide resolved
You probably need a rebase |
Previously, our submodule |
PLK has been updated to latest https://github.com/partiql/partiql-tests/tree/67d22dcd5a7eeaaa2624be9d1bb3da6a8b9faf0a by my last PR. |
partiql-planner/src/test/kotlin/org/partiql/planner/internal/typer/functions/UpperTest.kt
Outdated
Show resolved
Hide resolved
) { args -> | ||
val string = args[0].bytes.toString(Charsets.UTF_8) | ||
val result = string.lowercase() | ||
Datum.clob(result.toByteArray()) |
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.
out of curious, in Datum
, we treat PType.CLOB
as a byte array. I might be wrong here, but I think it should be just text by the SQL spec.
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.
We currently treat both CLOB
and BLOB
as byte[]
in Datum. See
partiql-lang-kotlin/partiql-spi/src/main/java/org/partiql/spi/value/Datum.java
Lines 723 to 763 in 154b9b4
static Datum clob(@NotNull byte[] value) throws PRuntimeException { | |
// TODO: Check size of value | |
return clob(value, Integer.MAX_VALUE); | |
} | |
/** | |
* @param value the backing value | |
* @param length the length of the clob to coerce the value to | |
* @return a value of type {@link PType#CLOB} with the default length | |
* @throws PRuntimeException if the value could not fit into the requested length, or if the requested length is not allowed ({@link org.partiql.spi.errors.PError#INTERNAL_ERROR}) | |
*/ | |
@NotNull | |
static Datum clob(@NotNull byte[] value, int length) throws PRuntimeException { | |
// TODO: Check size of value | |
return new DatumBytes(value, PType.clob(length)); | |
} | |
// BYTE STRINGS | |
/** | |
* @param value the backing value | |
* @return a value of type {@link PType#BLOB} with the default length | |
* @throws PRuntimeException if the value could not fit into the default length, or if the requested length is not allowed ({@link org.partiql.spi.errors.PError#INTERNAL_ERROR}) | |
*/ | |
@NotNull | |
static Datum blob(@NotNull byte[] value) throws PRuntimeException { | |
// TODO: Check size | |
return new DatumBytes(value, PType.blob(Integer.MAX_VALUE)); | |
} | |
/** | |
* @param value the backing value | |
* @param length the length of the clob to coerce the value to | |
* @return a value of type {@link PType#BLOB} with the default length | |
* @throws PRuntimeException if the value could not fit into the requested length, or if the length is not valid ({@link org.partiql.spi.errors.PError#INTERNAL_ERROR}) | |
*/ | |
@NotNull | |
static Datum blob(@NotNull byte[] value, int length) throws PRuntimeException { | |
// TODO: Check size | |
return new DatumBytes(value, PType.blob(length)); | |
} |
Thanks for the call out. Agree that CLOB
should be test-based instead. Both PType
and Datum
need to be formalized further.
partiql-planner/src/test/kotlin/org/partiql/planner/internal/typer/functions/TrimTest.kt
Show resolved
Hide resolved
partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/FnTrim.kt
Outdated
Show resolved
Hide resolved
partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/FnTrim.kt
Outdated
Show resolved
Hide resolved
The submodule currently in In the future, I think we should generally update the conformance submodule in its own PR so we can distinguish conformance report changes more easily. |
Synced Xuechun offline. The conformance submodule was updated to latest by my PR 6792e1d, It looks PR author is not aware of submodule update and may revert submodule unexpectedly as git add . will add reverted submodule automatically. |
partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/FnLower.kt
Outdated
Show resolved
Hide resolved
partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/FnLower.kt
Outdated
Show resolved
Hide resolved
partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/FnLower.kt
Outdated
Show resolved
Hide resolved
partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/FnTrim.kt
Outdated
Show resolved
Hide resolved
partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/FnConcat.kt
Outdated
Show resolved
Hide resolved
partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/FnConcat.kt
Outdated
Show resolved
Hide resolved
partiql-planner/src/test/kotlin/org/partiql/planner/internal/typer/functions/LowerTest.kt
Show resolved
Hide resolved
partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/FnConcat.kt
Show resolved
Hide resolved
partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/FnConcat.kt
Outdated
Show resolved
Hide resolved
partiql-spi/src/main/kotlin/org/partiql/spi/function/builtins/FnUpper.kt
Outdated
Show resolved
Hide resolved
|
||
### Changed | ||
- Formalize `UPPER`, `LOWER`, `TRIM` and `CONCAT` length and type handling on string types | ||
- `CLOB` now supports length parameters with `CLOB(n)` syntax |
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: Added support for max_length parameters in the CLOB
type, which is CLOB(n)
instead of CLOB
now. This change aligns our syntax with the SQL-99 specification, which defines CLOB as optionally accepting a length parameter:
<character string type> ::=
CHARACTER [ <left paren> <length> <right paren> ]
...
| CLOB [ <left paren> <large object length> <right paren> ]
PType.varchar(256), // TODO: Length | ||
PType.string(), | ||
PType.clob(Int.MAX_VALUE), // TODO: Length | ||
PType.clob(256), // TODO: Length |
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: This change avoid corner test (overflow) in planner. Previously CLOB actually had fixed param max_length = Int.MAX_VALUE in the implementation.
Relevant Issues
CHAR/VARCHAR
#1838Description
UPPER
,LOWER
andTRIM
functions support onCHAR/VARCHAR
types.Concat
operator length/type handling for string types.Other Information
License Information
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.