hugabora opened a new issue, #13496:
URL: https://github.com/apache/druid/issues/13496

   REPLACE statement with UNION ALL returns an error but executes partially the 
query and results in wrong data
   
   ### Affected Version
   
   24.0.0
   
   ### Description
   
   We had a need to run REPLACE for segments where the SELECT part is a UNION 
ALL of 2 (or more) queries.
   The API and the UI both throw an error saying the query with same id is 
already submitted. 
   Then looking at the tasks, we can see that the replace gets executed, but 
only the first select is used to get data and generate new segments.
   
   I included our workaround, which is actually a better solution.
   
   Hypothesis, the UNION ALL triggers 2 replace tasks. The 2nd will error out. 
   
   Query w error:
   
   ```sql
   REPLACE INTO my_table
   OVERWRITE WHERE __time >= TIMESTAMP '2021-01-01 00:00:00.000' AND __time < 
TIMESTAMP  '2021-02-01 00:00:00.000'
   SELECT __time, id, 'updated data' as data
     FROM my_table 
     WHERE __time >= TIMESTAMP '2021-01-01 00:00:00.000' AND __time < TIMESTAMP 
 '2021-02-01 00:00:00.000'
     AND id = '<updated id>'
   UNION ALL
   SELECT __time, id, data
     FROM my_table 
     WHERE __time >= TIMESTAMP '2021-01-01 00:00:00.000' AND __time < TIMESTAMP 
 '2021-02-01 00:00:00.000'
     AND id != '<updated id>'
   PARTITIONED BY MONTH
   ```
   
   Workaround or better solution to our problem:
   
   ```sql
   REPLACE INTO my_table
   OVERWRITE WHERE __time >= TIMESTAMP '2021-01-01 00:00:00.000' AND __time < 
TIMESTAMP  '2021-02-01 00:00:00.000'
   SELECT __time, id, 
          CASE id
            WHEN '<updated id>'
              THEN 'updated data'
            ELSE data
          END as data
     FROM my_table 
     WHERE __time >= TIMESTAMP '2021-01-01 00:00:00.000' AND __time < TIMESTAMP 
 '2021-02-01 00:00:00.000'
   PARTITIONED BY MONTH
   ```


-- 
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]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to