JiajunBernoulli opened a new pull request #2615:
URL: https://github.com/apache/calcite/pull/2615


   # insert union case
   
    Here is the sql:
   ```
   insert into t3 
   select 'a', 1.0, 1 union 
   select 'b', 2, 2 union 
   select 'c', 3.0, CAST(3 AS SMALLINT) union 
   select 'd', 4.0, 4 union 
   select 'e', 5.0, 5 
   ```
   but the validated sql is :
   ```
   INSERT INTO `CATALOG`.`SALES`.`T3`
   SELECT 'a', CAST(1.0 AS INTEGER), CAST(1 AS SMALLINT) UNION 
   SELECT 'b', 2, CAST(2 AS SMALLINT) UNION -- Encountered an integer and ended 
early
   SELECT 'c', 3.0, CAST(3 AS SMALLINT) UNION -- Encountered an samlint and 
ended early
   SELECT 'd', 4.0, 4 UNION -- should be cast  
   SELECT 'e', 5.0, 5 -- should be cast 
   ```
   This is why CALCITE-4458 changed '&&' to '||', the right validated sql is:
   ```
   INSERT INTO `CATALOG`.`SALES`.`T3`
   SELECT 'a', CAST(1.0 AS INTEGER), CAST(1 AS SMALLINT)
   UNION
   SELECT 'b', 2, CAST(2 AS SMALLINT)
   UNION
   SELECT 'c', CAST(3.0 AS INTEGER), CAST(3 AS SMALLINT)
   UNION
   SELECT 'd', CAST(4.0 AS INTEGER), CAST(4 AS SMALLINT)
   UNION
   SELECT 'e', CAST(5.0 AS INTEGER), CAST(5 AS SMALLINT)
    ```
   
   # case2
   Here is the sql
   ```
   INSERT INTO `CATALOG`.`SALES`.`T3`
   SELECT 'a', CAST(1.0 AS INTEGER), CAST(1 AS SMALLINT)
   UNION
   SELECT 'b', 2, CAST(2 AS SMALLINT)
   UNION
   SELECT 'c', 3.0, CAST(3 AS SMALLINT)
   UNION
   SELECT 'd', 4.0, 4
   UNION
   SELECT 'e', 5.0, 5 
   ```
    the validated sql is :
   ```
   INSERT INTO `CATALOG`.`SALES`.`T3`
   VALUES ROW('a', CAST(1.0 AS INTEGER), CAST(1 AS SMALLINT)),
   ROW('b', 2, CAST(2 AS SMALLINT)),-- Encountered an integer and ended early
   ROW('c', 3.0, CAST(3 AS SMALLINT)),Encountered an samllint and ended early 
ROW('d', 4.0, 4),
   ROW('e', 5.0, 5) 
   ```
   the right validated sql is:
   ```
   INSERT INTO `CATALOG`.`SALES`.`T3`
   SELECT 'a', CAST(1.0 AS INTEGER), CAST(1 AS SMALLINT)
   UNION
   SELECT 'b', 2, CAST(2 AS SMALLINT)
   UNION
   SELECT 'c', CAST(3.0 AS INTEGER), CAST(3 AS SMALLINT)
   UNION
   SELECT 'd', CAST(4.0 AS INTEGER), CAST(4 AS SMALLINT)
   UNION
   SELECT 'e', CAST(5.0 AS INTEGER), CAST(5 AS SMALLINT) 
   ```


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to