-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathmain.go
53 lines (46 loc) · 1.43 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
package main
import (
"database/sql"
"log"
"os"
"github.com/aliyun/aliyun-odps-go-sdk/sqldriver"
)
func main() {
config, err := sqldriver.NewConfigFromIni(os.Args[1])
if err != nil {
log.Fatalf("%+v", err)
}
dsn := config.FormatDsn()
// or dsn := "http://<accessId>:<accessKey>@<endpoint>?project=<project>"
db, err := sql.Open("odps", dsn)
if err != nil {
log.Fatalf("%+v", err)
}
sqlStr := "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," +
" timestamp_ntz_type timestamp_ntz," +
" boolean_type boolean," +
" map_type map<string, bigint>," +
" array_type array< string>," +
" struct_type struct<arr:ARRAY<STRING>, name:STRING>," +
" json_type json" +
") " +
"partitioned by (p1 bigint, p2 string);"
_, err = db.Exec(sqlStr)
if err != nil {
log.Fatalf("%+v", err)
}
}