Veeupup / naive-query-engine

A Toy Query Engine & SQL interface
Apache License 2.0
64 stars 7 forks source link

Cross join #51

Closed ywqzzy closed 2 years ago

ywqzzy commented 2 years ago
fn execute(&self) -> Result<Vec<RecordBatch>> {
        // TODO(ywq)
        let outer_table = self.left.execute()?;
        let inner_table = self.right.execute()?;

        let batches: Vec<RecordBatch> = vec![];

        for outer in &outer_table {
            for inner in &inner_table {
                let mut columns = vec![];
                let left_rows = outer.num_rows();
                let right_rows = inner.num_rows();
                println!("{} {}", left_rows, right_rows);
                for i in 0..self.left.schema().fields().len() {
                    let array = outer.column(i);
                    // vector init
                    for j in 0..right_rows {
                        // push to vector
                    }
                    // push to columns
                }
                for i in 0..self.right.schema().fields().len() {
                    let array = inner.column(i);
                    // vector init
                    for j in 0..left_rows {
                        // push to vector
                    }
                    // push to columns
                }
            }
        }
        Ok(batches)
    }

The execution process will like this, but I was struggled in rust(as I am a rust newbee).

Veeupup commented 2 years ago

Good Job! ❤️ It is also a good change to learn Rust 😄 ! we can reference to https://github.com/apache/arrow-datafusion/blob/master/datafusion/core/src/physical_plan/cross_join.rs