Skip to content

Commit 45e0b61

Browse files
committed
error on group by
1 parent c18b800 commit 45e0b61

2 files changed

Lines changed: 11 additions & 56 deletions

File tree

bttest/sql_parse.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ import (
1111
// restricted GoogleSQL subset using SPLIT(_key, sep)[SAFE_OFFSET(n)] AS alias
1212
// to extract row key components.
1313
var (
14-
reFrom = regexp.MustCompile("(?i)FROM\\s+`([^`]+)`")
14+
reFrom = regexp.MustCompile("(?i)FROM\\s+`([^`]+)`")
15+
reGroupBy = regexp.MustCompile(`(?i)\bGROUP\s+BY\b`)
1516

1617
// Matches: SPLIT(_key, '#')[SAFE_OFFSET(3)] AS alias
1718
reSplitOffset = regexp.MustCompile(
@@ -38,6 +39,10 @@ var (
3839
//
3940
// The ORDER BY clause determines the CMV key component ordering.
4041
func ParseCMVConfigFromSQL(viewID, query string) (*CMVConfig, error) {
42+
if reGroupBy.MatchString(query) {
43+
return nil, fmt.Errorf("GROUP BY (aggregation) queries are not supported; only ORDER BY (key re-mapping) CMVs are emulated")
44+
}
45+
4146
cfg := &CMVConfig{ViewID: viewID}
4247

4348
sourceTable, err := parseSourceTable(query)

bttest/sql_parse_test.go

Lines changed: 5 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -99,62 +99,12 @@ ORDER BY b, a`,
9999
},
100100
},
101101
{
102-
// https://github.com/googleapis/google-cloud-go/blob/main/bigtable/integration_test.go#L4831C36-L4831C101
103-
query: "SELECT _key, count(fam1['col1']) as count FROM `t1` GROUP BY _key",
104-
expectCfg: &CMVConfig{
105-
SourceTable: "t1",
106-
IncludeFamilies: []string{"fam1"},
107-
},
108-
},
109-
{
110-
// https://docs.cloud.google.com/bigtable/docs/continuous-materialized-view-queries#aggregated-data
111-
query: `SELECT
112-
fam["baz"] AS baz,
113-
SUM(fam["foo"]) AS sum_foo,
114-
SUM(fam["bar"]) AS sum_bar
115-
FROM
116-
` + "`TABLE`" + `
117-
GROUP BY
118-
baz`,
119-
expectCfg: &CMVConfig{
120-
SourceTable: "TABLE",
121-
},
122-
},
123-
{
124-
// https://docs.cloud.google.com/bigtable/docs/continuous-materialized-view-queries#select-statement
125-
query: `SELECT
126-
myfamily["node"] AS node,
127-
myfamily["type"] AS type,
128-
COUNT(clicks) AS clicks_per_key
129-
FROM
130-
` + "`mytable`" + `
131-
GROUP BY
132-
node,
133-
type`,
134-
expectCfg: &CMVConfig{
135-
SourceTable: "mytable",
136-
},
102+
// GROUP BY (aggregation) queries are not supported — the emulator only handles
103+
// ORDER BY (key re-mapping) CMVs. Aggregation requires maintaining running state
104+
// across writes, which is a fundamentally different execution model.
105+
query: "SELECT _key, count(fam1['col1']) as count FROM `t1` GROUP BY _key",
106+
expectErr: "GROUP BY",
137107
},
138-
{
139-
// https://docs.cloud.google.com/bigtable/docs/continuous-materialized-view-queries#timestamps
140-
query: `SELECT
141-
_key,
142-
TIMESTAMP_TRUNC(_timestamp, DAY) AS _timestamp,
143-
SUM(sum_family["sum_column"]) AS sum_column,
144-
SUM(sum_family["foo"]) AS second_sum_column
145-
FROM
146-
UNPACK(
147-
SELECT
148-
*
149-
FROM
150-
my_table(with_history => TRUE))
151-
GROUP BY
152-
1,
153-
2`,
154-
expectCfg: &CMVConfig{
155-
SourceTable: "my_table",
156-
},
157-
}
158108
}
159109

160110
for i, tc := range tests {

0 commit comments

Comments
 (0)