Skip to content

Commit d7a78e7

Browse files
committed
fix: construct ordered column with header separation first
1 parent 60f3b60 commit d7a78e7

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

mc2mc/internal/client/client.go

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -68,12 +68,14 @@ func (c *Client) Execute(ctx context.Context, tableID, queryFilePath string) err
6868
}
6969

7070
// get column names
71-
columnNames, err := c.OdpsClient.GetOrderedColumns(tableID)
72-
if err != nil {
73-
return errors.WithStack(err)
71+
if tableID != "" {
72+
columnNames, err := c.OdpsClient.GetOrderedColumns(tableID)
73+
if err != nil {
74+
return errors.WithStack(err)
75+
}
76+
// construct query with ordered columns
77+
queryRaw = constructQueryWithOrderedColumns(queryRaw, columnNames)
7478
}
75-
// construct query with ordered columns
76-
queryRaw = constructQueryWithOrderedColumns(queryRaw, columnNames)
7779

7880
if c.enablePartitionValue && !c.enableAutoPartition {
7981
queryRaw = addPartitionValueColumn(queryRaw)
@@ -110,5 +112,6 @@ func addPartitionValueColumn(rawQuery []byte) []byte {
110112
}
111113

112114
func constructQueryWithOrderedColumns(query []byte, orderedColumns []string) []byte {
113-
return []byte(loader.ConstructQueryWithOrderedColumns(string(query), orderedColumns))
115+
header, qr := loader.SeparateHeadersAndQuery(string(query))
116+
return []byte(fmt.Sprintf("%s %s", header, loader.ConstructQueryWithOrderedColumns(qr, orderedColumns)))
114117
}

0 commit comments

Comments
 (0)