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

Function RunSQLProgramAndPrintResult

go/step/step.go:37–55  ·  view source on GitHub ↗

RunSQLProgramAndPrintResult execute SQL statement and print the logs and select result TODO(yancey1989): more meanful argument isTerminal and it2Check

(sqlStmt string, modelDir string, session *pb.Session, table tablewriter.TableWriter, isTerminal, it2Check bool)

Source from the content-addressed store, hash-verified

35// RunSQLProgramAndPrintResult execute SQL statement and print the logs and select result
36// TODO(yancey1989): more meanful argument isTerminal and it2Check
37func RunSQLProgramAndPrintResult(sqlStmt string, modelDir string, session *pb.Session, table tablewriter.TableWriter, isTerminal, it2Check bool) error {
38 startTime := time.Now().UnixNano()
39 defer log.Printf("(%.2f sec)\n", float64(time.Now().UnixNano()-startTime)/1e9)
40 // note(yancey1989): if the input sql program contain `\n`, bufio.Text() would deal with
41 // it as a text string with two character instead of one character "\n".
42 // readStmt(bufio.Scanner) should deal with that by replacing `\n` with '\n'
43 // TODO(yancey1989): finding a normative way to deal with that.
44 replacer := strings.NewReplacer(`\n`, "\n", `\t`, "\t", `\r`, "\r")
45 sqlStmt = replacer.Replace(sqlStmt)
46
47 log.SetFlags(0)
48 stream := sql.RunSQLProgram(sqlStmt, modelDir, session)
49 for res := range stream.ReadAll() {
50 if e := Render(res, table, isTerminal, it2Check); e != nil {
51 return e
52 }
53 }
54 return table.Flush()
55}
56
57// Render output according to calling environment
58func Render(rsp interface{}, table tablewriter.TableWriter, isTerminal, it2Check bool) error {

Callers 2

runFunction · 0.92
TestStepTrainSQLFunction · 0.85

Calls 4

RunSQLProgramFunction · 0.92
RenderFunction · 0.85
ReadAllMethod · 0.80
FlushMethod · 0.65

Tested by 1

TestStepTrainSQLFunction · 0.68