Skip to content

Conversation

@sgrebnov
Copy link

@sgrebnov sgrebnov commented Jul 12, 2024

Which issue does this PR close?

Fixes spiceai/spiceai#1948

Rationale for this change

MySQL cast function does not support TEXT and requires CHAR (automatically returns VARCHAR, TEXT, LONGTEXT)

CHAR[(N)] [charset_info]
Produces a string with the VARCHAR data type, unless the expression expr is empty (zero length), in which case the result type is CHAR(0). If the optional length N is given, CHAR(N) causes the cast to use no more than N characters of the argument. No padding occurs for values shorter than N characters. If the optional length N is not given, MySQL calculates the maximum length from the expression. If the supplied or calculated length is greater than an internal threshold, the result type is TEXT. If the length is still too long, the result type is LONGTEXT.

Example query:

 select * from customer where c_custkey = 'building

Before this change (fails in MySQL)

SELECT `customer`.`c_custkey`, ... FROM `customer` WHERE (CAST(`customer`.`c_custkey` AS TEXT) = 'building')

After this change (works in MySQL)

SELECT `customer`.`c_custkey`,  ... FROM `customer` WHERE (CAST(`customer`.`c_custkey` AS CHAR) = 'building')

@sgrebnov sgrebnov self-assigned this Jul 12, 2024
@sgrebnov sgrebnov changed the title Add use_char_for_utf8_cast Dialect param Add use_char_for_utf8_cast Dialect param (MySQL string literals cast fix) Jul 12, 2024
@sgrebnov sgrebnov changed the title Add use_char_for_utf8_cast Dialect param (MySQL string literals cast fix) Add dialect param for strings casting (MySQL strings cast fix) Jul 12, 2024
@sgrebnov sgrebnov force-pushed the sgrebnov/mysql-text-cast-fix branch from d5be971 to d594e1b Compare July 12, 2024 19:43
@sgrebnov sgrebnov force-pushed the sgrebnov/mysql-text-cast-fix branch from d594e1b to 107c02a Compare July 12, 2024 19:51
@sgrebnov sgrebnov changed the title Add dialect param for strings casting (MySQL strings cast fix) Add dialect param to use CHAR instead of TEXT for Utf8 unparsing for MySQL Jul 12, 2024
@sgrebnov sgrebnov merged commit 1ba91ee into spiceai-39 Jul 13, 2024
@phillipleblanc phillipleblanc deleted the sgrebnov/mysql-text-cast-fix branch July 14, 2024 22:57
Sevenannn pushed a commit that referenced this pull request Jul 18, 2024
* Add dialect param to use CHAR instead of TEXT for Utf8 unparsing for MySQL (#12)

* Configurable data type instead of flag for Utf8 unparsing

* Fix type in comment
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.

4 participants