gcp_bigquery_client/model/
time_partitioning.rs1use serde::{Deserialize, Serialize};
2use std::time::Duration;
3
4#[derive(Debug, Default, Clone, Serialize, Deserialize)]
5#[serde(rename_all = "camelCase")]
6pub struct TimePartitioning {
7 #[serde(skip_serializing_if = "Option::is_none")]
9 pub expiration_ms: Option<String>,
10 #[serde(skip_serializing_if = "Option::is_none")]
12 pub field: Option<String>,
13 #[serde(skip_serializing_if = "Option::is_none")]
14 pub require_partition_filter: Option<bool>,
15 #[serde(rename = "type")]
17 pub r#type: String,
18}
19
20impl TimePartitioning {
21 pub fn new(r#type: String) -> Self {
25 Self {
26 expiration_ms: None,
27 field: None,
28 require_partition_filter: None,
29 r#type,
30 }
31 }
32
33 pub fn per_hour() -> Self {
35 Self {
36 expiration_ms: None,
37 field: None,
38 require_partition_filter: None,
39 r#type: "HOUR".to_string(),
40 }
41 }
42
43 pub fn per_day() -> Self {
45 Self {
46 expiration_ms: None,
47 field: None,
48 require_partition_filter: None,
49 r#type: "DAY".to_string(),
50 }
51 }
52
53 pub fn per_month() -> Self {
55 Self {
56 expiration_ms: None,
57 field: None,
58 require_partition_filter: None,
59 r#type: "MONTH".to_string(),
60 }
61 }
62
63 pub fn per_year() -> Self {
65 Self {
66 expiration_ms: None,
67 field: None,
68 require_partition_filter: None,
69 r#type: "YEAR".to_string(),
70 }
71 }
72
73 pub fn expiration_ms(mut self, duration: Duration) -> Self {
75 self.expiration_ms = Some(duration.as_millis().to_string());
76 self
77 }
78
79 pub fn field(mut self, field: &str) -> Self {
81 self.field = Some(field.to_string());
82 self
83 }
84}