mirror of
https://github.com/featurebasedb/featurebase.git
synced 2026-08-28 02:44:59 +00:00
produce a better error when a user tries to sort something unsortable (#2324)
(cherry picked from commit 1ce3a1c103)
This commit is contained in:
parent
aaf963c9bd
commit
c210aaba48
5 changed files with 55 additions and 0 deletions
|
|
@ -80,6 +80,7 @@ const (
|
|||
// expected errors
|
||||
ErrExpectedColumnReference errors.Code = "ErrExpectedColumnReference"
|
||||
ErrExpectedSortExpressionReference errors.Code = "ErrExpectedSortExpressionReference"
|
||||
ErrExpectedSortableExpression errors.Code = "ErrExpectedSortableExpression"
|
||||
|
||||
// call errors
|
||||
ErrCallUnknownFunction errors.Code = "ErrCallUnknownFunction"
|
||||
|
|
@ -531,6 +532,13 @@ func NewErrExpectedSortExpressionReference(line, col int) error {
|
|||
)
|
||||
}
|
||||
|
||||
func NewErrExpectedSortableExpression(line, col int, typeName string) error {
|
||||
return errors.New(
|
||||
ErrExpectedSortExpressionReference,
|
||||
fmt.Sprintf("[%d:%d] unable to sort a column of type '%s'", line, col, typeName),
|
||||
)
|
||||
}
|
||||
|
||||
// calls
|
||||
|
||||
func NewErrCallParameterCountMismatch(line, col int, functionName string, formalCount, actualCount int) error {
|
||||
|
|
|
|||
|
|
@ -9,6 +9,7 @@ import (
|
|||
"github.com/featurebasedb/featurebase/v3/pql"
|
||||
)
|
||||
|
||||
// TODO(pok) make all these lower case
|
||||
const (
|
||||
FieldTypeBool = "BOOL"
|
||||
FieldTypeDecimal = "DECIMAL"
|
||||
|
|
|
|||
|
|
@ -124,6 +124,12 @@ func (p *ExecutionPlanner) compileSelectStatement(stmt *parser.SelectStatement,
|
|||
// get the data type from the projection
|
||||
projDataType := projections[index].Type()
|
||||
|
||||
// don't let a sort happen on something unsortable right now
|
||||
switch projDataType.(type) {
|
||||
case *parser.DataTypeStringSet, *parser.DataTypeIDSet:
|
||||
return nil, sql3.NewErrExpectedSortableExpression(0, 0, projDataType.TypeDescription())
|
||||
}
|
||||
|
||||
f := &OrderByExpression{
|
||||
Index: index,
|
||||
ExprType: projDataType,
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@ var TableTests []TableTest = []TableTest{
|
|||
|
||||
selectTests,
|
||||
selectKeyedTests,
|
||||
orderByTests,
|
||||
|
||||
topTests,
|
||||
|
||||
|
|
|
|||
39
sql3/test/defs/defs_orderby.go
Normal file
39
sql3/test/defs/defs_orderby.go
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
package defs
|
||||
|
||||
var orderByTests = TableTest{
|
||||
name: "orderByTests",
|
||||
Table: tbl(
|
||||
"order_by_test",
|
||||
srcHdrs(
|
||||
srcHdr("_id", fldTypeID),
|
||||
srcHdr("an_int", fldTypeInt, "min 0", "max 100"),
|
||||
srcHdr("an_id_set", fldTypeIDSet),
|
||||
srcHdr("an_id", fldTypeID),
|
||||
srcHdr("a_string", fldTypeString),
|
||||
srcHdr("a_string_set", fldTypeStringSet),
|
||||
srcHdr("a_decimal", fldTypeDecimal2),
|
||||
),
|
||||
srcRows(
|
||||
srcRow(int64(1), int64(11), []int64{11, 12, 13}, int64(101), "str1", []string{"a1", "b1", "c1"}, float64(123.45)),
|
||||
srcRow(int64(2), int64(22), []int64{21, 22, 23}, int64(201), "str2", []string{"a2", "b2", "c2"}, float64(234.56)),
|
||||
srcRow(int64(3), int64(33), []int64{31, 32, 33}, int64(301), "str3", []string{"a3", "b3", "c3"}, float64(345.67)),
|
||||
srcRow(int64(4), int64(44), []int64{41, 42, 43}, int64(401), "str4", []string{"a4", "b4", "c4"}, float64(456.78)),
|
||||
),
|
||||
),
|
||||
SQLTests: []SQLTest{
|
||||
{
|
||||
name: "order-by-stringset",
|
||||
SQLs: sqls(
|
||||
"select * from order_by_test order by a_string_set asc",
|
||||
),
|
||||
ExpErr: "unable to sort a column of type 'STRINGSET'",
|
||||
},
|
||||
{
|
||||
name: "order-by-idset",
|
||||
SQLs: sqls(
|
||||
"select * from order_by_test order by an_id_set asc",
|
||||
),
|
||||
ExpErr: "unable to sort a column of type 'IDSET'",
|
||||
},
|
||||
},
|
||||
}
|
||||
Loading…
Add table
Reference in a new issue