-
Notifications
You must be signed in to change notification settings - Fork 12
/
main.go
58 lines (50 loc) · 1.72 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
package main
import (
"log"
"os"
"github.com/aliyun/aliyun-odps-go-sdk/odps"
"github.com/aliyun/aliyun-odps-go-sdk/odps/account"
)
func main() {
conf, err := odps.NewConfigFromIni(os.Args[1])
if err != nil {
log.Fatalf("%+v", err)
}
aliAccount := account.NewAliyunAccount(conf.AccessId, conf.AccessKey)
odpsIns := odps.NewOdps(aliAccount, conf.Endpoint)
odpsIns.SetDefaultProjectName(conf.ProjectName)
sql := "create table if not exists all_types_demo (" +
" tiny_int_type tinyint," +
" small_int_type smallint," +
" int_type int," +
" bigint_type bigint," +
" binary_type binary," +
" float_type float," +
" double_type double," +
" decimal_type decimal(10, 8)," +
" varchar_type varchar(500)," +
" char_type varchar(254)," +
" string_type string," +
" date_type date," +
" datetime_type datetime," +
" timestamp_type timestamp," +
" boolean_type boolean," +
" map_type map<string, bigint>," +
" array_type array< string>," +
" struct_type struct<arr:ARRAY<STRING>, name:STRING>" +
") " +
"partitioned by (p1 bigint, p2 string);"
// 如果project的数据类型版本是1.0,需要通过下面的hints使用mc 2.0数据类型
//hints := make(map[string]string)
//hints["odps.sql.type.system.odps2"] = "true"
//hints["odps.sql.decimal.odps2"] = "true"
//ins, err := odpsIns.ExecSQlWithHints(sql, hints)
ins, err := odpsIns.ExecSQl(sql)
if err != nil {
log.Fatalf("%+v", err)
}
err = ins.WaitForSuccess()
if err != nil {
log.Fatalf("%+v", err)
}
}