Skip to content

Commit

Permalink
Merge pull request #58 from dpguthrie/neo-demo
Browse files Browse the repository at this point in the history
spatial data
  • Loading branch information
dpguthrie authored Feb 11, 2024
2 parents 34b6a87 + c7d589e commit 624ba0c
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 0 deletions.
12 changes: 12 additions & 0 deletions models/demo_examples/bike_station_point_features.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{{
config(
materialized='table',
post_hook='alter table {{ this }} add search optimization on geo(point_features);'
)
}}

select

-- https://docs.snowflake.com/en/sql-reference/functions/st_collect
st_collect(point) as point_features
from {{ ref('stg_bikes_station_info') }}
21 changes: 21 additions & 0 deletions models/staging/bikes/_bikes__sources.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
version: 2


sources:
- name: bikes
database: chicago_divvy_bike_station_status
schema: public
tables:
- name: station_info_flatten
columns:
- name: station_id
tests:
- not_null
- unique
- name: lat
tests:
- dbt_utils.expression_is_true:
expression: "lat between -90 and 90"
- dbt_utils.expression_is_true:
expression: "lon between -180 and 180"
- name: station_status_flatten_full
26 changes: 26 additions & 0 deletions models/staging/bikes/stg_bikes_station_info.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
with source as (
select * from {{ source('bikes', 'station_info_flatten') }}
),

recast as (
select
short_name::varchar as short_name,
station_type::varchar as station_type,
name::varchar as name,
electric_bike_surcharge_waiver,
external_id::varchar as external_id,
legacy_id::int as legacy_id,
capacity,
has_kiosk,
station_id::varchar as station_id,
region_id::int as region_id,
eightd_station_services,
lat as latitude,
lon as longitude,

-- https://docs.snowflake.com/en/sql-reference/functions/st_makepoint
st_makepoint(lon, lat) as point
from source
)

select * from recast
25 changes: 25 additions & 0 deletions models/staging/bikes/stg_bikes_station_status.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
with source as (
select * from {{ source('bikes', 'station_status_flatten_full') }}
),

recast as (
select
station_id::varchar as station_id,
station_status::varchar as station_status,
num_ebikes_available,
num_bikes_available,
num_docks_available,
num_docks_disabled,
num_bikes_disabled,
is_installed,
num_ebikes_available_bool as is_ebikes_available,
is_renting,
is_returning,
eightd_has_available_keys,
legacy_id::varchar as legacy_id,
last_updated,
last_reported
from source
)

select * from recast

0 comments on commit 624ba0c

Please sign in to comment.