Dandandan commented on a change in pull request #11:
URL: https://github.com/apache/arrow-datafusion/pull/11#discussion_r615808450



##########
File path: datafusion/src/physical_plan/cross_join.rs
##########
@@ -0,0 +1,315 @@
+// 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.
+
+//! Defines the join plan for executing partitions in parallel and then 
joining the results
+//! into a set of partitions.
+
+use futures::{lock::Mutex, StreamExt};
+use std::{any::Any, sync::Arc, task::Poll};
+
+use crate::physical_plan::memory::MemoryStream;
+use arrow::datatypes::{Schema, SchemaRef};
+use arrow::error::Result as ArrowResult;
+use arrow::record_batch::RecordBatch;
+
+use futures::{Stream, TryStreamExt};
+
+use super::{hash_utils::check_join_is_valid, merge::MergeExec};
+use crate::{
+    error::{DataFusionError, Result},
+    scalar::ScalarValue,
+};
+use async_trait::async_trait;
+use std::time::Instant;
+
+use super::{ExecutionPlan, Partitioning, RecordBatchStream, 
SendableRecordBatchStream};
+use crate::physical_plan::coalesce_batches::concat_batches;
+use log::debug;
+
+/// Data of the left side
+type JoinLeftData = RecordBatch;
+
+/// executes partitions in parallel and combines them into a set of
+/// partitions by combining all values from the left with all values on the 
right
+#[derive(Debug)]
+pub struct CrossJoinExec {
+    /// left (build) side which gets loaded in memory
+    left: Arc<dyn ExecutionPlan>,
+    /// right (probe) side which are combined with left side
+    right: Arc<dyn ExecutionPlan>,
+    /// The schema once the join is applied
+    schema: SchemaRef,
+    /// Build-side data
+    build_side: Arc<Mutex<Option<JoinLeftData>>>,
+}
+
+impl CrossJoinExec {
+    /// Tries to create a new [CrossJoinExec].
+    /// # Error
+    /// This function errors when it is not possible to join the left and 
right sides on keys `on`.
+    pub fn try_new(
+        left: Arc<dyn ExecutionPlan>,
+        right: Arc<dyn ExecutionPlan>,
+    ) -> Result<Self> {
+        let left_schema = left.schema();
+        let right_schema = right.schema();
+        check_join_is_valid(&left_schema, &right_schema, &[])?;
+
+        let left_schema = left.schema();
+        let left_fields = left_schema.fields().iter();
+        let right_schema = right.schema();
+
+        let right_fields = right_schema.fields().iter();
+
+        // left then right
+        let all_columns = left_fields.chain(right_fields).cloned().collect();

Review comment:
       Will see if I can simplify, I saw there exists a `join` method too, 
maybe it can be reused




-- 
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.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


Reply via email to