- 
                Notifications
    You must be signed in to change notification settings 
- Fork 1.7k
Indexed field access for List #1006
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
      
      
    
  
     Merged
                    Changes from all commits
      Commits
    
    
            Show all changes
          
          
            15 commits
          
        
        Select commit
          Hold shift + click to select a range
      
      b2a7a82
              
                enable GetIndexedField for Array and Dictionary
              
              
                Igosuki 98cb0a8
              
                fix GetIndexedField which should index slices not values
              
              
                Igosuki 7b5aec6
              
                Compat with latest sqlparser
              
              
                Igosuki c0b0920
              
                Add two tests for indexed_field access, level one and level two nesting
              
              
                Igosuki 60ba858
              
                fix compilation issues
              
              
                Igosuki c96cc6b
              
                try fixing dictionary lookup
              
              
                Igosuki 16d190d
              
                address clippy warnings
              
              
                Igosuki f04507f
              
                fix test
              
              
                Igosuki fb018c0
              
                Revert dictionary lookup for indexed fields
              
              
                Igosuki a630bcd
              
                Reject negative ints when accessing list values in get indexed field
              
              
                Igosuki f0dfe94
              
                Fix doc in get_indexed_field
              
              
                Igosuki 53d361b
              
                use GetIndexedFieldExpr directly
              
              
                Igosuki b2012b6
              
                return the data type in unavailable field indexation error message
              
              
                Igosuki 24bac8b
              
                Add unit tests for the physical plan of get_indexed_field
              
              
                Igosuki 5d61ce5
              
                Fix missing clause for const evaluator
              
              
                Igosuki 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
    
  
  
    
              | Original file line number | Diff line number | Diff line change | 
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| // Licensed to the Apache Software Foundation (ASF) under one | ||
| // or more contributor license agreements. See the NOTICE file | ||
| // distributed with this work for additional information | ||
| // regarding copyright ownership. The ASF licenses this file | ||
| // to you under the Apache License, Version 2.0 (the | ||
| // "License"); you may not use this file except in compliance | ||
| // with the License. You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, | ||
| // software distributed under the License is distributed on an | ||
| // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
| // KIND, either express or implied. See the License for the | ||
| // specific language governing permissions and limitations | ||
| // under the License. | ||
|  | ||
| //! Utility functions for complex field access | ||
|  | ||
| use arrow::datatypes::{DataType, Field}; | ||
|  | ||
| use crate::error::{DataFusionError, Result}; | ||
| use crate::scalar::ScalarValue; | ||
|  | ||
| /// Returns the field access indexed by `key` from a [`DataType::List`] | ||
| /// # Error | ||
| /// Errors if | ||
| /// * the `data_type` is not a Struct or, | ||
| /// * there is no field key is not of the required index type | ||
| pub fn get_indexed_field(data_type: &DataType, key: &ScalarValue) -> Result<Field> { | ||
| match (data_type, key) { | ||
| (DataType::List(lt), ScalarValue::Int64(Some(i))) => { | ||
| if *i < 0 { | ||
| Err(DataFusionError::Plan(format!( | ||
| "List based indexed access requires a positive int, was {0}", | ||
| i | ||
| ))) | ||
| } else { | ||
| Ok(Field::new(&i.to_string(), lt.data_type().clone(), false)) | ||
| } | ||
| } | ||
| (DataType::List(_), _) => Err(DataFusionError::Plan( | ||
| "Only ints are valid as an indexed field in a list".to_string(), | ||
| )), | ||
| _ => Err(DataFusionError::Plan( | ||
| "The expression to get an indexed field is only valid for `List` types" | ||
| .to_string(), | ||
| )), | ||
| } | ||
| } | ||
  
    
      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
    
  
  
    
              
  
    
      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
    
  
  
    
              
      
      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.
  
    
  
    
Uh oh!
There was an error while loading. Please reload this page.