cognite/dto/data_ingestion/
raw.rs

1use serde::{Deserialize, Serialize};
2use serde_with::skip_serializing_none;
3
4use crate::{to_query, IntoParams, SetCursor};
5
6#[derive(Serialize, Deserialize, Debug, Clone)]
7#[serde(rename_all = "camelCase")]
8/// A raw database
9pub struct Database {
10    /// Raw database name
11    pub name: String,
12}
13
14#[derive(Serialize, Deserialize, Debug)]
15#[serde(rename_all = "camelCase")]
16/// Request for deleting raw databases.
17pub struct DeleteDatabasesRequest {
18    /// List of databases to delete.
19    pub items: Vec<Database>,
20    /// Whether to allow deleting databases with tables in them.
21    pub recursive: bool,
22}
23
24#[derive(Serialize, Deserialize, Debug, Clone)]
25#[serde(rename_all = "camelCase")]
26/// A raw table.
27pub struct Table {
28    /// Raw table name.
29    pub name: String,
30}
31
32#[derive(Serialize, Deserialize, Debug, Clone)]
33#[serde(rename_all = "camelCase")]
34/// A raw row.
35pub struct RawRow {
36    /// Raw row key.
37    pub key: String,
38    /// Raw row columns
39    pub columns: ::serde_json::Value,
40    /// When this column was last updated, in milliseconds since epoch.
41    pub last_updated_time: i64,
42}
43
44#[derive(Serialize, Deserialize, Debug, Default, Clone)]
45/// Create a raw row.
46pub struct RawRowCreate {
47    /// Raw row key.
48    pub key: String,
49    /// Raw row columns.
50    pub columns: ::serde_json::Value,
51}
52
53#[derive(Serialize, Deserialize, Debug, Clone)]
54/// Delete a raw row.
55pub struct DeleteRow {
56    /// Raw row key.
57    pub key: String,
58}
59
60#[derive(Debug, Default, Clone)]
61/// Query for retrieving cursors for parallel read.
62pub struct RetrieveCursorsQuery {
63    /// Minimum last updated time, in milliseconds since epoch.
64    pub min_last_updated_time: Option<i64>,
65    /// Maximum last updated time, in milliseconds since epoch.
66    pub max_last_updated_time: Option<i64>,
67    /// Requested number of cursors.
68    pub number_of_cursors: Option<i32>,
69}
70
71impl IntoParams for RetrieveCursorsQuery {
72    fn into_params(self) -> Vec<(String, String)> {
73        let mut params = Vec::<(String, String)>::new();
74        to_query(
75            "minLastUpdatedTime",
76            &self.min_last_updated_time,
77            &mut params,
78        );
79        to_query(
80            "maxLastUpdatedTime",
81            &self.max_last_updated_time,
82            &mut params,
83        );
84        to_query("numberOfCursors", &self.number_of_cursors, &mut params);
85        params
86    }
87}
88
89#[skip_serializing_none]
90#[derive(Debug, Default, Serialize, Clone)]
91/// Query for retrieving raw rows from a table.
92pub struct RetrieveRowsQuery {
93    /// Maximum number of rows to return.
94    pub limit: Option<i32>,
95    /// List of columns to return. Can be left out to return all columns.
96    pub columns: Option<Vec<String>>,
97    /// Optional cursor for pagination.
98    pub cursor: Option<String>,
99    /// Minimum last updated time, in millisecond since epoch.
100    pub min_last_updated_time: Option<i64>,
101    /// Maximum last updated time, in milliseconds since epoch.
102    pub max_last_updated_time: Option<i64>,
103}
104
105impl IntoParams for RetrieveRowsQuery {
106    fn into_params(self) -> Vec<(String, String)> {
107        let mut params = Vec::<(String, String)>::new();
108        to_query("limit", &self.limit, &mut params);
109        if let Some(columns) = self.columns {
110            to_query("columns", &Some(columns.join(",")), &mut params);
111        }
112        to_query("cursor", &self.cursor, &mut params);
113        to_query(
114            "minLastUpdatedTime",
115            &self.min_last_updated_time,
116            &mut params,
117        );
118        to_query(
119            "maxLastUpdatedTime",
120            &self.max_last_updated_time,
121            &mut params,
122        );
123        params
124    }
125}
126
127impl SetCursor for RetrieveRowsQuery {
128    fn set_cursor(&mut self, cursor: Option<String>) {
129        self.cursor = cursor;
130    }
131}
132
133#[derive(Debug, Default, Clone, Copy)]
134/// Query for whether to create missing parents when working with
135/// tables or rows.
136pub struct EnsureParentQuery {
137    /// Set to `true` to create missing parents.
138    pub ensure_parent: Option<bool>,
139}
140
141impl EnsureParentQuery {
142    /// Create a new ensure parent query.
143    ///
144    /// # Arguments
145    ///
146    /// * `ensure_parent` - `true` to create missing raw tables and destinations.
147    pub fn new(ensure_parent: bool) -> Self {
148        Self {
149            ensure_parent: Some(ensure_parent),
150        }
151    }
152}
153
154impl IntoParams for EnsureParentQuery {
155    fn into_params(self) -> Vec<(String, String)> {
156        let mut params = Vec::<(String, String)>::new();
157        to_query("ensureParent", &self.ensure_parent, &mut params);
158        params
159    }
160}
161
162#[derive(Debug, Default, Clone)]
163/// Query for retrieving all rows using partitioned reads from a table.
164pub struct RetrieveAllPartitionedQuery {
165    /// Minimum last updated time, in millisecond since epoch.
166    pub min_last_updated_time: Option<i64>,
167    /// Maximum last updated time, in milliseconds since epoch.
168    pub max_last_updated_time: Option<i64>,
169    /// Requested number of parallel reads.
170    pub number_of_cursors: Option<i32>,
171    /// List of columns to return. Can be left out to return all columns.
172    pub columns: Option<Vec<String>>,
173    /// Maximum number of rows to return per request.
174    pub limit: Option<i32>,
175}