Skip to content

Commit

Permalink
Add support for join expression in array scans
Browse files Browse the repository at this point in the history
  • Loading branch information
hannes-ucsc committed Jan 13, 2024
1 parent 5d37d29 commit 93ea9da
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions internal/formatter.go
Original file line number Diff line number Diff line change
Expand Up @@ -658,6 +658,16 @@ func (n *ArrayScanNode) FormatSQL(ctx context.Context) (string, error) {
if err != nil {
return "", err
}
var onClause string
if n.node.JoinExpr() == nil {
onClause = ""
} else {
joinExpr, err := newNode(n.node.JoinExpr()).FormatSQL(ctx)
if err != nil {
return "", err
}
onClause = " ON " + joinExpr
}
colName := uniqueColumnName(ctx, n.node.ElementColumn())
if n.node.InputScan() != nil {
input, err := newNode(n.node.InputScan()).FormatSQL(ctx)
Expand All @@ -669,16 +679,18 @@ func (n *ArrayScanNode) FormatSQL(ctx context.Context) (string, error) {
return "", err
}
return fmt.Sprintf(
"SELECT *, json_each.value AS `%s` %s, json_each(zetasqlite_decode_array(%s))",
"SELECT *, json_each.value AS `%s` %s, json_each(zetasqlite_decode_array(%s))%s",
colName,
formattedInput,
arrayExpr,
onClause,
), nil
}
return fmt.Sprintf(
"SELECT json_each.value AS `%s` FROM json_each(zetasqlite_decode_array(%s))",
"SELECT json_each.value AS `%s` FROM json_each(zetasqlite_decode_array(%s))%s",
colName,
arrayExpr,
onClause,
), nil
}

Expand Down

0 comments on commit 93ea9da

Please sign in to comment.