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