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
15mod df_substrait;
16pub mod error;
17pub mod extension_serializer;
18
19use async_trait::async_trait;
20use bytes::{Buf, Bytes};
21use datafusion::execution::context::SessionState;
22pub use datafusion::execution::registry::SerializerRegistry;
23/// Re-export the Substrait module of datafusion,
24/// note this is a different version of the `substrait_proto` crate
25pub use datafusion_substrait::substrait as substrait_proto_df;
26pub use datafusion_substrait::{logical_plan as df_logical_plan, variation_const};
27pub use substrait_proto;
28
29pub use crate::df_substrait::DFLogicalSubstraitConvertor;
30#[async_trait]
31pub trait SubstraitPlan {
32    type Error: std::error::Error;
33
34    type Plan;
35
36    async fn decode<B: Buf + Send>(
37        &self,
38        message: B,
39        state: SessionState,
40    ) -> Result<Self::Plan, Self::Error>;
41
42    fn encode(
43        &self,
44        plan: &Self::Plan,
45        serializer: impl SerializerRegistry + 'static,
46    ) -> Result<Bytes, Self::Error>;
47}