Skip to content
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

feat: support trim with numeric and variant types #69

Merged
merged 3 commits into from
Apr 19, 2024

Conversation

seruman
Copy link
Contributor

@seruman seruman commented Mar 28, 2024

Snowflake's TRIM accepts any type and returns VARCHAR, docs does not mentioned it but it seems to only works on VARCHAR/TEXT typed inputs and acts as a cast to VARCHAR for others. DuckDB's TRIM only accepts VARCHAR. It seemed safe to me to cast input to VARCHAR to mimic similar behaviour.

select 
    trim(5) as c_number, SYSTEM$TYPEOF(c_number),
    trim(' str ') as c_varchar, SYSTEM$TYPEOF(c_varchar),
    trim(to_variant({'k': 'v'})) as c_variant, SYSTEM$TYPEOF(c_variant)
;
C_NUMBER SYSTEM$TYPEOF(C_NUMBER) C_VARCHAR SYSTEM$TYPEOF(C_VARCHAR) C_VARIANT SYSTEM$TYPEOF(C_VARIANT)
5 VARCHAR(16777216)[LOB] str VARCHAR(5)[LOB] {"k":"v"} VARCHAR(16777216)[LOB]

@seruman seruman changed the title feat: cast trim input to varchar implicitly feat: cast trim input to varchar Mar 28, 2024
@seruman seruman force-pushed the trim_cast_varchar branch 2 times, most recently from 65b83ef to 19a4c28 Compare April 2, 2024 09:40
Comment on lines 1268 to 1408
cur.execute(
"""insert into trim_cast_varchar_variant_field(data) values ('{"k1": " v11 "}'),('{"k1": 21}');"""
)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This fails for me on a real Snowflake instance with:

ProgrammingError: 002023 (22000): SQL compilation error:
Expression type does not match column data type, expecting VARIANT but got VARCHAR(18) for column DATA

Am guessing we need to convert it to variant first?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My bad again, updated.

As on #78 tests seems to fail due to -guessing- sqlalchemy version
#78 (comment)

@tekumara tekumara changed the title feat: cast trim input to varchar feat: support trim with numeric and variant types Apr 19, 2024
@tekumara tekumara merged commit 00ab619 into tekumara:main Apr 19, 2024
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants