Skip to content

Commit

Permalink
feat(mc2mc): set execution project (#60)
Browse files Browse the repository at this point in the history
feat: set execution project
  • Loading branch information
deryrahman authored Jan 7, 2025
1 parent 7575928 commit debc45a
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 0 deletions.
1 change: 1 addition & 0 deletions mc2mc/internal/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (

type OdpsClient interface {
ExecSQL(ctx context.Context, query string) error
SetDefaultProject(project string)
}

type Client struct {
Expand Down
5 changes: 5 additions & 0 deletions mc2mc/internal/client/odps.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,11 @@ func (c *odpsClient) ExecSQL(ctx context.Context, query string) error {
}
}

// SetDefaultProject sets the default project of the odps client
func (c *odpsClient) SetDefaultProject(project string) {
c.client.SetDefaultProjectName(project)
}

// GetPartitionNames returns the partition names of the given table
// by querying the table schema.
func (c *odpsClient) GetPartitionNames(_ context.Context, tableID string) ([]string, error) {
Expand Down
10 changes: 10 additions & 0 deletions mc2mc/internal/client/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,16 @@ import (

type SetupFn func(c *Client) error

func SetupDefaultProject(project string) SetupFn {
return func(c *Client) error {
if c.OdpsClient == nil {
return errors.New("odps client is required")
}
c.OdpsClient.SetDefaultProject(project)
return nil
}
}

func SetupLogger(logger *slog.Logger) SetupFn {
return func(c *Client) error {
c.logger = logger
Expand Down
1 change: 1 addition & 0 deletions mc2mc/internal/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ type ConfigEnv struct {
DestinationTableID string `env:"DESTINATION_TABLE_ID"`
DStart string `env:"DSTART"`
DEnd string `env:"DEND"`
ExecutionProject string `env:"EXECUTION_PROJECT"`
// TODO: delete this
DevEnablePartitionValue string `env:"DEV__ENABLE_PARTITION_VALUE" envDefault:"false"`
DevEnableAutoPartition string `env:"DEV__ENABLE_AUTO_PARTITION" envDefault:"false"`
Expand Down
1 change: 1 addition & 0 deletions mc2mc/mc2mc.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ func mc2mc(envs []string) error {
client.SetupLogger(l),
client.SetupOTelSDK(cfg.OtelCollectorGRPCEndpoint, cfg.OtelAttributes),
client.SetupODPSClient(cfg.GenOdps()),
client.SetupDefaultProject(cfg.ExecutionProject),
)
if err != nil {
return errors.WithStack(err)
Expand Down

0 comments on commit debc45a

Please sign in to comment.