Skip to content

Commit 5ebd86b

Browse files
authored
cscl - make lionkey unique (#2070)
* guarantee seqnum uniqueness by bfc * simplify query slightly * use lionkey instead of lionkey_dev * add source table pk constraint to int__segments * reorganize lion ctes * rename int segments model yml * keep globalid through lion transformations * alphabetize
1 parent 93cb9ef commit 5ebd86b

16 files changed

+157
-96
lines changed

.github/workflows/build.yml

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,12 @@ on:
1616
- checkbook
1717
- colp
1818
- cpdb
19+
- cscl
1920
- developments
2021
- facilities
2122
- factfinder
2223
- green_fast_track
2324
- knownprojects
24-
- cscl
2525
- pluto
2626
- ztl
2727
- all
@@ -197,6 +197,17 @@ jobs:
197197
recipe_file: ${{ inputs.recipe_file }}
198198
plan_command: ${{ needs.health_check.outputs.plan_command }}
199199
dev_bucket: ${{ inputs.dev_bucket && format('de-dev-{0}', inputs.dev_bucket) || '' }}
200+
cscl:
201+
needs: health_check
202+
if: inputs.dataset_name == 'cscl' || inputs.dataset_name == 'all'
203+
uses: ./.github/workflows/cscl_build.yml
204+
secrets: inherit
205+
with:
206+
image_tag: ${{ needs.health_check.outputs.tag }}
207+
recipe_file: ${{ inputs.recipe_file }}
208+
build_name: ${{ needs.health_check.outputs.build_name }}
209+
plan_command: ${{ needs.health_check.outputs.plan_command }}
210+
dev_bucket: ${{ inputs.dev_bucket && format('de-dev-{0}', inputs.dev_bucket) || '' }}
200211
developments:
201212
needs: health_check
202213
if: inputs.dataset_name == 'developments' || inputs.dataset_name == 'all'
@@ -251,17 +262,6 @@ jobs:
251262
recipe_file: ${{ inputs.recipe_file }}
252263
plan_command: ${{ needs.health_check.outputs.plan_command }}
253264
dev_bucket: ${{ inputs.dev_bucket && format('de-dev-{0}', inputs.dev_bucket) || '' }}
254-
cscl:
255-
needs: health_check
256-
if: inputs.dataset_name == 'cscl' || inputs.dataset_name == 'all'
257-
uses: ./.github/workflows/cscl_build.yml
258-
secrets: inherit
259-
with:
260-
image_tag: ${{ needs.health_check.outputs.tag }}
261-
recipe_file: ${{ inputs.recipe_file }}
262-
build_name: ${{ needs.health_check.outputs.build_name }}
263-
plan_command: ${{ needs.health_check.outputs.plan_command }}
264-
dev_bucket: ${{ inputs.dev_bucket && format('de-dev-{0}', inputs.dev_bucket) || '' }}
265265
pluto:
266266
needs: health_check
267267
if: inputs.dataset_name == 'pluto' || inputs.dataset_name == 'all'

.github/workflows/test_helper.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,8 @@ jobs:
8787
- cdbg
8888
- ceqr
8989
- cpdb
90-
- green_fast_track
9190
- cscl
91+
- green_fast_track
9292
- pluto
9393
- zoningtaxlots
9494
steps:

products/cscl/models/intermediate/adjacent_polygons/int__segment_atomicpolygons.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ WITH segment_offsets AS (
99
)
1010

1111
SELECT
12-
so.lionkey_dev,
12+
so.lionkey,
1313
so.segmentid,
1414
so.boroughcode AS segment_borocode,
1515
left_poly.atomicid AS left_atomicid,

products/cscl/models/intermediate/adjacent_polygons/int__segment_nypdbeat.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ WITH segment_offsets AS (
99
)
1010

1111
SELECT
12-
co.lionkey_dev,
12+
co.lionkey,
1313
co.segmentid,
1414
left(left_beat.post, 1) AS left_nypd_service_area,
1515
left(right_beat.post, 1) AS right_nypd_service_area

products/cscl/models/intermediate/adjacent_polygons/int__segment_offsets.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ WITH segments AS (
77
)
88

99
SELECT
10-
lionkey_dev,
10+
lionkey,
1111
segmentid,
1212
boroughcode,
1313
feature_type,

products/cscl/models/intermediate/adjacent_polygons/int__segment_zipcodes.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ WITH segment_offsets AS (
99
SELECT * FROM {{ ref("int__segment_offsets") }}
1010
)
1111
SELECT
12-
so.lionkey_dev,
12+
so.lionkey,
1313
so.segmentid,
1414
leftzip.zip_code AS l_zip,
1515
rightzip.zip_code AS r_zip

products/cscl/models/intermediate/int__lion.sql

Lines changed: 19 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,73 +1,64 @@
11
{{ config(
22
materialized = 'table',
33
indexes=[
4-
{'columns': ['segmentid']},
4+
{'columns': ['lionkey']},
55
{'columns': ['boroughcode', 'segment_seqnum', 'segmentid']}
66
]
77
) }}
88

9+
-- backbone
910
WITH segments AS (
1011
SELECT * FROM {{ ref("int__segments") }}
1112
),
1213

13-
segment_locational_status AS (
14-
SELECT * FROM {{ ref("int__segment_locational_status") }}
15-
),
16-
14+
-- source data lookup tables
1715
centerline AS (
1816
SELECT * FROM {{ ref("stg__centerline") }}
1917
),
20-
2118
rail AS (
2219
SELECT * FROM {{ ref("stg__rail_and_subway" ) }}
2320
),
24-
2521
nsf AS (
2622
SELECT * FROM {{ ref("stg__nonstreetfeatures") }}
2723
),
24+
proto AS (
25+
SELECT * FROM {{ ref("stg__altsegmentdata_proto") }}
26+
),
2827

28+
-- transformation lookup tables
29+
segment_locational_status AS (
30+
SELECT * FROM {{ ref("int__segment_locational_status") }}
31+
),
2932
atomic_polygons AS (
3033
SELECT * FROM {{ ref("int__segment_atomicpolygons") }}
3134
),
32-
3335
nodes AS (
3436
SELECT * FROM {{ ref("int__segments_with_nodes") }}
3537
),
36-
3738
saf AS (
3839
SELECT * FROM {{ ref("int__segment_specialaddress") }}
3940
),
40-
4141
centerline_curve AS (
4242
SELECT * FROM {{ ref("int__centerline_curve") }}
4343
),
44-
4544
sedat AS (
4645
SELECT * FROM {{ ref("int__split_election_district") }}
4746
),
48-
4947
nypd_service_areas AS (
5048
SELECT * FROM {{ ref("int__segment_nypdbeat") }}
5149
),
52-
5350
zips AS (
5451
SELECT * FROM {{ ref("int__segment_zipcodes") }}
5552
),
56-
5753
centerline_coincident_subway_or_rail AS (
5854
SELECT * FROM {{ ref("int__centerline_coincident_subway_or_rail") }}
5955
),
60-
6156
noncl_coincident_segment AS (
6257
SELECT * FROM {{ ref("int__noncenterline_coincident_segment_count") }}
63-
),
64-
65-
proto AS (
66-
SELECT * FROM {{ ref("stg__altsegmentdata_proto") }}
6758
)
6859

6960
SELECT
70-
segments.lionkey_dev,
61+
segments.lionkey,
7162
segments.boroughcode,
7263
segments.face_code,
7364
segments.segment_seqnum,
@@ -262,6 +253,7 @@ SELECT
262253
segments.feature_type_description,
263254
segments.source_table,
264255
segments.geom,
256+
segments.globalid,
265257
CASE
266258
WHEN segments.feature_type = 'centerline' THEN centerline.include_in_geosupport_lion
267259
WHEN segments.feature_type = 'rail_and_subway' THEN rail.include_in_geosupport_lion
@@ -272,20 +264,20 @@ SELECT
272264
ELSE TRUE
273265
END AS include_in_bytes_lion
274266
FROM segments
275-
LEFT JOIN nodes ON segments.lionkey_dev = nodes.lionkey_dev
276-
LEFT JOIN segment_locational_status ON segments.lionkey_dev = segment_locational_status.lionkey_dev
267+
LEFT JOIN nodes ON segments.lionkey = nodes.lionkey
268+
LEFT JOIN segment_locational_status ON segments.lionkey = segment_locational_status.lionkey
277269
LEFT JOIN
278270
atomic_polygons AS ap_left
279271
ON
280-
segments.lionkey_dev = ap_left.lionkey_dev
272+
segments.lionkey = ap_left.lionkey
281273
AND segment_locational_status.borough_boundary_indicator IS DISTINCT FROM 'L'
282274
LEFT JOIN
283275
atomic_polygons AS ap_right
284276
ON
285-
segments.lionkey_dev = ap_right.lionkey_dev
277+
segments.lionkey = ap_right.lionkey
286278
AND segment_locational_status.borough_boundary_indicator IS DISTINCT FROM 'R'
287279
LEFT JOIN saf ON segments.segmentid = saf.segmentid AND segments.boroughcode = saf.boroughcode
288-
LEFT JOIN nypd_service_areas ON segments.lionkey_dev = nypd_service_areas.lionkey_dev
280+
LEFT JOIN nypd_service_areas ON segments.lionkey = nypd_service_areas.lionkey
289281
LEFT JOIN sedat ON segments.segmentid = sedat.segmentid AND segments.boroughcode = sedat.boroughcode
290282
-- centerline only
291283
LEFT JOIN centerline AS primary_centerline ON segments.segmentid = primary_centerline.segmentid
@@ -298,5 +290,5 @@ LEFT JOIN centerline_coincident_subway_or_rail
298290
LEFT JOIN rail ON segments.segmentid = rail.segmentid
299291
-- other
300292
LEFT JOIN noncl_coincident_segment ON segments.segmentid = noncl_coincident_segment.segmentid
301-
LEFT JOIN zips ON segments.lionkey_dev = zips.lionkey_dev AND segments.feature_type <> 'centerline'
302-
LEFT JOIN proto ON segments.source_table = 'altsegmentdata' AND segments.ogc_fid = proto.ogc_fid
293+
LEFT JOIN zips ON segments.lionkey = zips.lionkey AND segments.feature_type <> 'centerline'
294+
LEFT JOIN proto ON segments.globalid = proto.globalid

products/cscl/models/intermediate/nodes/int__segments_to_nodes.sql

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,22 +16,22 @@ nodes AS (
1616

1717
segment_endpoints AS (
1818
SELECT
19-
lionkey_dev,
19+
lionkey,
2020
segmentid,
2121
'from' AS direction,
2222
start_point AS geom
2323
FROM segments
2424
UNION ALL
2525
SELECT
26-
lionkey_dev,
26+
lionkey,
2727
segmentid,
2828
'to' AS direction,
2929
end_point AS geom
3030
FROM segments
3131
)
3232

3333
SELECT
34-
seg.lionkey_dev,
34+
seg.lionkey,
3535
seg.segmentid,
3636
seg.direction,
3737
nodes.nodeid

products/cscl/models/intermediate/nodes/int__segments_with_nodes.sql

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
WITH segments AS (
99
SELECT
10-
lionkey_dev,
10+
lionkey,
1111
segmentid,
1212
st_startpoint(geom) AS from_geom,
1313
st_endpoint(geom) AS to_geom
@@ -19,7 +19,7 @@ segments_to_nodes AS (
1919
)
2020

2121
SELECT
22-
segments.lionkey_dev,
22+
segments.lionkey,
2323
segments.segmentid,
2424
st_x(segments.from_geom) AS from_x,
2525
st_y(segments.from_geom) AS from_y,
@@ -31,9 +31,9 @@ SELECT
3131
to_sm.sectional_map AS to_sectionalmap
3232
FROM segments
3333
LEFT JOIN segments_to_nodes AS n_from
34-
ON segments.lionkey_dev = n_from.lionkey_dev AND n_from.direction = 'from'
34+
ON segments.lionkey = n_from.lionkey AND n_from.direction = 'from'
3535
LEFT JOIN segments_to_nodes AS n_to
36-
ON segments.lionkey_dev = n_to.lionkey_dev AND n_to.direction = 'to'
36+
ON segments.lionkey = n_to.lionkey AND n_to.direction = 'to'
3737
LEFT JOIN
3838
{{ source("recipe_sources", "dcp_cscl_sectionalmap") }} AS from_sm
3939
ON st_contains(from_sm.geom, segments.from_geom)

products/cscl/models/intermediate/other_lion_intermediates/int__segment_locational_status.sql

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
{{ config(
22
materialized = 'table',
33
indexes=[
4-
{'columns': ['lionkey_dev']},
4+
{'columns': ['lionkey']},
55
]
66
) }}
77

88
WITH atomicpolygons AS (
99
SELECT
10-
lionkey_dev,
10+
lionkey,
1111
segmentid,
1212
segment_borocode,
1313
left_atomicid,
@@ -35,11 +35,11 @@ segments_by_node AS (
3535

3636
segments_n_neighbors AS (
3737
SELECT
38-
lionkey_dev,
38+
lionkey,
3939
min(n_segments) AS minimum_neighbors -- between the two nodes, minimum number of segments joined
4040
FROM segments_to_nodes AS s2n
4141
INNER JOIN segments_by_node AS sbn ON s2n.nodeid = sbn.nodeid
42-
GROUP BY lionkey_dev
42+
GROUP BY lionkey
4343
),
4444

4545
-- All CTEs below divide the atomicpolygons into different categories.
@@ -74,7 +74,7 @@ same_ap AS (
7474
WHEN snn.minimum_neighbors > 1 THEN 'H'
7575
END AS segment_locational_status
7676
FROM atomicpolygons AS ap
77-
LEFT JOIN segments_n_neighbors AS snn ON ap.lionkey_dev = snn.lionkey_dev
77+
LEFT JOIN segments_n_neighbors AS snn ON ap.lionkey = snn.lionkey
7878
WHERE ap.left_atomicid = ap.right_atomicid
7979
),
8080
different_aps_different_boros AS (

0 commit comments

Comments
 (0)