Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions bigframes/core/compile/sqlglot/sqlglot_ir.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,18 +134,20 @@ def from_table(
"""
version = (
sge.Version(
this="TIMESTAMP",
expression=sge.Literal(this=system_time.isoformat(), is_string=True),
this=sge.Identifier(this="SYSTEM_TIME", quoted=False),
expression=sge.Literal.string(system_time.isoformat()),
kind="AS OF",
)
if system_time
else None
)
table_alias = next(uid_gen.get_uid_stream("bft_"))
table_expr = sge.Table(
this=sg.to_identifier(table_id, quoted=cls.quoted),
db=sg.to_identifier(dataset_id, quoted=cls.quoted),
catalog=sg.to_identifier(project_id, quoted=cls.quoted),
version=version,
alias=sge.Identifier(this=table_alias, quoted=cls.quoted),
)
if sql_predicate:
select_expr = sge.Select().select(sge.Star()).from_(table_expr)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ WITH `bfcte_0` AS (
SELECT
`int64_col`,
`float64_col`
FROM `bigframes-dev`.`sqlglot_test`.`scalar_types`
FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0`
), `bfcte_1` AS (
SELECT
CORR(`int64_col`, `float64_col`) AS `bfcol_2`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ WITH `bfcte_0` AS (
SELECT
`int64_col`,
`float64_col`
FROM `bigframes-dev`.`sqlglot_test`.`scalar_types`
FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0`
), `bfcte_1` AS (
SELECT
COVAR_SAMP(`int64_col`, `float64_col`) AS `bfcol_2`
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
SELECT
ROW_NUMBER() OVER () - 1 AS `row_number`
FROM `bigframes-dev`.`sqlglot_test`.`scalar_types`
FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0`
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
SELECT
ROW_NUMBER() OVER (ORDER BY `int64_col` ASC NULLS LAST) - 1 AS `row_number`
FROM `bigframes-dev`.`sqlglot_test`.`scalar_types`
FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0`
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
WITH `bfcte_0` AS (
SELECT
*
FROM `bigframes-dev`.`sqlglot_test`.`scalar_types`
FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0`
), `bfcte_1` AS (
SELECT
COUNT(1) AS `bfcol_32`
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
WITH `bfcte_0` AS (
SELECT
`int64_col`
FROM `bigframes-dev`.`sqlglot_test`.`scalar_types`
FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0`
), `bfcte_1` AS (
SELECT
ARRAY_AGG(`int64_col` IGNORE NULLS ORDER BY `int64_col` IS NULL ASC, `int64_col` ASC) AS `bfcol_1`
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
WITH `bfcte_0` AS (
SELECT
`string_col`
FROM `bigframes-dev`.`sqlglot_test`.`scalar_types`
FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0`
), `bfcte_1` AS (
SELECT
COALESCE(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ WITH `bfcte_0` AS (
SELECT
`bool_col`,
`int64_col`
FROM `bigframes-dev`.`sqlglot_test`.`scalar_types`
FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0`
), `bfcte_1` AS (
SELECT
COALESCE(LOGICAL_AND(`bool_col`), TRUE) AS `bfcol_2`,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
SELECT
COALESCE(LOGICAL_AND(`bool_col`) OVER (), TRUE) AS `agg_bool`
FROM `bigframes-dev`.`sqlglot_test`.`scalar_types`
FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0`
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ WITH `bfcte_0` AS (
SELECT
`bool_col`,
`int64_col`
FROM `bigframes-dev`.`sqlglot_test`.`scalar_types`
FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0`
), `bfcte_1` AS (
SELECT
COALESCE(LOGICAL_OR(`bool_col`), FALSE) AS `bfcol_2`,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
WITH `bfcte_0` AS (
SELECT
`int64_col`
FROM `bigframes-dev`.`sqlglot_test`.`scalar_types`
FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0`
), `bfcte_1` AS (
SELECT
ANY_VALUE(`int64_col`) AS `bfcol_1`
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
SELECT
ANY_VALUE(`int64_col`) OVER () AS `agg_int64`
FROM `bigframes-dev`.`sqlglot_test`.`scalar_types`
FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0`
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
SELECT
ANY_VALUE(`int64_col`) OVER (PARTITION BY `string_col`) AS `agg_int64`
FROM `bigframes-dev`.`sqlglot_test`.`scalar_types`
FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0`
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
SELECT
COALESCE(LOGICAL_OR(`bool_col`) OVER (), FALSE) AS `agg_bool`
FROM `bigframes-dev`.`sqlglot_test`.`scalar_types`
FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0`
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
WITH `bfcte_0` AS (
SELECT
`int64_col`
FROM `bigframes-dev`.`sqlglot_test`.`scalar_types`
FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0`
), `bfcte_1` AS (
SELECT
APPROX_QUANTILES(`int64_col`, 4)[OFFSET(1)] AS `bfcol_1`,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
WITH `bfcte_0` AS (
SELECT
`int64_col`
FROM `bigframes-dev`.`sqlglot_test`.`scalar_types`
FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0`
), `bfcte_1` AS (
SELECT
APPROX_TOP_COUNT(`int64_col`, 10) AS `bfcol_1`
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
WITH `bfcte_0` AS (
SELECT
`int64_col`
FROM `bigframes-dev`.`sqlglot_test`.`scalar_types`
FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0`
), `bfcte_1` AS (
SELECT
COUNT(`int64_col`) AS `bfcol_1`
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
SELECT
COUNT(`int64_col`) OVER () AS `agg_int64`
FROM `bigframes-dev`.`sqlglot_test`.`scalar_types`
FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0`
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
SELECT
COUNT(`int64_col`) OVER (PARTITION BY `string_col`) AS `agg_int64`
FROM `bigframes-dev`.`sqlglot_test`.`scalar_types`
FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0`
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,4 @@ SELECT
) + 0 AS `right_inclusive`
)
END AS `int_bins`
FROM `bigframes-dev`.`sqlglot_test`.`scalar_types`
FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0`
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ SELECT
) IS NOT NULL
THEN 'c'
END AS `int_bins_labels`
FROM `bigframes-dev`.`sqlglot_test`.`scalar_types`
FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0`
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ SELECT
WHEN `int64_col` > 1 AND `int64_col` <= 2
THEN STRUCT(1 AS `left_exclusive`, 2 AS `right_inclusive`)
END AS `interval_bins`
FROM `bigframes-dev`.`sqlglot_test`.`scalar_types`
FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0`
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ SELECT
WHEN `int64_col` > 1 AND `int64_col` <= 2
THEN 1
END AS `interval_bins_labels`
FROM `bigframes-dev`.`sqlglot_test`.`scalar_types`
FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0`
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
SELECT
DENSE_RANK() OVER (ORDER BY `int64_col` DESC) AS `agg_int64`
FROM `bigframes-dev`.`sqlglot_test`.`scalar_types`
FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0`
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
SELECT
`bool_col` <> LAG(`bool_col`, 1) OVER (ORDER BY `bool_col` DESC) AS `diff_bool`
FROM `bigframes-dev`.`sqlglot_test`.`scalar_types`
FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0`
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ SELECT
CAST(FLOOR(
DATE_DIFF(`date_col`, LAG(`date_col`, 1) OVER (ORDER BY `date_col` ASC NULLS LAST), DAY) * 86400000000
) AS INT64) AS `diff_date`
FROM `bigframes-dev`.`sqlglot_test`.`scalar_types`
FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0`
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ SELECT
LAG(`datetime_col`, 1) OVER (ORDER BY `datetime_col` ASC NULLS LAST),
MICROSECOND
) AS `diff_datetime`
FROM `bigframes-dev`.`sqlglot_test`.`scalar_types`
FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0`
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
SELECT
`int64_col` - LAG(`int64_col`, 1) OVER (ORDER BY `int64_col` ASC NULLS LAST) AS `diff_int`
FROM `bigframes-dev`.`sqlglot_test`.`scalar_types`
FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0`
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ SELECT
LAG(`timestamp_col`, 1) OVER (ORDER BY `timestamp_col` DESC),
MICROSECOND
) AS `diff_timestamp`
FROM `bigframes-dev`.`sqlglot_test`.`scalar_types`
FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0`
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ SELECT
ORDER BY `int64_col` DESC
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
) AS `agg_int64`
FROM `bigframes-dev`.`sqlglot_test`.`scalar_types`
FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0`
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ SELECT
ORDER BY `int64_col` ASC NULLS LAST
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
) AS `agg_int64`
FROM `bigframes-dev`.`sqlglot_test`.`scalar_types`
FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0`
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ SELECT
ORDER BY `int64_col` DESC
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
) AS `agg_int64`
FROM `bigframes-dev`.`sqlglot_test`.`scalar_types`
FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0`
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ SELECT
ORDER BY `int64_col` ASC NULLS LAST
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
) AS `agg_int64`
FROM `bigframes-dev`.`sqlglot_test`.`scalar_types`
FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0`
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
WITH `bfcte_0` AS (
SELECT
`int64_col`
FROM `bigframes-dev`.`sqlglot_test`.`scalar_types`
FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0`
), `bfcte_1` AS (
SELECT
MAX(`int64_col`) AS `bfcol_1`
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
SELECT
MAX(`int64_col`) OVER () AS `agg_int64`
FROM `bigframes-dev`.`sqlglot_test`.`scalar_types`
FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0`
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
SELECT
MAX(`int64_col`) OVER (PARTITION BY `string_col`) AS `agg_int64`
FROM `bigframes-dev`.`sqlglot_test`.`scalar_types`
FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0`
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ WITH `bfcte_0` AS (
`int64_col` AS `bfcol_6`,
`bool_col` AS `bfcol_7`,
`duration_col` AS `bfcol_8`
FROM `bigframes-dev`.`sqlglot_test`.`scalar_types`
FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0`
), `bfcte_1` AS (
SELECT
AVG(`bfcol_6`) AS `bfcol_12`,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
SELECT
AVG(`int64_col`) OVER () AS `agg_int64`
FROM `bigframes-dev`.`sqlglot_test`.`scalar_types`
FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0`
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
SELECT
AVG(`int64_col`) OVER (PARTITION BY `string_col`) AS `agg_int64`
FROM `bigframes-dev`.`sqlglot_test`.`scalar_types`
FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0`
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ WITH `bfcte_0` AS (
`date_col`,
`int64_col`,
`string_col`
FROM `bigframes-dev`.`sqlglot_test`.`scalar_types`
FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0`
), `bfcte_1` AS (
SELECT
APPROX_QUANTILES(`int64_col`, 2)[OFFSET(1)] AS `bfcol_3`,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
WITH `bfcte_0` AS (
SELECT
`int64_col`
FROM `bigframes-dev`.`sqlglot_test`.`scalar_types`
FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0`
), `bfcte_1` AS (
SELECT
MIN(`int64_col`) AS `bfcol_1`
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
SELECT
MIN(`int64_col`) OVER () AS `agg_int64`
FROM `bigframes-dev`.`sqlglot_test`.`scalar_types`
FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0`
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
SELECT
MIN(`int64_col`) OVER (PARTITION BY `string_col`) AS `agg_int64`
FROM `bigframes-dev`.`sqlglot_test`.`scalar_types`
FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0`
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
WITH `bfcte_0` AS (
SELECT
`int64_col`
FROM `bigframes-dev`.`sqlglot_test`.`scalar_types`
FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0`
), `bfcte_1` AS (
SELECT
COUNT(DISTINCT `int64_col`) AS `bfcol_1`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ WITH `bfcte_0` AS (
SELECT
`bool_col`,
`int64_col`
FROM `bigframes-dev`.`sqlglot_test`.`scalar_types`
FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0`
), `bfcte_1` AS (
SELECT
VAR_POP(`int64_col`) AS `bfcol_4`,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
SELECT
VAR_POP(`int64_col`) OVER () AS `agg_int64`
FROM `bigframes-dev`.`sqlglot_test`.`scalar_types`
FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0`
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
WITH `bfcte_0` AS (
SELECT
`int64_col`
FROM `bigframes-dev`.`sqlglot_test`.`scalar_types`
FROM `bigframes-dev`.`sqlglot_test`.`scalar_types` AS `bft_0`
), `bfcte_1` AS (
SELECT
CASE
Expand Down
Loading
Loading