Skip to content

Conversation

@fivetran-amrutabhimsenayachit
Copy link
Collaborator

The current transpilation converts MAX_BY to ARG_MAX but loses struct field names, causing incorrect results in DuckDB.

python3 -c "import sqlglot as sg; print(sg.transpile(\"SELECT MAX_BY(name, score) FROM UNNEST([STRUCT('Alice' AS name, 85 AS score), STRUCT('Bob', 92), STRUCT('Diana', 95)])\", read='bigquery', write='duckdb')[0])"
-->SELECT ARG_MAX(name, score) FROM (SELECT UNNEST([{'name': 'Alice', 'score': 85}, {'_0': 'Bob', '_1': 92}, {'_0': 'Diana', '_1': 95}], max_depth => 2))


duckdb -c "SELECT ARG_MAX(name, score) FROM (SELECT UNNEST([{'name': 'Alice', 'score': 85}, {'_0': 'Bob', '_1': 92}, {'_0': 'Diana', '_1': 95}], max_depth => 2))"
┌────────────────────────┐
│ arg_max("name", score) │
│        varchar         │
├────────────────────────┤
│ Alice                  │
└────────────────────────┘

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants