Skip to content

Commit

Permalink
fixed limit expression parse bug
Browse files Browse the repository at this point in the history
* fixed limit expression parse bug

* added test

* load dataset

* fix engine

* voting log

* log schema info with loadDataset error

---------

Co-authored-by: Jonathan Chappelow <jon@kwil.com>
  • Loading branch information
brennanjl and jchappelow authored Jun 11, 2024
1 parent 0fd8e09 commit 412791f
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 4 deletions.
2 changes: 1 addition & 1 deletion internal/engine/execution/global.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ func NewGlobalContext(ctx context.Context, db sql.Executor, extensionInitializer
for _, schema := range orderSchemas(schemas) {
err := g.loadDataset(ctx, schema)
if err != nil {
return nil, err
return nil, fmt.Errorf("%w: schema (%s / %s / %s)", err, schema.Name, schema.DBID(), schema.Owner)
}
}

Expand Down
2 changes: 1 addition & 1 deletion internal/voting/voting.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func initializeVoteStore(ctx context.Context, db sql.TxMaker) error {
resolutions := resolutions.ListResolutions()
for _, name := range resolutions {
uuid := types.NewUUIDV5([]byte(name))
fmt.Println("Creating resolution type", name, " with UUID: ", uuid, " value: ", *uuid, " uuid[:] ", uuid[:])
fmt.Printf("Creating resolution type %q with UUID %v\n", name, uuid)
_, err := tx.Execute(ctx, createResolutionType, uuid[:], name)
if err != nil {
return err
Expand Down
4 changes: 2 additions & 2 deletions parse/antlr.go
Original file line number Diff line number Diff line change
Expand Up @@ -920,10 +920,10 @@ func (s *schemaVisitor) VisitSelect_statement(ctx *gen.Select_statementContext)
}

if ctx.GetLimit() != nil {
stmt.Limit = ctx.GetLimit().Accept(s).(*ExpressionLiteral)
stmt.Limit = ctx.GetLimit().Accept(s).(Expression)
}
if ctx.GetOffset() != nil {
stmt.Offset = ctx.GetOffset().Accept(s).(*ExpressionLiteral)
stmt.Offset = ctx.GetOffset().Accept(s).(Expression)
}

stmt.Set(ctx)
Expand Down
29 changes: 29 additions & 0 deletions parse/parse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2533,6 +2533,35 @@ func Test_SQL(t *testing.T) {
err: parse.ErrUnnamedJoin,
},
{name: "non utf-8", sql: "\xbd\xb2\x3d\xbc\x20\xe2\x8c\x98;", err: parse.ErrSyntax},
{
// this select doesn't make much sense, however
// it is a regression test for a previously known bug
// https://github.com/kwilteam/kwil-db/pull/810
name: "offset and limit",
sql: `SELECT * FROM users LIMIT id OFFSET id;`,
want: &parse.SQLStatement{
SQL: &parse.SelectStatement{
SelectCores: []*parse.SelectCore{
{
Columns: []parse.ResultColumn{
&parse.ResultColumnWildcard{},
},
From: &parse.RelationTable{
Table: "users",
},
},
},
Offset: exprColumn("", "id"),
Limit: exprColumn("", "id"),
// apply default ordering
Ordering: []*parse.OrderingTerm{
{
Expression: exprColumn("users", "id"),
},
},
},
},
},
}

for _, tt := range tests {
Expand Down

0 comments on commit 412791f

Please sign in to comment.