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

Refactor JSONB functions: Improved API, Documentation, and Data Structures #75

Merged
merged 6 commits into from
Jan 4, 2025

Conversation

b41sh
Copy link
Member

@b41sh b41sh commented Dec 26, 2024

This PR introduces several enhancements to the JSONB functions:

1. New Data Structures: OwnedJsonb and RawJsonb

Two new structs have been added:

  • OwnedJsonb: This struct represents a JSONB value that owns its underlying data (a Vec<u8>). It provides ownership over the binary JSONB representation, facilitating easier manipulation and passing of JSONB data within the application.
  • RawJsonb: This struct is a lightweight wrapper around a borrowed byte slice (&[u8]). It provides a convenient way to work with JSONB data without unnecessary copying, making it more memory-efficient for operations on existing data. RawJsonb is primarily used for read-only operations or when passing JSONB data to functions without transferring ownership.

2. API Redesign: Improved Function Interfaces

The JSONB function interfaces have been significantly redesigned to improve clarity, consistency, and ease of use. Key improvements include:

  • Elimination of unnecessary &[u8] parameters: The previous API often passed raw byte slices (&[u8]) directly to functions. This approach obscured the data's meaning and made the code harder to understand. The introduction of OwnedJsonb and RawJsonb eliminates the need for these opaque byte slices, leading to a cleaner and more readable API.
  • Improved Function Structure: The revised functions have more clearly defined responsibilities, making the code easier to understand and maintain.
  • Abstraction of Internal Encoding Details: The use of RawJsonb hides the internal binary encoding details, making it significantly easier to extend the library to support additional JSONB dialects (other database implementations of JSONB, like SQLite and PostgreSQL) in the future.
  • Enhanced User Experience: The redesigned interfaces are more intuitive and user-friendly, making it easier for developers to work with JSONB data.

These changes result in a more maintainable, extensible, and user-friendly library.

3. Enhanced Documentation:

Comprehensive documentation, including detailed usage examples, has been added to all functions. This improves the understandability and usability of the library.

part of #73

@b41sh b41sh requested a review from sundy-li December 26, 2024 05:39
src/jsonpath/selector.rs Outdated Show resolved Hide resolved
src/raw.rs Outdated Show resolved Hide resolved
@b41sh b41sh marked this pull request as ready for review January 4, 2025 08:09
@b41sh b41sh merged commit 7694b92 into databendlabs:main Jan 4, 2025
1 check passed
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