mz_compute_types/sinks.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 sinks.
11
12use mz_expr::ColumnOrder;
13use mz_repr::refresh_schedule::RefreshSchedule;
14use mz_repr::{CatalogItemId, GlobalId, RelationDesc, Timestamp};
15use mz_storage_types::connections::aws::AwsConnection;
16use mz_storage_types::sinks::S3UploadInfo;
17use serde::{Deserialize, Serialize};
18use timely::progress::Antichain;
19
20/// A sink for updates to a relational collection.
21#[derive(Clone, Debug, Serialize, Deserialize, Eq, PartialEq)]
22pub struct ComputeSinkDesc<S: 'static = ()> {
23 /// TODO(database-issues#7533): Add documentation.
24 pub from: GlobalId,
25 /// TODO(database-issues#7533): Add documentation.
26 pub from_desc: RelationDesc,
27 /// TODO(database-issues#7533): Add documentation.
28 pub connection: ComputeSinkConnection<S>,
29 /// TODO(database-issues#7533): Add documentation.
30 pub with_snapshot: bool,
31 /// TODO(database-issues#7533): Add documentation.
32 pub up_to: Antichain<Timestamp>,
33 /// TODO(database-issues#7533): Add documentation.
34 pub non_null_assertions: Vec<usize>,
35 /// TODO(database-issues#7533): Add documentation.
36 pub refresh_schedule: Option<RefreshSchedule>,
37}
38
39/// TODO(database-issues#7533): Add documentation.
40#[derive(Clone, Debug, Serialize, Deserialize, Eq, PartialEq)]
41pub enum ComputeSinkConnection<S: 'static = ()> {
42 /// TODO(database-issues#7533): Add documentation.
43 Subscribe(SubscribeSinkConnection),
44 /// TODO(database-issues#7533): Add documentation.
45 MaterializedView(MaterializedViewSinkConnection<S>),
46 /// A compute sink to do a oneshot copy to s3.
47 CopyToS3Oneshot(CopyToS3OneshotSinkConnection),
48 /// A compute sink that writes rows into the in-process Prometheus metrics registry.
49 MetricSink(MetricSinkConnection),
50}
51
52impl<S> ComputeSinkConnection<S> {
53 /// Returns the name of the sink connection.
54 pub fn name(&self) -> &'static str {
55 match self {
56 ComputeSinkConnection::Subscribe(_) => "subscribe",
57 ComputeSinkConnection::MaterializedView(_) => "materialized_view",
58 ComputeSinkConnection::CopyToS3Oneshot(_) => "copy_to_s3_oneshot",
59 ComputeSinkConnection::MetricSink(_) => "metric_sink",
60 }
61 }
62
63 /// True if the sink is a subscribe, which is differently recoverable than other sinks.
64 pub fn is_subscribe(&self) -> bool {
65 if let ComputeSinkConnection::Subscribe(_) = self {
66 true
67 } else {
68 false
69 }
70 }
71}
72
73/// TODO(database-issues#7533): Add documentation.
74#[derive(Clone, Debug, Serialize, Deserialize, Eq, PartialEq)]
75pub struct SubscribeSinkConnection {
76 /// An ordering for the data in the subscribe.
77 pub output: Vec<ColumnOrder>,
78}
79
80/// Connection for a sink that publishes rows into the in-process Prometheus metrics registry.
81///
82/// Carries no payload: the identity of the metric to update is the sink's `GlobalId`, and the
83/// sink does not write to persist, so there is no storage metadata to parameterize over.
84#[derive(Clone, Debug, Serialize, Deserialize, Eq, PartialEq)]
85pub struct MetricSinkConnection {}
86
87/// Connection attributes required to do a oneshot copy to s3.
88#[derive(Clone, Debug, Serialize, Deserialize, Eq, PartialEq)]
89pub struct CopyToS3OneshotSinkConnection {
90 /// Information specific to the upload.
91 pub upload_info: S3UploadInfo,
92 /// The AWS connection information to do the writes.
93 pub aws_connection: AwsConnection,
94 /// The ID of the Connection object, used to generate the External ID when
95 /// using AssumeRole with AWS connection.
96 pub connection_id: CatalogItemId,
97 /// The number of batches the COPY TO output will be divided into
98 /// where each worker will process 0 or more batches of data.
99 pub output_batch_count: u64,
100}
101
102/// TODO(database-issues#7533): Add documentation.
103#[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize)]
104pub struct MaterializedViewSinkConnection<S> {
105 /// TODO(database-issues#7533): Add documentation.
106 pub value_desc: RelationDesc,
107 /// TODO(database-issues#7533): Add documentation.
108 pub storage_metadata: S,
109}