Skip to content

Conversation

cvvergara
Copy link
Member

@cvvergara cvvergara commented Oct 7, 2025

Changes proposed in this pull request:

  • Rewrite of the chapter about creating/using a SQL function
    • From the exercise the function is created
  • Updated images

@pgRouting/admins

Summary by CodeRabbit

  • New Features

    • Routing function enhanced to return human-readable route, route geometry and azimuth; accepts dynamic network selection.
    • Added a view for easy route-geometry retrieval.
  • Refactor

    • Replaced legacy image-based routing with the enhanced routing implementation; removed outdated example views.
  • Documentation

    • Major rewrite of the SQL function chapter: updated examples, parameters, images and exercise flow.
    • Renamed doc substitution tokens to use generic IDs; updated doc image set.
  • Chores

    • Updated localization files and metadata.

@cvvergara cvvergara added this to the FOSS4G 2025 milestone Oct 7, 2025
@cvvergara cvvergara requested a review from iosefa October 7, 2025 14:45
Copy link

coderabbitai bot commented Oct 7, 2025

Walkthrough

Reorders two CMake variable initializations; replaces several chapter images and rewrites the SQL function chapter and related script/build files; renames Sphinx substitution tokens; removes wrk_image and adds/expands wrk_dijkstra outputs and a sql_route_geom view; adds ID lookup queries; refreshes localization strings.

Changes

Cohort / File(s) Summary
Top-level build config
CMakeLists.txt
Moved initialization of CH7_PLACE_2 and CH7_OSMID_2 earlier in the file and removed the later duplicate initializations.
Docs images config
docs/basic/images/sql_function/CMakeLists.txt
Replaced several ch7-*.png entries with sql_*.png entries in PGR_WORKSHOP_IMG_FILES, changing which images are configured for the chapter.
SQL function chapter (RST)
docs/basic/sql_function.rst
Reworked chapter layout and wording: updated image refs, renamed sections, changed parameter names (source_osmsource, target_osmtarget), reordered/renamed outputs, and updated literalinclude/start-end markers and exercise flow.
Sphinx substitutions
docs/conf.py
Renamed rst_epilog tokens from ch7_osmid_1/ch7_osmid_2 to ch7_id_1/ch7_id_2 and updated substitution values to CH7_ID_1/CH7_ID_2.
Scripts build rules
docs/scripts/basic/sql_function/CMakeLists.txt
Replaced BYPRODUCTS list for the custom command: removed previous exercise_7_* targets and added new generated filenames (e.g., get_more_info.txt, get_read_geom.txt, get_geom.txt, fix_directionality.txt, use_directionality.txt, using_fn1.txt, etc.).
Images / views SQL
docs/scripts/basic/sql_function/images.sql
Removed wrk_image function and the using_taxi / using_walk views; modified using_vehicle to call wrk_dijkstra('vehicle_net', @CH7_ID_1@, @CH7_ID_2@); added new view sql_route_geom that materializes seq,id,geom by querying wrk_dijkstra and joining back to vehicle_net.
Core SQL function evolutions
docs/scripts/basic/sql_function/sql_function.sql
Multiple iterative rewrites of wrk_dijkstra: changed to accept edges_subset as REGCLASS and source/target IDs, replaced hard-coded table refs with dynamic table selection, and progressively extended OUT columns to include route_readable, route_geom, and azimuth. Example SELECTs and redirected outputs updated accordingly.
ID configuration queries
docs/scripts/configuration/osmid_configuration.sql
Added WITH blocks that map osm_id → internal id producing CH7_ID_1/CH7_ID_2 values (appended alongside existing ID_ blocks).
Localization — English
locale/en/LC_MESSAGES/basic/sql_function.po
Large-scale rewording and reflow of translation strings to reflect the reorganized chapter, renamed sections, and revised terminology and examples; metadata updates.
Localization template
locale/pot/basic/sql_function.pot
Updated POT metadata and many msgids to match reorganized docs and new terminology (e.g., route_readable/route_geom/azimuth), plus relocated anchors and examples.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  participant Client
  participant View as View (using_vehicle / sql_route_geom)
  participant FN as wrk_dijkstra(edges_subset, source, target)
  participant PGR as pgr_dijkstra
  participant Net as edges table (vehicle_net)

  Client->>View: SELECT ... FROM view
  View->>FN: call wrk_dijkstra('vehicle_net', CH7_ID_1, CH7_ID_2)
  FN->>PGR: pgr_dijkstra(using dynamic edges_subset, source, target)
  PGR-->>FN: routing rows (seq, edge, node, cost)
  FN->>Net: JOIN routing rows to edges_subset to fetch geom/attrs
  Note over FN: construct outputs → seq,id,seconds,name,length\noptionally route_readable / route_geom / azimuth
  FN-->>View: SETOF route rows
  View-->>Client: final result set (e.g., seq,id,geom or seq,azimuth)
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

Suggested reviewers

  • iosefa

Poem

A rabbit hops through edges and rails,
Mapping IDs where route detail sails.
Old images swapped, new views take flight,
Geoms and azimuths shine in the light.
I nibble carrots, then I cheer: the path is clear! 🐇

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The title clearly summarizes the main change of rewriting the SQL function chapter and directly reflects the author’s objectives. It is concise, free of unrelated noise, and specific to the documentation overhaul being proposed. While it does not enumerate every detail such as image updates, high-level titles need not capture every facet. Therefore it aligns with the guidelines for a clear and focused pull request title.
Docstring Coverage ✅ Passed No functions found in the changes. Docstring coverage check skipped.
✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between e02a870 and 6084351.

📒 Files selected for processing (2)
  • docs/scripts/basic/sql_function/CMakeLists.txt (1 hunks)
  • docs/scripts/configuration/osmid_configuration.sql (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • docs/scripts/configuration/osmid_configuration.sql
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: Build
🔇 Additional comments (1)
docs/scripts/basic/sql_function/CMakeLists.txt (1)

14-23: BYPRODUCTS align with SQL outputs
All ten files listed in CMakeLists.txt have matching \o <filename> directives in sql_function.sql.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between c0ddb6a and e02a870.

⛔ Files ignored due to path filters (11)
  • docs/basic/images/sql_function/ch7-e4.png is excluded by !**/*.png
  • docs/basic/images/sql_function/ch7-e5.png is excluded by !**/*.png
  • docs/basic/images/sql_function/ch7-e6.png is excluded by !**/*.png
  • docs/basic/images/sql_function/ch7-e7.png is excluded by !**/*.png
  • docs/basic/images/sql_function/ch7-e8-1.png is excluded by !**/*.png
  • docs/basic/images/sql_function/ch7-e8.png is excluded by !**/*.png
  • docs/basic/images/sql_function/sql_azimuth_fixed.png is excluded by !**/*.png
  • docs/basic/images/sql_function/sql_route_geom.png is excluded by !**/*.png
  • docs/basic/images/sql_function/sql_route_geom_detail.png is excluded by !**/*.png
  • docs/basic/images/sql_function/sql_route_names.png is excluded by !**/*.png
  • docs/basic/images/sql_function/sql_route_readable.png is excluded by !**/*.png
📒 Files selected for processing (10)
  • CMakeLists.txt (1 hunks)
  • docs/basic/images/sql_function/CMakeLists.txt (1 hunks)
  • docs/basic/sql_function.rst (13 hunks)
  • docs/conf.py (1 hunks)
  • docs/scripts/basic/sql_function/CMakeLists.txt (1 hunks)
  • docs/scripts/basic/sql_function/images.sql (1 hunks)
  • docs/scripts/basic/sql_function/sql_function.sql (1 hunks)
  • docs/scripts/configuration/osmid_configuration.sql (1 hunks)
  • locale/en/LC_MESSAGES/basic/sql_function.po (3 hunks)
  • locale/pot/basic/sql_function.pot (2 hunks)
🧰 Additional context used
🧠 Learnings (1)
📚 Learning: 2025-10-04T19:55:45.645Z
Learnt from: cvvergara
PR: pgRouting/workshop#257
File: docs/basic/pedestrian.rst:160-161
Timestamp: 2025-10-04T19:55:45.645Z
Learning: In the pgRouting workshop's pedestrian routing chapter (docs/basic/pedestrian.rst), the same image can be used for both many-to-one and one-to-many routing exercises because pedestrian routes are undirected (bidirectional). The visual representation of the path is identical regardless of direction.

Applied to files:

  • docs/basic/sql_function.rst
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: Build
🔇 Additional comments (17)
CMakeLists.txt (1)

82-84: LGTM!

Reordering the CH7 variable initializations groups them together logically. The values remain unchanged, and this improves readability.

docs/scripts/configuration/osmid_configuration.sql (1)

23-29: LGTM!

The new WITH blocks for CH7_OSMID_1 and CH7_OSMID_2 follow the same pattern as the existing ID_ blocks. The output is correctly prefixed with 'CH7_ID_' to distinguish these identifiers, which aligns with the broader refactoring in this PR.

locale/pot/basic/sql_function.pot (2)

2-11: LGTM!

The POT file metadata has been updated correctly to reflect the 2025 copyright, version 3.1, and the latest creation date. These changes align with the project's versioning and documentation refresh.


36-567: Localization strings updated to reflect documentation changes.

The extensive updates to msgid entries throughout this POT file accurately reflect the documentation rewrite, including:

  • Terminology changes (source_osm → source, target_osm → target)
  • New output descriptions (azimuth, route_readable, route_geom)
  • Exercise restructuring and renaming

As this is an auto-generated localization file, these changes are expected and consistent with the broader PR.

docs/basic/sql_function.rst (9)

14-14: Verify that the new image file exists.

The image reference has been changed from pedestrian_one_to_one.png to sql_route_names.png. Ensure this new image file exists in the docs/basic/images/sql_function/ directory.

This verification is covered by the script in the first file review.


29-48: LGTM!

The section heading change from "The application requirements" to "The function requirements" better reflects that this chapter focuses on creating a SQL function wrapper. The updated list clearly specifies the function's purpose (wrapping pgr_dijkstra), supported networks, and required outputs.


61-62: LGTM!

Simplifying parameter names from source_osm/target_osm to source/target improves clarity and aligns with the broader identifier refactoring in this PR (moving from OSMID-based to ID-based references).


162-174: Verify exercise 2 literalinclude references.

Similar to exercise 1, verify that the markers get_read_geom.txt and get_geom.txt exist in sql_function.sql and that the emphasized lines (6, 11, 19) are correct.

This verification is covered by the script in the previous comment.


200-210: Verify exercise 3 literalinclude references.

Verify that the markers get_geom.txt and wrong_directionality.txt exist in sql_function.sql and that the emphasized lines (7, 21) are correct.

This verification is covered by the script above.


266-275: Verify exercise 4 literalinclude references.

Verify that the markers fix_directionality.txt and good_directionality.txt exist in sql_function.sql.

This verification is covered by the script above.


316-326: Verify exercise 5 literalinclude references.

Verify that the markers use_directionality.txt and using_fn1.txt exist in sql_function.sql and that the emphasized lines (8, 18, 35) are correct.

This verification is covered by the script above.


90-210: Consider consolidating image verification comments.

Multiple image files are referenced throughout this document (sql_route_names.png, sql_route_readable.png, sql_route_geom.png, sql_route_geom_detail.png, sql_azimuth_fixed.png). The verification script in the first file review already checks for all these images.


118-128: All markers and emphases verified. The get_more_info.txt and get_read_geom.txt markers exist, and lines 4, 12, and 17 in the snippet correctly highlight the function signature, the start of the main SELECT block, and the end of the subquery.

docs/basic/images/sql_function/CMakeLists.txt (1)

6-11: New images present and old files removed
All five sql_*.png files exist in docs/basic/images/sql_function/ and there are no remaining ch7-*.png files or references.

docs/scripts/basic/sql_function/images.sql (2)

2-4: No action needed – wrk_dijkstra signature confirmed: wrk_dijkstra is defined in docs/scripts/basic/sql_function/sql_function.sql and accepts (IN edges_subset REGCLASS, IN source BIGINT, IN target BIGINT).


6-9: Removed views not referenced; new view linked correctly
✓ No occurrences of using_taxi, using_walk, or wrk_image found in docs.
✓ sql_route_geom is referenced in documentation and image assets.

docs/scripts/basic/sql_function/sql_function.sql (1)

191-196: Construct comment:

**Join should honor the edges_subset argument**

Hard-coded join to vehicle_net ...

Add fix suggestion maybe unstoppable.

Let's craft comment with short explanation and diff.

Diff propose converting join to dynamic referencing edges subset? Provide diff snippet.

Maybe simple fix: LEFT JOIN vehicle_net replaced with LEFT JOIN pg_catalog.quote_ident? can't in static diff. maybe quick fix:

-  LEFT JOIN vehicle_net USING (id)
+  LEFT JOIN pg_temp_edges_subset USING (id)

But unstoppable.

Better to propose convert to plpgsql? diff more complex.

We can provide high-level suggestion without diff? instructions prefer diff but only if applicable; we can skip if fix not straightforward.

But we can show diff converting to dynamic EXECUTE format. Could be large though; but mania.

Maybe more manageable to wrap join to use format('%s', edges_subset) by calling REGCLASS edges_subset within SQL function by using format('%s', edges_subset)? Wait within SQL function we can't call format? There is format function accessible format('%s', edges_subset) inside plain SQL? we can call SELECT format('%s', edges_subset); but we can't parameterize table name. But we can try to use LEFT JOIN (SELECT * FROM public.vehicle_net)?? can't.

Therefore recommending restructure to plpgsql.

Let's craft comment referencing this change and propose to convert function to plpgsql so dynamic join uses the regclass. Provide diff.

Due to instructions to be precise, we can supply diff snippet but intangible.

Maybe glimpsed:

-$BODY$
-... LEFT JOIN vehicle_net USING (id)
+DECLARE
+  edges_sql text := format('%s', edges_subset);
+BEGIN
+  RETURN QUERY EXECUTE format($f$
+    WITH results AS (... 'SELECT * FROM %1$s' ... )
+    SELECT ...
+    FROM results
+    LEFT JOIN %1$s USING (id)
+    ORDER BY seq
+  $f$, edges_sql) USING source, target;
+END;
+$BODY$
-LANGUAGE SQL;
+LANGUAGE plpgsql;

Need to include TOT? We'll craft diff accordingly.

Let's produce comment now.

Finally close file_end. Done.

@cvvergara cvvergara merged commit 656fbf5 into pgRouting:develop Oct 7, 2025
2 checks passed
@cvvergara cvvergara deleted the sql_function_rewrite branch October 7, 2025 15:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant