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
5 changes: 3 additions & 2 deletions compiler/semantic/expr.go
Original file line number Diff line number Diff line change
Expand Up @@ -309,18 +309,19 @@ func (t *translator) expr(e ast.Expr) sem.Expr {
}
// XXX type checker should remove this check when it finds it redundant
is := sem.NewCall(e, "is", []sem.Expr{expr, &sem.LiteralExpr{Node: e.Expr, Value: "<string>"}})
indexBase := t.scope.indexBase()
slice := &sem.SliceExpr{
Node: e,
Expr: expr,
From: t.exprNullable(e.From),
Base1: true,
Base1: indexBase == 1,
}
if e.For != nil {
to := t.expr(e.For)
if slice.From != nil {
slice.To = sem.NewBinaryExpr(e, "+", slice.From, to)
} else {
slice.To = sem.NewBinaryExpr(e, "+", to, &sem.LiteralExpr{Node: e, Value: "1"})
slice.To = sem.NewBinaryExpr(e, "+", to, &sem.LiteralExpr{Node: e, Value: sup.FormatValue(super.NewInt64(int64(indexBase)))})
}
}
serr := sem.NewStructuredError(e, "SUBSTRING: string value required", expr)
Expand Down
8 changes: 8 additions & 0 deletions compiler/ztests/pragma-index-base-substring.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
spq: |
pragma index_base = 1
values substring("foobar" FROM 4)

vector: true

output: |
"bar"
2 changes: 1 addition & 1 deletion compiler/ztests/sql/substring.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
spq: values SUBSTRING(this FROM 4 FOR 2), SUBSTRING(this FROM 4), SUBSTRING(this FOR 3)
spq: values SUBSTRING(this FROM 3 FOR 2), SUBSTRING(this FROM 3), SUBSTRING(this FOR 3)

vector: true

Expand Down