Skip to content

Commit

Permalink
fix: fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Mryashbhardwaj committed Dec 27, 2024
1 parent 33bb0b6 commit 34cd48b
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 13 deletions.
32 changes: 25 additions & 7 deletions ext/sheets/gsheet/gsheet.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
}
3 changes: 2 additions & 1 deletion ext/store/maxcompute/external_table.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}
Expand Down
6 changes: 1 addition & 5 deletions ext/store/maxcompute/sheet_sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,18 +92,14 @@ 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
}
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")
}
Expand Down

0 comments on commit 34cd48b

Please sign in to comment.