This repository has been archived by the owner on Feb 18, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 102
/
test.go
135 lines (101 loc) · 2.45 KB
/
test.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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
package main
import (
"fmt"
// "reflect"
// "sort"
// "time"
"encoding/json"
"github.com/gocql/gocql"
"github.com/urfave/cli"
)
/*
func test(c *cli.Context, mc *metadataClient) error {
if c.NArg() < 3 {
return fmt.Errorf("specify table and column")
}
// 'store_extents' table:
var writeTimeMs int64
tbl := c.Args()[0]
row := c.Args()[1]
col := c.Args()[2]
cql := fmt.Sprintf(`SELECT WRITETIME(%s) FROM %s WHERE %s`, col, tbl, row)
err := mc.session.Query(cql).Scan(&writeTimeMs)
if err != nil {
fmt.Printf("ERROR running query '%s': %v\n", cql, err)
}
fmt.Printf("tbl:%s row:%s col:%s WRITETIME=%v\n", tbl, row, col, time.Unix(0, writeTimeMs*1000))
return nil
}
*/
/*
func test(c *cli.Context, mc *metadataClient) error {
if c.NArg() == 0 {
fmt.Printf("uuid not specified")
return nil
}
uuid := c.Args()[0]
cql := fmt.Sprintf("SELECT * FROM destinations WHERE uuid=%v ALLOW FILTERING", uuid)
row, err := mc.QueryRow(cql)
if err != nil {
fmt.Printf("test: '%v': %v\n", cql, err)
return nil
}
fmt.Printf("destinations[%v]:\n", uuid)
prefix := "\t"
var keys []string
for k := range row {
keys = append(keys, k)
}
sort.Strings(keys)
for _, k := range keys {
fmt.Printf("%s%v:", prefix, k)
switch row[k].(type) {
case map[string]interface{}:
fmt.Printf("\n")
printRow(prefix+"\t", row[k].(map[string]interface{}))
case map[string]map[string]interface{}:
fmt.Printf("\n")
printRow(prefix+"\t", row[k].(map[string]interface{}))
default:
fmt.Printf("(%v) %v\n", reflect.TypeOf(row[k]), row[k])
}
}
return nil
}
*/
/*
func rowString(row map[string]interface{}) string {
for k, v := range row {
switch v.(type) {
}
}
}
*/
func test(c *cli.Context, mc *metadataClient) error {
cql := "SELECT * FROM store_extents"
getIterator := func(cql string) (iter *gocql.Iter, close func() error) {
iter = mc.session.Query(cql).RetryPolicy(&gocql.SimpleRetryPolicy{NumRetries: 16 /*mc.retries*/}).Iter()
close = func() (err error) {
if err = iter.Close(); err != nil {
fmt.Printf("ERROR from query '%v': %v\n", cql, err)
}
return
}
return
}
iter, close := getIterator(cql)
defer close()
for {
row := make(map[string]interface{})
if !iter.MapScan(row) {
break
}
// extUUID := row["extent_uuid"]
j, _ := json.Marshal(row)
// fmt.Printf("%v, %v\n", string(j), e)
fmt.Printf("INSERT INTO store_extents VALUES %v\n", string(j))
break
}
fmt.Printf("\n")
return nil
}