-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Indexed field access for List (#1006)
* enable GetIndexedField for Array and Dictionary * fix GetIndexedField which should index slices not values * Compat with latest sqlparser * Add two tests for indexed_field access, level one and level two nesting * fix compilation issues * try fixing dictionary lookup * address clippy warnings * fix test * Revert dictionary lookup for indexed fields * Reject negative ints when accessing list values in get indexed field * Fix doc in get_indexed_field * use GetIndexedFieldExpr directly * return the data type in unavailable field indexation error message * Add unit tests for the physical plan of get_indexed_field * Fix missing clause for const evaluator
- Loading branch information
Showing
11 changed files
with
458 additions
and
1 deletion.
There are no files selected for viewing
This file contains 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 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 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 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 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.