Skip to content

Commit

Permalink
Merge pull request #18 from goccy/update-zetasql
Browse files Browse the repository at this point in the history
Update go-zetasql to v0.3.2
  • Loading branch information
goccy authored Aug 15, 2022
2 parents 558159d + 9d82874 commit 6ea1b8f
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 35 deletions.
2 changes: 1 addition & 1 deletion cmd/zetasqlite-cli/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ require (
require (
github.com/dgryski/go-farm v0.0.0-20200201041132-a6ae2369ad13 // indirect
github.com/goccy/go-json v0.9.10 // indirect
github.com/goccy/go-zetasql v0.3.1 // indirect
github.com/goccy/go-zetasql v0.3.2 // indirect
github.com/google/uuid v1.3.0 // indirect
github.com/mattn/go-sqlite3 v1.14.14 // indirect
golang.org/x/sys v0.0.0-20220310020820-b874c991c1a5 // indirect
Expand Down
4 changes: 2 additions & 2 deletions cmd/zetasqlite-cli/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ github.com/dgryski/go-farm v0.0.0-20200201041132-a6ae2369ad13 h1:fAjc9m62+UWV/WA
github.com/dgryski/go-farm v0.0.0-20200201041132-a6ae2369ad13/go.mod h1:SqUrOPUnsFjfmXRMNPybcSiG0BgUW2AuFH8PAnS2iTw=
github.com/goccy/go-json v0.9.10 h1:hCeNmprSNLB8B8vQKWl6DpuH0t60oEs+TAk9a7CScKc=
github.com/goccy/go-json v0.9.10/go.mod h1:6MelG93GURQebXPDq3khkgXZkazVtN9CRI+MGFi0w8I=
github.com/goccy/go-zetasql v0.3.1 h1:6iY3ssyXnlDX71zmxOHvyP9+BxJsV1yxoi1msRRAWkI=
github.com/goccy/go-zetasql v0.3.1/go.mod h1:6W14CJVKh7crrSPyj6NPk4c49L2NWnxvyDLsRkOm4BI=
github.com/goccy/go-zetasql v0.3.2 h1:+HxuazroaYJnZYZdBgeRwxnRmXO+OTE+EMQ9hQwHhUA=
github.com/goccy/go-zetasql v0.3.2/go.mod h1:6W14CJVKh7crrSPyj6NPk4c49L2NWnxvyDLsRkOm4BI=
github.com/google/go-cmp v0.5.8 h1:e6P7q2lk1O+qJJb4BtCQXlK8vWEO8V1ZeuEdJNOqZyg=
github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I=
github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ module github.com/goccy/go-zetasqlite
go 1.17

require (
github.com/goccy/go-zetasql v0.3.1
github.com/goccy/go-zetasql v0.3.2
github.com/mattn/go-sqlite3 v1.14.14
)

Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ github.com/dgryski/go-farm v0.0.0-20200201041132-a6ae2369ad13 h1:fAjc9m62+UWV/WA
github.com/dgryski/go-farm v0.0.0-20200201041132-a6ae2369ad13/go.mod h1:SqUrOPUnsFjfmXRMNPybcSiG0BgUW2AuFH8PAnS2iTw=
github.com/goccy/go-json v0.9.10 h1:hCeNmprSNLB8B8vQKWl6DpuH0t60oEs+TAk9a7CScKc=
github.com/goccy/go-json v0.9.10/go.mod h1:6MelG93GURQebXPDq3khkgXZkazVtN9CRI+MGFi0w8I=
github.com/goccy/go-zetasql v0.3.1 h1:6iY3ssyXnlDX71zmxOHvyP9+BxJsV1yxoi1msRRAWkI=
github.com/goccy/go-zetasql v0.3.1/go.mod h1:6W14CJVKh7crrSPyj6NPk4c49L2NWnxvyDLsRkOm4BI=
github.com/goccy/go-zetasql v0.3.2 h1:+HxuazroaYJnZYZdBgeRwxnRmXO+OTE+EMQ9hQwHhUA=
github.com/goccy/go-zetasql v0.3.2/go.mod h1:6W14CJVKh7crrSPyj6NPk4c49L2NWnxvyDLsRkOm4BI=
github.com/google/go-cmp v0.5.8 h1:e6P7q2lk1O+qJJb4BtCQXlK8vWEO8V1ZeuEdJNOqZyg=
github.com/google/go-cmp v0.5.8/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I=
Expand Down
52 changes: 23 additions & 29 deletions internal/formatter.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,22 +42,16 @@ func getTableName(ctx context.Context, t types.Table) string {
)
}

func uniqueColumnName(ctx context.Context, col *ast.Column) []byte {
colName := string([]byte(col.Name()))
func uniqueColumnName(ctx context.Context, col *ast.Column) string {
colName := col.Name()
if useTableNameForColumn(ctx) {
copied := make([]byte, 0, len(col.TableName())+len(colName)+5)
copied = append(copied, fmt.Sprintf("%s.%s", col.TableName(), colName)...)
return copied
return fmt.Sprintf("%s.%s", col.TableName(), colName)
}
if useColumnID(ctx) {
colID := col.ColumnID()
copied := make([]byte, 0, len(colName)+len(fmt.Sprint(colID))+1)
copied = append(copied, fmt.Sprintf("%s#%d", colName, colID)...)
return copied
return fmt.Sprintf("%s#%d", colName, colID)
}
copied := make([]byte, 0, len(colName))
copied = append(copied, colName...)
return copied
return colName
}

func existsJoinExpr(node ast.Node) bool {
Expand Down Expand Up @@ -208,7 +202,7 @@ func (n *ColumnRefNode) FormatSQL(ctx context.Context) (string, error) {
}
columnMap := columnRefMap(ctx)
col := n.node.Column()
colName := string(uniqueColumnName(ctx, col))
colName := uniqueColumnName(ctx, col)
if ref, exists := columnMap[colName]; exists {
delete(columnMap, colName)
return ref, nil
Expand Down Expand Up @@ -280,11 +274,11 @@ func (n *AggregateFunctionCallNode) FormatSQL(ctx context.Context) (string, erro
var opts []string
for _, item := range n.node.OrderByItemList() {
columnRef := item.ColumnRef()
colName := []byte(uniqueColumnName(ctx, columnRef.Column()))
colName := uniqueColumnName(ctx, columnRef.Column())
if item.IsDescending() {
opts = append(opts, fmt.Sprintf("zetasqlite_order_by_string(`%s`, false)", string(colName)))
opts = append(opts, fmt.Sprintf("zetasqlite_order_by_string(`%s`, false)", colName))
} else {
opts = append(opts, fmt.Sprintf("zetasqlite_order_by_string(`%s`, true)", string(colName)))
opts = append(opts, fmt.Sprintf("zetasqlite_order_by_string(`%s`, true)", colName))
}
}
if n.node.Distinct() {
Expand Down Expand Up @@ -501,7 +495,7 @@ func (n *SubqueryExprNode) FormatSQL(ctx context.Context) (string, error) {
if len(n.node.Subquery().ColumnList()) == 0 {
return "", fmt.Errorf("failed to find computed column names for array subquery")
}
colName := string(uniqueColumnName(ctx, n.node.Subquery().ColumnList()[0]))
colName := uniqueColumnName(ctx, n.node.Subquery().ColumnList()[0])
return fmt.Sprintf("zetasqlite_array_array(`%s`) FROM (%s)", colName, sql), nil
case ast.SubqueryTypeExists:
return fmt.Sprintf("EXISTS (%s)", sql), nil
Expand Down Expand Up @@ -594,7 +588,7 @@ func (n *JoinScanNode) FormatSQL(ctx context.Context) (string, error) {
columnMap = columnRefMap(ctx)
)
for _, col := range n.node.ColumnList() {
colName := string(uniqueColumnName(ctx, col))
colName := uniqueColumnName(ctx, col)
if ref, exists := columnMap[colName]; exists {
columns = append(columns, ref)
delete(columnMap, colName)
Expand All @@ -619,7 +613,7 @@ func (n *ArrayScanNode) FormatSQL(ctx context.Context) (string, error) {
if err != nil {
return "", err
}
colName := string(uniqueColumnName(ctx, n.node.ElementColumn()))
colName := uniqueColumnName(ctx, n.node.ElementColumn())
if n.node.InputScan() != nil {
input, err := newNode(n.node.InputScan()).FormatSQL(ctx)
if err != nil {
Expand Down Expand Up @@ -695,7 +689,7 @@ func (n *AggregateScanNode) FormatSQL(ctx context.Context) (string, error) {
if _, err := newNode(col).FormatSQL(ctx); err != nil {
return "", err
}
colName := string(uniqueColumnName(ctx, col.Column()))
colName := uniqueColumnName(ctx, col.Column())
groupByColumns = append(groupByColumns, fmt.Sprintf("`%s`", colName))
groupByColumnMap[colName] = struct{}{}
}
Expand All @@ -709,7 +703,7 @@ func (n *AggregateScanNode) FormatSQL(ctx context.Context) (string, error) {
columnMap := columnRefMap(ctx)
columnNames := []string{}
for _, col := range n.node.ColumnList() {
colName := string(uniqueColumnName(ctx, col))
colName := uniqueColumnName(ctx, col)
columnNames = append(columnNames, colName)
if ref, exists := columnMap[colName]; exists {
columns = append(columns, ref)
Expand All @@ -731,7 +725,7 @@ func (n *AggregateScanNode) FormatSQL(ctx context.Context) (string, error) {
groupBySetColumns := []string{}
groupBySetColumnMap := map[string]struct{}{}
for _, col := range set.GroupByColumnList() {
colName := string(uniqueColumnName(ctx, col.Column()))
colName := uniqueColumnName(ctx, col.Column())
groupBySetColumns = append(groupBySetColumns, fmt.Sprintf("`%s`", colName))
groupBySetColumnMap[colName] = struct{}{}
}
Expand Down Expand Up @@ -861,7 +855,7 @@ func (n *OrderByScanNode) FormatSQL(ctx context.Context) (string, error) {
columns := []string{}
columnMap := columnRefMap(ctx)
for _, col := range n.node.ColumnList() {
colName := string(uniqueColumnName(ctx, col))
colName := uniqueColumnName(ctx, col)
if ref, exists := columnMap[colName]; exists {
columns = append(columns, ref)
delete(columnMap, colName)
Expand Down Expand Up @@ -916,7 +910,7 @@ func (n *LimitOffsetScanNode) FormatSQL(ctx context.Context) (string, error) {
columns := []string{}
columnMap := columnRefMap(ctx)
for _, col := range n.node.ColumnList() {
colName := string(uniqueColumnName(ctx, col))
colName := uniqueColumnName(ctx, col)
if ref, exists := columnMap[colName]; exists {
columns = append(columns, ref)
delete(columnMap, colName)
Expand Down Expand Up @@ -1023,10 +1017,10 @@ func (n *AnalyticScanNode) FormatSQL(ctx context.Context) (string, error) {
formattedColName := fmt.Sprintf("`%s`", colName)
orderByColumns = append(
orderByColumns,
string(formattedColName),
formattedColName,
)
orderColumnNames.values = append(orderColumnNames.values, &analyticOrderBy{
column: string(formattedColName),
column: formattedColName,
isAsc: !item.IsDescending(),
})
}
Expand All @@ -1038,7 +1032,7 @@ func (n *AnalyticScanNode) FormatSQL(ctx context.Context) (string, error) {
columns := []string{}
columnMap := columnRefMap(ctx)
for _, col := range n.node.ColumnList() {
colName := string(uniqueColumnName(ctx, col))
colName := uniqueColumnName(ctx, col)
if ref, exists := columnMap[colName]; exists {
columns = append(columns, ref)
delete(columnMap, colName)
Expand Down Expand Up @@ -1086,7 +1080,7 @@ func (n *ComputedColumnNode) FormatSQL(ctx context.Context) (string, error) {
return "", err
}
col := n.node.Column()
uniqueName := string(uniqueColumnName(ctx, col))
uniqueName := uniqueColumnName(ctx, col)
query := fmt.Sprintf("%s AS `%s`", expr, uniqueColumnName(ctx, col))
columnMap := columnRefMap(ctx)
columnMap[uniqueName] = query
Expand Down Expand Up @@ -1135,7 +1129,7 @@ func (n *OutputColumnNode) FormatSQL(ctx context.Context) (string, error) {
}
columnMap := columnRefMap(ctx)
col := n.node.Column()
uniqueName := string(uniqueColumnName(ctx, col))
uniqueName := uniqueColumnName(ctx, col)
if ref, exists := columnMap[uniqueName]; exists {
return ref, nil
}
Expand All @@ -1159,7 +1153,7 @@ func (n *ProjectScanNode) FormatSQL(ctx context.Context) (string, error) {
columns := []string{}
columnMap := columnRefMap(ctx)
for _, col := range n.node.ColumnList() {
colName := string(uniqueColumnName(ctx, col))
colName := uniqueColumnName(ctx, col)
if ref, exists := columnMap[colName]; exists {
columns = append(columns, ref)
delete(columnMap, colName)
Expand Down

0 comments on commit 6ea1b8f

Please sign in to comment.