dqkqd commented on issue #17771:
URL: https://github.com/apache/datafusion/issues/17771#issuecomment-3392929602

   I bisected and found that this is fixed by #17419
   
   ```
   > WITH part AS (
     SELECT *
     FROM (VALUES (1, 'A'), (2, 'B')) AS t(partkey, name)
   ),
   RevenueCTE AS (
     SELECT partkey, total_revenue
     FROM (VALUES (1, 10.0), (2, 5.0)) AS t(partkey, total_revenue)
   ),
   SupplierCTE AS (
     SELECT partkey, total_supply_cost
     FROM (VALUES (1, 2.0), (2, 3.0)) AS t(partkey, total_supply_cost)
   ),
   RankedParts AS (
     SELECT
       p.partkey,
       p.name,
       COALESCE(r.total_revenue, 0)       AS total_revenue,
       COALESCE(s.total_supply_cost, 0)   AS total_supply_cost,
       RANK() OVER (
         ORDER BY COALESCE(r.total_revenue, 0) DESC
       )                                   AS revenue_rank
     FROM part AS p
     LEFT JOIN RevenueCTE  AS r ON p.partkey = r.partkey
     LEFT JOIN SupplierCTE AS s ON p.partkey = s.partkey
   )
   SELECT
     partkey,
     name,
     total_revenue,
     total_supply_cost,
     CASE
       WHEN total_supply_cost > 0 THEN total_revenue / total_supply_cost
       ELSE NULL
     END AS ratio
   FROM RankedParts
   WHERE revenue_rank <= 10
   ORDER BY total_revenue DESC;
   +---------+------+---------------+-------------------+--------------------+
   | partkey | name | total_revenue | total_supply_cost | ratio              |
   +---------+------+---------------+-------------------+--------------------+
   | 1       | A    | 10.0          | 2.0               | 5.0                |
   | 2       | B    | 5.0           | 3.0               | 1.6666666666666667 |
   +---------+------+---------------+-------------------+--------------------+
   2 row(s) fetched.
   Elapsed 0.039 seconds.
   
   >
   ```


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