-
Notifications
You must be signed in to change notification settings - Fork 3.6k
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
Mean and percentile function fixes #2404
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
297ebda
Simplify os.RemoveAll calls in tests
jwilder d0cc983
Fix error calling MarshalJSON for type *influxdb.Result: json: unsupp…
jwilder 155adb7
Fix panic: runtime error: index out of range
jwilder 8174f6f
Fix panic: interface conversion: interface is nil, not []interface {}
jwilder e1bb340
Update changelog
jwilder File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1456,9 +1456,7 @@ func TestSingleServerDiags(t *testing.T) { | |
t.Skip(fmt.Sprintf("skipping '%s'", testName)) | ||
} | ||
dir := tempfile() | ||
defer func() { | ||
os.RemoveAll(dir) | ||
}() | ||
defer os.RemoveAll(dir) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think |
||
|
||
config := main.NewConfig() | ||
config.Monitoring.Enabled = true | ||
|
@@ -1476,9 +1474,7 @@ func TestSingleServer(t *testing.T) { | |
t.Skip(fmt.Sprintf("skipping '%s'", testName)) | ||
} | ||
dir := tempfile() | ||
defer func() { | ||
os.RemoveAll(dir) | ||
}() | ||
defer os.RemoveAll(dir) | ||
|
||
nodes := createCombinedNodeCluster(t, testName, dir, 1, nil) | ||
defer nodes.Close() | ||
|
@@ -1495,9 +1491,7 @@ func Test3NodeServer(t *testing.T) { | |
t.Skip(fmt.Sprintf("skipping '%s'", testName)) | ||
} | ||
dir := tempfile() | ||
defer func() { | ||
os.RemoveAll(dir) | ||
}() | ||
defer os.RemoveAll(dir) | ||
|
||
nodes := createCombinedNodeCluster(t, testName, dir, 3, nil) | ||
defer nodes.Close() | ||
|
@@ -1514,9 +1508,7 @@ func Test3NodeServerFailover(t *testing.T) { | |
t.Skip(fmt.Sprintf("skipping '%s'", testName)) | ||
} | ||
dir := tempfile() | ||
defer func() { | ||
os.RemoveAll(dir) | ||
}() | ||
defer os.RemoveAll(dir) | ||
|
||
nodes := createCombinedNodeCluster(t, testName, dir, 3, nil) | ||
|
||
|
@@ -1539,9 +1531,7 @@ func Test5NodeClusterPartiallyReplicated(t *testing.T) { | |
t.Skip(fmt.Sprintf("skipping '%s'", testName)) | ||
} | ||
dir := tempfile() | ||
defer func() { | ||
os.RemoveAll(dir) | ||
}() | ||
defer os.RemoveAll(dir) | ||
|
||
nodes := createCombinedNodeCluster(t, testName, dir, 5, nil) | ||
defer nodes.Close() | ||
|
@@ -1557,9 +1547,7 @@ func TestClientLibrary(t *testing.T) { | |
t.Skip(fmt.Sprintf("skipping '%s'", testName)) | ||
} | ||
dir := tempfile() | ||
defer func() { | ||
os.RemoveAll(dir) | ||
}() | ||
defer os.RemoveAll(dir) | ||
|
||
now := time.Now().UTC() | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
package influxql | ||
|
||
import "testing" | ||
|
||
type point struct { | ||
seriesID uint64 | ||
timestamp int64 | ||
value interface{} | ||
} | ||
|
||
type testIterator struct { | ||
values []point | ||
} | ||
|
||
func (t *testIterator) Next() (seriesID uint64, timestamp int64, value interface{}) { | ||
if len(t.values) > 0 { | ||
v := t.values[0] | ||
t.values = t.values[1:] | ||
return v.seriesID, v.timestamp, v.value | ||
} | ||
return 0, 0, nil | ||
} | ||
|
||
func TestMapMeanNoValues(t *testing.T) { | ||
iter := &testIterator{} | ||
if got := MapMean(iter); got != nil { | ||
t.Errorf("output mismatch: exp nil got %v", got) | ||
} | ||
} | ||
|
||
func TestMapMean(t *testing.T) { | ||
|
||
tests := []struct { | ||
input []point | ||
output *meanMapOutput | ||
}{ | ||
{ // Single point | ||
input: []point{ | ||
point{0, 1, 1.0}, | ||
}, | ||
output: &meanMapOutput{1, 1}, | ||
}, | ||
{ // Two points | ||
input: []point{ | ||
point{0, 1, 2.0}, | ||
point{0, 2, 8.0}, | ||
}, | ||
output: &meanMapOutput{2, 5.0}, | ||
}, | ||
} | ||
|
||
for _, test := range tests { | ||
iter := &testIterator{ | ||
values: test.input, | ||
} | ||
|
||
got := MapMean(iter) | ||
if got == nil { | ||
t.Fatalf("MapMean(%v): output mismatch: exp %v got %v", test.input, test.output, got) | ||
} | ||
|
||
if got.(*meanMapOutput).Count != test.output.Count || got.(*meanMapOutput).Mean != test.output.Mean { | ||
t.Errorf("output mismatch: exp %v got %v", test.output, got) | ||
} | ||
|
||
} | ||
} | ||
|
||
func TestInitializeReduceFuncPercentile(t *testing.T) { | ||
// No args | ||
c := &Call{ | ||
Name: "percentile", | ||
Args: []Expr{}, | ||
} | ||
_, err := InitializeReduceFunc(c) | ||
if err == nil { | ||
t.Errorf("InitializedReduceFunc(%v) expected error. got nil", c) | ||
} | ||
|
||
if exp := "expected float argument in percentile()"; err.Error() != exp { | ||
t.Errorf("InitializedReduceFunc(%v) mismatch. exp %v got %v", c, exp, err.Error()) | ||
} | ||
|
||
// No percentile arg | ||
c = &Call{ | ||
Name: "percentile", | ||
Args: []Expr{ | ||
&VarRef{Val: "field1"}, | ||
}, | ||
} | ||
|
||
_, err = InitializeReduceFunc(c) | ||
if err == nil { | ||
t.Errorf("InitializedReduceFunc(%v) expected error. got nil", c) | ||
} | ||
|
||
if exp := "expected float argument in percentile()"; err.Error() != exp { | ||
t.Errorf("InitializedReduceFunc(%v) mismatch. exp %v got %v", c, exp, err.Error()) | ||
} | ||
} | ||
|
||
func TestReducePercentileNil(t *testing.T) { | ||
|
||
// ReducePercentile should ignore nil values when calculating the percentile | ||
fn := ReducePercentile(100) | ||
input := []interface{}{ | ||
nil, | ||
} | ||
|
||
got := fn(input) | ||
if got != nil { | ||
t.Fatalf("ReducePercentile(100) returned wrong type. exp nil got %v", got) | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know this is a small thing, but I am pretty sure @pauldix does not want this format. He specially told me links to PRs only a few months back. Not a big deal, but you should check with him when you get a chance.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Link to PR is preferable, but either works. If the PR mentions the issue then they'll be linked together either way.