Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix updating valhalla.json after changes in valhalla configuration #180

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

mlidodo
Copy link

@mlidodo mlidodo commented Jan 20, 2025

After changes done in valhalla/valhalla#5010, the scripts/configure_valhalla.json cannot update valhalla.json anymore:

jq: error: syntax error, unexpected LITERAL, expecting end of file (Unix shell quoting issues?) at <top-level>, line 1:
.thor.costmatrix.hierarchy_limits.max_up_transitions.1 | if type == "null" then false else true end                                                    

The reason is that when retrieving value of a key using jq, where a component of the key is a number in string:

"bidirectional_astar": {
    "hierarchy_limits": {
        "max_up_transitions": {
            "1": 400,
            "2": 100,
        },
        "expand_within_distance": {"0": 1e8, "1": 20000, "2": 5000},
    }
}

The issue is in the loop, which retrieves all keys from valhalla.json:

jq -r 'paths | select(map(type) | index("number") | not ) | "." + join(".")' ${TMP_CONFIG_FILE} | while read key ; do
# if the key path does not exist in the existing config
jq -e "${key} | if type == \"null\" then false else true end" ${CONFIG_FILE} >/dev/null
if [ $? -eq 1 ]; then
# get its value from the temp config
newval=$(jq "${key}" ${TMP_CONFIG_FILE})
echo "INFO: copied new config entry ${key}=${newval} into existing config."

I was able to fix the expression by transforming the keys into object index syntax (instead of the object identifier-index syntax), it should look like this:

paths(scalars | true) | select(map(type) | index("number") | not ) | [.[] | ".[\"\(.)\"]"] | join("")

The generated keys now look like this:

.["thor"].["bidirectional_astar"].["hierarchy_limits"].["expand_within_distance"].["0"]
.["thor"].["bidirectional_astar"].["hierarchy_limits"].["expand_within_distance"].["1"]
.["thor"].["bidirectional_astar"].["hierarchy_limits"].["expand_within_distance"].["2"]
.["thor"].["bidirectional_astar"].["hierarchy_limits"].["max_up_transitions"].["1"]
.["thor"].["bidirectional_astar"].["hierarchy_limits"].["max_up_transitions"].["2"]

With these, jq is now able to retrieve the values correctly:

100000000.0
20000
5000
400
100

@chrstnbwnkl
Copy link
Collaborator

Ah yes thank you! I feared this was going to happen with the config updates... I'll try to get this merged soon.

chrstnbwnkl
chrstnbwnkl previously approved these changes Jan 20, 2025
@chrstnbwnkl chrstnbwnkl dismissed their stale review January 21, 2025 09:43

test failure

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.

2 participants