Skip to content

Spark, Databricks, Hive, Oracle: Parse numeric literal type suffixes - #2912

Open
andygrove wants to merge 3 commits into
apache:mainfrom
andygrove:spark-numeric-literal-suffixes
Open

andygrove wants to merge 3 commits into
apache:mainfrom
andygrove:spark-numeric-literal-suffixes

Conversation

@andygrove

@andygrove andygrove commented Nov 11, 2026 •

Copy link
Copy Markdown
Member

Spark, Databricks and Hive give a numeric literal a type with a case-insensitive suffix, such as 10Y or 1.5BD, and Oracle has F and D. sqlparser reads the suffix as a column alias, or, in Databricks and Hive, the whole literal as a column name:

SELECT 10Y, 1.5D
-- Spark today: SELECT 10 AS Y, 1.5 AS D

This adds Dialect::is_numeric_literal_suffix(number, suffix), which the tokenizer asks about the identifier characters directly after a number. An accepted suffix stays in the number's text, as in Value::Number("10Y", false), except that L in either case still sets the long flag. The dialects accept:

  • Spark and Databricks: L, S, Y after an integer, F, D, BD after any number
  • Hive: L, S, Y after an integer, D, BD after any number
  • Oracle: F, D after any number

A suffix must end the word, so 1Dx is unchanged, and in Databricks and Hive t.1D and 1La stay column names. This also covers the 1L of #2771. Other dialects are unchanged. With the bigdecimal feature, a number with a suffix fails to parse, since a BigDecimal can't hold it.

Docs: Spark, Databricks, Hive's lexer, Oracle

This PR was prepared with AI assistance (Claude).

Dialects: Spark, Databricks, Hive, Oracle

Spark SQL types a numeric literal by a case-insensitive suffix: `Y`,
`S` and `L` after an integer, and `F`, `D` and `BD` after any number.
The tokenizer read `1D` as the number `1` followed by the alias `D`.
…ber's text

Instead of a NumberSuffix enum and new Token and Value variants, the
tokenizer asks Dialect::is_numeric_literal_suffix about the identifier
characters after a number and keeps an accepted suffix in the
Token::Number text. Spark, Databricks, Hive and Oracle each list their
own suffixes.
@andygrove andygrove changed the title Spark: Parse typed numeric literal suffixes Spark, Databricks, Hive, Oracle: Parse numeric literal type suffixes Nov 11, 2026
@andygrove
andygrove marked this pull request as ready for review November 11, 2026 19:43
@codecov-commenter

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 83.24%. Comparing base (8a176d9) to head (40445a4).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2912      +/-   ##
==========================================
+ Coverage   83.20%   83.24%   +0.03%     
==========================================
  Files          42       42              
  Lines       36471    36536      +65     
  Branches    36471    36536      +65     
==========================================
+ Hits        30345    30413      +68     
  Misses       2632     2632              
+ Partials     3494     3491       -3     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants