From 1ad5bf20d2f46f16b424cc2ceaf2262b2def206b Mon Sep 17 00:00:00 2001 From: Yuce Tekol Date: Thu, 6 Sep 2018 23:19:10 +0300 Subject: [PATCH] Adds more tests; better help text; updated defaults for cache type, size --- cmd/import.go | 19 +++++++++---------- cmd/import_test.go | 38 +++++++++++++++++++++++++++++++++++--- 2 files changed, 44 insertions(+), 13 deletions(-) diff --git a/cmd/import.go b/cmd/import.go index 7cb6c34c3..7bfca1a84 100644 --- a/cmd/import.go +++ b/cmd/import.go @@ -18,6 +18,8 @@ import ( "context" "io" + "github.com/pilosa/pilosa" + "github.com/spf13/cobra" "github.com/pilosa/pilosa/ctl" @@ -51,19 +53,16 @@ omitted. If it is present then its format should be YYYY-MM-DDTHH:MM. flags.StringVarP(&Importer.Host, "host", "", "localhost:10101", "host:port of Pilosa.") flags.StringVarP(&Importer.Index, "index", "i", "", "Pilosa index to import into.") flags.StringVarP(&Importer.Field, "field", "f", "", "Field to import into.") - flags.BoolVar(&Importer.IndexOptions.Keys, "index-keys", false, "specify keys=true when creating an index") - flags.BoolVar(&Importer.FieldOptions.Keys, "field-keys", false, "specify keys=true when creating a field") - flags.Int64Var(&Importer.FieldOptions.Min, "field-min", 0, "specify the minimum for an int field on creation") - flags.Int64Var(&Importer.FieldOptions.Max, "field-max", 0, "specify the maximum for an int field on creation") - flags.StringVar(&Importer.FieldOptions.CacheType, "field-cache-type", "", "specify the cache type for a set field on creation") - flags.Uint32Var(&Importer.FieldOptions.CacheSize, "field-cache-size", 0, "specify the cache size for a set field on creation") - flags.Var(&Importer.FieldOptions.TimeQuantum, "field-time-quantum", "specify the time quantum for a time field on creation") + flags.BoolVar(&Importer.IndexOptions.Keys, "index-keys", false, "Specify keys=true when creating an index") + flags.BoolVar(&Importer.FieldOptions.Keys, "field-keys", false, "Specify keys=true when creating a field") + flags.Int64Var(&Importer.FieldOptions.Min, "field-min", 0, "Specify the minimum for an int field on creation") + flags.Int64Var(&Importer.FieldOptions.Max, "field-max", 0, "Specify the maximum for an int field on creation") + flags.StringVar(&Importer.FieldOptions.CacheType, "field-cache-type", pilosa.CacheTypeRanked, "Specify the cache type for a set field on creation. One of: none, lru, ranked") + flags.Uint32Var(&Importer.FieldOptions.CacheSize, "field-cache-size", 50000, "Specify the cache size for a set field on creation") + flags.Var(&Importer.FieldOptions.TimeQuantum, "field-time-quantum", "Specify the time quantum for a time field on creation. One of: D, DH, H, M, MD, MDH, Y, YM, YMD, YMDH") flags.IntVarP(&Importer.BufferSize, "buffer-size", "s", 10000000, "Number of bits to buffer/sort before importing.") flags.BoolVarP(&Importer.Sort, "sort", "", false, "Enables sorting before import.") flags.BoolVarP(&Importer.CreateSchema, "create", "e", false, "Create the schema if it does not exist before import.") - //flags.Var(&Importer.FieldOptions.TimeQuantum, "field-time-quantum", "Time quantum for the field") - //flags.StringVar(&Importer.FieldOptions.CacheType, "field-cache-type", pilosa.CacheTypeRanked, "Cache type for the field; valid values: none, lru, ranked") - //flags.Uint32Var(&Importer.FieldOptions.CacheSize, "field-cache-size", 50000, "Cache size for the field") ctl.SetTLSConfig(flags, &Importer.TLS.CertificatePath, &Importer.TLS.CertificateKeyPath, &Importer.TLS.SkipVerify) return importCmd diff --git a/cmd/import_test.go b/cmd/import_test.go index 9a68a1218..ba015dc04 100644 --- a/cmd/import_test.go +++ b/cmd/import_test.go @@ -50,15 +50,47 @@ field = "f1" }, }, { - args: []string{"import", "--index", "i1", "--field", "f1", "--field-keys", "--field-max", "100"}, + args: []string{"import", "--index", "i1", "--field", "f1", "--field-keys", "--field-min", "-10", "--field-max", "100"}, env: map[string]string{}, validation: func() error { v := validator{} v.Check(cmd.Importer.Index, "i1") v.Check(cmd.Importer.Field, "f1") v.Check(cmd.Importer.FieldOptions, pilosa.FieldOptions{ - Keys: true, - Max: 100, + Keys: true, + Max: 100, + Min: -10, + CacheType: pilosa.CacheTypeRanked, + CacheSize: 50000, + }) + return v.Error() + }, + }, + { + args: []string{"import", "--index", "i1", "--field", "f1", "--field-time-quantum", "YMD"}, + env: map[string]string{}, + validation: func() error { + v := validator{} + v.Check(cmd.Importer.Index, "i1") + v.Check(cmd.Importer.Field, "f1") + v.Check(cmd.Importer.FieldOptions, pilosa.FieldOptions{ + TimeQuantum: "YMD", + CacheType: pilosa.CacheTypeRanked, + CacheSize: 50000, + }) + return v.Error() + }, + }, + { + args: []string{"import", "--index", "i1", "--field", "f1", "--field-cache-type", "lru", "--field-cache-size", "100"}, + env: map[string]string{}, + validation: func() error { + v := validator{} + v.Check(cmd.Importer.Index, "i1") + v.Check(cmd.Importer.Field, "f1") + v.Check(cmd.Importer.FieldOptions, pilosa.FieldOptions{ + CacheType: "lru", + CacheSize: 100, }) return v.Error() },