clean up some docs and code, including: (#479)

- typo fixes
- docstring format fixes
- unused variables fixes
- introducing first usages of testutil.ParseDocumentPaths function, which was previously unused
This commit is contained in:
Alex Ostrikov
2022-08-06 11:43:06 +02:00
committed by GitHub
parent 742593faa4
commit 46b3af6a31
7 changed files with 32 additions and 33 deletions

View File

@@ -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

View File

@@ -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
}

View File

@@ -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).

View File

@@ -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 {

View File

@@ -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,

View File

@@ -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())

View File

@@ -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.