Baike.dev
All toolsAI codingTrendingOpen sourceNewsSubmit
Log in
Back to tool/Back to issues
#78815·starrocks

[Bug] Trino dialect uses floating-point division for integer operands

Author: yohengyangCreated Sep 8, 2026Updated Sep 15, 2026
Labelstype/bug

Steps to reproduce the behavior (Required)

Run the following statements with the Trino dialect enabled:

sql
SET sql_dialect = 'trino';

SELECT 7 / 2;
SELECT -7 / 2;
SELECT CAST(7 AS BIGINT) / CAST(2 AS BIGINT);

Expected behavior (Required)

In Trino, / between two integer operands performs integer division and truncates toward zero:

7 / 2  -> 3
-7 / 2 -> -3

Reference: Trino arithmetic functions.

The existing division behavior should remain unchanged when either operand is DOUBLE or DECIMAL. The default StarRocks dialect should also remain unchanged.

Real behavior (Required)

StarRocks currently resolves integer / to the regular divide function even when sql_dialect = 'trino'. The analyzer casts both integer operands to DOUBLE, so the statements above return floating-point results:

7 / 2  -> 3.5
-7 / 2 -> -3.5

For integer column expressions, the generated expression is equivalent to:

CAST(a AS DOUBLE) / CAST(b AS DOUBLE)

This differs from Trino semantics and can change query results when Trino SQL is migrated to StarRocks.

StarRocks version (Required)

Reproducible on main at commit:

45b9f5a636219b6839c5ebc425316054a75296f6

Proposed fix and behavior boundary

This choice cannot be made reliably in the Trino parser because column types are not available while building the AST. After expression types are resolved, the analyzer should select int_divide only when:

  • sql_dialect = 'trino'; and
  • both operands are integer types.

The scalar-operator translation should preserve that analyzed function. DOUBLE/DECIMAL division and the default StarRocks dialect must keep their existing behavior.

Implementation branch: https://github.com/StarRocks/starrocks/pull/79119

Source: StarRocks/starrocks

View original on GitHubView discussion on GitHub