Skip to content

Commit 8d07a38

Browse files
authored
Add back 0-based indexes (#6348)
This commit adds back 0-based index/slice expressions to the language. It also institutes pragmas declarations that allow users to specify 1-based or 0-based indexes for a given scope.
1 parent 9503916 commit 8d07a38

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

42 files changed

+4473
-4197
lines changed

book/src/super-sql/functions/records/unflatten.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ _Flatten to unflatten_
3737
```mdtest-spq
3838
# spq
3939
unnest flatten(this) into (
40-
key[1] != "rm"
40+
key[0] != "rm"
4141
| values collect(this)
4242
)
4343
| values unflatten(this)

book/src/super-sql/functions/strings/upper.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ values upper(this)
3131
```mdtest-spq
3232
# spq
3333
fn capitalize(str): (
34-
upper(str[1:2]) + str[2:]
34+
upper(str[0:1]) + str[1:]
3535
)
3636
values capitalize(this)
3737
# input

book/src/super-sql/operators/unnest.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ unnest {s,a} into ( sum(a) by s )
184184
_Unnested the elements of a record by flattening it_
185185
```mdtest-spq
186186
# spq
187-
unnest {s,f:flatten(r)} into ( values {s,key:f.key[1],val:f.value} )
187+
unnest {s,f:flatten(r)} into ( values {s,key:f.key[0],val:f.value} )
188188
# input
189189
{s:"foo",r:{a:1,b:2}}
190190
{s:"bar",r:{a:3,b:4}}

compiler/ast/decl.go

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,13 @@ type OpDecl struct {
2727
Loc `json:"loc"`
2828
}
2929

30+
type PragmaDecl struct {
31+
Kind string `json:"kind" unpack:""`
32+
Name *ID `json:"name"`
33+
Expr Expr `json:"expr"`
34+
Loc `json:"loc"`
35+
}
36+
3037
type QueryDecl struct {
3138
Kind string `json:"kind" unpack:""`
3239
Name *ID `json:"name"`
@@ -41,8 +48,9 @@ type TypeDecl struct {
4148
Loc `json:"loc"`
4249
}
4350

44-
func (*ConstDecl) declNode() {}
45-
func (*FuncDecl) declNode() {}
46-
func (*OpDecl) declNode() {}
47-
func (*QueryDecl) declNode() {}
48-
func (*TypeDecl) declNode() {}
51+
func (*ConstDecl) declNode() {}
52+
func (*FuncDecl) declNode() {}
53+
func (*OpDecl) declNode() {}
54+
func (*PragmaDecl) declNode() {}
55+
func (*QueryDecl) declNode() {}
56+
func (*TypeDecl) declNode() {}

compiler/ast/unpack.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ var unpacker = unpack.New(
6565
OpDecl{},
6666
OutputOp{},
6767
PassOp{},
68+
PragmaDecl{},
6869
Primitive{},
6970
PutOp{},
7071
Record{},

compiler/dag/expr.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ type (
6969
Kind string `json:"kind" unpack:""`
7070
Expr Expr `json:"expr"`
7171
Index Expr `json:"index"`
72+
Base1 bool `json:"base1"`
7273
}
7374
IsNullExpr struct {
7475
Kind string `json:"kind" unpack:""`
@@ -112,10 +113,11 @@ type (
112113
Elems []VectorElem `json:"elems"`
113114
}
114115
SliceExpr struct {
115-
Kind string `json:"kind" unpack:""`
116-
Expr Expr `json:"expr"`
117-
From Expr `json:"from"`
118-
To Expr `json:"to"`
116+
Kind string `json:"kind" unpack:""`
117+
Expr Expr `json:"expr"`
118+
From Expr `json:"from"`
119+
To Expr `json:"to"`
120+
Base1 bool `json:"base1"`
119121
}
120122
SortExpr struct {
121123
Key Expr `json:"key"`

0 commit comments

Comments
 (0)