Skip to content

Commit

Permalink
add alias (#516)
Browse files Browse the repository at this point in the history
  • Loading branch information
agonist authored and asdine committed Dec 25, 2023
1 parent 6b241e2 commit 2b20819
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 9 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ func main() {
}
```

Checkout the [SQL documentation](https://chaisql.com/docs/essentials/sql-introduction/), the [Go doc](https://pkg.go.dev/github.com/chaisql/chai) and the [usage example](#usage) in the README to get started quickly.
Checkout the [Go doc](https://pkg.go.dev/github.com/chaisql/chai) and the [usage example](#usage) in the README to get started quickly.

### In-memory database

Expand Down Expand Up @@ -177,4 +177,4 @@ A big thanks to our [contributors](https://github.com/chaisql/chai/graphs/contri

Made with [contrib.rocks](https://contrib.rocks).

For any questions or discussions, join our [Gophers Slack channel](https://gophers.slack.com/messages/CKPCYQFE0) or open an [issue](https://github.com/chaisql/chai/issues/new).
For any questions or discussions, open an [issue](https://github.com/chaisql/chai/issues/new).
24 changes: 18 additions & 6 deletions cmd/chai/doc/doc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package doc_test
import (
"fmt"
"regexp"
"strings"
"testing"

"github.com/chaisql/chai/cmd/chai/doc"
Expand All @@ -17,13 +18,24 @@ func TestFunctions(t *testing.T) {
for pkgname, pkg := range packages {
for fname, def := range pkg {
if pkgname == "" {
t.Run(fmt.Sprintf("%s is documented and has all its arguments mentioned", fname), func(t *testing.T) {
str, err := doc.DocString(fname)
assert.NoError(t, err)
for i := 0; i < def.Arity(); i++ {
require.Contains(t, trimDocPromt(str), fmt.Sprintf("arg%d", i+1))
var isAlias = false
for pkgname2, pkg2 := range packages {
if pkgname2 != "" {
_, ok := pkg2[strings.ToLower(fname)]
if ok {
isAlias = true
}
}
})
}
if !isAlias {
t.Run(fmt.Sprintf("%s is documented and has all its arguments mentioned", fname), func(t *testing.T) {
str, err := doc.DocString(fname)
assert.NoError(t, err)
for i := 0; i < def.Arity(); i++ {
require.Contains(t, trimDocPromt(str), fmt.Sprintf("arg%d", i+1))
}
})
}
} else {
t.Run(fmt.Sprintf("%s.%s is documented and has all its arguments mentioned", pkgname, fname), func(t *testing.T) {
str, err := doc.DocString(fmt.Sprintf("%s.%s", pkgname, fname))
Expand Down
19 changes: 19 additions & 0 deletions internal/expr/functions/builtins.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,25 @@ var builtinFunctions = Definitions{
return &Now{}, nil
},
},

// strings alias
"lower": stringsFunctions["lower"],
"upper": stringsFunctions["upper"],
"trim": stringsFunctions["trim"],
"ltrim": stringsFunctions["ltrim"],
"rtrim": stringsFunctions["rtrim"],

// math alias
"floor": mathFunctions["floor"],
"abs": mathFunctions["abs"],
"acos": mathFunctions["acos"],
"acosh": mathFunctions["acosh"],
"asin": mathFunctions["asin"],
"asinh": mathFunctions["asinh"],
"atan": mathFunctions["atan"],
"atan2": mathFunctions["atan2"],
"random": mathFunctions["random"],
"sqrt": mathFunctions["sqrt"],
}

// BuiltinDefinitions returns a map of builtin functions.
Expand Down
2 changes: 1 addition & 1 deletion internal/expr/functions/math.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ var sqrt = &ScalarDefinition{
if args[0].Type() != types.DoubleValue && args[0].Type() != types.IntegerValue {
return types.NewNullValue(), nil
}
v, err := document.CastAs(args[0], types.DoubleValue)
v, err := object.CastAs(args[0], types.DoubleValue)
if err != nil {
return nil, err
}
Expand Down

0 comments on commit 2b20819

Please sign in to comment.