Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Relaxed linting #56

Merged
merged 9 commits into from Jun 1, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 0 additions & 1 deletion .circleci/config.yml
Expand Up @@ -17,7 +17,6 @@ jobs:
- run: make

- run: go get github.com/alecthomas/gometalinter
- run: go get github.com/bradleyfalzon/revgrep/cmd/revgrep
- run:
name: Run linters
command: |
Expand Down
5 changes: 5 additions & 0 deletions .gometalinter.json
@@ -0,0 +1,5 @@
{
"Exclude": [
"TableBlock..getIntInfo"
]
}
3 changes: 1 addition & 2 deletions Makefile
Expand Up @@ -40,9 +40,8 @@ test:
lint:
gometalinter -t --disable-all \
--enable=vet \
--enable=golint \
--enable=megacheck \
--deadline=3m ./... 2>&1 | revgrep origin/master
--deadline=3m ./... 2>&1

testv:
${GOBIN} test ./src/sybil/ -race -v -debug
Expand Down
2 changes: 1 addition & 1 deletion src/cmd/cmd_digest.go
Expand Up @@ -22,7 +22,7 @@ func RunDigestCmdLine() {
sybil.DELETE_BLOCKS_AFTER_QUERY = false

t := sybil.GetTable(*sybil.FLAGS.TABLE)
if t.LoadTableInfo() == false {
if !t.LoadTableInfo() {
sybil.Warn("Couldn't read table info, exiting early")
return
}
Expand Down
14 changes: 6 additions & 8 deletions src/cmd/cmd_ingest.go
Expand Up @@ -33,7 +33,7 @@ func ingestDictionary(r *sybil.Record, recordmap *Dictionary, prefix string) {
prefixName := fmt.Sprint(keyName, "_")
switch iv := v.(type) {
case string:
if INT_CAST[keyName] == true {
if INT_CAST[keyName] {
val, err := strconv.ParseInt(iv, 10, 64)
if err == nil {
r.AddIntField(keyName, int64(val))
Expand Down Expand Up @@ -125,9 +125,7 @@ func importCsvRecords() {
}

func jsonQuery(obj *interface{}, path []string) []interface{} {

var ret interface{}
ret = *obj
ret := *obj

for _, key := range path {
if key == "$" {
Expand Down Expand Up @@ -222,7 +220,7 @@ func RunIngestCmdLine() {

flag.Parse()

digestfile := fmt.Sprintf("%s", *ingestfile)
digestfile := *ingestfile

if *sybil.FLAGS.TABLE == "" {
flag.PrintDefaults()
Expand Down Expand Up @@ -265,21 +263,21 @@ func RunIngestCmdLine() {
var loadedTable = false
for i := 0; i < TABLE_INFO_GRABS; i++ {
loaded := t.LoadTableInfo()
if loaded == true || t.HasFlagFile() == false {
if loaded || !t.HasFlagFile() {
loadedTable = true
break
}
time.Sleep(time.Millisecond * 10)
}

if loadedTable == false {
if !loadedTable {
if t.HasFlagFile() {
sybil.Warn("INGESTOR COULDNT READ TABLE INFO, LOSING SAMPLES")
return
}
}

if *fCsv == false {
if !*fCsv {
importJSONRecords()
} else {
importCsvRecords()
Expand Down
4 changes: 2 additions & 2 deletions src/cmd/cmd_query.go
Expand Up @@ -110,7 +110,7 @@ func RunQueryCmdLine() {
sybil.OPTS.DISTINCT = distinct
}

if *NO_RECYCLE_MEM == true {
if *NO_RECYCLE_MEM {
sybil.FLAGS.RECYCLE_MEM = sybil.NewFalseFlag()
}

Expand Down Expand Up @@ -272,7 +272,7 @@ func RunQueryCmdLine() {
start := time.Now()
// We can load and query at the same time
if *sybil.FLAGS.LOAD_AND_QUERY {
count = t.LoadAndQueryRecords(&loadSpec, &querySpec)
t.LoadAndQueryRecords(&loadSpec, &querySpec)

end := time.Now()
sybil.Debug("LOAD AND QUERY RECORDS TOOK", end.Sub(start))
Expand Down
4 changes: 2 additions & 2 deletions src/cmd/cmd_rebuild.go
Expand Up @@ -23,7 +23,7 @@ func RunRebuildCmdLine() {

t := sybil.GetTable(*sybil.FLAGS.TABLE)

loaded := t.LoadTableInfo() && *FORCE_UPDATE == false
loaded := t.LoadTableInfo() && !*FORCE_UPDATE
if loaded {
sybil.Print("TABLE INFO ALREADY EXISTS, NOTHING TO REBUILD!")
return
Expand All @@ -33,7 +33,7 @@ func RunRebuildCmdLine() {

// TODO: prompt to see if this table info looks good and then write it to
// original info.db
if *REPLACE_INFO == true {
if *REPLACE_INFO {
sybil.Print("REPLACING info.db WITH DATA COMPUTED ABOVE")
lock := sybil.Lock{Table: t, Name: "info"}
lock.ForceDeleteFile()
Expand Down
6 changes: 3 additions & 3 deletions src/cmd/cmd_trim.go
Expand Up @@ -51,7 +51,7 @@ func RunTrimCmdLine() {
sybil.DELETE_BLOCKS_AFTER_QUERY = false

t := sybil.GetTable(*sybil.FLAGS.TABLE)
if t.LoadTableInfo() == false {
if !t.LoadTableInfo() {
sybil.Warn("Couldn't read table info, exiting early")
return
}
Expand All @@ -73,10 +73,10 @@ func RunTrimCmdLine() {
}

if *DELETE {
if *REALLY != true {
if !*REALLY {
// TODO: prompt for deletion
fmt.Println("DELETE THE ABOVE BLOCKS? (Y/N)")
if askConfirmation() == false {
if !askConfirmation() {
sybil.Debug("ABORTING")
return
}
Expand Down
2 changes: 1 addition & 1 deletion src/sybil/aggregate.go
Expand Up @@ -101,7 +101,7 @@ func FilterAndAggRecords(querySpec *QuerySpec, recordsPtr *RecordList) int {
// {{{ FILTERING
for j := 0; j < len(querySpec.Filters); j++ {
// returns True if the record matches!
ret := querySpec.Filters[j].Filter(r) != true
ret := !querySpec.Filters[j].Filter(r)
if ret {
add = false
break
Expand Down
12 changes: 3 additions & 9 deletions src/sybil/aggregate_test.go
Expand Up @@ -162,8 +162,7 @@ func TestHistograms(t *testing.T) {

prevCount := int64(math.MaxInt64)
// testing that a histogram with single value looks uniform
for k, v := range querySpec.Results {
k = strings.Replace(k, GROUP_DELIMITER, "", 1)
for _, v := range querySpec.Results {
percentiles := v.Hists["age"].GetPercentiles()

if v.Count > prevCount {
Expand Down Expand Up @@ -194,16 +193,12 @@ func TestHistograms(t *testing.T) {

prevAvg := float64(0)
// testing that a histogram with single value looks uniform
for k, v := range querySpec.Results {
k = strings.Replace(k, GROUP_DELIMITER, "", 1)
for _, v := range querySpec.Results {
avg := v.Hists["age"].Mean()

if avg < prevAvg {
t.Error("RESULTS CAME BACK OUT OF COUNT ORDER")
}

prevCount = v.Count

}
}

Expand Down Expand Up @@ -325,8 +320,7 @@ func TestOrderBy(t *testing.T) {
t.Error("NO RESULTS RETURNED FOR QUERY!")
}

for k, v := range querySpec.Results {
k = strings.Replace(k, GROUP_DELIMITER, "", 1)
for _, v := range querySpec.Results {
avg := v.Hists["age"].Mean()

if avg < prevAvg {
Expand Down
4 changes: 2 additions & 2 deletions src/sybil/column_store_io.go
Expand Up @@ -426,7 +426,7 @@ func (tb *TableBlock) SaveToColumns(filename string) bool {
tb.Name = dirname

defer tb.table.ReleaseBlockLock(filename)
if tb.table.GrabBlockLock(filename) == false {
if !tb.table.GrabBlockLock(filename) {
Debug("Can't grab lock to save block", filename)
return false
}
Expand Down Expand Up @@ -519,7 +519,7 @@ func (tb *TableBlock) unpackStrCol(dec FileDecoder, info SavedColumnInfo) {
bucketReplace := make(map[int32]int32)
var re *regexp.Regexp
if ok {
re, err = regexp.Compile(strReplace.Pattern)
re, _ = regexp.Compile(strReplace.Pattern)
}

for k, v := range into.StringTable {
Expand Down
4 changes: 2 additions & 2 deletions src/sybil/file_decoder_test.go
Expand Up @@ -59,7 +59,7 @@ func TestOpenCompressedInfoDB(t *testing.T) {
loadSpec.LoadAllColumns = true

loaded := nt.LoadTableInfo()
if loaded == false {
if !loaded {
t.Error("COULDNT LOAD ZIPPED TABLE INFO!")
}

Expand Down Expand Up @@ -138,7 +138,7 @@ func TestOpenCompressedColumn(t *testing.T) {
loadSpec.LoadAllColumns = true

loaded := bt.LoadTableInfo()
if loaded == false {
if !loaded {
t.Error("COULDNT LOAD ZIPPED TABLE INFO!")
}

Expand Down
8 changes: 0 additions & 8 deletions src/sybil/file_encoder.go
Expand Up @@ -17,14 +17,6 @@ type FileEncoder interface {
CloseFile() bool
}

func encodeInto(filename string, obj interface{}) error {
enc := GetFileEncoder(filename)
defer enc.CloseFile()

err := enc.Encode(obj)
return err
}

func GetFileEncoder(filename string) FileEncoder {
// otherwise, we just return vanilla decoder for this file

Expand Down
6 changes: 3 additions & 3 deletions src/sybil/filter.go
Expand Up @@ -42,7 +42,7 @@ func BuildFilters(t *Table, loadSpec *LoadSpec, filterSpec FilterSpec) []Filter
op := tokens[1]
val, _ := strconv.ParseInt(tokens[2], 10, 64)

if checkTable(tokens, t) != true {
if !checkTable(tokens, t) {
continue
}

Expand All @@ -67,7 +67,7 @@ func BuildFilters(t *Table, loadSpec *LoadSpec, filterSpec FilterSpec) []Filter
op := tokens[1]
val := tokens[2]

if checkTable(tokens, t) != true {
if !checkTable(tokens, t) {
continue
}
loadSpec.Set(col)
Expand All @@ -82,7 +82,7 @@ func BuildFilters(t *Table, loadSpec *LoadSpec, filterSpec FilterSpec) []Filter
op := tokens[1]
val := tokens[2]

if checkTable(tokens, t) != true {
if !checkTable(tokens, t) {
continue
}

Expand Down
3 changes: 0 additions & 3 deletions src/sybil/filter_test.go
Expand Up @@ -190,9 +190,6 @@ func testStrNeq(t *testing.T, tableName string) {
aggs := []Aggregation{}
aggs = append(aggs, nt.Aggregation("age", "avg"))

groupings := []Grouping{}
groupings = append(groupings, nt.Grouping("age"))

querySpec := QuerySpec{QueryParams: QueryParams{Filters: filters, Aggregations: aggs}}

nt.MatchAndAggregate(&querySpec)
Expand Down
4 changes: 2 additions & 2 deletions src/sybil/hist_basic.go
Expand Up @@ -219,7 +219,7 @@ func (h *BasicHist) GetStdDev() float64 {
}

func (h *BasicHist) GetSparseBuckets() map[int64]int64 {
ret := make(map[int64]int64, 0)
ret := make(map[int64]int64)

for k, v := range h.Values {
if v > 0 {
Expand All @@ -239,7 +239,7 @@ func (h *BasicHist) GetSparseBuckets() map[int64]int64 {
}

func (h *BasicHist) GetStrBuckets() map[string]int64 {
ret := make(map[string]int64, 0)
ret := make(map[string]int64)

for k, v := range h.Values {
ret[strconv.FormatInt(int64(k)*int64(h.BucketSize)+h.Min, 10)] = v
Expand Down
4 changes: 2 additions & 2 deletions src/sybil/hist_multi.go
Expand Up @@ -171,7 +171,7 @@ func (h *MultiHist) GetNonZeroBuckets() map[string]int64 {
}

func (h *MultiHist) GetStrBuckets() map[string]int64 {
allBuckets := make(map[string]int64, 0)
allBuckets := make(map[string]int64)
for _, subhist := range h.Subhists {
for key, count := range subhist.GetStrBuckets() {
allBuckets[key] = count
Expand All @@ -182,7 +182,7 @@ func (h *MultiHist) GetStrBuckets() map[string]int64 {
}

func (h *MultiHist) GetSparseBuckets() map[int64]int64 {
allBuckets := make(map[int64]int64, 0)
allBuckets := make(map[int64]int64)
for _, subhist := range h.Subhists {
for key, count := range subhist.GetSparseBuckets() {
_, ok := allBuckets[key]
Expand Down
14 changes: 6 additions & 8 deletions src/sybil/node_aggregator.go
Expand Up @@ -65,9 +65,7 @@ func (vt *VTable) AggregateSamples(dirs []string) {
samples := make([]*Sample, 0)

for _, res := range allResults {
for _, s := range res.Samples {
samples = append(samples, s)
}
samples = append(samples, res.Samples...)
}

if len(samples) > limit {
Expand All @@ -85,7 +83,7 @@ func (vt *VTable) AggregateTables(dirs []string) {
allResults := vt.findResultsInDirs(dirs)
Debug("FOUND", len(allResults), "SPECS TO AGG")

allTables := make(map[string]int, 0)
allTables := make(map[string]int)

for _, res := range allResults {
for _, table := range res.Tables {
Expand Down Expand Up @@ -119,7 +117,7 @@ func (vt *VTable) AggregateInfo(dirs []string) {
size += block.Size
}

res.Table.BlockList = make(map[string]*TableBlock, 0)
res.Table.BlockList = make(map[string]*TableBlock)

res.Table.initLocks()
res.Table.populateStringIDLookup()
Expand Down Expand Up @@ -179,17 +177,17 @@ func (vt *VTable) AggregateSpecs(dirs []string) {
func (vt *VTable) StitchResults(dirs []string) {
vt.initDataStructures()

if FLAGS.LIST_TABLES != nil && *FLAGS.LIST_TABLES == true {
if FLAGS.LIST_TABLES != nil && *FLAGS.LIST_TABLES {
vt.AggregateTables(dirs)
return
}

if FLAGS.PRINT_INFO != nil && *FLAGS.PRINT_INFO == true {
if FLAGS.PRINT_INFO != nil && *FLAGS.PRINT_INFO {
vt.AggregateInfo(dirs)
return
}

if FLAGS.SAMPLES != nil && *FLAGS.SAMPLES == true {
if FLAGS.SAMPLES != nil && *FLAGS.SAMPLES {
vt.AggregateSamples(dirs)
return
}
Expand Down