Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 1 addition & 19 deletions book/src/super-sql/aggregates/and.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,35 +25,17 @@ true
false
```

Continuous AND of simple sequence:
```mdtest-spq
# spq
values and(this)
# input
true
false
true
# expected output
true
false
false
```

Unrecognized types are ignored and not coerced for truthiness:
```mdtest-spq
# spq
values and(this)
and(this)
# input
true
"foo"
0
false
true
# expected output
true
true
true
false
false
```

Expand Down
13 changes: 0 additions & 13 deletions book/src/super-sql/aggregates/any.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,6 @@ any(this)
1
```

Continuous any over a simple sequence:
```mdtest-spq
# spq
values any(this)
# input
1 2 3 4
# expected output
1
1
1
1
```

Any is not sensitive to mixed types as it just picks one:
```mdtest-spq
# spq
Expand Down
16 changes: 0 additions & 16 deletions book/src/super-sql/aggregates/avg.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,22 +27,6 @@ avg(this)
2.5
```

Continuous average of simple sequence:
```mdtest-spq
# spq
values avg(this)
# input
1
2
3
4
# expected output
1.
1.5
2.
2.5
```

Unrecognized types are ignored:
```mdtest-spq
# spq
Expand Down
16 changes: 0 additions & 16 deletions book/src/super-sql/aggregates/collect.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,22 +28,6 @@ collect(this)
[1,2,3,4]
```

Continuous collection over a simple sequence:
```mdtest-spq
# spq
values collect(this)
# input
1
2
3
4
# expected output
[1]
[1,2]
[1,2,3]
[1,2,3,4]
```

Mixed types create a union type for the array elements:
```mdtest-spq
# spq
Expand Down
14 changes: 0 additions & 14 deletions book/src/super-sql/aggregates/collect_map.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,20 +27,6 @@ collect_map(|{stock:price}|)
|{"APPL":145.03,"GOOG":87.07}|
```

Continuous collection over a simple sequence:
```mdtest-spq
# spq
values collect_map(this)
# input
|{"APPL":145.03}|
|{"GOOG":87.07}|
|{"APPL":150.13}|
# expected output
|{"APPL":145.03}|
|{"APPL":145.03,"GOOG":87.07}|
|{"APPL":150.13,"GOOG":87.07}|
```

Create maps by key:
```mdtest-spq {data-layout="stacked"}
# spq
Expand Down
18 changes: 1 addition & 17 deletions book/src/super-sql/aggregates/count.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,31 +25,15 @@ count()
3::uint64
```

Continuous count of simple sequence:
```mdtest-spq
# spq
values count()
# input
1
2
3
# expected output
1::uint64
2::uint64
3::uint64
```

Mixed types are handled:
```mdtest-spq
# spq
values count()
count()
# input
1
"foo"
10.0.0.1
# expected output
1::uint64
2::uint64
3::uint64
```

Expand Down
20 changes: 1 addition & 19 deletions book/src/super-sql/aggregates/dcount.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,33 +27,15 @@ dcount(this)
3::uint64
```

Continuous count of simple sequence:
```mdtest-spq
# spq
values dcount(this)
# input
1
2
2
3
# expected output
1::uint64
2::uint64
2::uint64
3::uint64
```

Mixed types are handled:
```mdtest-spq
# spq
values dcount(this)
dcount(this)
# input
1
"foo"
10.0.0.1
# expected output
1::uint64
2::uint64
3::uint64
```

Expand Down
29 changes: 4 additions & 25 deletions book/src/super-sql/aggregates/intro.md
Original file line number Diff line number Diff line change
@@ -1,31 +1,10 @@
## Aggregate Functions

Aggregate functions appear in either the [`aggregate`](../operators/aggregate.md) operator
or in an [expression](../expressions.md).
Aggregate functions appear in the [`aggregate`](../operators/aggregate.md)
operator.

When called within an expression, an output value is produced for every input value
using state from all values previously processed.
Because aggregate functions carry such state, their use can prevent the runtime
optimizer from parallelizing a query.

That said, aggregate function calls can be quite useful in a number of contexts.
For example, a unique ID can be assigned to the input quite easily:
```mdtest-spq
# spq
values {id:count(),value:this}
# input
"foo"
"bar"
"baz"
# expected output
{id:1::uint64,value:"foo"}
{id:2::uint64,value:"bar"}
{id:3::uint64,value:"baz"}
```

In contrast, calling aggregate functions from within the
[`aggregate`](../operators/aggregate.md) operator
produces just one output value.
Calling aggregate functions from within the [`aggregate`](../operators/aggregate.md)
operator produces just one output value.
```mdtest-spq {data-layout="stacked"}
# spq
aggregate count(),union(this)
Expand Down
16 changes: 0 additions & 16 deletions book/src/super-sql/aggregates/max.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,22 +31,6 @@ max(this)
4
```

Continuous maximum of simple numeric sequence:
```mdtest-spq
# spq
values max(this)
# input
1
2
3
4
# expected output
1
2
3
4
```

Maximum of several string values:
```mdtest-spq
# spq
Expand Down
16 changes: 0 additions & 16 deletions book/src/super-sql/aggregates/min.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,22 +31,6 @@ min(this)
1
```

Continuous minimum of simple numeric sequence:
```mdtest-spq
# spq
values min(this)
# input
1
2
3
4
# expected output
1
1
1
1
```

Minimum of several string values:
```mdtest-spq
# spq
Expand Down
20 changes: 1 addition & 19 deletions book/src/super-sql/aggregates/or.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,35 +25,17 @@ false
true
```

Continuous OR of simple sequence:
```mdtest-spq
# spq
values or(this)
# input
false
true
false
# expected output
false
true
true
```

Unrecognized types are ignored and not coerced for truthiness:
```mdtest-spq
# spq
values or(this)
or(this)
# input
false
"foo"
1
true
false
# expected output
false
false
false
true
true
```

Expand Down
16 changes: 0 additions & 16 deletions book/src/super-sql/aggregates/sum.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,22 +26,6 @@ sum(this)
10
```

Continuous sum of simple sequence:
```mdtest-spq
# spq
values sum(this)
# input
1
2
3
4
# expected output
1
3
6
10
```

Unrecognized types are ignored:
```mdtest-spq
# spq
Expand Down
16 changes: 0 additions & 16 deletions book/src/super-sql/aggregates/union.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,22 +29,6 @@ union(this)
|[1,2,3]|
```

Create sets continuously from values in a simple sequence:
```mdtest-spq
# spq
values union(this)
# input
1
2
3
3
# expected output
|[1]|
|[1,2]|
|[1,2,3]|
|[1,2,3]|
```

Mixed types create a union type for the set elements:
```mdtest-spq
# spq
Expand Down
2 changes: 1 addition & 1 deletion book/src/super-sql/functions/records/unflatten.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ _Flatten to unflatten_
# spq
unnest flatten(this) into (
key[0] != "rm"
| values collect(this)
| collect(this)
)
| values unflatten(this)
# input
Expand Down
3 changes: 1 addition & 2 deletions compiler/rungen/aggregate.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (
)

func (b *Builder) compileAggregate(parent sbuf.Puller, a *dag.AggregateOp) (*aggregate.Op, error) {
b.resetResetters()
keys, err := b.compileAssignments(a.Keys)
if err != nil {
return nil, err
Expand All @@ -23,7 +22,7 @@ func (b *Builder) compileAggregate(parent sbuf.Puller, a *dag.AggregateOp) (*agg
return nil, err
}
dir := order.Direction(a.InputSortDir)
return aggregate.New(b.rctx, parent, keys, names, reducers, a.Limit, dir, a.PartialsIn, a.PartialsOut, b.resetters)
return aggregate.New(b.rctx, parent, keys, names, reducers, a.Limit, dir, a.PartialsIn, a.PartialsOut)
}

func (b *Builder) compileAggAssignments(assignments []dag.Assignment) (field.List, []*expr.Aggregator, error) {
Expand Down
8 changes: 0 additions & 8 deletions compiler/rungen/expr.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,14 +50,6 @@ func (b *Builder) compileExpr(e dag.Expr) (expr.Evaluator, error) {
return nil, errors.New("null expression not allowed")
}
switch e := e.(type) {
case *dag.AggExpr:
agg, err := b.compileAgg(e)
if err != nil {
return nil, err
}
aggexpr := expr.NewAggregatorExpr(b.sctx(), agg)
b.resetters = append(b.resetters, aggexpr)
return aggexpr, nil
case *dag.ArrayExpr:
return b.compileArrayExpr(e)
case *dag.BinaryExpr:
Expand Down
Loading