- 
                Notifications
    
You must be signed in to change notification settings  - Fork 133
 
Enable Dataframe to be converted into views which can be used in register_table #1016
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
          
     Merged
      
      
    
      
        
          +203
        
        
          −0
        
        
          
        
      
    
  
  
     Merged
                    Changes from 9 commits
      Commits
    
    
            Show all changes
          
          
            21 commits
          
        
        Select commit
          Hold shift + click to select a range
      
      9d589a2
              
                add test_view
              
              
                kosiew 648c185
              
                feat: add into_view method to register DataFrame as a view
              
              
                kosiew e55ac9f
              
                add pytableprovider
              
              
                kosiew ca42449
              
                feat: add as_table method to PyTableProvider and update into_view to …
              
              
                kosiew d0c3163
              
                refactor: simplify as_table method and update documentation for into_…
              
              
                kosiew 8578713
              
                test: improve test_register_filtered_dataframe by removing redundant …
              
              
                kosiew 9cdd0dc
              
                test: enhance test_register_filtered_dataframe with additional assert…
              
              
                kosiew c207b6c
              
                ruff formatted
              
              
                kosiew 20dbfe8
              
                cleanup: remove unused imports from test_view.py
              
              
                kosiew 4b4c641
              
                docs: add example for registering a DataFrame as a view in README.md
              
              
                kosiew 12c4fe3
              
                docs: update docstring for into_view method to clarify usage as ViewT…
              
              
                kosiew 15ead1f
              
                chore: add license header to test_view.py
              
              
                kosiew 48eb8db
              
                ruff correction
              
              
                kosiew f73eebb
              
                refactor: rename into_view method to _into_view
              
              
                kosiew 6bba2e2
              
                ruff lint
              
              
                kosiew 7b0cbf1
              
                refactor: simplify into_view method and update Rust binding convention
              
              
                kosiew f594b46
              
                docs: add views section to user guide with example on registering views
              
              
                kosiew 90a6a8b
              
                feat: add register_view method to SessionContext for DataFrame regist…
              
              
                kosiew c31395f
              
                Merge branch 'main' into view
              
              
                kosiew f0837de
              
                docs: update README and user guide to reflect register_view method fo…
              
              
                kosiew 9d8cdb5
              
                docs: remove some documentation from PyDataFrame
              
              
                kosiew File filter
Filter by extension
Conversations
          Failed to load comments.   
        
        
          
      Loading
        
  Jump to
        
          Jump to file
        
      
      
          Failed to load files.   
        
        
          
      Loading
        
  Diff view
Diff view
There are no files selected for viewing
  
    
      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
    
  
  
    
              
  
    
      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
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| from datafusion import SessionContext, col, literal | ||
| 
     | 
||
| 
     | 
||
| def test_register_filtered_dataframe(): | ||
| ctx = SessionContext() | ||
| 
     | 
||
| data = {"a": [1, 2, 3, 4, 5], "b": [10, 20, 30, 40, 50]} | ||
| 
     | 
||
| df = ctx.from_pydict(data, "my_table") | ||
| 
     | 
||
| df_filtered = df.filter(col("a") > literal(2)) | ||
| view = df_filtered.into_view() | ||
| 
     | 
||
| assert view.kind == "view" | ||
| 
     | 
||
| ctx.register_table("view1", view) | ||
| 
     | 
||
| df_view = ctx.sql("SELECT * FROM view1") | ||
| 
     | 
||
| filtered_results = df_view.collect() | ||
| 
     | 
||
| result_dicts = [batch.to_pydict() for batch in filtered_results] | ||
| 
     | 
||
| expected_results = [{"a": [3, 4, 5], "b": [30, 40, 50]}] | ||
| 
     | 
||
| assert result_dicts == expected_results | ||
| 
     | 
||
| df_results = df.collect() | ||
| 
     | 
||
| df_result_dicts = [batch.to_pydict() for batch in df_results] | ||
| 
     | 
||
| expected_df_results = [{"a": [1, 2, 3, 4, 5], "b": [10, 20, 30, 40, 50]}] | ||
| 
     | 
||
| assert df_result_dicts == expected_df_results | ||
  
    
      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
    
  
  
    
              
      
      Oops, something went wrong.
        
    
  
  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.
  
    
  
    
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is modelled after how into_view is used in datafusion: