Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Capture AST for DataFrame.pivot and DataFrame.unpivot #2287

Conversation

sfc-gh-oplaton
Copy link
Contributor

  1. Which Jira issue is this PR addressing? Make sure that there is an accompanying issue to your PR.

    Fixes SNOW-1491297

  2. Fill out the following pre-review checklist:

    • I am adding a new automated test(s) to verify correctness of my new code
      • If this test skips Local Testing mode, I'm requesting review from @snowflakedb/local-testing
    • I am adding new logging messages
    • I am adding a new telemetry message
    • I am adding new credentials
    • I am adding a new dependency
    • If this is a new feature/behavior, I'm adding the Local Testing parity changes.
  3. Please describe how your code solves the related issue.

Capture AST for DataFrame.pivot and DataFrame.unpivot.
Add expectation test for pivot.
I was unable to resolve the local testing issue for unpivot. Adding a disabled test for now, and will revisit the test issue separately.

Will update the expected AST and Python
The test still fails with an unexpected exception
@sfc-gh-lspiegelberg
Copy link
Contributor

Few nits, do you have by chance the error that happens in local testing mode for unpivot?

@sfc-gh-oplaton
Copy link
Contributor Author

Few nits, do you have by chance the error that happens in local testing mode for unpivot?

The verbatim error is:

session = <snowflake.snowpark.session.Session object at 0x16ddc9e80>
test_case = TestCase(filename='DataFrame.unpivot.test', source='\ndf = session.create_dataframe(\n    [(1, "electronics", 100, 200... df.unpivot("sales", "month", ["jan", "feb"]).sort("empid")\n\n\n', expected_ast_base64='', expected_ast_unparsed='\n')

    @pytest.mark.parametrize("test_case", load_test_cases(), ids=idfn)
    def test_ast(session, test_case):
>       actual, base64_str = run_test(
            session, test_case.filename.replace(".", "_"), test_case.source
        )

/Users/oplaton/src/snowparkpy/tests/ast/test_ast_driver.py:252: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
/Users/oplaton/src/snowparkpy/tests/ast/test_ast_driver.py:243: in run_test
    base64_batches = test_module.run_test(session)
/var/folders/5r/s68_pbc972lfk7s9qms41w1c0000gn/T/test_asthorw47_6.py:94: in run_test
    ???
/Users/oplaton/src/snowparkpy/src/snowflake/snowpark/_internal/telemetry.py:212: in wrap
    r = func(*args, **kwargs)
/Users/oplaton/src/snowparkpy/src/snowflake/snowpark/dataframe.py:2263: in unpivot
    from_=SelectSnowflakePlan(
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

self = <snowflake.snowpark._internal.analyzer.select_statement.SelectSnowflakePlan object at 0x16dd3a640>
snowflake_plan = <snowflake.snowpark._internal.analyzer.unary_plan_node.Unpivot object at 0x16e05dac0>

    def __init__(self, snowflake_plan: LogicalPlan, *, analyzer: "Analyzer") -> None:
        super().__init__(analyzer)
        self._snowflake_plan: SnowflakePlan = (
            snowflake_plan
            if isinstance(snowflake_plan, SnowflakePlan)
            else analyzer.resolve(snowflake_plan)
        )
>       self.expr_to_alias.update(self._snowflake_plan.expr_to_alias)
E       AttributeError: 'NoneType' object has no attribute 'expr_to_alias'

/Users/oplaton/src/snowparkpy/src/snowflake/snowpark/_internal/analyzer/select_statement.py:552: AttributeError

Copy link
Contributor

@sfc-gh-lspiegelberg sfc-gh-lspiegelberg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work!

@sfc-gh-oplaton sfc-gh-oplaton merged commit f01c914 into ls-SNOW-1491199-merge-phase0-server-side Sep 13, 2024
9 of 30 checks passed
@sfc-gh-oplaton sfc-gh-oplaton deleted the oplaton/SNOW-1491297-pivot branch September 13, 2024 19:50
@github-actions github-actions bot locked and limited conversation to collaborators Sep 13, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants