[GitHub] hequn8128 edited a comment on issue #6519: [FLINK-9559] [table] The type of a union of CHAR columns of different lengths should be VARCHAR
hequn8128 edited a comment on issue #6519: [FLINK-9559] [table] The type of a union of CHAR columns of different lengths should be VARCHAR URL: https://github.com/apache/flink/pull/6519#issuecomment-416501305 @pnowojski Thanks for looking into it. I think there are bugs in all your 4 sqls, so we can't get the conclusions from them. - In mysql, trailing spaces are removed when CHAR values are retrieved from a table. - You use literal of length 3('aa ') to compare to CHAR(4) and VARCHAR(4). - Except for mysql, other database will not remove trailing spaces so that the result of `case when` contains blanks. What result type of `case when`? Should we change case when result type to varchar? I think we can get the answer form the following sqls. 1. Mysql There are no doubt, since mysql Reference Manual says the return type is VARCHAR. 2. Oracle [http://sqlfiddle.com/#!4/cd577/2/0](http://sqlfiddle.com/#!4/cd577/2/0) 3. PostgreSql [http://sqlfiddle.com/#!17/c20bd/3/0](http://sqlfiddle.com/#!17/c20bd/3/0) 4. SqlServer [http://sqlfiddle.com/#!18/c20bd/10/0](http://sqlfiddle.com/#!18/c20bd/10/0) From the results, we can see that - There are no trailing spaces - The result type length should not be 1, i.e., can not be char(1) or varchar(1). It should be char(3) or varchar(3) - Result of `concat(CAST('a' AS char(3)), '|')` contains blanks while `concat(CAST('a' AS varchar(3)), '|')` not, so the result type of `case when` should be varchar. In Calcite, character constant, for example 'Hello, world!', '', _N'Bonjour', _ISO-8859-1'It''s superman!' COLLATE SHIFT_JIS$ja_JP$2. These are always CHAR, never VARCHAR. So it seems not possible or acceptable to change all literals to VARCHAR in Calcite. I think it is meaningful to turn the result type of `case when` to VARCHAR. What do you think? Thanks, Hequn This is an automated message from the Apache Git Service. To respond to the message, please log on GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org With regards, Apache Git Services
[GitHub] hequn8128 edited a comment on issue #6519: [FLINK-9559] [table] The type of a union of CHAR columns of different lengths should be VARCHAR
hequn8128 edited a comment on issue #6519: [FLINK-9559] [table] The type of a union of CHAR columns of different lengths should be VARCHAR URL: https://github.com/apache/flink/pull/6519#issuecomment-415735866 Hi @pnowojski , thanks for your reply. There are many cases need this feature. Not only `case when`, but also `nvl`, `greatest` and `least`. Most users encounter the blank problem is `case when`. Examples have been added in the test cases. Below I will add some more examples: 1. ``` SELECT country_name FROM ( SELECT CASE id WHEN 1 THEN 'GERMANY' WHEN 2 THEN 'CANADA' ELSE 'INVALID COUNTRY ID' END AS country_name FROM country_id ) WHERE country_name = 'GERMANY' ``` This sql will output nothing since the blank problem. It is very confused. 2. ``` SELECT country_name, country_info FROM ( SELECT CASE id WHEN 1 THEN 'GERMANY' WHEN 2 THEN 'CANADA' ELSE 'INVALID COUNTRY ID' END AS country_name FROM country_id ) nameTable join infoTable on nameTable.country_name = infoTable.country_name; ``` This sql cannot join correctly since the blank problem. 'GERMANY' in nameTable becomes 'GERMANY---'. BTW, '-' means the blank. It is true the sql standard returns CHAR type, but nearly all major DBMSs return VARCHAR without blank-padded. A tool for easy online testing: http://sqlfiddle.com/ Thanks, Hequn This is an automated message from the Apache Git Service. To respond to the message, please log on GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org With regards, Apache Git Services
[GitHub] hequn8128 edited a comment on issue #6519: [FLINK-9559] [table] The type of a union of CHAR columns of different lengths should be VARCHAR
hequn8128 edited a comment on issue #6519: [FLINK-9559] [table] The type of a union of CHAR columns of different lengths should be VARCHAR URL: https://github.com/apache/flink/pull/6519#issuecomment-415735866 Hi @pnowojski , thanks for your reply. There are many cases need this feature. Not only `case when`, but also `nvl`, `greatest` and `least`. Most users encounter the blank problem is `case when`. Examples have been added in the test cases. Below I will add some more examples: 1. ``` SELECT country_name FROM ( SELECT CASE id WHEN 1 THEN 'GERMANY' WHEN 2 THEN 'CANADA' ELSE 'INVALID COUNTRY ID' END AS country_name FROM country_id ) WHERE country_name = 'GERMANY' ``` This sql will output nothing since the blank problem. It is very confused. 2. ``` SELECT country_name, country_info FROM ( SELECT CASE id WHEN 1 THEN 'GERMANY' WHEN 2 THEN 'CANADA' ELSE 'INVALID COUNTRY ID' END AS country_name FROM country_id ) nameTable join infoTable on nameTable.country_name = infoTable.country_name; ``` This sql cannot join correctly since the blank problem. 'GERMANY' in nameTable becomes 'GERMANY---'. BTW, '-' means the blank. It is true the sql standard returns CHAR type, but nearly all major DBMSs return VARCHAR without blank-padded. Thanks, Hequn This is an automated message from the Apache Git Service. To respond to the message, please log on GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org With regards, Apache Git Services