Skip to content

Commit a3a05c9

Browse files
committed
WIP
1 parent 6ebc460 commit a3a05c9

File tree

7 files changed

+38
-3
lines changed

7 files changed

+38
-3
lines changed

index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ const convertGtfsToSql = async (pathToDb, files, opt = {}) => {
6161
dep: [],
6262
},
6363

64+
// todo: currently doesn't fail if *neither* calendar nor calendar_dates is present!
65+
6466
// special handling of calendar/calendar_dates:
6567
// service_days relies on *both* calendar's & calendar_dates' tables to
6668
// be present, so we add mock tasks here. Each of these mock tasks get

lib/deps.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,8 @@ const getDependencies = (opt, files) => {
7979
),
8080
...(files.includes('calendar') ? ['calendar'] : []),
8181
...(files.includes('calendar_dates') ? ['calendar_dates'] : []),
82-
// not supported yet: attributions
82+
// todo: support attributions
83+
// related: https://github.com/hove-io/transit_model/pull/994/files
8384
// not supported yet: fare_attributes/fare_rules
8485
// not supported yet: frequencies
8586
// not supported yet: transfers

lib/feed_info.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ CREATE TABLE feed_info (
1919
feed_start_date DATE,
2020
feed_end_date DATE,
2121
feed_version TEXT,
22+
-- todo: optional, how to handle this?
2223
feed_contact_email TEXT,
2324
feed_contact_url TEXT
2425
);

lib/shapes.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ CREATE TABLE shapes (
3030
3131
INSERT INTO shapes
3232
-- WITH
33+
-- -- todo: explicitly specify if we want materialization!
34+
-- -- see also https://github.com/duckdb/duckdb/pull/17459
3335
-- csv_columns AS (
3436
-- SELECT list(column_name) AS cols
3537
-- FROM (
@@ -42,6 +44,8 @@ INSERT INTO shapes
4244
-- )
4345
-- ) columns
4446
-- ),
47+
-- -- todo: explicitly specify if we want materialization!
48+
-- -- see also https://github.com/duckdb/duckdb/pull/17459
4549
-- table_columns AS (
4650
-- SELECT list(column_name)
4751
-- FROM (

lib/stats_active_trips_by_hour.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,39 +22,53 @@ const createStatsActiveTripsByHourView = async (db, _, opt) => {
2222
-- see also https://github.com/duckdb/duckdb/discussions/3638
2323
CREATE TABLE feed_time_frame AS
2424
WITH
25+
-- todo: explicitly specify if we want materialization!
26+
-- see also https://github.com/duckdb/duckdb/pull/17459
2527
dates AS (
2628
SELECT
2729
min("date") AS min,
2830
max("date") AS max
2931
FROM service_days
3032
),
33+
-- todo: explicitly specify if we want materialization!
34+
-- see also https://github.com/duckdb/duckdb/pull/17459
3135
date_offset AS (
3236
SELECT
3337
largest AS o
3438
FROM largest_arr_dep_time
3539
),
40+
-- todo: explicitly specify if we want materialization!
41+
-- see also https://github.com/duckdb/duckdb/pull/17459
3642
date_min_max AS (
3743
SELECT
3844
-- todo
3945
date_trunc('day', min + o) AS min,
4046
date_trunc('day', max - o) AS max
4147
FROM dates, date_offset
4248
),
49+
-- todo: explicitly specify if we want materialization!
50+
-- see also https://github.com/duckdb/duckdb/pull/17459
4351
min_dep AS (
4452
SELECT min("t_departure") AS t
4553
FROM arrivals_departures, date_min_max
4654
WHERE date <= (SELECT min FROM date_min_max)
4755
),
56+
-- todo: explicitly specify if we want materialization!
57+
-- see also https://github.com/duckdb/duckdb/pull/17459
4858
min_arr AS (
4959
SELECT min("t_arrival") AS t
5060
FROM arrivals_departures, date_min_max
5161
WHERE date <= (SELECT min FROM date_min_max)
5262
),
63+
-- todo: explicitly specify if we want materialization!
64+
-- see also https://github.com/duckdb/duckdb/pull/17459
5365
max_dep AS (
5466
SELECT min("t_departure") AS t
5567
FROM arrivals_departures, date_min_max
5668
WHERE date >= (SELECT max FROM date_min_max)
5769
),
70+
-- todo: explicitly specify if we want materialization!
71+
-- see also https://github.com/duckdb/duckdb/pull/17459
5872
max_arr AS (
5973
SELECT min("t_arrival") AS t
6074
FROM arrivals_departures, date_min_max

lib/stop_times.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ CREATE TABLE stop_times (
4040
arrival_time INTERVAL,
4141
departure_time INTERVAL,
4242
stop_id TEXT NOT NULL,
43-
FOREIGN KEY (stop_id) REFERENCES stops,
43+
FOREIGN KEY (stop_id) REFERENCES stops(stop_id),
4444
stop_sequence INT NOT NULL,
4545
stop_sequence_consec INT,
4646
stop_headsign TEXT,
@@ -87,7 +87,11 @@ FROM read_csv(
8787
drop_off_type: 'INTEGER',
8888
${has_shape_dist_traveled ? `shape_dist_traveled: 'REAL',` : ``}
8989
${has_timepoint ? `timepoint: 'INTEGER',` : ``}
90-
}
90+
},
91+
-- skip DuckDB's automatic format detection
92+
delim = ',',
93+
quote = '"',
94+
escape = '"'
9195
);
9296
9397
-- For a primary key, DuckDB doesn't create an index automatically.
@@ -107,6 +111,8 @@ CREATE INDEX stop_times_trip_id_stop_sequence_consec ON stop_times (trip_id, sto
107111
-- see also https://github.com/duckdb/duckdb/discussions/3638
108112
CREATE TABLE largest_arr_dep_time AS
109113
WITH
114+
-- todo: explicitly specify if we want materialization!
115+
-- see also https://github.com/duckdb/duckdb/pull/17459
110116
largest_departure_time AS (
111117
SELECT departure_time
112118
FROM stop_times stop_times
@@ -119,6 +125,8 @@ WITH
119125
ORDER BY departure_time DESC
120126
LIMIT 1
121127
),
128+
-- todo: explicitly specify if we want materialization!
129+
-- see also https://github.com/duckdb/duckdb/pull/17459
122130
largest_arrival_time AS (
123131
SELECT arrival_time
124132
FROM stop_times stop_times

lib/stops.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ CREATE TABLE stops (
8282
-- In stops.txt, *any* row's parent_station might reference *any* other row. Essentially, stops.txt describes a tree.
8383
-- As of DuckDB v1.0.0, it *seems* like adding a foreign key constraint here doesn't work, even if we order the stops to put parents before their children (see below).
8484
-- todo: Report this with DuckDB? Alternatively, add the constraint after the import (see below).
85+
-- maybe related? https://github.com/duckdb/duckdb/issues/10574
8586
-- FOREIGN KEY (parent_station) REFERENCES stops,
8687
stop_timezone TEXT,
8788
FOREIGN KEY (stop_timezone) REFERENCES valid_timezones,
@@ -96,6 +97,8 @@ INSERT INTO stops
9697
-- todo: handle the CSV file having *additional* columns
9798
BY NAME
9899
WITH RECURSIVE
100+
-- todo: explicitly specify if we want materialization!
101+
-- see also https://github.com/duckdb/duckdb/pull/17459
99102
stops AS (
100103
SELECT
101104
${has_stop_code ? `` : `NULL AS stop_code,`}
@@ -146,6 +149,8 @@ WITH RECURSIVE
146149
)
147150
),
148151
-- order the stops to put parents before their children
152+
-- todo: explicitly specify if we want materialization!
153+
-- see also https://github.com/duckdb/duckdb/pull/17459
149154
stops_sorted_by_parents AS (
150155
(
151156
SELECT

0 commit comments

Comments
 (0)