Skip to main content

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}
49
50impl<S> ComputeSinkConnection<S> {
51    /// Returns the name of the sink connection.
52    pub fn name(&self) -> &'static str {
53        match self {
54            ComputeSinkConnection::Subscribe(_) => "subscribe",
55            ComputeSinkConnection::MaterializedView(_) => "materialized_view",
56            ComputeSinkConnection::CopyToS3Oneshot(_) => "copy_to_s3_oneshot",
57        }
58    }
59
60    /// True if the sink is a subscribe, which is differently recoverable than other sinks.
61    pub fn is_subscribe(&self) -> bool {
62        if let ComputeSinkConnection::Subscribe(_) = self {
63            true
64        } else {
65            false
66        }
67    }
68}
69
70/// TODO(database-issues#7533): Add documentation.
71#[derive(Clone, Debug, Serialize, Deserialize, Eq, PartialEq)]
72pub struct SubscribeSinkConnection {
73    /// An ordering for the data in the subscribe.
74    pub output: Vec<ColumnOrder>,
75}
76
77/// Connection attributes required to do a oneshot copy to s3.
78#[derive(Clone, Debug, Serialize, Deserialize, Eq, PartialEq)]
79pub struct CopyToS3OneshotSinkConnection {
80    /// Information specific to the upload.
81    pub upload_info: S3UploadInfo,
82    /// The AWS connection information to do the writes.
83    pub aws_connection: AwsConnection,
84    /// The ID of the Connection object, used to generate the External ID when
85    /// using AssumeRole with AWS connection.
86    pub connection_id: CatalogItemId,
87    /// The number of batches the COPY TO output will be divided into
88    /// where each worker will process 0 or more batches of data.
89    pub output_batch_count: u64,
90}
91
92/// TODO(database-issues#7533): Add documentation.
93#[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize)]
94pub struct MaterializedViewSinkConnection<S> {
95    /// TODO(database-issues#7533): Add documentation.
96    pub value_desc: RelationDesc,
97    /// TODO(database-issues#7533): Add documentation.
98    pub storage_metadata: S,
99}