Skip to content

Commit

Permalink
docs: add example for field_references (#520)
Browse files Browse the repository at this point in the history
related PR: substrait-io/substrait-java#150

---------

Co-authored-by: David Sisson <[email protected]>
  • Loading branch information
MasseGuillaume and EpsilonPrime authored Nov 22, 2023
1 parent 2847a7a commit 9f2a09c
Showing 1 changed file with 69 additions and 2 deletions.
71 changes: 69 additions & 2 deletions site/docs/expressions/field_references.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,78 @@ In Substrait, all fields are dealt with on a positional basis. Field names are o

References are typically constructed as a sequence. For example: [struct position 0, struct position 1, array offset 2, array slice 1..3].

#### Validation
Field references are in the same order they are defined in their schema. For example, let's consider the following schema:

References must validate against the schema of the record being referenced. If not, an error is expected.
```
column a:
struct<
b: list<
struct<
c: map<string,
struct<
x: i32>>>>>
```

If we want to represent the SQL expression:

```
a.b[2].c['my_map_key'].x
```

We will need to declare the nested field such that:

``
Struct field reference a
Struct field b
List offset 2
Struct field c
Map key my_map_key
Struct field x
```
Or more formally in Protobuf Text, we get:
```
selection {
direct_reference {
struct_field {
field: 0 # .a
child {
struct_field {
field: 0 # .b
child {
list_element {
offset: 2
child {
struct_field {
field: 0 # .c
child {
map_key {
map_key {
string: "my_map_key" # ['my_map_key']
}
child {
struct_field {
field: 0 # .x
}
}
}
}
}
}
}
}
}
}
}
}
root_reference { }
}
```
#### Validation
References must validate against the schema of the record being referenced. If not, an error is expected.
### Masked Complex Expression
Expand Down

0 comments on commit 9f2a09c

Please sign in to comment.