MCPcopy Create free account
hub / github.com/sql-machine-learning/sqlflow / MockInDB

Function MockInDB

go/model/model.go:333–343  ·  view source on GitHub ↗

MockInDB mocks a model meta structure which saved in database for testing

(cwd, trainSelect, table string)

Source from the content-addressed store, hash-verified

331
332// MockInDB mocks a model meta structure which saved in database for testing
333func MockInDB(cwd, trainSelect, table string) error {
334 m := New(cwd, trainSelect)
335 metaStr := fmt.Sprintf(`{"original_sql": "%s"}`, strings.ReplaceAll(strings.ReplaceAll(trainSelect, "\n", " "), `"`, `\"`))
336 if e := decodeMeta(m, []byte(metaStr)); e != nil {
337 return e
338 }
339 if e := ioutil.WriteFile(path.Join(cwd, modelMetaFileName), []byte(metaStr), 0644); e != nil {
340 return e
341 }
342 return m.saveDB(database.GetTestingDBSingleton().URL(), table, database.GetSessionFromTestingDB())
343}

Callers 2

TestGeneratePredictStmtFunction · 0.92
TestGenerateExplainStmtFunction · 0.92

Calls 6

GetTestingDBSingletonFunction · 0.92
GetSessionFromTestingDBFunction · 0.92
decodeMetaFunction · 0.85
saveDBMethod · 0.80
URLMethod · 0.80
NewFunction · 0.70

Tested by 2

TestGeneratePredictStmtFunction · 0.74
TestGenerateExplainStmtFunction · 0.74