[ 
https://issues.apache.org/jira/browse/FLINK-21563?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17294237#comment-17294237
 ] 

Jark Wu commented on FLINK-21563:
---------------------------------

Not sure how SQL standard and other database vendors handle this. I just 
checked MySQL, and it supports this. 

{code}
mysql> CREATE TABLE triangle (
    ->   sidea DOUBLE,
    ->   sideb DOUBLE,
    ->   sidec DOUBLE AS (SQRT(sidea * sidea + sideb * sideb)),
    ->   sided DOUBLE AS (sidec+1)
    -> );
Query OK, 0 rows affected (0.01 sec)

mysql> INSERT INTO triangle (sidea, sideb) VALUES(1,1),(3,4),(6,8);
Query OK, 3 rows affected (0.01 sec)
Records: 3  Duplicates: 0  Warnings: 0

mysql> select * from triangle;
+-------+-------+--------------------+-------------------+
| sidea | sideb | sidec              | sided             |
+-------+-------+--------------------+-------------------+
|     1 |     1 | 1.4142135623730951 | 2.414213562373095 |
|     3 |     4 |                  5 |                 6 |
|     6 |     8 |                 10 |                11 |
+-------+-------+--------------------+-------------------+
3 rows in set (0.00 sec)

{code}

> Support using computed columns when defining new computed columns
> -----------------------------------------------------------------
>
>                 Key: FLINK-21563
>                 URL: https://issues.apache.org/jira/browse/FLINK-21563
>             Project: Flink
>          Issue Type: New Feature
>          Components: Table SQL / API
>    Affects Versions: 1.11.3
>            Reporter: Nico Kruber
>            Priority: Major
>         Attachments: flights-21563.csv
>
>
> To avoid code duplications, it would be nice to be able to use computed 
> columns in later computations of new computed columns, e.g.
> {code}
> CREATE TABLE `flights` (
>   `_YEAR` CHAR(4),
>   `_MONTH` CHAR(2),
>   `_DAY` CHAR(2),
>   `_SCHEDULED_DEPARTURE` CHAR(4),
>   `SCHEDULED_DEPARTURE` AS TO_TIMESTAMP(`_YEAR` || '-' || `_MONTH` || '-' || 
> `_DAY` || ' ' || SUBSTRING(`_SCHEDULED_DEPARTURE` FROM 0 FOR 2) || ':' || 
> SUBSTRING(`_SCHEDULED_DEPARTURE` FROM 3) || ':00'),
>   `_DEPARTURE_TIME` CHAR(4),
>   `DEPARTURE_DELAY` SMALLINT,
>   `DEPARTURE_TIME` AS TIMESTAMPADD(MINUTE, CAST(`DEPARTURE_DELAY` AS INT), 
> SCHEDULED_DEPARTURE)
> )...
> {code}
> Otherwise, a user would have to repeat these calculations over and over again 
> which is not that maintainable.
> Currently, for a minimal working example with the attached input file, it 
> would look like this, e.g. in the SQL CLI:
> {code}
> CREATE TABLE `flights` (
>   `_YEAR` CHAR(4),
>   `_MONTH` CHAR(2),
>   `_DAY` CHAR(2),
>   `_SCHEDULED_DEPARTURE` CHAR(4),
>   `SCHEDULED_DEPARTURE` AS TO_TIMESTAMP(`_YEAR` || '-' || `_MONTH` || '-' || 
> `_DAY` || ' ' || SUBSTRING(`_SCHEDULED_DEPARTURE` FROM 0 FOR 2) || ':' || 
> SUBSTRING(`_SCHEDULED_DEPARTURE` FROM 3) || ':00'),
>   `_DEPARTURE_TIME` CHAR(4),
>   `DEPARTURE_DELAY` SMALLINT,
>   `DEPARTURE_TIME` AS TIMESTAMPADD(MINUTE, CAST(`DEPARTURE_DELAY` AS INT), 
> TO_TIMESTAMP(`_YEAR` || '-' || `_MONTH` || '-' || `_DAY` || ' ' || 
> SUBSTRING(`_SCHEDULED_DEPARTURE` FROM 0 FOR 2) || ':' || 
> SUBSTRING(`_SCHEDULED_DEPARTURE` FROM 3) || ':00'))
> ) WITH (
>   'connector' = 'filesystem',
>   'path' = 'file:///tmp/kaggle-flight-delay/flights-21563.csv',
>   'format' = 'csv'
> );
> SELECT * FROM flights;
> {code}



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Reply via email to