I recently moved from using apache hive to GCP big query as my SQL database.
I have a set of data as follows,
ID | GROUP | GROUP_TYPE | OFFSET | OFFSET_IDENTIFIER |
---|---|---|---|---|
1 | 100 | A | 120 | 1 |
2 | 100 | A | 140 | 2 |
3 | 500 | B | 120 | 1 |
4 | 500 | B | 140 | 2 |
5 | 5000 | C | 300 | 1 |
6 | 5000 | C | 250 | 2 |
7 | 10000 | D | 24 | 1 |
8 | 10000 | D | 46 | 2 |
9 | 10000 | D | 99 | 3 |
10 | 10000 | D | 11 | 4 |
In hive I used the following query to get the min of offset by group_type and returned the min offset and corresponding offset identifier,
select
ID,
GROUP,
GROUP_TYPE,
min(struct(OFFSET,OFFSET_IDENTIFIER)).col1 as min_offset,
min(struct(OFFSET,OFFSET_IDENTIFIER)).col2 as offset_identifier from eng.offsets
group by ID,GROUP,GROUP_TYPE;
The output I get from this query is as follows,
ID | GROUP | GROUP_TYPE | OFFSET | OFFSET_IDENTIFIER |
---|---|---|---|---|
1 | 100 | A | 120 | 1 |
3 | 500 | B | 120 | 1 |
6 | 5000 | C | 250 | 2 |
10 | 10000 | D | 11 | 4 |
But when I execute the same query in BQ,
select
ID,
GROUP,
GROUP_TYPE,
min(struct(OFFSET,OFFSET_IDENTIFIER)).OFFSET as min_offset,
min(struct(OFFSET,OFFSET_IDENTIFIER)).OFFSET_IDENTIFIER as offset_identifier
from eng.offsets
group by ID,GROUP,GROUP_TYPE;
I get the following error: MIN is not defined for arguments of type STRUCT
May I check if there is any solution to this issue/a way to get the min of struct?
Thank you for your inputs!