Skip to main content

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;
23pub use datafusion_substrait::extensions::Extensions;
24/// Re-export the Substrait module of datafusion,
25pub use datafusion_substrait::substrait as substrait_proto_df;
26pub use datafusion_substrait::{logical_plan as df_logical_plan, variation_const};
27
28pub use crate::df_substrait::DFLogicalSubstraitConvertor;
29#[async_trait]
30pub trait SubstraitPlan {
31    type Error: std::error::Error;
32
33    type Plan;
34
35    async fn decode<B: Buf + Send>(
36        &self,
37        message: B,
38        state: SessionState,
39    ) -> Result<Self::Plan, Self::Error>;
40
41    fn encode(
42        &self,
43        plan: &Self::Plan,
44        serializer: impl SerializerRegistry + 'static,
45    ) -> Result<Bytes, Self::Error>;
46}