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

Refinement of FOR JSON PATH & Nested Functionality #239

Conversation

Jakeowen1
Copy link
Contributor

@Jakeowen1 Jakeowen1 commented Oct 17, 2023

Currently FOR JSON PATH is implemented in Babelfish using string manipulation. This change will implement FOR JSON PATH using PostgreSQL's JsonbValue and HTAB. The reason for this change is because the current implementation of FOR JSON PATH does not support the full functionality of the feature. Nested outputs determined by aliases in the SELECT statement are not supported. By implementing FOR JSON PATH using JsonbValue and HTAB, we provide an efficient solution that also supports nested json objects, while also setting the foundation for FOR JSON AUTO to be implemented.

BABELFISH_EXTENSIONS CHANGES:

  • Switched from String Manipulation implementation of FOR JSON PATH to an implementation using JsonbValue.
  • Wrapper function to add a value to JsonbValue and handle datatype checks.
  • Supporting functions to determine path to insert a JsonbValue object and key for HashTable.
  • Create json and insert into existing json functions that are used when dealing with nested json objects.
  • Implemented Nested Output tracking using PostgreSQL's HTAB library (HashTable)
  • Corrected the tests to showcase the new functionality of nested json objects
  • Added another set of tests to more thoroughly test the nested json object functionality.

POSTGRESQL_MODIFIED_FOR_BABELFISH CHANGES:

  • Created a public wrapper function in jsonb.h to call add_jsonb() from forjson.c

TEST CASES:

  • Added a test that checks the functionality and accuracy of the nested json feature. Includes cases with multiple layers, deeply nested layers, values in different stages of json layers, nested null outputs.
  • Organized version upgrade tests so previous versions use previous implementation of FOR JSON PATH and updated the schedule for each version.
  • Modified existing test cases to correctly showcase the nested functionality if the given test uses alias that cause nested json objects to be created.
  • Changed the expected outputs to include spaces as JsonbValue does when converted to a string.

@2jungkook 2jungkook merged commit 70666bc into babelfish-for-postgresql:BABEL_2_X_DEV__PG_14_X Oct 17, 2023
1 check passed
@2jungkook 2jungkook deleted the jira-babel-3407-14 branch October 17, 2023 22:27
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