Skip to content

Instantly share code, notes, and snippets.

@lacerogers20
Last active August 26, 2022 09:39
Show Gist options
  • Save lacerogers20/aed630cbbb1a8cd11de4efa27155243f to your computer and use it in GitHub Desktop.
Save lacerogers20/aed630cbbb1a8cd11de4efa27155243f to your computer and use it in GitHub Desktop.
This will use "create table" and generate a new table with clustering and partitioning
CREATE TABLE
`testing.insert` (date DATE OPTIONS( description='date' ),
unique_visits INT64 OPTIONS( description='counts' ))
PARTITION BY
date
CLUSTER BY
unique_visits OPTIONS ( description="A table with a date partition",
labels=[("testing",
"data_is_great")],
expiration_timestamp=TIMESTAMP "2023-01-01 00:00:00 UTC"
) AS (
SELECT
DATE(TIMESTAMP_SECONDS( visitStartTime)) AS date,
COUNT(DISTINCT(visitid)) AS unique_visits
FROM
`bigquery-public-data.google_analytics_sample.ga_sessions_*`
WHERE
_table_suffix = '20170801'
GROUP BY
1);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment