Skip to content

Commit 0725895

Browse files
authored
refactor: use consts instead of hardcoded format strings (supabase#355)
1 parent 3d08fd7 commit 0725895

File tree

1 file changed

+20
-17
lines changed

1 file changed

+20
-17
lines changed

etl-destinations/src/bigquery/validation.rs

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
use chrono::{DateTime, NaiveDate, NaiveDateTime, NaiveTime, TimeZone, Utc};
22
use etl::error::{ErrorKind, EtlResult};
3-
use etl::types::{ArrayCellNonOptional, CellNonOptional, PgNumeric};
3+
use etl::types::{
4+
ArrayCellNonOptional, CellNonOptional, DATE_FORMAT, PgNumeric, TIME_FORMAT, TIMESTAMP_FORMAT,
5+
TIMESTAMPTZ_FORMAT_HH_MM,
6+
};
47
use etl::{bail, etl_error};
58
use std::sync::LazyLock;
69

@@ -138,8 +141,8 @@ pub fn validate_date_for_bigquery(date: &NaiveDate) -> EtlResult<()> {
138141
"Date value is before BigQuery's minimum supported date",
139142
format!(
140143
"The date '{}' is before BigQuery's minimum supported date '{}'. BigQuery DATE supports values from 0001-01-01 to 9999-12-31",
141-
date.format("%Y-%m-%d"),
142-
BIGQUERY_MIN_DATE.format("%Y-%m-%d")
144+
date.format(DATE_FORMAT),
145+
BIGQUERY_MIN_DATE.format(DATE_FORMAT)
143146
)
144147
);
145148
}
@@ -150,8 +153,8 @@ pub fn validate_date_for_bigquery(date: &NaiveDate) -> EtlResult<()> {
150153
"Date value is after BigQuery's maximum supported date",
151154
format!(
152155
"The date '{}' is after BigQuery's maximum supported date '{}'. BigQuery DATE supports values from 0001-01-01 to 9999-12-31",
153-
date.format("%Y-%m-%d"),
154-
BIGQUERY_MAX_DATE.format("%Y-%m-%d")
156+
date.format(DATE_FORMAT),
157+
BIGQUERY_MAX_DATE.format(DATE_FORMAT)
155158
)
156159
);
157160
}
@@ -170,8 +173,8 @@ pub fn validate_time_for_bigquery(time: &NaiveTime) -> EtlResult<()> {
170173
"Time value is before BigQuery's minimum supported time",
171174
format!(
172175
"The time '{}' is before BigQuery's minimum supported time '{}'. BigQuery TIME supports values from 00:00:00 to 23:59:59.999999",
173-
time.format("%H:%M:%S"),
174-
BIGQUERY_MIN_TIME.format("%H:%M:%S")
176+
time.format(TIME_FORMAT),
177+
BIGQUERY_MIN_TIME.format(TIME_FORMAT)
175178
)
176179
);
177180
}
@@ -182,8 +185,8 @@ pub fn validate_time_for_bigquery(time: &NaiveTime) -> EtlResult<()> {
182185
"Time value is after BigQuery's maximum supported time",
183186
format!(
184187
"The time '{}' is after BigQuery's maximum supported time '{}'. BigQuery TIME supports values from 00:00:00 to 23:59:59.999999",
185-
time.format("%H:%M:%S%.6f"),
186-
BIGQUERY_MAX_TIME.format("%H:%M:%S%.6f")
188+
time.format(TIME_FORMAT),
189+
BIGQUERY_MAX_TIME.format(TIME_FORMAT)
187190
)
188191
);
189192
}
@@ -202,8 +205,8 @@ pub fn validate_datetime_for_bigquery(datetime: &NaiveDateTime) -> EtlResult<()>
202205
"DateTime value is before BigQuery's minimum supported datetime",
203206
format!(
204207
"The datetime '{}' is before BigQuery's minimum supported datetime '{}'. BigQuery DATETIME supports values from 0001-01-01 00:00:00 to 9999-12-31 23:59:59.999999",
205-
datetime.format("%Y-%m-%d %H:%M:%S"),
206-
BIGQUERY_MIN_DATETIME.format("%Y-%m-%d %H:%M:%S")
208+
datetime.format(TIMESTAMP_FORMAT),
209+
BIGQUERY_MIN_DATETIME.format(TIMESTAMP_FORMAT)
207210
)
208211
);
209212
}
@@ -214,8 +217,8 @@ pub fn validate_datetime_for_bigquery(datetime: &NaiveDateTime) -> EtlResult<()>
214217
"DateTime value is after BigQuery's maximum supported datetime",
215218
format!(
216219
"The datetime '{}' is after BigQuery's maximum supported datetime '{}'. BigQuery DATETIME supports values from 0001-01-01 00:00:00 to 9999-12-31 23:59:59.999999",
217-
datetime.format("%Y-%m-%d %H:%M:%S%.6f"),
218-
BIGQUERY_MAX_DATETIME.format("%Y-%m-%d %H:%M:%S%.6f")
220+
datetime.format(TIMESTAMP_FORMAT),
221+
BIGQUERY_MAX_DATETIME.format(TIMESTAMP_FORMAT)
219222
)
220223
);
221224
}
@@ -234,8 +237,8 @@ pub fn validate_timestamptz_for_bigquery(timestamptz: &DateTime<Utc>) -> EtlResu
234237
"Timestamp value is before BigQuery's minimum supported timestamp",
235238
format!(
236239
"The timestamp '{}' is before BigQuery's minimum supported timestamp '{}'. BigQuery TIMESTAMP supports values from 0001-01-01 00:00:00 UTC to 9999-12-31 23:59:59.999999 UTC",
237-
timestamptz.format("%Y-%m-%d %H:%M:%S%z"),
238-
BIGQUERY_MIN_TIMESTAMP.format("%Y-%m-%d %H:%M:%S%z")
240+
timestamptz.format(TIMESTAMPTZ_FORMAT_HH_MM),
241+
BIGQUERY_MIN_TIMESTAMP.format(TIMESTAMPTZ_FORMAT_HH_MM)
239242
)
240243
);
241244
}
@@ -246,8 +249,8 @@ pub fn validate_timestamptz_for_bigquery(timestamptz: &DateTime<Utc>) -> EtlResu
246249
"Timestamp value is after BigQuery's maximum supported timestamp",
247250
format!(
248251
"The timestamp '{}' is after BigQuery's maximum supported timestamp '{}'. BigQuery TIMESTAMP supports values from 0001-01-01 00:00:00 UTC to 9999-12-31 23:59:59.999999 UTC",
249-
timestamptz.format("%Y-%m-%d %H:%M:%S%.6f%z"),
250-
BIGQUERY_MAX_TIMESTAMP.format("%Y-%m-%d %H:%M:%S%.6f%z")
252+
timestamptz.format(TIMESTAMPTZ_FORMAT_HH_MM),
253+
BIGQUERY_MAX_TIMESTAMP.format(TIMESTAMPTZ_FORMAT_HH_MM)
251254
)
252255
);
253256
}

0 commit comments

Comments
 (0)