cognite/dto/data_modeling/streams.rs
1use serde::{Deserialize, Serialize};
2
3use crate::{to_query, IntoParams};
4
5#[derive(Debug, Default, Clone, Serialize, Deserialize)]
6#[serde(rename_all = "camelCase")]
7/// Reference to a template used to create a stream.
8pub struct StreamTemplate {
9 /// Name of the template.
10 pub name: String,
11}
12#[derive(Debug, Default, Clone, Serialize, Deserialize)]
13#[serde(rename_all = "camelCase")]
14/// Settings for creating a stream.
15pub struct StreamSettingsWrite {
16 /// The template to use when creating the stream.
17 pub template: StreamTemplate,
18}
19
20/// A stream to create in CDF.
21#[derive(Debug, Default, Clone, Serialize, Deserialize)]
22#[serde(rename_all = "camelCase")]
23pub struct StreamWrite {
24 /// Stream identifier. The identifier must be unique within the project
25 /// and must be a valid stream identifier. Stream identifiers can
26 /// only consist of alphanumeric characters, hyphens, and underscores.
27 /// It must not start with cdf_ or cognite_, as those are reserved
28 /// for future use. Stream id cannot be logs or records.
29 /// Max length is 100 characters.
30 pub external_id: String,
31 /// Settings for the stream.
32 pub settings: StreamSettingsWrite,
33}
34
35impl From<Stream> for StreamWrite {
36 fn from(stream: Stream) -> Self {
37 Self {
38 external_id: stream.external_id,
39 settings: StreamSettingsWrite {
40 template: StreamTemplate {
41 name: stream.created_from_template,
42 },
43 },
44 }
45 }
46}
47
48#[derive(Debug, Default, Clone, Serialize, Deserialize)]
49/// Type of stream. See the [API documentation](https://api-docs.cognite.com/20230101/tag/Streams#section/Available-stream-templates) for details.
50pub enum StreamType {
51 #[default]
52 /// The stream is immutable. Immutable streams allow ingestion
53 /// of very large amounts of data.
54 Immutable,
55 /// The stream is mutable. Mutable streams allow modification
56 /// and deletion of records, but have lower ingestion limits.
57 Mutable,
58}
59
60#[derive(Debug, Default, Clone, Serialize, Deserialize)]
61#[serde(rename_all = "camelCase")]
62/// Lifecycle settings for a stream.
63pub struct StreamLifecycle {
64 /// ISO-8601 formatted date string for when data in the stream
65 /// will be automatically deleted.
66 pub data_deleted_after: Option<String>,
67 /// ISO-8601 formatted date string for when the stream
68 /// will be deleted once it is soft-deleted.
69 pub retained_after_soft_delete: String,
70}
71
72#[derive(Debug, Default, Clone, Serialize, Deserialize)]
73#[serde(rename_all = "camelCase")]
74/// Resource limits and metrics for a stream.
75pub struct StreamResourceLimits {
76 /// Provisioned capacity for the stream.
77 pub provisioned: f64,
78 /// Consumed capacity for the stream. Only included if `includeStatistics` is `true`.
79 pub consumed: Option<f64>,
80}
81
82#[derive(Debug, Default, Clone, Serialize, Deserialize)]
83#[serde(rename_all = "camelCase")]
84/// Limits for a stream.
85pub struct StreamLimits {
86 /// Maximum length of time that the `lastUpdatedTime` filter can retrieve
87 /// records for, in ISO-8601 format. This setting is only available for immutable
88 /// streams.
89 pub max_filtering_interval: Option<String>,
90 /// Maximum number of records allowed in the stream.
91 pub max_records_total: StreamResourceLimits,
92 /// Maximum total size of all records in the stream, in gigabytes.
93 pub max_giga_bytes_total: StreamResourceLimits,
94}
95
96#[derive(Debug, Default, Clone, Serialize, Deserialize)]
97#[serde(rename_all = "camelCase")]
98/// Settings for a stream.
99pub struct StreamSettings {
100 /// Lifecycle settings for the stream.
101 pub lifecycle: StreamLifecycle,
102 /// Limits for the stream.
103 pub limits: StreamLimits,
104}
105
106/// A stream in CDF.
107#[derive(Debug, Default, Clone, Serialize, Deserialize)]
108#[serde(rename_all = "camelCase")]
109pub struct Stream {
110 /// Stream identifier.
111 pub external_id: String,
112 /// Time the stream was created.
113 pub created_time: i64,
114 /// Name of the template used for creating this stream. Note:
115 /// This value is for information only. The template might have been modified
116 /// or even entirely deleted after the stream was created.
117 pub created_from_template: String,
118 /// Defines type of the stream.
119 pub r#type: StreamType,
120 /// Settings for the stream.
121 pub settings: Option<StreamSettings>,
122}
123
124/// Query parameters for listing streams.
125#[derive(Debug, Default)]
126pub struct ListStreamParams {}
127
128impl IntoParams for ListStreamParams {
129 fn into_params(self) -> Vec<(String, String)> {
130 vec![]
131 }
132}
133
134#[derive(Debug, Default)]
135/// Query parameters for retrieving a stream.
136pub struct RetrieveStreamParams {
137 /// Whether to include statistics about resource consumption.
138 pub include_statistics: Option<bool>,
139}
140
141impl IntoParams for RetrieveStreamParams {
142 fn into_params(self) -> Vec<(String, String)> {
143 let mut params = Vec::new();
144 to_query("includeStatistics", &self.include_statistics, &mut params);
145 params
146 }
147}