Skip to content

v.db.select: rewrite JSON output using gjson library#7032

Open
Abhi-d-gr8 wants to merge 3 commits intoOSGeo:mainfrom
Abhi-d-gr8:feat/6969-vdbselect-parson
Open

v.db.select: rewrite JSON output using gjson library#7032
Abhi-d-gr8 wants to merge 3 commits intoOSGeo:mainfrom
Abhi-d-gr8:feat/6969-vdbselect-parson

Conversation

@Abhi-d-gr8
Copy link
Contributor

I've gone ahead and refactored v.db.select so it now uses the official gjson library instead of manually building JSON strings with fprintf.

This makes the code quite a bit cleaner. I've updated the main attribute records, the column metadata, and the region extent (-r) logic to use the library. I also made sure to handle an edge case where skipping records with the -f flag could have led to a small memory leak.

I verified everything by running the tests in vector/v.db.select/testsuite/test_v_db_select_json_csv.py, and they are all passing perfectly.

Fixes #6969

@github-actions github-actions bot added vector Related to vector data processing C Related code is in C module labels Feb 3, 2026
@github-actions github-actions bot added Python Related code is in Python tests Related to Test Suite labels Feb 3, 2026
Copy link
Member

@wenzeslaus wenzeslaus left a comment

Choose a reason for hiding this comment

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

Since the code is touching format == CSV code, it would be good to test that beyond the one test which is there which is looking at the values but in a way abstracts the format itself. Add a test which is in the same style as testComma, but with format="csv". Attach screenshots which show the test actually runs and also that it fails if you intentionally introduce error into the code.

Similarly, extent test is missing as far as I can tell. We can't merge these without a clear proof these are actually running.

json.loads(sel.outputs.stdout)
actual_json = json.loads(sel.outputs.stdout)
reference_json = json.loads(out_json)
self.assertEqual(actual_json, reference_json)
Copy link
Member

Choose a reason for hiding this comment

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

Leave the assert out of try-except block.

Comment on lines +340 to 343
if (flags.region->answer) {
/* Extent output - structure will be built later */
}
else {
Copy link
Member

Choose a reason for hiding this comment

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

No empty blocks please.

G_json_object_set_value(info_object, "columns", columns_value);
G_json_object_set_value(root_object, "info", info_value);

/* Initialize records array */
Copy link
Member

Choose a reason for hiding this comment

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

No comments for obvious code. Eval the others, too.

Comment on lines +444 to +446
/* Note: Parson library handles JSON escaping automatically,
* so we only escape for non-JSON formats when flag is set
*/
Copy link
Member

Choose a reason for hiding this comment

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

Good to mention in the context. Use period at the end of sentences, leave out "note". We are adopting // for comments as we go.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

C Related code is in C CMake module Python Related code is in Python tests Related to Test Suite vector Related to vector data processing

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feat] Rewrite v.db.select JSON output to use parson library

2 participants