Skip to content

Commit

Permalink
chore: add query to fix splice wrong timezone
Browse files Browse the repository at this point in the history
  • Loading branch information
d116626 committed Jul 19, 2024
1 parent b47abef commit d2284ca
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions queries/models/utils/fix_splice_wrong_timezone.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
-- Declare the year and month variable
DECLARE year_month STRING DEFAULT '2024_07';

-- Create the table with partitioning and clustering
EXECUTE IMMEDIATE FORMAT("""
CREATE OR REPLACE TABLE `rj-cetrio.ocr_radar.readings_%s`
PARTITION BY
TIMESTAMP_TRUNC(
datahora
, HOUR)
CLUSTER BY placa
OPTIONS (
require_partition_filter = FALSE
)
AS (
SELECT
datahora_captura,
placa,
tipoveiculo,
velocidade,
CASE
WHEN datahora <= "2024-07-19 16:02:41 UTC" AND empresa = "SPLICE"
THEN TIMESTAMP_ADD(datahora, INTERVAL 3 HOUR)
ELSE datahora
END AS datahora,
camera_numero,
camera_latitude,
camera_longitude,
empresa
FROM `rj-cetrio.ocr_radar.readings_%s`
)
""", year_month, year_month);

0 comments on commit d2284ca

Please sign in to comment.