-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathmain.go
60 lines (49 loc) · 1.27 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package main
import (
"fmt"
"io"
"log"
"github.com/aliyun/aliyun-odps-go-sdk/odps"
"github.com/aliyun/aliyun-odps-go-sdk/odps/account"
)
func main() {
// Specify the ini file path
configPath := "./config.ini"
conf, err := odps.NewConfigFromIni(configPath)
if err != nil {
log.Fatalf("%+v", err)
}
aliAccount := account.NewAliyunAccount(conf.AccessId, conf.AccessKey)
odpsIns := odps.NewOdps(aliAccount, conf.Endpoint)
// Set the Default Maxcompute project used By Odps instance
odpsIns.SetDefaultProjectName(conf.ProjectName)
sql := "select * from all_types_demo where p1>0 or p2 > '';"
// The flags used by sql engine, such as odps.sql.skewjoin
var hints map[string]string = nil
// Create a SqlTask
sqlTask := odps.NewSqlTask("select", sql, hints)
// Run the sql with the quota associated with a project
project := odpsIns.DefaultProjectName()
ins, err := sqlTask.Run(odpsIns, project)
if err != nil {
log.Fatalf("%+v", err)
}
err = ins.WaitForSuccess()
if err != nil {
log.Fatalf("%+v", err)
}
csvReader, err := sqlTask.GetSelectResultAsCsv(ins, true)
if err != nil {
log.Fatalf("%+v", err)
}
for {
record, err := csvReader.Read()
if err == io.EOF {
break
}
if err != nil {
log.Fatalf("%+v", err)
}
fmt.Printf("%v\n", record)
}
}