adriangb commented on code in PR #18393: URL: https://github.com/apache/datafusion/pull/18393#discussion_r2546596785
########## datafusion/physical-plan/src/joins/hash_join/inlist_builder.rs: ########## @@ -0,0 +1,174 @@ +// 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. + +//! Utilities for building InList expressions from hash join build side data + +use std::sync::Arc; + +use arrow::array::{ArrayRef, StructArray}; +use arrow::datatypes::{Field, FieldRef, Fields}; +use arrow::downcast_dictionary_array; +use arrow_schema::DataType; +use datafusion_common::Result; + +pub(super) fn build_struct_fields(data_types: &[DataType]) -> Result<Fields> { + data_types + .iter() + .enumerate() + .map(|(i, dt)| Ok(Field::new(format!("c{i}"), dt.clone(), true))) + .collect() +} + +/// Flattens dictionary-encoded arrays to their underlying value arrays. +/// Non-dictionary arrays are returned as-is. +fn flatten_dictionary_array(array: &ArrayRef) -> ArrayRef { + downcast_dictionary_array! { + array => { + // Recursively flatten in case of nested dictionaries + flatten_dictionary_array(array.values()) + } + _ => Arc::clone(array) + } +} + +/// Builds InList values from join key column arrays. +/// +/// If `join_key_arrays` is: +/// 1. A single array, let's say Int32, this will produce a flat +/// InList expression where the lookup is expected to be scalar Int32 values, +/// that is: this will produce `IN LIST (1, 2, 3)` expected to be used as `2 IN LIST (1, 2, 3)`. +/// 2. An Int32 array and a Utf8 array, this will produce a Struct InList expression +/// where the lookup is expected to be Struct values with two fields (Int32, Utf8), +/// that is: this will produce `IN LIST ((1, "a"), (2, "b"))` expected to be used as `(2, "b") IN LIST ((1, "a"), (2, "b"))`. +/// The field names of the struct are auto-generated as "c0", "c1", ... and should match the struct expression used in the join keys. +/// +/// Note that this will not deduplicate values, that will happen later when building an InList expression from this array. +/// +/// Returns `None` if the estimated size exceeds `max_size_bytes`. +/// Performs deduplication to ensure unique values only. Review Comment: It was a bad comment, updated -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
