[
https://issues.apache.org/jira/browse/FLINK-32721?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17750618#comment-17750618
]
Yao Zhang commented on FLINK-32721:
-----------------------------------
Hi [~libenchao] and [~jackylau],
Thank you for your contribution.
In this PR you introduced CharMaxAggFunction and CharMinAggFunction especially
for char fields. They have overwritten the getResultType method. I am confused
about the way this method works. Does it affect the downstream external system,
by providing the correct field types? It seems that legacy Flink does not
distinguish varchar and char. I tested it by using the following sql with Flink
1.15.4 (without this PR min function works correctly with char field type):
{code:java}
tEnv.executeSql("create table test(name char(10)) with ('connector' =
'datagen')");
tEnv.executeSql("select typeof(min(name)) from test limit 10").print();
{code}
I tested char(10), varchar(10) and string types. For all of them we can get the
correct field types using typeof function.
> agg max/min supports char type
> ------------------------------
>
> Key: FLINK-32721
> URL: https://issues.apache.org/jira/browse/FLINK-32721
> Project: Flink
> Issue Type: Improvement
> Components: Table SQL / Planner
> Affects Versions: 1.18.0
> Reporter: Jacky Lau
> Assignee: Jacky Lau
> Priority: Major
> Labels: pull-request-available
> Fix For: 1.18.0
>
>
> {code:java}
> // flink
> Flink SQL> CREATE TABLE Orders (
> > name char(10),
> > price DECIMAL(32,2),
> > buyer ROW<first_name STRING, last_name STRING>,
> > order_time TIMESTAMP(3)
> > ) WITH (
> > 'connector' = 'datagen'
> > );
> [INFO] Execute statement succeed.
> Flink SQL> select max(name) from Orders;
> [ERROR] Could not execute SQL statement. Reason:
> org.apache.flink.table.api.TableException: Max aggregate function does not
> support type: ''CHAR''.
> Please re-check the data type. {code}
> {code:java}
> // mysql
> CREATE TABLE IF NOT EXISTS `docs` (
> `id` int(6) unsigned NOT NULL,
> `rev` int(3) unsigned NOT NULL,
> `content` char(200) NOT NULL,
> PRIMARY KEY (`id`,`rev`)
> ) DEFAULT CHARSET=utf8;
> INSERT INTO `docs` (`id`, `rev`, `content`) VALUES
> ('1', '1', 'The earth is flat'),
> ('2', '1', 'One hundred angels can dance on the head of a pin'),
> ('1', '2', 'The earth is flat and rests on a bull\'s horn'),
> ('1', '3', 'The earth is like a ball.');
> select max(content) from docs;
> // result
> |max(content)|
> The earth is like a ball.{code}
--
This message was sent by Atlassian Jira
(v8.20.10#820010)