mz_compute_types/
sources.rs

1// Copyright Materialize, Inc. and contributors. All rights reserved.
2//
3// Use of this software is governed by the Business Source License
4// included in the LICENSE file.
5//
6// As of the Change Date specified in that file, in accordance with
7// the Business Source License, use of this software will be governed
8// by the Apache License, Version 2.0.
9
10//! Types for describing dataflow sources.
11
12use mz_proto::{IntoRustIfSome, ProtoType, RustType, TryFromProtoError};
13use mz_repr::RelationType;
14use mz_storage_types::controller::CollectionMetadata;
15use proptest_derive::Arbitrary;
16use serde::{Deserialize, Serialize};
17
18include!(concat!(env!("OUT_DIR"), "/mz_compute_types.sources.rs"));
19
20/// A description of an instantiation of a source.
21///
22/// This includes a description of the source, but additionally any
23/// context-dependent options like the ability to apply filtering and
24/// projection to the records as they emerge.
25#[derive(Arbitrary, Debug, Clone, Eq, PartialEq, Serialize, Deserialize)]
26pub struct SourceInstanceDesc<M> {
27    /// Arguments for this instantiation of the source.
28    pub arguments: SourceInstanceArguments,
29    /// Additional metadata used by the storage client of a compute instance to read it.
30    pub storage_metadata: M,
31    /// The relation type of this source
32    pub typ: RelationType,
33}
34
35impl RustType<ProtoSourceInstanceDesc> for SourceInstanceDesc<CollectionMetadata> {
36    fn into_proto(&self) -> ProtoSourceInstanceDesc {
37        ProtoSourceInstanceDesc {
38            arguments: Some(self.arguments.into_proto()),
39            storage_metadata: Some(self.storage_metadata.into_proto()),
40            typ: Some(self.typ.into_proto()),
41        }
42    }
43
44    fn from_proto(proto: ProtoSourceInstanceDesc) -> Result<Self, TryFromProtoError> {
45        Ok(SourceInstanceDesc {
46            arguments: proto
47                .arguments
48                .into_rust_if_some("ProtoSourceInstanceDesc::arguments")?,
49            storage_metadata: proto
50                .storage_metadata
51                .into_rust_if_some("ProtoSourceInstanceDesc::storage_metadata")?,
52            typ: proto
53                .typ
54                .into_rust_if_some("ProtoSourceInstanceDesc::typ")?,
55        })
56    }
57}
58
59/// Per-source construction arguments.
60#[derive(Arbitrary, Debug, Clone, Eq, PartialEq, Serialize, Deserialize)]
61pub struct SourceInstanceArguments {
62    /// Linear operators to be applied record-by-record.
63    pub operators: Option<mz_expr::MapFilterProject>,
64}
65
66impl RustType<ProtoSourceInstanceArguments> for SourceInstanceArguments {
67    fn into_proto(&self) -> ProtoSourceInstanceArguments {
68        ProtoSourceInstanceArguments {
69            operators: self.operators.into_proto(),
70        }
71    }
72
73    fn from_proto(proto: ProtoSourceInstanceArguments) -> Result<Self, TryFromProtoError> {
74        Ok(SourceInstanceArguments {
75            operators: proto.operators.into_rust()?,
76        })
77    }
78}