Skip to content

Conversation

@hubgeter
Copy link
Contributor

bp #47471
Related PR: #32873

Problem Summary:

Explicitly defines the behavior of column type conversions.

image

Special notes are as follows:

String => boolean: In Parquet, only "false", "off", "no", "0", and an empty string ("") are considered false; otherwise, it is true. In Orc, a string can be parsed as a number, and if that number is 0, it is considered false; otherwise, it is true. If parsing the number fails, it results in null.

Conversion between Int/smallint/tinyint/bigint:
Unless the conversion can be perfectly represented, an error will be reported.
For example:
Bigint column => smallint column
Reason: [INTERNAL_ERROR] Failed to cast value '9223372036854775807' to Nullable(Int16) column.

Conversion between Decimal:
Unless the conversion can be perfectly done, an error will be reported.

String => Int/smallint/tinyint/bigint:
It can be successfully converted to a number, and the number can be correctly stored. Otherwise, the result is null.

Int/smallint/tinyint/bigint => float:
The conversion is successful only if abs(number type) < 2^23.

Int/smallint/tinyint/bigint => double:
The conversion is successful only if abs(number type) < 2^52.

Decimal => Int/smallint/tinyint/bigint:
If the integer part of the decimal can be perfectly stored, only the integer part will be shown; otherwise, it will result in null.

Float => double:
Refer to the C++ static_cast(float).

Decimal => float/double:
Attempt to store the approximate value.

Boolean => string:
The conversion will result in “TRUE” or “FALSE”.

TODO: conversion to char/varchar type requires truncation.

Release note

None

Check List (For Author)

  • Test

    • Regression test
    • Unit Test
    • Manual test (add detailed scripts or steps below)
    • No need to test or manual test. Explain why:
      • This is a refactor/code format and no logic has been changed.
      • Previous test can cover this change.
      • No code files have been changed.
      • Other reason
  • Behavior changed:

    • No.
    • Yes.
  • Does this need documentation?

    • No.
    • Yes.

Check List (For Reviewer who merge this PR)

  • Confirm the release note
  • Confirm test cases
  • Confirm document
  • Add branch pick label

…ma change. (apache#47471)

Related PR: apache#32873

Problem Summary:

Explicitly defines the behavior of column type conversions.

<img width="935" alt="image"
src="https://github.com/user-attachments/assets/1e5afcf6-fbcf-4c36-b44e-82843feacb05"
/>

Special notes are as follows:

`String => boolean`: In Parquet, only "false", "off", "no", "0", and an
empty string ("") are considered false; otherwise, it is true. In Orc, a
string can be parsed as a number, and if that number is 0, it is
considered false; otherwise, it is true. If parsing the number fails, it
results in null.

Conversion between `Int/smallint/tinyint/bigint`:
Unless the conversion can be perfectly represented, an error will be
reported.
For example:
Bigint column => smallint column
Reason: [INTERNAL_ERROR] Failed to cast value '9223372036854775807' to
Nullable(Int16) column.

Conversion between `Decimal`:
Unless the conversion can be perfectly done, an error will be reported.

`String => Int/smallint/tinyint/bigint`:
It can be successfully converted to a number, and the number can be
correctly stored. Otherwise, the result is null.

`Int/smallint/tinyint/bigint => float`:
The conversion is successful only if abs(number type) < 2^23.

`Int/smallint/tinyint/bigint => double`:
The conversion is successful only if abs(number type) < 2^52.

`Decimal => Int/smallint/tinyint/bigint`:
If the integer part of the decimal can be perfectly stored, only the
integer part will be shown; otherwise, it will result in null.

`Float => double`:
Refer to the C++ static_cast<double>(float).

`Decimal => float/double`:
Attempt to store the approximate value.

`Boolean => string`:
The conversion will result in “TRUE” or “FALSE”.

TODO:  conversion to `char/varchar` type requires truncation.
@hubgeter hubgeter requested a review from morrySnow as a code owner June 23, 2025 06:48
@Thearas
Copy link
Contributor

Thearas commented Jun 23, 2025

Thank you for your contribution to Apache Doris.
Don't know what should be done next? See How to process your PR.

Please clearly describe your PR:

  1. What problem was fixed (it's best to include specific error reporting information). How it was fixed.
  2. Which behaviors were modified. What was the previous behavior, what is it now, why was it modified, and what possible impacts might there be.
  3. What features were added. Why was this function added?
  4. Which code was refactored and why was this part of the code refactored?
  5. Which functions were optimized and what is the difference before and after the optimization?

@hubgeter
Copy link
Contributor Author

run buildall

@hubgeter
Copy link
Contributor Author

run buildall

@doris-robot
Copy link

BE UT Coverage Report

Increment line coverage 78.48% (350/446) 🎉

Increment coverage report
Complete coverage report

Category Coverage
Function Coverage 41.32% (10954/26511)
Line Coverage 32.18% (94102/292389)
Region Coverage 31.27% (48547/155248)
Branch Coverage 27.96% (25069/89648)

@morrySnow morrySnow merged commit 4a9f898 into apache:branch-3.1 Jun 23, 2025
19 of 21 checks 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.

4 participants