diff --git a/internal/expr/expr.go b/internal/expr/expr.go index 252d0122..1d7ff3a0 100644 --- a/internal/expr/expr.go +++ b/internal/expr/expr.go @@ -108,11 +108,11 @@ func (e *NamedExpr) String() string { type Function interface { Expr - // Returns the list of parameters this function has received. + // Params returns the list of parameters this function has received. Params() []Expr } -// A Aggregator is an expression that aggregates documents into one result. +// An Aggregator is an expression that aggregates documents into one result. type Aggregator interface { Expr diff --git a/internal/expr/functions/builtins.go b/internal/expr/functions/builtins.go index a3b07678..cc5d431b 100644 --- a/internal/expr/functions/builtins.go +++ b/internal/expr/functions/builtins.go @@ -241,7 +241,7 @@ func (c *CountAggregator) Aggregate(env *environment.Environment) error { } // Eval returns the result of the aggregation as an integer. -func (c *CountAggregator) Eval(env *environment.Environment) (types.Value, error) { +func (c *CountAggregator) Eval(_ *environment.Environment) (types.Value, error) { return types.NewIntegerValue(c.Count), nil } @@ -342,7 +342,7 @@ func (m *MinAggregator) Aggregate(env *environment.Environment) error { } // Eval return the minimum value. -func (m *MinAggregator) Eval(env *environment.Environment) (types.Value, error) { +func (m *MinAggregator) Eval(_ *environment.Environment) (types.Value, error) { if m.Min == nil { return types.NewNullValue(), nil } @@ -446,7 +446,7 @@ func (m *MaxAggregator) Aggregate(env *environment.Environment) error { } // Eval return the maximum value. -func (m *MaxAggregator) Eval(env *environment.Environment) (types.Value, error) { +func (m *MaxAggregator) Eval(_ *environment.Environment) (types.Value, error) { if m.Max == nil { return types.NewNullValue(), nil } @@ -553,7 +553,7 @@ func (s *SumAggregator) Aggregate(env *environment.Environment) error { } // Eval return the aggregated sum. -func (s *SumAggregator) Eval(env *environment.Environment) (types.Value, error) { +func (s *SumAggregator) Eval(_ *environment.Environment) (types.Value, error) { if s.SumF != nil { return types.NewDoubleValue(*s.SumF), nil } @@ -641,7 +641,7 @@ func (s *AvgAggregator) Aggregate(env *environment.Environment) error { } // Eval returns the aggregated average as a double. -func (s *AvgAggregator) Eval(env *environment.Environment) (types.Value, error) { +func (s *AvgAggregator) Eval(_ *environment.Environment) (types.Value, error) { if s.Counter == 0 { return types.NewDoubleValue(0), nil } diff --git a/internal/expr/functions/scalar_definition.go b/internal/expr/functions/scalar_definition.go index eb004d83..08d71c0a 100644 --- a/internal/expr/functions/scalar_definition.go +++ b/internal/expr/functions/scalar_definition.go @@ -10,7 +10,7 @@ import ( ) // A ScalarDefinition is the definition type for functions which operates on scalar values in contrast to other SQL functions -// such as the SUM aggregator wich operates on expressions instead. +// such as the SUM aggregator which operates on expressions instead. // // This difference allows to simply define them with a CallFn function that takes multiple document.Value and // return another types.Value, rather than having to manually evaluate expressions (see Definition). diff --git a/internal/query/statement/stream.go b/internal/query/statement/stream.go index b657a2f0..70e4d244 100644 --- a/internal/query/statement/stream.go +++ b/internal/query/statement/stream.go @@ -14,8 +14,7 @@ type StreamStmt struct { ReadOnly bool } -// Run returns a result containing the stream. The stream will be executed by calling the Iterate method of -// the result. +// Prepare implements the Preparer interface. func (s *StreamStmt) Prepare(ctx *Context) (Statement, error) { st, err := planner.Optimize(s.Stream, ctx.Catalog) if err != nil { diff --git a/internal/stream/index/scan_test.go b/internal/stream/index/scan_test.go index de294198..2f4766b8 100644 --- a/internal/stream/index/scan_test.go +++ b/internal/stream/index/scan_test.go @@ -101,7 +101,7 @@ func testIndexScan(t *testing.T, getOp func(db *database.Database, tx *database. testutil.MakeDocuments(t, `{"a": 1, "b": 2}`, `{"a": 2, "b": 2}`), testutil.MakeDocuments(t, `{"a": 2, "b": 2}`), stream.Ranges{ - stream.Range{Max: testutil.ExprList(t, `[2, 2]`), Paths: []document.Path{testutil.ParseDocumentPath(t, "a"), testutil.ParseDocumentPath(t, "b")}}, + stream.Range{Max: testutil.ExprList(t, `[2, 2]`), Paths: testutil.ParseDocumentPaths(t, "a", "b")}, }, false, false, }, @@ -110,7 +110,7 @@ func testIndexScan(t *testing.T, getOp func(db *database.Database, tx *database. testutil.MakeDocuments(t, `{"a": 1, "b": 2}`, `{"a": 2, "b": 2}`), testutil.MakeDocuments(t, `{"a": 2, "b": 2}`), stream.Ranges{ - stream.Range{Max: testutil.ExprList(t, `[2, 2.2]`), Paths: []document.Path{testutil.ParseDocumentPath(t, "a"), testutil.ParseDocumentPath(t, "b")}}, + stream.Range{Max: testutil.ExprList(t, `[2, 2.2]`), Paths: testutil.ParseDocumentPaths(t, "a", "b")}, }, false, false, }, @@ -128,7 +128,7 @@ func testIndexScan(t *testing.T, getOp func(db *database.Database, tx *database. testutil.MakeDocuments(t, `{"a": 1, "b": 2}`, `{"a": 2, "b": 2}`), testutil.MakeDocuments(t, `{"a": 1, "b": 2}`), stream.Ranges{ - stream.Range{Max: testutil.ExprList(t, `[1, 2]`), Paths: []document.Path{testutil.ParseDocumentPath(t, "a"), testutil.ParseDocumentPath(t, "b")}}, + stream.Range{Max: testutil.ExprList(t, `[1, 2]`), Paths: testutil.ParseDocumentPaths(t, "a", "b")}, }, false, false, }, @@ -137,7 +137,7 @@ func testIndexScan(t *testing.T, getOp func(db *database.Database, tx *database. testutil.MakeDocuments(t, `{"a": 1, "b": 2}`, `{"a": 2, "b": 2}`), testutil.MakeDocuments(t), stream.Ranges{ - stream.Range{Max: testutil.ExprList(t, `[1.1, 2]`), Paths: []document.Path{testutil.ParseDocumentPath(t, "a"), testutil.ParseDocumentPath(t, "b")}}, + stream.Range{Max: testutil.ExprList(t, `[1.1, 2]`), Paths: testutil.ParseDocumentPaths(t, "a", "b")}, }, false, false, }, @@ -164,7 +164,7 @@ func testIndexScan(t *testing.T, getOp func(db *database.Database, tx *database. testutil.MakeDocuments(t, `{"a": 1, "b": 1}`, `{"a": 2, "b": 2}`), testutil.MakeDocuments(t, `{"a": 2, "b": 2}`), stream.Ranges{ - stream.Range{Min: testutil.ExprList(t, `[1]`), Paths: []document.Path{testutil.ParseDocumentPath(t, "a"), testutil.ParseDocumentPath(t, "b")}, Exclusive: true}, + stream.Range{Min: testutil.ExprList(t, `[1]`), Paths: testutil.ParseDocumentPaths(t, "a", "b"), Exclusive: true}, }, false, false, }, @@ -175,7 +175,7 @@ func testIndexScan(t *testing.T, getOp func(db *database.Database, tx *database. stream.Ranges{ stream.Range{ Min: testutil.ExprList(t, `[2, 1]`), - Paths: []document.Path{testutil.ParseDocumentPath(t, "a"), testutil.ParseDocumentPath(t, "b")}, + Paths: testutil.ParseDocumentPaths(t, "a", "b"), }, }, false, false, @@ -187,7 +187,7 @@ func testIndexScan(t *testing.T, getOp func(db *database.Database, tx *database. stream.Ranges{ stream.Range{ Min: testutil.ExprList(t, `[2, 1.5]`), - Paths: []document.Path{testutil.ParseDocumentPath(t, "a"), testutil.ParseDocumentPath(t, "b")}, + Paths: testutil.ParseDocumentPaths(t, "a", "b"), }, }, false, false, @@ -213,7 +213,7 @@ func testIndexScan(t *testing.T, getOp func(db *database.Database, tx *database. stream.Range{ Min: testutil.ExprList(t, `[1, 1]`), Max: testutil.ExprList(t, `[2, 2]`), - Paths: []document.Path{testutil.ParseDocumentPath(t, "a"), testutil.ParseDocumentPath(t, "b")}, + Paths: testutil.ParseDocumentPaths(t, "a", "b"), }, }, false, false, @@ -226,7 +226,7 @@ func testIndexScan(t *testing.T, getOp func(db *database.Database, tx *database. stream.Range{ Min: testutil.ExprList(t, `[1, 1]`), Max: testutil.ExprList(t, `[2, 2]`), - Paths: []document.Path{testutil.ParseDocumentPath(t, "a"), testutil.ParseDocumentPath(t, "b")}, + Paths: testutil.ParseDocumentPaths(t, "a", "b"), }, }, false, false, @@ -253,7 +253,7 @@ func testIndexScan(t *testing.T, getOp func(db *database.Database, tx *database. stream.Ranges{ stream.Range{ Max: testutil.ExprList(t, `[2, 2]`), - Paths: []document.Path{testutil.ParseDocumentPath(t, "a"), testutil.ParseDocumentPath(t, "b")}, + Paths: testutil.ParseDocumentPaths(t, "a", "b"), }, }, true, false, @@ -283,7 +283,7 @@ func testIndexScan(t *testing.T, getOp func(db *database.Database, tx *database. stream.Ranges{ stream.Range{ Min: testutil.ExprList(t, `[1, 1]`), - Paths: []document.Path{testutil.ParseDocumentPath(t, "a"), testutil.ParseDocumentPath(t, "b")}, + Paths: testutil.ParseDocumentPaths(t, "a", "b"), }, }, true, false, @@ -309,7 +309,7 @@ func testIndexScan(t *testing.T, getOp func(db *database.Database, tx *database. stream.Range{ Min: testutil.ExprList(t, `[1, 1]`), Max: testutil.ExprList(t, `[2, 2]`), - Paths: []document.Path{testutil.ParseDocumentPath(t, "a"), testutil.ParseDocumentPath(t, "b")}, + Paths: testutil.ParseDocumentPaths(t, "a", "b"), }, }, true, false, @@ -321,7 +321,7 @@ func testIndexScan(t *testing.T, getOp func(db *database.Database, tx *database. stream.Ranges{ stream.Range{ Max: testutil.ExprList(t, `[1]`), - Paths: []document.Path{testutil.ParseDocumentPath(t, "a"), testutil.ParseDocumentPath(t, "b")}, + Paths: testutil.ParseDocumentPaths(t, "a", "b"), }, }, false, false, @@ -335,7 +335,7 @@ func testIndexScan(t *testing.T, getOp func(db *database.Database, tx *database. Max: testutil.ExprList(t, `[1]`), Exclusive: false, Exact: false, - Paths: []document.Path{testutil.ParseDocumentPath(t, "a"), testutil.ParseDocumentPath(t, "b")}, + Paths: testutil.ParseDocumentPaths(t, "a", "b"), }, }, true, false, @@ -346,7 +346,7 @@ func testIndexScan(t *testing.T, getOp func(db *database.Database, tx *database. testutil.MakeDocuments(t, `{"a": 1, "b": 2, "c": 1}`, `{"a": 1, "b": 2, "c": 9223372036854775807}`), stream.Ranges{ stream.Range{ - Max: testutil.ExprList(t, `[1, 2]`), Paths: []document.Path{testutil.ParseDocumentPath(t, "a"), testutil.ParseDocumentPath(t, "b"), testutil.ParseDocumentPath(t, "c")}, + Max: testutil.ExprList(t, `[1, 2]`), Paths: testutil.ParseDocumentPaths(t, "a", "b", "c"), }, }, false, false, @@ -356,7 +356,7 @@ func testIndexScan(t *testing.T, getOp func(db *database.Database, tx *database. testutil.MakeDocuments(t, `{"a": 1, "b": -2}`, `{"a": -2, "b": 2}`, `{"a": 1, "b": 1}`), testutil.MakeDocuments(t, `{"a": 1, "b": -2}`, `{"a": 1, "b": 1}`), stream.Ranges{ - stream.Range{Min: testutil.ExprList(t, `[1]`), Paths: []document.Path{testutil.ParseDocumentPath(t, "a"), testutil.ParseDocumentPath(t, "b")}}, + stream.Range{Min: testutil.ExprList(t, `[1]`), Paths: testutil.ParseDocumentPaths(t, "a", "b")}, }, false, false, }, @@ -365,7 +365,7 @@ func testIndexScan(t *testing.T, getOp func(db *database.Database, tx *database. testutil.MakeDocuments(t, `{"a": 1, "b": -2, "c": 0}`, `{"a": -2, "b": 2, "c": 1}`, `{"a": 1, "b": 1, "c": 2}`), testutil.MakeDocuments(t, `{"a": 1, "b": -2, "c": 0}`, `{"a": 1, "b": 1, "c": 2}`), stream.Ranges{ - stream.Range{Min: testutil.ExprList(t, `[1]`), Paths: []document.Path{testutil.ParseDocumentPath(t, "a"), testutil.ParseDocumentPath(t, "b"), testutil.ParseDocumentPath(t, "c")}}, + stream.Range{Min: testutil.ExprList(t, `[1]`), Paths: testutil.ParseDocumentPaths(t, "a", "b", "c")}, }, false, false, }, @@ -374,7 +374,7 @@ func testIndexScan(t *testing.T, getOp func(db *database.Database, tx *database. testutil.MakeDocuments(t, `{"a": 1, "b": -2}`, `{"a": -2, "b": 2}`, `{"a": 1, "b": 1}`), testutil.MakeDocuments(t, `{"a": 1, "b": 1}`, `{"a": 1, "b": -2}`), stream.Ranges{ - stream.Range{Min: testutil.ExprList(t, `[1]`), Paths: []document.Path{testutil.ParseDocumentPath(t, "a"), testutil.ParseDocumentPath(t, "b")}}, + stream.Range{Min: testutil.ExprList(t, `[1]`), Paths: testutil.ParseDocumentPaths(t, "a", "b")}, }, true, false, }, @@ -386,7 +386,7 @@ func testIndexScan(t *testing.T, getOp func(db *database.Database, tx *database. stream.Range{ Min: testutil.ExprList(t, `[1]`), Max: testutil.ExprList(t, `[2]`), - Paths: []document.Path{testutil.ParseDocumentPath(t, "a"), testutil.ParseDocumentPath(t, "b")}, + Paths: testutil.ParseDocumentPaths(t, "a", "b"), }, }, false, false, @@ -399,7 +399,7 @@ func testIndexScan(t *testing.T, getOp func(db *database.Database, tx *database. stream.Range{ Min: testutil.ExprList(t, `[1]`), Max: testutil.ExprList(t, `[2]`), - Paths: []document.Path{testutil.ParseDocumentPath(t, "a"), testutil.ParseDocumentPath(t, "b")}, + Paths: testutil.ParseDocumentPaths(t, "a", "b"), }, }, true, false, diff --git a/internal/testutil/expr.go b/internal/testutil/expr.go index 2ae745fe..3ce14cca 100644 --- a/internal/testutil/expr.go +++ b/internal/testutil/expr.go @@ -192,7 +192,7 @@ func ExprRunner(t *testing.T, testfile string) { } else { t.Run("NOK "+stmt.Expr, func(t *testing.T) { t.Helper() - // parse the given epxr + // parse the given expr e, err := parser.NewParser(strings.NewReader(stmt.Expr)).ParseExpr() if err != nil { require.Regexp(t, regexp.MustCompile(regexp.QuoteMeta(stmt.Res)), err.Error()) diff --git a/types/types.go b/types/types.go index 141b4750..40087ee3 100644 --- a/types/types.go +++ b/types/types.go @@ -20,7 +20,7 @@ type ValueType uint8 // List of supported value types. const ( - // denote the absence of type + // AnyValue denotes the absence of type AnyValue ValueType = 0x00 NullValue ValueType = 0x05 @@ -87,7 +87,7 @@ type Document interface { // If the given function returns an error, the iteration stops. Iterate(fn func(field string, value Value) error) error // GetByField returns a value by field name. - // Must return ErrFieldNotFound if the field doesnt exist. + // Must return ErrFieldNotFound if the field doesn't exist. GetByField(field string) (Value, error) // MarshalJSON implements the json.Marshaler interface.