RamakrishnaChilaka opened a new pull request, #21177: URL: https://github.com/apache/datafusion/pull/21177
## Which issue does this PR close? - Closes #21176 ## Rationale for this change When `SELECT` projects columns in a different order than the table schema (e.g., `SELECT col_c, col_b` vs schema order `col_a, col_b, col_c`), the `LIMIT` clause is silently ignored — all rows are returned instead of the requested limit. The physical optimizer runs `LimitPushdown` (which correctly sets `fetch=N` on `MemorySourceConfig`) **before** `ProjectionPushdown`. When the projection is pushed down, `try_swapping_with_projection()` creates a new `MemorySourceConfig` via `try_new()`, which resets `fetch` to `None`, silently dropping the limit. ## What changes are included in this PR? One-line fix in `MemorySourceConfig::try_swapping_with_projection` to preserve `self.fetch` on the newly created config: ```rust // Before: .map(|s| Arc::new(s) as Arc<dyn DataSource>) // After: .map(|s| Arc::new(s.with_limit(self.fetch)) as Arc<dyn DataSource>) ``` ## Are these changes tested? Yes. - **Unit test** (`try_swapping_with_projection_preserves_fetch`): directly verifies `fetch` is preserved after projection pushdown. Confirmed it fails without the fix (`None` vs `Some(5)`). - **SQL logic test** (`limit.slt`, table `t21176`): end-to-end regression test for `SELECT col_c, col_b FROM t LIMIT 5` with reverse column order. ## Are there any user-facing changes? No API changes. This is a correctness fix — `LIMIT` now works correctly regardless of `SELECT` column order against in-memory tables. -- 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]
