mirror of
https://github.com/featurebasedb/featurebase.git
synced 2026-08-28 10:54:59 +00:00
This commit is contained in:
parent
bc3f329e8f
commit
397d37a129
2 changed files with 54 additions and 1 deletions
|
|
@ -25,7 +25,9 @@ import (
|
|||
"github.com/pilosa/pilosa/v2/pql"
|
||||
pb "github.com/pilosa/pilosa/v2/proto"
|
||||
"github.com/pilosa/pilosa/v2/server"
|
||||
"github.com/pilosa/pilosa/v2/sql"
|
||||
"github.com/pilosa/pilosa/v2/test"
|
||||
"github.com/pkg/errors"
|
||||
"google.golang.org/grpc/codes"
|
||||
"google.golang.org/grpc/status"
|
||||
)
|
||||
|
|
@ -770,6 +772,50 @@ func TestQuerySQLUnary(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestQuerySQLUnaryWithError(t *testing.T) {
|
||||
|
||||
ctx := context.Background()
|
||||
gh, tearDownFunc := setUpTestQuerySQLUnary(ctx, t)
|
||||
defer tearDownFunc()
|
||||
|
||||
tests := []struct {
|
||||
sql string
|
||||
err error
|
||||
}{
|
||||
{
|
||||
|
||||
sql: "select * from index_not_found",
|
||||
err: pilosa.ErrIndexNotFound,
|
||||
},
|
||||
{
|
||||
|
||||
sql: "select field_not_found from grouper",
|
||||
err: pilosa.ErrFieldNotFound,
|
||||
},
|
||||
{
|
||||
|
||||
sql: "select * from grouper, index_not_found",
|
||||
err: sql.ErrUnsupportedQuery,
|
||||
},
|
||||
{
|
||||
|
||||
sql: "select _id, age, field_not_found from grouper",
|
||||
err: pilosa.ErrFieldNotFound,
|
||||
},
|
||||
}
|
||||
|
||||
for i, test := range tests {
|
||||
t.Run("test-"+strconv.Itoa(i), func(t *testing.T) {
|
||||
_, err := gh.QuerySQLUnary(ctx, &pb.QuerySQLRequest{Sql: test.sql})
|
||||
if err == nil {
|
||||
t.Fatalf("sql: %s, expected error: %v", test.sql, test.err)
|
||||
} else if errors.Cause(err) != test.err {
|
||||
t.Fatalf("sql: %s, expected error: %v, got: %v", test.sql, test.err, err)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func setUpTestQuerySQLUnary(ctx context.Context, t *testing.T) (gh *server.GRPCHandler, tearDownFunc func()) {
|
||||
t.Helper()
|
||||
|
||||
|
|
|
|||
|
|
@ -145,7 +145,11 @@ func extractSelectFields(index *pilosa.Index, stmt *sqlparser.Select) ([]Column,
|
|||
column = NewIDIndexColumn(index, alias)
|
||||
}
|
||||
} else {
|
||||
column = NewFieldColumn(index.Field(fieldName), alias)
|
||||
field := index.Field(fieldName)
|
||||
if field == nil {
|
||||
return nil, features, errors.Wrapf(pilosa.ErrFieldNotFound, "field %s", fieldName)
|
||||
}
|
||||
column = NewFieldColumn(field, alias)
|
||||
}
|
||||
case *sqlparser.FuncExpr:
|
||||
funcName := FuncName(strings.ToLower(colExpr.Name.String()))
|
||||
|
|
@ -160,6 +164,9 @@ func extractSelectFields(index *pilosa.Index, stmt *sqlparser.Select) ([]Column,
|
|||
if colExpr, ok := expr.Expr.(*sqlparser.ColName); ok {
|
||||
fieldName := colExpr.Name.String()
|
||||
field = index.Field(fieldName)
|
||||
if field == nil {
|
||||
return nil, features, errors.Wrapf(pilosa.ErrFieldNotFound, "field %s", fieldName)
|
||||
}
|
||||
} else {
|
||||
return nil, features, errors.New("table name is required")
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue