Add paths

This commit is contained in:
Andras Schmelczer 2026-03-10 21:51:06 +00:00
parent f3e3c1ee49
commit 02ec8ff4d2
4 changed files with 255 additions and 49 deletions

View file

@ -107,13 +107,19 @@ public class Parquet {
Files.move(tmp, outPath, StandardCopyOption.REPLACE_EXISTING, StandardCopyOption.ATOMIC_MOVE);
}
/** Write transit travel times with both median and best-case columns. */
/**
* Write transit travel times with median, best-case, and optional journey columns.
* @param journeys may be null (no journey column written) or non-null (journey VARCHAR added, individual elements may be null)
*/
static void writeTransitTravelTimes(DuckDBConnection conn, Path outPath,
String[] postcodes, short[] times, short[] bestTimes) throws Exception {
String[] postcodes, short[] times, short[] bestTimes, String[] journeys) throws Exception {
Path tmp = outPath.resolveSibling(outPath.getFileName() + ".tmp");
boolean hasJourneys = journeys != null;
try (Statement stmt = conn.createStatement()) {
stmt.execute("DROP TABLE IF EXISTS t");
stmt.execute("CREATE TABLE t (pcds VARCHAR, travel_minutes SMALLINT, best_minutes SMALLINT)");
stmt.execute(hasJourneys
? "CREATE TABLE t (pcds VARCHAR, travel_minutes SMALLINT, best_minutes SMALLINT, journey VARCHAR)"
: "CREATE TABLE t (pcds VARCHAR, travel_minutes SMALLINT, best_minutes SMALLINT)");
}
try (DuckDBAppender appender = conn.createAppender("main", "t")) {
for (int i = 0; i < postcodes.length; i++) {
@ -121,6 +127,7 @@ public class Parquet {
appender.append(postcodes[i]);
appender.append(times[i]);
appender.append(bestTimes[i]);
if (hasJourneys) appender.append(journeys[i]); // null-safe: DuckDB appends SQL NULL
appender.endRow();
}
}