Fix explain() mislabeling pushed-down GroupBy/apply as Pandas#576
Merged
Conversation
LazyGroupByAgg.execution_engine() returned the non-canonical literal "SQL", and LazyApply.execution_engine() did the same in its pushable branch. DataStore.explain() only recognizes the canonical "chDB" / "Pandas" literals (as documented on the base LazyOp), so "SQL" silently fell through to the Pandas branch. As a result the explain output labeled GroupBy/apply ops as Pandas even when the segment header said chDB and the generated SQL clearly contained GROUP BY pushed to chDB. Both implementations now return "chDB" / "Pandas" based on can_push_to_sql(). Updated two existing assertions that had baked in the buggy "SQL" literal, and added a regression test class covering the original user scenario (agg with dict-of-list), simple agg, the non-pushable case, groupby().apply(sum), and a direct unit test on LazyGroupByAgg.execution_engine().
4 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
DataStore.explain()was labelingGroupBy/groupby().apply()ops as 🐼[Pandas]even when they were clearly pushed down to chDB — the segment header said[chDB]and the generated SQL containedGROUP BY, but the per-op line lied.Root cause
The base
LazyOp.execution_engine()contract (lazy_ops.py:113-126) requires returning the canonical literals"chDB"or"Pandas".DataStore.explain()(core.py:801-816) only branches on"chDB"; anything else falls into the Pandas branch.Two implementations returned the non-canonical literal
"SQL":LazyGroupByAgg.execution_engine()always returned"SQL".LazyApply.execution_engine()returned"SQL"in its pushable branch.So pushed-down GroupBy and apply ops silently rendered as Pandas. Display-only bug — execution path was unaffected; no consumer was matching on
"SQL".Reproduction (before fix)
Before:
After:
Changes
datastore/lazy_ops.py:LazyGroupByAgg.execution_engine()andLazyApply.execution_engine()now return"chDB"/"Pandas"based oncan_push_to_sql().datastore/tests/test_groupby_apply_sql_pushdown.py: two existing assertions had baked in the buggy"SQL"literal — updated to"chDB".datastore/tests/test_explain_method.py: newTestExplainEngineLabelingForPushedOpsclass with 5 regression tests covering the original user scenario (agg dict-of-list), simple.mean()agg, the non-pushable case (must stay Pandas),groupby().apply(sum)pushdown, and a direct unit test on the canonical-literal contract.Test plan
pytest datastore/tests/test_explain_method.py— 22 passedpytest datastore/tests/test_groupby_apply_sql_pushdown.py— 28 passedpytest test_explain_segmented_execution.py test_comprehensive_segmented_execution.py test_sql_vs_pandas_filter.py test_lazy_chain_engine_verification.py test_lazy_execution.py test_case_when.py test_nullable_sql_pushdown.py— 203 passed, 1 xfailed (pre-existing, unrelated)[chDB].