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
6 changes: 3 additions & 3 deletions book/src/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@
- [Operators](super-sql/operators/intro.md)
- [aggregate](super-sql/operators/aggregate.md)
- [assert](super-sql/operators/assert.md)
- [blend](super-sql/operators/blend.md)
- [count](super-sql/operators/count.md)
- [cut](super-sql/operators/cut.md)
- [debug](super-sql/operators/debug.md)
Expand All @@ -81,6 +80,7 @@
- [shapes](super-sql/operators/shapes.md)
- [skip](super-sql/operators/skip.md)
- [sort](super-sql/operators/sort.md)
- [superfuse](super-sql/operators/superfuse.md)
- [switch](super-sql/operators/switch.md)
- [tail](super-sql/operators/tail.md)
- [top](super-sql/operators/top.md)
Expand Down Expand Up @@ -162,16 +162,15 @@
- [nameof](super-sql/functions/types/nameof.md)
- [optionize](super-sql/functions/types/optionize.md)
- [sum_type](super-sql/functions/types/sum_type.md)
- [superdefuse](super-sql/functions/types/superdefuse.md)
- [typename](super-sql/functions/types/typename.md)
- [typeof](super-sql/functions/types/typeof.md)
- [unblend](super-sql/functions/types/unblend.md)
- [upcast](super-sql/functions/types/upcast.md)
- [Aggregate Functions](super-sql/aggregates/intro.md)
- [and](super-sql/aggregates/and.md)
- [any](super-sql/aggregates/any.md)
- [array_agg](super-sql/aggregates/array_agg.md)
- [avg](super-sql/aggregates/avg.md)
- [blend](super-sql/aggregates/blend.md)
- [collect](super-sql/aggregates/collect.md)
- [collect_map](super-sql/aggregates/collect_map.md)
- [count](super-sql/aggregates/count.md)
Expand All @@ -181,6 +180,7 @@
- [min](super-sql/aggregates/min.md)
- [or](super-sql/aggregates/or.md)
- [sum](super-sql/aggregates/sum.md)
- [superfuse](super-sql/aggregates/superfuse.md)
- [union](super-sql/aggregates/union.md)
- [Type Fusion](super-sql/type-fusion.md)
!!- [Tutorials](tutorials/intro.md)
Expand Down
10 changes: 5 additions & 5 deletions book/src/command/output.md
Original file line number Diff line number Diff line change
Expand Up @@ -131,23 +131,23 @@ echo '{x:1}{s:"hello"}' | super -o out.parquet -
```
causes this error
```mdtest-output
parquetio: encountered multiple types (consider 'blend'): {x:int64} and {s:string}
parquetio: encountered multiple types (consider 'fuse'): {x:int64} and {s:string}
```

To write heterogeneous data to a schema-based file format, you must
convert the data to a monolithic type. To handle this,
you can either [blend](../super-sql/operators/blend.md)
you can either [fuse](../super-sql/operators/fuse.md)
the data into a single type or you can specify
the `-split` flag to indicate a destination directory that receives
a separate output file for each output type.

## Fused Data

The [blend](../super-sql/operators/blend.md) operator uses
The [fuse](../super-sql/operators/fuse.md) operator uses
[type fusion](../super-sql/type-fusion.md) to merge different record
types into a blended type, e.g.,
types into a fused type, e.g.,
```mdtest-command-skip
echo '{x:1}{s:"hello"}' | super -o out.parquet -c blend -
echo '{x:1}{s:"hello"}' | super -o out.parquet -c fuse -
super -s out.parquet
```
which produces
Expand Down
4 changes: 2 additions & 2 deletions book/src/dev/libraries/python.md
Original file line number Diff line number Diff line change
Expand Up @@ -150,10 +150,10 @@ is stored in a list, and the list has an arbitrary order.
an incompatible record. `query()` guards against this by default: it runs a
pre-flight check and raises `MixedTypesError` (with a `type_count` attribute)
if more than one distinct type is detected. If encountered, one possible
way to work around this is append the [blend](../../super-sql/operators/blend.md)
way to work around this is append the [fuse](../../super-sql/operators/fuse.md)
operator to your query to merge all types into a single type:
```
from mytable | ... | blend
from mytable | ... | fuse
```
If you know your data is homogeneous and want to avoid the extra round trip,
pass `safe=False` — but results will be silently truncated if mixed types are
Expand Down
4 changes: 2 additions & 2 deletions book/src/getting-started/playground.md
Original file line number Diff line number Diff line change
Expand Up @@ -148,10 +148,10 @@ a:=a::int64

---

**_Make a schema-rigid Parquet file using blend, then output the Parquet file
**_Make a schema-rigid Parquet file using fuse, then output the Parquet file
as [SUP](../formats/sup.md)_**
```mdtest-command-skip
echo '{a:1}{a:2}{b:3}' | super -o tmp.parquet -c blend -
echo '{a:1}{a:2}{b:3}' | super -o tmp.parquet -c fuse -
super -s tmp.parquet
```
produces
Expand Down
46 changes: 0 additions & 46 deletions book/src/super-sql/aggregates/blend.md

This file was deleted.

27 changes: 22 additions & 5 deletions book/src/super-sql/aggregates/fuse.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# fuse

compute a complete fused type of input values
compute a fused type of input values

## Synopsis

Expand All @@ -11,9 +11,13 @@ fuse(any) -> type
## Description

The _fuse_ aggregate function applies [type fusion](../type-fusion.md)
to its input and returns the fused type. A fused type differs
from a [blended type](blend.md) as it includes fusion types in the nested type hierarchy
wherever type changes were made to combine types in the type fusion process.
to its input and returns the fused type. Unlike [superfuse](superfuse.md),
fuse does not employ fusion types and therefore it is not possible in general
to recover the original input from a fused input.

It is useful with grouped aggregation for data exploration and discovery
when searching for shaping rules to cluster a large number of varied input
types to a smaller number of fused types each from a set of interrelated types.

## Examples

Expand All @@ -25,5 +29,18 @@ fuse(this)
{a:1,b:2}
{a:2,b:"foo"}
# expected output
<{a:int64,b:fusion(int64|string)}>
<{a:int64,b:int64|string}>
```

Fuse records with a grouping key:
```mdtest-spq {data-layout="stacked"}
# spq
fuse(this) by b | sort
# input
{a:1,b:"bar"}
{a:2.1,b:"foo"}
{a:3,b:"bar"}
# expected output
{b:"bar",fuse:<{a:int64,b:string}>}
{b:"foo",fuse:<{a:float64,b:string}>}
```
29 changes: 29 additions & 0 deletions book/src/super-sql/aggregates/superfuse.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# superfuse

compute a complete fused type of input values

## Synopsis

```
superfuse(any) -> type
```

## Description

The _superfuse_ aggregate function applies [type fusion](../type-fusion.md)
to its input and returns the fused type. A superfused type differs
from a [fused type](fuse.md) as it includes fusion types in the nested type hierarchy
wherever type changes were made to combine types in the type fusion process.

## Examples

Superfuse two records:
```mdtest-spq
# spq
superfuse(this)
# input
{a:1,b:2}
{a:2,b:"foo"}
# expected output
<{a:int64,b:fusion(int64|string)}>
```
18 changes: 11 additions & 7 deletions book/src/super-sql/functions/types/defuse.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# defuse

undo the effects of complete fusion
undo the effects of fuse

## Synopsis

Expand All @@ -10,9 +10,13 @@ defuse(val any) -> any

## Description

The `defuse` function converts a value `val` containing any fusion types
into its original type by downcasting all instances of fusion values to their
subtype equivalent.
The `defuse` function converts a value `val` from a fused representation
to a plain representation by
* replacing any value nested within `val` that is a union type with its
underlying non-union value, and
* eliminating all optional fields from record types within `val` by
replacing each optional field with value with its non-optional equivalent
and eliminating entirely any optional fields without a value.

## Examples

Expand All @@ -24,16 +28,16 @@ _Remove union types_
# spq
defuse(this)
# input
fusion({a:1::(int64|string)},<{a:int64}>)
fusion({a:"foo"::(int64|string)},<{a:string}>)
{a:1::(int64|string)}
{a:"foo"::(int64|string)}
# expected output
{a:1}
{a:"foo"}
```

---

_Retain optional fields using complete fusion_
_Create then remove optional fields_

```mdtest-spq {data-layout="stacked"}
# spq
Expand Down
6 changes: 3 additions & 3 deletions book/src/super-sql/functions/types/optionize.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Since an option type already represents an absent value, any `none` or
option members of such a union are absorbed into the result.
Record fields of option type are optional fields.

`optionize` is useful for turning a [blended type](../../aggregates/blend.md),
`optionize` is useful for turning a [fused type](../../aggregates/fuse.md),
where a field absent from some values has type `missing|T`, into a type
with optional fields, which can then be the target of a [cast](cast.md),
where an absent field is cast to `none`.
Expand Down Expand Up @@ -48,11 +48,11 @@ values optionize(this)

---

_Optionize a blended type_
_Optionize a fused type_

```mdtest-spq
# spq
aggregate t:=blend(this)
aggregate t:=fuse(this)
| values optionize(t)
# input
{x:1}
Expand Down
6 changes: 3 additions & 3 deletions book/src/super-sql/functions/types/sum_type.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,12 @@ type Rect={width:float64,height:float64}

---

_Compute a sum type of events from their blended types_
_Compute a sum type of events from their fused types_

```mdtest-spq
# spq
blend(this) by kind
| collect_map(map{kind:blend})
fuse(this) by kind
| collect_map(map{kind:fuse})
| values sum_type(this)
# input
{kind:"Push",ref:"main"}
Expand Down
49 changes: 49 additions & 0 deletions book/src/super-sql/functions/types/superdefuse.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# superdefuse

undo the effects of complete fusion

## Synopsis

```
superdefuse(val any) -> any
```

## Description

The `superdefuse` function converts a value `val` containing any fusion types
into its original type by downcasting all instances of fusion values to their
subtype equivalent.

## Examples

---

_Remove union types_

```mdtest-spq {data-layout="stacked"}
# spq
superdefuse(this)
# input
fusion({a:1::(int64|string)},<{a:int64}>)
fusion({a:"foo"::(int64|string)},<{a:string}>)
# expected output
{a:1}
{a:"foo"}
```

---

_Retain optional fields using complete fusion_

```mdtest-spq {data-layout="stacked"}
# spq
superfuse | superdefuse(this)
# input
{x:1}
{x:2,y:3}
{x:4,z?:none::int64}
# expected output
{x:1}
{x:2,y:3}
{x:4,z?:none::int64}
```
Loading
Loading