Skip to content

Commit 677317e

Browse files
committed
add comments and add --skip-rows for load csv
1 parent b46abb6 commit 677317e

File tree

5 files changed

+30
-7
lines changed

5 files changed

+30
-7
lines changed

cmd_flags.go

+2
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,12 @@ var DeleteOptsKeywordList = []string{
3838
///////////////// loadcsv options //////////////////////
3939
var (
4040
LoadFileOptBatchSize string = "batch-size"
41+
LoadFileoptSkipRows string = "skip-rows"
4142
)
4243

4344
var LoadFileOptsKeywordList = []string{
4445
LoadFileOptBatchSize,
46+
LoadFileoptSkipRows,
4547
}
4648

4749
//////////////// end of loadcsv options ///////////////

kvcmds/cmd_backup.go

+3
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,10 @@ Usage:
3232
Options:
3333
--batch-size=<size>, default 1000
3434
Example:
35+
# backup all kvs with prefix "t_" to csv file
3536
backup "t_" backup.csv --batch-size=5000
37+
38+
# backup all kvs to csv file
3639
backup * backup.csv
3740
backup $head backup.csv
3841
`)

kvcmds/cmd_delete_prefix.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ Alias:
2929
deletep, removep, rmp
3030
Options:
3131
--yes, force yes
32-
--limit, default: 1000
32+
--limit=<limit>, default: 1000
3333
`
3434
return s
3535
}

kvcmds/cmd_loadfile.go

+16-6
Original file line numberDiff line numberDiff line change
@@ -34,23 +34,27 @@ Usage:
3434
Alias:
3535
lcsv
3636
Options:
37-
--batch-size: int, how many records in one tikv transaction, default: 1000
37+
--batch-size=<size>: int, how many records in one tikv transaction, default: 1000
3838
Examples:
39-
loadcsv sample.csv
39+
# load csv file to tikv
40+
loadcsv sample.csv
41+
42+
# load csv file to tikv with key prefix: "prefix_"
4043
loadcsv sample.csv "prefix_" --batch-size=100
44+
45+
# load csv file to tikv with key prefix and skip first row (header)
46+
loadcsv sample.csv "prefix_" --batch-size=100 --skip-rows=1
4147
`
4248
return s
4349
}
4450

4551
func (c LoadCsvCmd) processCSV(prop *properties.Properties, rc io.Reader, keyPrefix []byte) error {
4652
r := csv.NewReader(rc)
47-
if _, err := r.Read(); err != nil { //read header
48-
return err
49-
}
5053
var cnt int
5154
var batch []client.KV
5255

5356
batchSize := prop.GetInt(tcli.LoadFileOptBatchSize, 1000)
57+
skips := prop.GetInt(tcli.LoadFileoptSkipRows, 0)
5458
for {
5559
rawRec, err := r.Read()
5660
if err != nil {
@@ -59,6 +63,13 @@ func (c LoadCsvCmd) processCSV(prop *properties.Properties, rc io.Reader, keyPre
5963
}
6064
return err
6165
}
66+
if skips > 0 {
67+
skips--
68+
continue
69+
}
70+
if len(rawRec) != 2 {
71+
return fmt.Errorf("invalid csv record: %v, format should be: <key>,<value>", rawRec)
72+
}
6273
k, _ := utils.GetStringLit(rawRec[0])
6374
v, _ := utils.GetStringLit(rawRec[1])
6475
cnt++
@@ -74,7 +85,6 @@ func (c LoadCsvCmd) processCSV(prop *properties.Properties, rc io.Reader, keyPre
7485
K: key,
7586
V: v,
7687
})
77-
7888
if len(batch) == batchSize {
7989
// do insert
8090
err := client.GetTiKVClient().BatchPut(context.TODO(), batch)

kvcmds/cmd_scan.go

+8
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,18 @@ Options:
3131
--strict-prefix=<true|false>, default false
3232
--count-only=<true|false>, default false
3333
Examples:
34+
# scan from "a", max 10 keys
3435
scan "a" --limit=10
36+
37+
# scan from "a", max 10 keys, output key-only
3538
scan "a" --limit=10 --key-only=true
39+
40+
# scan from "a", max 10 keys, output key-only, the result keys are strictly prefix
3641
scan "a" --limit=10 --strict-prefix
42+
43+
# scan from "a", count the number of keys, max 10 keys
3744
scan "a" --limit=10 --count-only
45+
3846
scan "a" --limit=10 --strict-prefix --key-only=true
3947
scan $head --limit=10 --key-only=true
4048
`

0 commit comments

Comments
 (0)