-
Notifications
You must be signed in to change notification settings - Fork 4.5k
Use orjson for json_dumps #7391
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
Open
EugeneChung
wants to merge
5
commits into
getredash:master
Choose a base branch
from
EugeneChung:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Basic test works SELECT 'NaN'::float AS not_a_number, 'Inf'::float AS inf, now() AS date |
(venv) ~/project/private/redash git:[master]
ruff check --fix tests/test_utils.py
warning: The top-level linter settings are deprecated in favour of their counterparts in the `lint` section. Please update the following options in `pyproject.toml`:
- 'ignore' -> 'lint.ignore'
- 'select' -> 'lint.select'
- 'mccabe' -> 'lint.mccabe'
- 'per-file-ignores' -> 'lint.per-file-ignores'
All checks passed!
(venv) ~/project/private/redash git:[master]
ruff --version
ruff 0.11.2 |
Is there a difference in the way key-value values are formatted? - Options: {"dbname":"testdb1","host":"example.com"}
+ Options: {"dbname": "testdb1", "host": "example.com"} https://github.com/getredash/redash/actions/runs/14329251848/job/40418005004?pr=7391 |
This was referenced Apr 12, 2025
* add orjson 3.10.15 * before calling orjson.dumps, process data using JSONEncoder to conform to the AS-IS redash spec * Support mapping of some json.dumps options * orjson.OPT_NON_STR_KEYS | orjson.OPT_UTC_Z is similar to ensure_ascii=False. * add pytest cases
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What type of PR is this?
Description
Following the discussion in #7339 (comment), I updated
utils.json_dumps
to useorjson
for improved serialization performance.Key implementation details:
orjson.dumps
, data is pre-processed recursively using the existing customJSONEncoder
to maintain compatibility with Redash's current serialization specifications.datetime
serialization differs:JSONEncoder
:{"time": "2024-03-01T15:30:45.123"}
orjson
:{"time": "2024-03-01T15:30:45.123456"}
json
module,orjson
does not allow overriding serialization behavior for supported native types. The provideddefault
function isn't called for these built-in supported types.orjson.OPT_NON_STR_KEYS | orjson.OPT_UTC_Z
, aligning withensure_ascii=False
behavior.sort_keys
parameter maps directly toOPT_SORT_KEYS
.JSONEncoder
specifications.How is this tested?
For Athena and Trino, the result of
select 1.0, cast('NaN' as double), cast('Infinity' as double), cast('-Infinity' as double)
is1.0, null, null, null
as expected.Related Tickets & Documents
NaN
#6992