Skip to content
This repository was archived by the owner on Apr 1, 2026. It is now read-only.

Commit f6b45ea

Browse files
committed
fix str_slice
1 parent 3e70ce6 commit f6b45ea

File tree

2 files changed

+9
-3
lines changed
  • bigframes/core/compile/sqlglot/expressions
  • tests/unit/core/compile/sqlglot/expressions/snapshots/test_string_ops/test_str_slice

2 files changed

+9
-3
lines changed

bigframes/core/compile/sqlglot/expressions/string_ops.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -366,10 +366,16 @@ def string_slice(
366366
column_length + sge.convert(start + 1),
367367
]
368368
)
369-
length_expr = sge.convert(op_end) - sge.Greatest(
369+
length_expr = sge.Greatest(
370370
expressions=[
371371
sge.convert(0),
372-
column_length + sge.convert(start),
372+
sge.convert(op_end)
373+
- sge.Greatest(
374+
expressions=[
375+
sge.convert(0),
376+
column_length + sge.convert(start),
377+
]
378+
),
373379
]
374380
)
375381
else:

tests/unit/core/compile/sqlglot/expressions/snapshots/test_string_ops/test_str_slice/out.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,6 @@ SELECT
1313
SUBSTRING(
1414
`string_col`,
1515
GREATEST(1, LENGTH(`string_col`) + -2),
16-
5 - GREATEST(0, LENGTH(`string_col`) + -3)
16+
GREATEST(0, 5 - GREATEST(0, LENGTH(`string_col`) + -3))
1717
) AS `m3_5`
1818
FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0`

0 commit comments

Comments
 (0)