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/// The sink does not write to persist, so there is no storage metadata to parameterize over.
83#[derive(Clone, Debug, Serialize, Deserialize, Eq, PartialEq)]
84pub struct MetricSinkConnection {
85 /// Value of the `sink` label on the sink's health gauges. A user sink passes its `GlobalId`,
86 /// which is durable. A coordinator-installed curated sink passes its definition name, because
87 /// its `GlobalId` is transient and would churn the label on every boot.
88 pub label: String,
89}
90
91/// Connection attributes required to do a oneshot copy to s3.
92#[derive(Clone, Debug, Serialize, Deserialize, Eq, PartialEq)]
93pub struct CopyToS3OneshotSinkConnection {
94 /// Information specific to the upload.
95 pub upload_info: S3UploadInfo,
96 /// The AWS connection information to do the writes.
97 pub aws_connection: AwsConnection,
98 /// The ID of the Connection object, used to generate the External ID when
99 /// using AssumeRole with AWS connection.
100 pub connection_id: CatalogItemId,
101 /// The number of batches the COPY TO output will be divided into
102 /// where each worker will process 0 or more batches of data.
103 pub output_batch_count: u64,
104}
105
106/// TODO(database-issues#7533): Add documentation.
107#[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize)]
108pub struct MaterializedViewSinkConnection<S> {
109 /// TODO(database-issues#7533): Add documentation.
110 pub value_desc: RelationDesc,
111 /// TODO(database-issues#7533): Add documentation.
112 pub storage_metadata: S,
113}