Skip to content

Fix Python SDKs lowercasing output expressions (corrupts string literals) - #3480

Open
Harsh23Kashyap wants to merge 1 commit into
infiniflow:mainfrom
Harsh23Kashyap:fix-sdk-output-lowercase
Open

Harsh23Kashyap wants to merge 1 commit into
infiniflow:mainfrom
Harsh23Kashyap:fix-sdk-output-lowercase

Conversation

@Harsh23Kashyap

Copy link
Copy Markdown

Summary

Both Python SDK query builders lowercased each output() column string before parsing it, to match the special output tokens case-insensitively. That also rewrote string literals inside real expressions: output(["'ACTIVE'"]) silently selected 'active', and json_extract(data, '$.UserName') (once it parses through the SDKs, see #3463) would query the key $.username. The HTTP API forwards the strings untouched, so the same query returned different data per client.

The special tokens are now matched against a lowercased copy while the original string is parsed. Plain identifiers are still lowercased by the exp.Column arm, so column-name handling is unchanged; only string literals keep their case.

Fixes #3479

Testing

  • Reproduced on current main (eca7266, sqlglot 30.18.0): before the fix both SDKs built a constant holding 'active'; after the fix they hold 'ACTIVE'. _SCORE still maps to score, MyCol still normalizes to mycol, * still works.
  • Added test_output_preserves_string_literal_case to python/test_pysdk/test_condition.py (thrift builder directly, embedded builder in embedded mode).
  • The full pysdk suite was not run locally (needs a running server / built embedded engine); the change is confined to the two output() methods.

…erals

Both Python SDK query builders lowercased every output column string
before parsing it, to match the special tokens (*, _row_id, _score, ...)
case-insensitively. That also rewrites string literals inside real
expressions: output(["'ACTIVE'"]) selects 'active', and once
json_extract(...) parses through the SDKs, json_extract(data,
'$.UserName') would silently query key '$.username'.

Match the special tokens against a lowercased copy and parse the
original string. Plain identifiers are still lowercased by the Column
arm, so name handling is unchanged.

Regression test: test_output_preserves_string_literal_case.
@coderabbitai

coderabbitai Bot commented Sep 9, 2026 •

Copy link
Copy Markdown

Review Change StackReview Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Advanced

Run ID: 5dc309e0-1e71-4325-90a2-4be3a0b90177

📥 Commits

Reviewing files that changed from the base of the PR and between eca7266 and 888b398.

📒 Files selected for processing (3)
  • python/infinity_embedded/local_infinity/query_builder.py
  • python/infinity_sdk/infinity/remote_thrift/query_builder.py
  • python/test_pysdk/test_condition.py

Included review availability: Your plan provides up to 8 included reviews per hour; 3 remain after this review.


📝 Walkthrough

Walkthrough

The Python embedded and Thrift query builders now preserve string literal case in output() expressions while matching special output tokens case-insensitively. A regression test covers literal preservation and _SCORE resolution in both builders.

Changes

Output expression case preservation

Layer / File(s) Summary
Preserve original output expressions
python/infinity_embedded/local_infinity/query_builder.py, python/infinity_sdk/infinity/remote_thrift/query_builder.py
Both builders match special tokens with a lowercased copy and parse the original expression.
Validate output parsing
python/test_pysdk/test_condition.py
Tests confirm that 'ACTIVE' retains its case and _SCORE resolves to score in both builders.

Priority: ➖ Normal

Estimated code review effort: 2 (Simple) | ~10 minutes

Severity of issue fixed: Medium

Merge Risk: ⚪ Minimal · up to 888b3

Output expressions now preserve string-literal case while special output tokens remain case-insensitive, with regression coverage for both Python query builders. No current merge-blocking risk remains.

Suggested reviewers: qinling0210

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 4 functions across 3 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the primary fix: preventing Python SDKs from lowercasing output expressions and corrupting string literals.
Description check ✅ Passed The description includes the required Summary section and provides relevant problem, fix, scope, and testing details.
Linked Issues check ✅ Passed The changes satisfy issue #3479 by fixing both query builders, preserving string literal case, retaining identifier and special-token behavior, and adding regression coverage.
Out of Scope Changes check ✅ Passed The changes are limited to the two affected output methods and targeted regression coverage. No unrelated code changes are present.
  • Fix all pre-merge checks with AI

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

A rabbit keeps case safe,
'ACTIVE' stays bright and true,
_SCORE finds its path,
Builders parse the source intact,
Tests guard each output line.

Comment @coderabbitai help to get the list of available commands.

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.

[Bug]: Python SDKs lowercase output expressions, silently corrupting string literals

1 participant