Skip to content

Conversation

hatyo
Copy link
Contributor

@hatyo hatyo commented Sep 29, 2025

This implements SQL CAST operator with comprehensive type conversion support, including casting of one-dimensional arrays.

This PR adds the SQL CAST operator to enable explicit type conversions between supported data types. The implementation follows SQL standard semantics as much as possible, in addition to few non-standard additions, and includes comprehensive validation and error handling.

Key examples:

  -- Basic type conversions
  SELECT CAST(123 AS STRING)           -- Returns '123'
  SELECT CAST('42' AS INTEGER)         -- Returns 42
  SELECT CAST(true AS INTEGER)         -- Returns 1

-- Array casting with element-wise conversion

  SELECT CAST([1, 2, 3] AS STRING ARRAY)  -- Returns ['1', '2', '3']
  SELECT CAST([] AS INTEGER ARRAY)        -- Returns empty integer array

The CAST operator supports conversions between primitive types (integers, strings, booleans, floating-point numbers) and extends naturally to arrays by applying the same conversion rules recursively to array elements. Proper error handling ensures invalid conversions fail with appropriate SQL error codes.

This fixes #3589.

Example Usage:
 SELECT CAST(123 AS STRING)        -- Returns '123'
 SELECT CAST('123' AS INTEGER)     -- Returns 123
 SELECT CAST(true AS INTEGER)      -- Returns 1
 SELECT CAST(null AS STRING)       -- Returns NULL
@hatyo hatyo added enhancement New feature or request relational issues related to relational FDB labels Sep 29, 2025
Copy link

github-actions bot commented Oct 3, 2025

📊 Metrics Diff Analysis Report

Summary

  • New queries: 23
  • Dropped queries: 0
  • Plan changed + metrics changed: 0
  • Plan unchanged + metrics changed: 0
ℹ️ About this analysis

This automated analysis compares query planner metrics between the base branch and this PR. It categorizes changes into:

  • New queries: Queries added in this PR
  • Dropped queries: Queries removed in this PR. These should be reviewed to ensure we are not losing coverage.
  • Plan changed + metrics changed: The query plan has changed along with planner metrics.
  • Metrics only changed: Same plan but different metrics

The last category in particular may indicate planner regressions that should be investigated.

New Queries

Count of new queries by file:

  • yaml-tests/src/test/resources/cast-tests.metrics.yaml: 23

@hatyo hatyo mentioned this pull request Oct 3, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request relational issues related to relational FDB
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Implement explicit CAST operator
1 participant