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.
910//! Types for describing dataflow sources.
1112use mz_proto::{IntoRustIfSome, ProtoType, RustType, TryFromProtoError};
13use mz_repr::RelationType;
14use mz_storage_types::controller::CollectionMetadata;
15use proptest_derive::Arbitrary;
16use serde::{Deserialize, Serialize};
1718include!(concat!(env!("OUT_DIR"), "/mz_compute_types.sources.rs"));
1920/// 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.
28pub arguments: SourceInstanceArguments,
29/// Additional metadata used by the storage client of a compute instance to read it.
30pub storage_metadata: M,
31/// The relation type of this source
32pub typ: RelationType,
33}
3435impl RustType<ProtoSourceInstanceDesc> for SourceInstanceDesc<CollectionMetadata> {
36fn 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 }
4344fn from_proto(proto: ProtoSourceInstanceDesc) -> Result<Self, TryFromProtoError> {
45Ok(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}
5859/// 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.
63pub operators: Option<mz_expr::MapFilterProject>,
64}
6566impl RustType<ProtoSourceInstanceArguments> for SourceInstanceArguments {
67fn into_proto(&self) -> ProtoSourceInstanceArguments {
68 ProtoSourceInstanceArguments {
69 operators: self.operators.into_proto(),
70 }
71 }
7273fn from_proto(proto: ProtoSourceInstanceArguments) -> Result<Self, TryFromProtoError> {
74Ok(SourceInstanceArguments {
75 operators: proto.operators.into_rust()?,
76 })
77 }
78}