jacktengg opened a new pull request, #71085:
URL: https://github.com/apache/doris/pull/71085

   ### Background
   
   Nereids converts floating-point literals to legacy expressions. FE sends 
these literals to BE through Thrift. SIGNBIT reads the sign bit of a 
floating-point value, including NaN.
   
   ### What problem does this PR solve?
   
   Issue Number: None
   Related PR: #31781 (introduced the FLOAT text conversion), #68488 (existing 
NaN sign handling)
   PR Type: Bugfix
   
   Problem Summary:
   
   Negative NaNs lose their sign during legacy conversion and Java Thrift 
serialization. BE can then return false for SIGNBIT. Preserve the sign during 
conversion and send NaN bits in an optional integer field. User variables and 
FE request forwarding use the same encoding.
   
   One negative FLOAT NaN reproduces the legacy conversion error:
   
   ```java
   FloatLiteral value = new FloatLiteral(Float.intBitsToFloat(0xffc00000));
   Double.doubleToRawLongBits(value.toLegacyLiteral().getDoubleValue());
   ```
   
   | Version | Observed raw bits | Sign |
   | --- | --- | --- |
   | Before | 0x7ff8000000000000 | Positive |
   | After | 0xfff8000000000000 | Negative |
   
   ### Details
   
   - **Frequency:** Always when a negative NaN reaches these conversion or Java 
protocol paths.
   - **Root cause:** FLOAT-to-text conversion produces NaN without a sign. Java 
Thrift Binary and Compact protocols use Double.doubleToLongBits, which replaces 
NaNs with one positive NaN bit pattern.
   - **Why existing tests missed it:** FLOAT tests compared NaN values without 
checking the legacy sign. Thrift expression tests inspected in-memory objects 
without serializing bytes. Existing SQL tests folded SIGNBIT in FE or selected 
positive NaN. They did not require BE to read a negative NaN literal.
   - **Fix:** Share the sign-preserving FLOAT conversion between casts and 
legacy conversion. Send raw_bits only for NaNs. FE and BE readers use raw_bits 
when present and value otherwise.
   - **Other paths and branches:** Cover ordinary literals, user variables, and 
FE forwarding. C++ Thrift writers already preserve the bits. Checked master, 
3.1, 4.0, 4.1, and 4.2: each has the FLOAT text conversion, and field ID 2 is 
unused. Release-branch SQL tests were not run. Land the field on master first 
and retain its ID in backports.
   
   ### Testing
   
   - Local baseline: five targeted FE tests ran. Four failed because negative 
NaN became positive NaN. The old-message negative-zero control passed.
   - Local candidate: 37 targeted FE tests passed, including Binary and Compact 
byte round trips and the production FE forwarding reader.
   - Local ASAN candidate: three targeted BE tests passed after the final test 
source was rebuilt. They cover both NaN signs, FLOAT and DOUBLE decoding, 
old-message negative zero, and the existing ordinary-value path.
   - The final SQL suite uses one generated row and one element per array. The 
negative FLOAT and DOUBLE results are both true with and without FE folding. 
EXPLAIN retains SIGNBIT in the BE plan. Generated the output with the 
regression script and verified it with a second script run.
   
   ### Notes for Reviewers
   
   Old BE ignores raw_bits and retains the old limitation. The complete fix 
requires both FE and BE to be upgraded. Finite values do not gain a wire field.
   
   A separate optimizer defect can merge positive and negative NaN expressions 
in the same query. This change covers legacy conversion and Thrift transport. 
It does not change expression equality or reuse rules.
   
   ### Release note
   
   Fix negative NaN sign loss in legacy literal conversion and Thrift 
transport. These paths preserve the sign after both FE and BE are upgraded.
   
   ### Check List (For Author)
   
   - Behavior changed: No
   - Does this need documentation: No
   - Pre-submission status: Ready
   
   ### AI Disclosure
   
   - Tool: Codex (GPT-6)
   - Generated: Code, tests, and description.
   - Human review: not stated
   
   <!-- Recommended: develop the change with the develop-with-evidence skill 
and write this description with the doris-pr-description skill, both from 
https://github.com/apache/doris-skills (the doris-skills submodule of this 
repository). -->
   
   ### Background
   
   <!-- How the feature or module this PR touches works today, in two to four 
plain sentences, for a reviewer who doesn't know it. Link the user doc if there 
is one. Leave the problem and the fix to Problem Summary. -->
   
   ### What problem does this PR solve?
   
   <!-- Issue Number: "close #N" if this PR resolves the issue, "#N" if it only 
relates to it, "None" if there is none. A Feature needs an issue. -->
   <!-- Related PR: "#N (relation)" for each PR a reviewer should know about, 
such as "#123 (introduced the bug)", separated by commas. Write "None" if no 
related PR is known. -->
   <!-- PR Type: Bugfix, Performance, Feature, Enhancement, Refactor, Test, 
Build/CI/Chore, Revert, Release/Dependency, or Other. -->
   
   Issue Number:
   Related PR:
   PR Type:
   
   Problem Summary:
   
   <!-- Two to five sentences: the problem or need and who is affected; the 
approach in one sentence; when the diff is larger than that suggests, what else 
it had to handle, or that most of it is tests; and what existing users see 
after an upgrade. -->
   
   ### Details
   
   <!--
   For a diff of more than about 300 changed lines, start with "- **Change 
map:**": how many lines are production code, tests, generated files, and docs, 
then the code in parts, each with the problem it handles and its size.
   Then answer each field of your PR type on its own line, as "- **Field:** 
answer", in this order:
     Bugfix: Frequency, Root cause, Why existing tests missed it, Fix, Other 
paths and branches
     Performance: Why it was slow, Optimization, Results, Applicability and cost
     Feature: Scope, Design, Usage, Default behavior, Compatibility
     Enhancement: Before and after, Configs and defaults, Impact on existing 
users
     Refactor: Moves vs. logic changes, Behavior change, Compatibility, 
Performance impact, Rollback
     Test, adding tests: Scenarios, What existing tests miss, Fails when broken
     Test, fixing a test: Failure, Cause, Stability evidence
     Build/CI/Chore: Affected, Developer and release impact, License and 
third-party, Rollback
     Revert: Why not fix forward, Original author notified, Follow-up
     Release/Dependency: Versions, Upstream changes, Compatibility, Rollback
     Other: Why Other
   "None" is a valid answer when it is true. Don't restate the diff.
   -->
   
   ### Testing
   
   <!-- The tests, suites, or commands that ran, what each shows, and where it 
ran (locally or in CI). For a fix, the test that fails before it and passes 
after. -->
   
   ### Notes for Reviewers
   
   <!-- Optional; delete this section if there is nothing to say. Why each 
non-obvious edit was made, what you are unsure about, and where to start 
reading if Details has no Change map. -->
   
   ### Release note
   
   <!-- One paragraph on what users will notice, or None. -->
   
   ### Check List (For Author)
   
   <!-- Behavior changed: "No", or "Yes (see Details)" with a Behavior change 
field in Details. -->
   <!-- Does this need documentation: "No", or "Yes" with the 
apache/doris-website PR or the plan. -->
   <!-- Pre-submission status: "Ready"; "Partially verified: " and what is not 
verified; or "Not ready: " and why, for a Draft PR. -->
   
   - Behavior changed:
   - Does this need documentation:
   - Pre-submission status:
   
   ### AI Disclosure
   
   <!-- Tool: the agent and model, or None. Generated: the parts it wrote 
(code, tests, this description), or None. Human review: what you reviewed of 
the generated parts, or "Not applicable" without AI tools. You may add "- 
Prompts:" to summarize how you directed the agent. -->
   
   - Tool:
   - Generated:
   - Human review:
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to