Skip to content

Commit 2b20819

Browse files
agonistasdine
authored andcommitted
add alias (#516)
1 parent 6b241e2 commit 2b20819

File tree

4 files changed

+40
-9
lines changed

4 files changed

+40
-9
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ func main() {
114114
}
115115
```
116116

117-
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.
117+
Checkout the [Go doc](https://pkg.go.dev/github.com/chaisql/chai) and the [usage example](#usage) in the README to get started quickly.
118118

119119
### In-memory database
120120

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

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

180-
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).
180+
For any questions or discussions, open an [issue](https://github.com/chaisql/chai/issues/new).

cmd/chai/doc/doc_test.go

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package doc_test
33
import (
44
"fmt"
55
"regexp"
6+
"strings"
67
"testing"
78

89
"github.com/chaisql/chai/cmd/chai/doc"
@@ -17,13 +18,24 @@ func TestFunctions(t *testing.T) {
1718
for pkgname, pkg := range packages {
1819
for fname, def := range pkg {
1920
if pkgname == "" {
20-
t.Run(fmt.Sprintf("%s is documented and has all its arguments mentioned", fname), func(t *testing.T) {
21-
str, err := doc.DocString(fname)
22-
assert.NoError(t, err)
23-
for i := 0; i < def.Arity(); i++ {
24-
require.Contains(t, trimDocPromt(str), fmt.Sprintf("arg%d", i+1))
21+
var isAlias = false
22+
for pkgname2, pkg2 := range packages {
23+
if pkgname2 != "" {
24+
_, ok := pkg2[strings.ToLower(fname)]
25+
if ok {
26+
isAlias = true
27+
}
2528
}
26-
})
29+
}
30+
if !isAlias {
31+
t.Run(fmt.Sprintf("%s is documented and has all its arguments mentioned", fname), func(t *testing.T) {
32+
str, err := doc.DocString(fname)
33+
assert.NoError(t, err)
34+
for i := 0; i < def.Arity(); i++ {
35+
require.Contains(t, trimDocPromt(str), fmt.Sprintf("arg%d", i+1))
36+
}
37+
})
38+
}
2739
} else {
2840
t.Run(fmt.Sprintf("%s.%s is documented and has all its arguments mentioned", pkgname, fname), func(t *testing.T) {
2941
str, err := doc.DocString(fmt.Sprintf("%s.%s", pkgname, fname))

internal/expr/functions/builtins.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,25 @@ var builtinFunctions = Definitions{
8181
return &Now{}, nil
8282
},
8383
},
84+
85+
// strings alias
86+
"lower": stringsFunctions["lower"],
87+
"upper": stringsFunctions["upper"],
88+
"trim": stringsFunctions["trim"],
89+
"ltrim": stringsFunctions["ltrim"],
90+
"rtrim": stringsFunctions["rtrim"],
91+
92+
// math alias
93+
"floor": mathFunctions["floor"],
94+
"abs": mathFunctions["abs"],
95+
"acos": mathFunctions["acos"],
96+
"acosh": mathFunctions["acosh"],
97+
"asin": mathFunctions["asin"],
98+
"asinh": mathFunctions["asinh"],
99+
"atan": mathFunctions["atan"],
100+
"atan2": mathFunctions["atan2"],
101+
"random": mathFunctions["random"],
102+
"sqrt": mathFunctions["sqrt"],
84103
}
85104

86105
// BuiltinDefinitions returns a map of builtin functions.

internal/expr/functions/math.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ var sqrt = &ScalarDefinition{
184184
if args[0].Type() != types.DoubleValue && args[0].Type() != types.IntegerValue {
185185
return types.NewNullValue(), nil
186186
}
187-
v, err := document.CastAs(args[0], types.DoubleValue)
187+
v, err := object.CastAs(args[0], types.DoubleValue)
188188
if err != nil {
189189
return nil, err
190190
}

0 commit comments

Comments
 (0)