MCPcopy
hub / github.com/apache/devlake / ExportData

Function ExportData

backend/plugins/starrocks/tasks/tasks.go:64–132  ·  view source on GitHub ↗
(c plugin.SubTaskContext)

Source from the content-addressed store, hash-verified

62}
63
64func ExportData(c plugin.SubTaskContext) errors.Error {
65 logger := c.GetLogger()
66 config := c.GetData().(*StarRocksConfig)
67
68 // 1. Get db instance
69 var db dal.Dal
70 if config.SourceDsn != "" && config.SourceType != "" {
71 o, err := getDbInstance(c)
72 if err != nil {
73 return errors.Convert(err)
74 }
75 db = dalgorm.NewDalgorm(o)
76 sqlDB, err := o.DB()
77 if err != nil {
78 return errors.Convert(err)
79 }
80 defer sqlDB.Close()
81 } else {
82 db = c.GetDal()
83 }
84
85 // 2. Filter out the tables to export
86 starrocksTables, err := getExportingTables(c, db)
87 if err != nil {
88 return errors.Convert(err)
89 }
90 // 3. copy devlake data to starrocks
91 sr, err := gorm.Open(mysql.Open(fmt.Sprintf("%s:%s@tcp(%s:%d)/%s?charset=utf8mb4&parseTime=True&loc=Local", config.User, config.Password, config.Host, config.Port, config.Database)))
92 if err != nil {
93 return errors.Convert(err)
94 }
95 starrocksDb := dalgorm.NewDalgorm(sr)
96 sqlStarrocksDB, err := sr.DB()
97 if err != nil {
98 return errors.Convert(err)
99 }
100 defer sqlStarrocksDB.Close()
101
102 for _, table := range starrocksTables {
103 select {
104 case <-c.GetContext().Done():
105 return errors.Convert(c.GetContext().Err())
106 default:
107 }
108
109 dc := DataConfigParams{
110 Ctx: c,
111 Config: config,
112 SrcDb: db,
113 DestDb: starrocksDb,
114 SrcTableName: table,
115 DestTableName: table,
116 }
117 columnMap, orderBy, skip, err := createTmpTableInStarrocks(&dc)
118 if skip {
119 logger.Info(fmt.Sprintf("table %s is up to date, so skip it", table))
120 continue
121 }

Callers

nothing calls this directly

Calls 13

getDbInstanceFunction · 0.85
getExportingTablesFunction · 0.85
copyDataToDstFunction · 0.85
ErrMethod · 0.80
GetLoggerMethod · 0.65
GetDataMethod · 0.65
CloseMethod · 0.65
GetDalMethod · 0.65
GetContextMethod · 0.65
InfoMethod · 0.65
ErrorMethod · 0.65

Tested by

no test coverage detected