2010YOUY01 commented on code in PR #27746:
URL: https://github.com/apache/datafusion/pull/27746#discussion_r4705774527
##########
datafusion/physical-plan/src/joins/join_index/directory.rs:
##########
@@ -0,0 +1,368 @@
+// SPDX-License-Identifier: Apache-2.0
+// SPDX-FileCopyrightText: See the NOTICE file distributed with this work for
additional information regarding copyright ownership
+// SPDX-FileContributor: Licensed to the Apache Software Foundation (ASF)
under one or more contributor license agreements
+
+//! Exact-key directory layouts, construction, and typed integer lookup.
+//!
+//! Dense integers use an array slot: keys `[10, 11, 12]` live at `key - 10`.
+//! Sparse integers such as `[10, 1_000_000]` use SwissTable with the actual
key
+//! in each entry. General keys use a cached hash and a representative build
row
+//! whose Arrow values establish equality. All three identify exact keys and
+//! return the same singleton/group representation; only row IDs are grouped.
+
+use std::mem::size_of;
+
+use arrow::array::{ArrayRef, BooleanArray};
+use arrow::buffer::BooleanBuffer;
+use datafusion_common::hash_utils::{RandomState, create_hashes};
+use datafusion_common::{NullEquality, Result, internal_err};
+use datafusion_execution::memory_pool::MemoryReservation;
+
+use super::keys::{LookupScratch, hash_scratch_bytes};
+use super::matches::{
+ GroupRows, JoinHashLookup, LookupResult, MatchHandles, MatchedGroups,
+ MatchedGroupsBuilder, RowId,
+};
+use crate::joins::array_map::ArrayMap;
+use crate::joins::utils::matchable_join_keys;
+
+mod dense;
+mod general;
+mod integer;
+
+use dense::DenseIntegerDirectory;
+use general::GeneralDirectory;
+use integer::{IntegerDirectory, integer_hasher};
+
+/// See [`JoinHashIndex`] for the design overview.
+struct Probe<'a> {
+ build_keys: &'a [ArrayRef],
+ probe_keys: &'a [ArrayRef],
+ null_equality: NullEquality,
+ random_state: &'a RandomState,
+}
+
+/// See [`JoinHashIndex`] for the design overview.
+#[derive(Debug)]
+pub(super) enum IndexWidth {
+ U32(JoinHashIndex<u32>),
+ U64(JoinHashIndex<u64>),
+}
+
+impl IndexWidth {
+ /// See [`JoinHashIndex::build`] and
+ /// [`JoinIndexMap::try_new`](super::JoinIndexMap::try_new) for shared
argument documentation.
+ pub(super) fn build(
+ keys: &[ArrayRef],
+ random_state: &RandomState,
+ null_equality: NullEquality,
+ dense_range: Option<(u64, u64)>,
+ reservation: &MemoryReservation,
+ ) -> Result<Self> {
+ let Some(first) = keys.first() else {
+ return internal_err!("A join index requires at least one key
column");
+ };
+ let num_rows = first.len();
+ let scratch = reservation.new_empty();
+ // Keep validity unions and per-column metadata charged for every
layout.
+ // Dense keys are read directly, so only hash-based directories need
hashes.
+ scratch.try_grow(num_rows.div_ceil(8) * (keys.len() + 1) + keys.len()
* 256)?;
+ let hashes = if dense_range.is_none() {
+ scratch.try_grow(num_rows * size_of::<u64>() +
hash_scratch_bytes(keys))?;
+ let mut hashes = vec![0; num_rows];
+ create_hashes(keys, random_state, &mut hashes)?;
+ hashes
+ } else {
+ Vec::new()
+ };
Review Comment:
- RE hashing in chunk: addressed in
[8282c74](https://github.com/apache/datafusion/pull/27746/commits/8282c74c3d43690c44960fa85d6f9a60bfb85dd1)
- `MatchedGroupsBuilder` conservative reservation: I'll address it after
more perf investigations on other benchmarks
--
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]