Skip to content

Bug: Function parameter validation overly strict causing boundary value handling issues #23101

Closed

Description

@dengn

Description

MatrixOne's function parameter validation is overly strict in some boundary cases, causing valid boundary values to be rejected with "invalid argument" errors. This affects various functions including mathematical functions, type conversion functions, and string functions.

Error Messages

Multiple error patterns observed:

ERROR 20203 (HY000): invalid argument ln, bad value 0
ERROR 20203 (HY000): invalid argument cast to int, bad value <value>
ERROR 20203 (HY000): invalid argument Sqrt, bad value -1

Affected Cases

This issue affects 13 test cases from our boundary testing on the industry_radar_test database.

Failing SQL Statements

Example 1: Mathematical Function with Boundary Value

SELECT SQRT(POWER(2, 100)) as nested_math, EXP(LOG(0)) as exp_log_zero;

Error: ERROR 20203 (HY000): invalid argument ln, bad value 0

Issue: LOG(0) is mathematically undefined, but the error handling could be improved to return NULL or a more descriptive error.

Example 2: Type Conversion with Invalid String

SELECT CAST('invalid' AS INT) as cast_invalid_int, CAST('invalid' AS DATE) as cast_invalid_date;

Error: ERROR 20203 (HY000): invalid argument cast to int, bad value invalid

Issue: Invalid type conversion should return a more descriptive error message indicating which conversion failed.

Example 3: CASE WHEN with Mixed Types

SELECT CASE WHEN id > 0 THEN 'string' WHEN id > 100 THEN 123 ELSE 'mixed' END as case_mixed 
FROM company LIMIT 10;

Error: ERROR 20203 (HY000): invalid argument cast to int, bad value string

Issue: CASE WHEN with mixed return types should either be supported (with type coercion) or provide a clearer error message.

Example 4: COALESCE with Mixed Types

SELECT COALESCE(NULL, 1, 'string', 1.5) as mixed_types;

Error: ERROR 20203 (HY000): invalid argument cast to int, bad value string

Issue: COALESCE with mixed types should handle type coercion or provide clearer error messages.

Example 5: UNION with Type Mismatch

SELECT id FROM company UNION SELECT full_name FROM company LIMIT 10;

Error: ERROR 20203 (HY000): invalid argument cast to int, bad value <company_name>

Issue: UNION with incompatible types should provide a clearer error message about type mismatch.

Example 6: Date Functions with NULL

SELECT YEAR(NULL) as year_null, MONTH(NULL) as month_null, DAY(NULL) as day_null;

Error: ERROR 20203 (HY000): invalid argument ln, bad value 0

Issue: Date functions with NULL should return NULL, not an error.

Example 7: WHERE Condition with Integer Overflow

SELECT * FROM company WHERE id + 2147483647 = 0;

Error: ERROR 20203 (HY000): invalid argument cast to int, bad value string

Issue: Integer overflow in WHERE conditions should be handled gracefully.

Expected Behavior

  1. Mathematical Functions: Functions like LOG(0) should return NULL or a more descriptive error
  2. Type Conversion: Invalid conversions should provide clear error messages indicating the source and target types
  3. Mixed Types: CASE WHEN and COALESCE should handle type coercion or provide clear type mismatch errors
  4. NULL Handling: Functions should properly handle NULL values (return NULL) rather than throwing errors
  5. Type Mismatch: UNION and other operations with type mismatches should provide clear error messages

Impact

  • User Experience: Error messages are not descriptive enough to help users understand what went wrong
  • MySQL Compatibility: Some valid MySQL queries fail with unclear errors
  • Debugging: Difficult to debug issues due to generic error messages
  • Functionality: Some boundary cases that should work (like NULL handling) fail unexpectedly

Test Context

This issue was discovered during boundary testing using the industry_radar_test database. The test cases covered:

  • Mathematical function boundary values
  • Type conversion boundary cases
  • NULL value handling
  • Type mixing scenarios
  • Integer overflow cases

Suggested Fix

  1. Improve Error Messages: Provide more descriptive error messages that indicate:

    • Which function/operation failed
    • What the problematic value was
    • What the expected type/range was
    • Suggestions for fixing the issue
  2. NULL Handling: Ensure all functions properly handle NULL values:

    • Date functions with NULL should return NULL
    • Mathematical functions with NULL should return NULL
    • Type conversion with NULL should return NULL
  3. Type Coercion: Consider supporting type coercion in:

    • CASE WHEN expressions
    • COALESCE expressions
    • UNION operations (with clear rules)
  4. Boundary Value Handling: Improve handling of:

    • Mathematical boundary values (LOG(0), SQRT(-1))
    • Integer overflow cases
    • Type conversion edge cases
  5. Error Classification: Distinguish between:

    • True errors (invalid input)
    • Boundary cases (should return NULL or special value)
    • Type mismatches (should provide clear guidance)

Activity

  1. added
    kind/bug
    severity/s0
    on May 18, 2026
  2. added theissue type on May 18, 2026
  3. added this to the MO-202605 milestone on May 18, 2026
  4. VioletQwQ-0 commented on May 22, 2026

    @VioletQwQ-0
    Collaborator

    fixed by #24519

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

kind/bugseverity/s0

Type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions