substrait/
lib.rs

1// Copyright 2023 Greptime Team
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7//     http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15#![feature(let_chains)]
16
17mod df_substrait;
18pub mod error;
19pub mod extension_serializer;
20
21use async_trait::async_trait;
22use bytes::{Buf, Bytes};
23use datafusion::execution::context::SessionState;
24pub use datafusion::execution::registry::SerializerRegistry;
25/// Re-export the Substrait module of datafusion,
26/// note this is a different version of the `substrait_proto` crate
27pub use datafusion_substrait::substrait as substrait_proto_df;
28pub use datafusion_substrait::{logical_plan as df_logical_plan, variation_const};
29pub use substrait_proto;
30
31pub use crate::df_substrait::DFLogicalSubstraitConvertor;
32#[async_trait]
33pub trait SubstraitPlan {
34    type Error: std::error::Error;
35
36    type Plan;
37
38    async fn decode<B: Buf + Send>(
39        &self,
40        message: B,
41        state: SessionState,
42    ) -> Result<Self::Plan, Self::Error>;
43
44    fn encode(
45        &self,
46        plan: &Self::Plan,
47        serializer: impl SerializerRegistry + 'static,
48    ) -> Result<Bytes, Self::Error>;
49}