diff --git a/ext/sheets/gsheet/gsheet.go b/ext/sheets/gsheet/gsheet.go index 8b272a5385..a933ba4914 100644 --- a/ext/sheets/gsheet/gsheet.go +++ b/ext/sheets/gsheet/gsheet.go @@ -34,9 +34,6 @@ func (gs *GSheets) GetAsCSV(url, sheetRange string) (string, error) { return "", err } - if sheetRange == "" { - sheetRange = readRange - } content, err := gs.getSheetContent(info.SheetID, sheetRange) if err != nil { return "", err @@ -46,14 +43,35 @@ func (gs *GSheets) GetAsCSV(url, sheetRange string) (string, error) { } func (gs *GSheets) getSheetContent(sheetID, sheetRange string) ([][]interface{}, error) { - resp, err := gs.srv.Spreadsheets.Values.Get(sheetID, sheetRange).Do() + batchGetCall := gs.srv.Spreadsheets.Values.BatchGet(sheetID) + if sheetRange != "" { + batchGetCall = batchGetCall.Ranges(sheetRange) + } + resp, err := batchGetCall.Do() + if err != nil { return nil, err } - if len(resp.Values) == 0 { - return nil, errors.New("no data found in the sheet") + if len(resp.ValueRanges) == 0 { + return nil, errors.New("no sheets found in the spreadsheet ") } - return resp.Values, nil + if len(resp.ValueRanges[0].Values) == 0 { + return nil, errors.New("no data found in the sheet[0]") + } + return resp.ValueRanges[0].Values, nil +} + +func (gs *GSheets) GetSheetName(sheetID string) (string, error) { + spreadsheet, err := gs.srv.Spreadsheets.Get(sheetID).Do() + if err != nil { + return "", err + } + + if len(spreadsheet.Sheets) == 0 { + return "", errors.New("no sub sheet found") + } + sid := spreadsheet.Sheets[0].Properties.Title + return sid, err } diff --git a/ext/store/maxcompute/external_table.go b/ext/store/maxcompute/external_table.go index 952d72f4ad..ed47bb617b 100644 --- a/ext/store/maxcompute/external_table.go +++ b/ext/store/maxcompute/external_table.go @@ -36,8 +36,9 @@ func (e ExternalTableHandle) Create(res *resource.Resource) error { if err != nil { return err } + + tableSchema, err := buildExternalTableSchema(table, res.FullName()) table.Name = tableName - tableSchema, err := buildExternalTableSchema(table, table.Name.String()) if err != nil { return errors.AddErrContext(err, EntityExternalTable, "failed to build table schema to create for "+res.FullName()) } diff --git a/ext/store/maxcompute/sheet_sync.go b/ext/store/maxcompute/sheet_sync.go index c8b747943c..4e5f60f534 100644 --- a/ext/store/maxcompute/sheet_sync.go +++ b/ext/store/maxcompute/sheet_sync.go @@ -92,10 +92,6 @@ func (s *SyncerService) getBucketName(ctx context.Context, res *resource.Resourc } func (s *SyncerService) getObjectKey(ctx context.Context, res *resource.Resource, et *ExternalTable) (string, error) { - components, err := getURNComponent(res) - if err != nil { - return "", err - } location, err := s.getLocation(ctx, res, et) if err != nil { return "", err @@ -103,7 +99,7 @@ func (s *SyncerService) getObjectKey(ctx context.Context, res *resource.Resource parts := strings.Split(location, "/") if len(parts) > 4 { // nolint:mnd path := strings.Join(parts[4:], "/") - return fmt.Sprintf("%s%s/file.csv", path, components.Name), nil + return fmt.Sprintf("%s%s/file.csv", path, res.FullName()), nil } return "", errors.New("unable to get object path from location") }