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

Commit 08ac56a

Browse files
committed
Merge branch 'main' into shuowei-blob-image
2 parents 0e7eb69 + a5a1bc1 commit 08ac56a

289 files changed

Lines changed: 572 additions & 303 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

bigframes/core/compile/sqlglot/compiler.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919

2020
import bigframes_vendored.sqlglot.expressions as sge
2121

22+
from bigframes import dtypes
2223
from bigframes.core import (
2324
expression,
2425
guid,
@@ -277,6 +278,24 @@ def compile_explode(node: nodes.ExplodeNode, child: ir.SQLGlotIR) -> ir.SQLGlotI
277278
return child.explode(columns, offsets_col)
278279

279280

281+
@_compile_node.register
282+
def compile_fromrange(
283+
node: nodes.FromRangeNode, start: ir.SQLGlotIR, end: ir.SQLGlotIR
284+
) -> ir.SQLGlotIR:
285+
start_col_id = node.start.fields[0].id
286+
end_col_id = node.end.fields[0].id
287+
288+
start_expr = expression_compiler.expression_compiler.compile_expression(
289+
expression.DerefOp(start_col_id)
290+
)
291+
end_expr = expression_compiler.expression_compiler.compile_expression(
292+
expression.DerefOp(end_col_id)
293+
)
294+
step_expr = ir._literal(node.step, dtypes.INT_DTYPE)
295+
296+
return start.resample(end, node.output_id.sql, start_expr, end_expr, step_expr)
297+
298+
280299
@_compile_node.register
281300
def compile_random_sample(
282301
node: nodes.RandomSampleNode, child: ir.SQLGlotIR

bigframes/core/compile/sqlglot/sqlglot_ir.py

Lines changed: 45 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,18 +134,20 @@ def from_table(
134134
"""
135135
version = (
136136
sge.Version(
137-
this="TIMESTAMP",
138-
expression=sge.Literal(this=system_time.isoformat(), is_string=True),
137+
this=sge.Identifier(this="SYSTEM_TIME", quoted=False),
138+
expression=sge.Literal.string(system_time.isoformat()),
139139
kind="AS OF",
140140
)
141141
if system_time
142142
else None
143143
)
144+
table_alias = next(uid_gen.get_uid_stream("bft_"))
144145
table_expr = sge.Table(
145146
this=sg.to_identifier(table_id, quoted=cls.quoted),
146147
db=sg.to_identifier(dataset_id, quoted=cls.quoted),
147148
catalog=sg.to_identifier(project_id, quoted=cls.quoted),
148149
version=version,
150+
alias=sge.Identifier(this=table_alias, quoted=cls.quoted),
149151
)
150152
if sql_predicate:
151153
select_expr = sge.Select().select(sge.Star()).from_(table_expr)
@@ -410,6 +412,47 @@ def aggregate(
410412
new_expr = new_expr.where(condition, append=False)
411413
return SQLGlotIR(expr=new_expr, uid_gen=self.uid_gen)
412414

415+
def resample(
416+
self,
417+
right: SQLGlotIR,
418+
array_col_name: str,
419+
start_expr: sge.Expression,
420+
stop_expr: sge.Expression,
421+
step_expr: sge.Expression,
422+
) -> SQLGlotIR:
423+
# Get identifier for left and right by pushing them to CTEs
424+
left_select, left_id = self._select_to_cte()
425+
right_select, right_id = right._select_to_cte()
426+
427+
# Extract all CTEs from the returned select expressions
428+
_, left_ctes = _pop_query_ctes(left_select)
429+
_, right_ctes = _pop_query_ctes(right_select)
430+
merged_ctes = _merge_ctes(left_ctes, right_ctes)
431+
432+
generate_array = sge.func("GENERATE_ARRAY", start_expr, stop_expr, step_expr)
433+
434+
unnested_column_alias = sge.to_identifier(
435+
next(self.uid_gen.get_uid_stream("bfcol_")), quoted=self.quoted
436+
)
437+
unnest_expr = sge.Unnest(
438+
expressions=[generate_array],
439+
alias=sge.TableAlias(columns=[unnested_column_alias]),
440+
)
441+
442+
final_col_id = sge.to_identifier(array_col_name, quoted=self.quoted)
443+
444+
# Build final expression by joining everything directly in a single SELECT
445+
new_expr = (
446+
sge.Select()
447+
.select(unnested_column_alias.as_(final_col_id))
448+
.from_(sge.Table(this=left_id))
449+
.join(sge.Table(this=right_id), join_type="cross")
450+
.join(unnest_expr, join_type="cross")
451+
)
452+
new_expr = _set_query_ctes(new_expr, merged_ctes)
453+
454+
return SQLGlotIR(expr=new_expr, uid_gen=self.uid_gen)
455+
413456
def insert(
414457
self,
415458
destination: bigquery.TableReference,

setup.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,12 +122,18 @@
122122
name=name,
123123
version=version_id,
124124
description=description,
125+
download_url="https://github.com/googleapis/python-bigquery-dataframes/releases",
125126
long_description=readme,
126127
long_description_content_type="text/x-rst",
127128
author="Google LLC",
128129
author_email="bigframes-feedback@google.com",
129130
license="Apache 2.0",
130-
url="https://github.com/googleapis/python-bigquery-dataframes",
131+
url="https://dataframes.bigquery.dev",
132+
project_urls={
133+
"Source": "https://github.com/googleapis/python-bigquery-dataframes",
134+
"Changelog": "https://dataframes.bigquery.dev/changelog.html",
135+
"Issues": "https://github.com/googleapis/python-bigquery-dataframes/issues",
136+
},
131137
classifiers=[
132138
release_status,
133139
"Intended Audience :: Developers",

tests/unit/core/compile/sqlglot/aggregations/snapshots/test_binary_compiler/test_corr/out.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ WITH `bfcte_0` AS (
22
SELECT
33
`int64_col`,
44
`float64_col`
5-
FROM `bigframes-dev`.`sqlglot_test`.`scalar_types`
5+
FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0`
66
), `bfcte_1` AS (
77
SELECT
88
CORR(`int64_col`, `float64_col`) AS `bfcol_2`

tests/unit/core/compile/sqlglot/aggregations/snapshots/test_binary_compiler/test_cov/out.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ WITH `bfcte_0` AS (
22
SELECT
33
`int64_col`,
44
`float64_col`
5-
FROM `bigframes-dev`.`sqlglot_test`.`scalar_types`
5+
FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0`
66
), `bfcte_1` AS (
77
SELECT
88
COVAR_SAMP(`int64_col`, `float64_col`) AS `bfcol_2`
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
SELECT
22
ROW_NUMBER() OVER () - 1 AS `row_number`
3-
FROM `bigframes-dev`.`sqlglot_test`.`scalar_types`
3+
FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0`
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
SELECT
22
ROW_NUMBER() OVER (ORDER BY `int64_col` ASC NULLS LAST) - 1 AS `row_number`
3-
FROM `bigframes-dev`.`sqlglot_test`.`scalar_types`
3+
FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0`

tests/unit/core/compile/sqlglot/aggregations/snapshots/test_nullary_compiler/test_size/out.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
WITH `bfcte_0` AS (
22
SELECT
33
*
4-
FROM `bigframes-dev`.`sqlglot_test`.`scalar_types`
4+
FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0`
55
), `bfcte_1` AS (
66
SELECT
77
COUNT(1) AS `bfcol_32`

tests/unit/core/compile/sqlglot/aggregations/snapshots/test_ordered_unary_compiler/test_array_agg/out.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
WITH `bfcte_0` AS (
22
SELECT
33
`int64_col`
4-
FROM `bigframes-dev`.`sqlglot_test`.`scalar_types`
4+
FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0`
55
), `bfcte_1` AS (
66
SELECT
77
ARRAY_AGG(`int64_col` IGNORE NULLS ORDER BY `int64_col` IS NULL ASC, `int64_col` ASC) AS `bfcol_1`

tests/unit/core/compile/sqlglot/aggregations/snapshots/test_ordered_unary_compiler/test_string_agg/out.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
WITH `bfcte_0` AS (
22
SELECT
33
`string_col`
4-
FROM `bigframes-dev`.`sqlglot_test`.`scalar_types`
4+
FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0`
55
), `bfcte_1` AS (
66
SELECT
77
COALESCE(

0 commit comments

Comments
 (0)