diff --git a/ext/sheets/gsheet/gsheet.go b/ext/sheets/gsheet/gsheet.go index a933ba4914..56359482fb 100644 --- a/ext/sheets/gsheet/gsheet.go +++ b/ext/sheets/gsheet/gsheet.go @@ -48,7 +48,6 @@ func (gs *GSheets) getSheetContent(sheetID, sheetRange string) ([][]interface{}, batchGetCall = batchGetCall.Ranges(sheetRange) } resp, err := batchGetCall.Do() - if err != nil { return nil, err } diff --git a/ext/store/maxcompute/external_table.go b/ext/store/maxcompute/external_table.go index ed47bb617b..9925db68ca 100644 --- a/ext/store/maxcompute/external_table.go +++ b/ext/store/maxcompute/external_table.go @@ -19,6 +19,7 @@ type McExternalTable interface { hints, alias map[string]string, ) error BatchLoadTables(tableNames []string) ([]*odps.Table, error) + Delete(tableName string, ifExists bool) error } type ExternalTableHandle struct { @@ -53,9 +54,12 @@ func (e ExternalTableHandle) Create(res *resource.Resource) error { return nil } -func (ExternalTableHandle) Update(_ *resource.Resource) error { - // TODO implement me - panic("implement me") +func (e ExternalTableHandle) Update(res *resource.Resource) error { + err := e.mcExternalTable.Delete(res.FullName(), true) + if err != nil { + return err + } + return e.Create(res) } func (e ExternalTableHandle) Exists(tableName string) bool { diff --git a/ext/store/maxcompute/external_table_test.go b/ext/store/maxcompute/external_table_test.go index b845dd4780..abee410d03 100644 --- a/ext/store/maxcompute/external_table_test.go +++ b/ext/store/maxcompute/external_table_test.go @@ -85,8 +85,9 @@ func TestExternalTableHandle(t *testing.T) { defer schema.AssertExpectations(t) odpsIns := new(mockOdpsIns) - + odpsIns.On("SetCurrentSchemaName", mock.Anything) defer odpsIns.AssertExpectations(t) + tableHandle := maxcompute.NewExternalTableHandle(odpsIns, schema, table) res, err := resource.NewResource(fullName, maxcompute.KindExternalTable, mcStore, tnnt, &metadata, spec) @@ -104,7 +105,7 @@ func TestExternalTableHandle(t *testing.T) { defer schema.AssertExpectations(t) odpsIns := new(mockOdpsIns) - + odpsIns.On("SetCurrentSchemaName", mock.Anything) defer odpsIns.AssertExpectations(t) tableHandle := maxcompute.NewExternalTableHandle(odpsIns, schema, table) @@ -123,7 +124,7 @@ func TestExternalTableHandle(t *testing.T) { defer schema.AssertExpectations(t) odpsIns := new(mockOdpsIns) - + odpsIns.On("SetCurrentSchemaName", mock.Anything) defer odpsIns.AssertExpectations(t) tableHandle := maxcompute.NewExternalTableHandle(odpsIns, schema, table) @@ -174,6 +175,11 @@ func (m *mockExternalTable) CreateExternal(schema tableschema.TableSchema, creat return args.Error(0) } +func (m *mockExternalTable) Delete(tableName string, ifExists bool) error { + args := m.Called(tableName, ifExists) + return args.Error(0) +} + func (m *mockExternalTable) BatchLoadTables(tableNames []string) ([]*odps.Table, error) { args := m.Called(tableNames) if args.Get(0) == nil { diff --git a/ext/store/maxcompute/table_test.go b/ext/store/maxcompute/table_test.go index c8fd167cf0..156854bc69 100644 --- a/ext/store/maxcompute/table_test.go +++ b/ext/store/maxcompute/table_test.go @@ -63,6 +63,10 @@ func (m *mockOdpsIns) CurrentSchemaName() string { return args.String(0) } +func (m *mockOdpsIns) SetCurrentSchemaName(schemaName string) { + m.Called(schemaName) +} + func TestTableHandle(t *testing.T) { accessID, accessKey, endpoint := "LNRJ5tH1XMSINW5J3TjYAvfX", "lAZBJhdkNbwVj3bej5BuhjwbdV0nSp", "http://service.ap-southeast-5.maxcompute.aliyun.com/api" projectName, schemaName, tableName := "proj", "schema", "test_table"