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

fix(gen/tables): passing seed to tables generator #4866

Merged
merged 2 commits into from
Jun 13, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion libflux/go/libflux/buildinfo.gen.go
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,8 @@ var sourceHashes = map[string]string{
"stdlib/internal/boolean/boolean.flux": "1c0a1564911dd5f4c35c17efb32158ab31c51b20ac0f25175545e50aadc87c94",
"stdlib/internal/debug/debug.flux": "104485f6a8d6e1cd2fc8111367687fed4cef2a63b5a7657124571b89b0e2420c",
"stdlib/internal/debug/debug_test.flux": "063349cd314ed79906a96d84ed3c6829c734d1607e0bbae0654bdc9e22210e3c",
"stdlib/internal/gen/gen.flux": "320c005cffe97f28324a21054089cf78a2e6c511c639c4c0d1df727e46072c05",
"stdlib/internal/gen/gen.flux": "c8dbdf5cf9e9fe86c58f927875a7d80e1621e4d2d98d22c6325cb704e8269648",
"stdlib/internal/gen/tables_test.flux": "14a3d3542aa0815bf3fb912b045c23161322acff731bfa04ce380c5da9866654",
"stdlib/internal/influxql/influxql.flux": "51739e7d9026cae356fdef79a4340d2bda7fc10d1daa1a7adeae06014f85049c",
"stdlib/internal/location/location.flux": "e810d8264dd1590f9556259cfa76272c8e5698a0262509d0ca12bfd4c71342f5",
"stdlib/internal/promql/join_test.flux": "87fde732a159a2cffb81dbc21eebf70df352b69e04781e6e4526f57336b30146",
Expand Down
2 changes: 2 additions & 0 deletions stdlib/internal/gen/gen.flux
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@ package gen
// - n: Number of rows to generate.
// - nulls: Percentage chance that a null value will be used in the input. Valid value range is `[0.0 - 1.0]`.
// - tags: Set of tags with their cardinality to generate.
// - seed: Pass seed to tables generator to get the very same sequence each time
builtin tables : (
n: int,
?nulls: float,
?tags: [{name: string, cardinality: int}],
?seed: int,
) => stream[{A with _time: time, _value: float}]
8 changes: 8 additions & 0 deletions stdlib/internal/gen/tables.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ type TablesOpSpec struct {
N int `json:"n"`
Tags []Tag `json:"tags,omitempty"`
Nulls float64 `json:"nulls,omitempty"`
Seed int64 `json:"Seed,omitempty"`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you will want this to be a pointer, otherwise omitting the seed parameter default to using 0 as the seed.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for catching that @Marwes

}

func init() {
Expand Down Expand Up @@ -91,6 +92,12 @@ func createTablesOpSpec(args flux.Arguments, a *flux.Administration) (flux.Opera
spec.Nulls = nulls
}

if seed, ok, err := args.GetInt("seed"); err != nil {
return nil, err
} else if ok {
spec.Seed = seed
}

return spec, nil
}

Expand All @@ -116,6 +123,7 @@ func newTablesProcedure(qs flux.OperationSpec, pa plan.Administration) (plan.Pro
schema := gen.Schema{
NumPoints: spec.N,
Nulls: spec.Nulls,
Seed: &spec.Seed,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be nil if the seed is not specified in the function call

}

if len(spec.Tags) > 0 {
Expand Down
28 changes: 28 additions & 0 deletions stdlib/internal/gen/tables_test.flux
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package gen


import "array"
import "testing"
import "internal/gen"
import "internal/debug"

option now = () => 2030-01-01T00:00:00Z

testcase gen_tables_seed {
got =
gen.tables(n: 5, seed: 123)
|> drop(columns: ["_time"])

want =
array.from(
rows: [
{_value: -39.7289264835779},
{_value: 3.561659508431711},
{_value: 34.956531511845476},
{_value: -53.72013420347799},
{_value: 49.20701082669753},
],
)

testing.diff(got: got, want: want)
}