From f0bd8ecc5ad5652b9a633e52c3c29630cc9a8b9f Mon Sep 17 00:00:00 2001 From: Connor Tsui Date: Tue, 13 Feb 2024 13:44:25 -0500 Subject: [PATCH] start creating mapping --- .../src/execution/substrait/deserialize.rs | 11 ++++++++-- eggstrain/src/execution/substrait/mod.rs | 1 + .../execution/substrait/substrait_arrow.rs | 20 +++++++++++++++++++ eggstrain/src/main.rs | 5 +++-- 4 files changed, 33 insertions(+), 4 deletions(-) create mode 100644 eggstrain/src/execution/substrait/substrait_arrow.rs diff --git a/eggstrain/src/execution/substrait/deserialize.rs b/eggstrain/src/execution/substrait/deserialize.rs index bfb6321..5123102 100644 --- a/eggstrain/src/execution/substrait/deserialize.rs +++ b/eggstrain/src/execution/substrait/deserialize.rs @@ -1,13 +1,20 @@ use std::fs; -use substrait::proto::Plan; +use substrait::proto::{Plan, ReadRel}; pub fn read_str(path: &str) -> String { fs::read_to_string(path).unwrap_or_else(|_| panic!("Unable to read file {}", path)) } -pub fn get_json(path: &str) -> Plan { +pub fn get_plan(path: &str) -> Plan { let plan = serde_json::from_str::(&read_str(path)) .unwrap_or_else(|_| panic!("Could not parse json {:?} into Plan", path)); println!("{}", serde_json::to_string_pretty(&plan).unwrap()); plan } + +pub fn get_read(path: &str) -> ReadRel { + let read = serde_json::from_str::(&read_str(path)) + .unwrap_or_else(|_| panic!("Could not parse json {:?} into Plan", path)); + println!("{}", serde_json::to_string_pretty(&read).unwrap()); + read +} diff --git a/eggstrain/src/execution/substrait/mod.rs b/eggstrain/src/execution/substrait/mod.rs index c6ed2fb..0fb207d 100644 --- a/eggstrain/src/execution/substrait/mod.rs +++ b/eggstrain/src/execution/substrait/mod.rs @@ -1,2 +1,3 @@ pub mod deserialize; pub mod example; +pub mod substrait_arrow; diff --git a/eggstrain/src/execution/substrait/substrait_arrow.rs b/eggstrain/src/execution/substrait/substrait_arrow.rs new file mode 100644 index 0000000..42b7c20 --- /dev/null +++ b/eggstrain/src/execution/substrait/substrait_arrow.rs @@ -0,0 +1,20 @@ +use arrow::datatypes::{DataType, Schema}; +use std::sync::Arc; +use substrait::proto::{Type, NamedStruct}; + +/// https://docs.rs/substrait/latest/substrait/proto/struct.NamedStruct.html +/// https://docs.rs/substrait/latest/substrait/proto/type/struct.Struct.html +pub fn schema_translate(substrait_schema: NamedStruct) -> Arc { + for (i, name) in substrait_schema.names.iter().enumerate() { + todo!() + } + + todo!() +} + +/// https://docs.rs/substrait/latest/substrait/proto/struct.Type.html +/// https://docs.rs/arrow/latest/arrow/datatypes/enum.DataType.html +pub fn type_translate(typ: Type) -> DataType { + todo!() +} + diff --git a/eggstrain/src/main.rs b/eggstrain/src/main.rs index 91c5bd2..02cb54a 100644 --- a/eggstrain/src/main.rs +++ b/eggstrain/src/main.rs @@ -2,11 +2,12 @@ pub mod execution; pub mod scheduler_client; pub mod storage_client; -use execution::substrait::deserialize::get_json; +use execution::substrait::deserialize::*; #[tokio::main] async fn main() { println!("Hello, world!"); - get_json("../substrait/substrait_plan_example.json"); + // get_plan("../substrait/substrait_plan_example.json"); // get_json("../substrait/basic_query.json"); + get_read("../substrait/read_rel_example.json"); }