mirror of
https://github.com/pikami/cosmium.git
synced 2024-11-25 06:57:10 +00:00
131 lines
2.8 KiB
Go
131 lines
2.8 KiB
Go
package nosql_test
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/pikami/cosmium/parsers"
|
|
)
|
|
|
|
func Test_Parse_AggregateFunctions(t *testing.T) {
|
|
|
|
t.Run("Should parse function AVG()", func(t *testing.T) {
|
|
testQueryParse(
|
|
t,
|
|
`SELECT AVG(c.a1) FROM c`,
|
|
parsers.SelectStmt{
|
|
SelectItems: []parsers.SelectItem{
|
|
{
|
|
Type: parsers.SelectItemTypeFunctionCall,
|
|
Value: parsers.FunctionCall{
|
|
Type: parsers.FunctionCallAggregateAvg,
|
|
Arguments: []interface{}{
|
|
parsers.SelectItem{
|
|
Path: []string{"c", "a1"},
|
|
Type: parsers.SelectItemTypeField,
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
Table: parsers.Table{Value: "c"},
|
|
},
|
|
)
|
|
})
|
|
|
|
t.Run("Should parse function COUNT()", func(t *testing.T) {
|
|
testQueryParse(
|
|
t,
|
|
`SELECT COUNT(c.a1) FROM c`,
|
|
parsers.SelectStmt{
|
|
SelectItems: []parsers.SelectItem{
|
|
{
|
|
Type: parsers.SelectItemTypeFunctionCall,
|
|
Value: parsers.FunctionCall{
|
|
Type: parsers.FunctionCallAggregateCount,
|
|
Arguments: []interface{}{
|
|
parsers.SelectItem{
|
|
Path: []string{"c", "a1"},
|
|
Type: parsers.SelectItemTypeField,
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
Table: parsers.Table{Value: "c"},
|
|
},
|
|
)
|
|
})
|
|
|
|
t.Run("Should parse function MAX()", func(t *testing.T) {
|
|
testQueryParse(
|
|
t,
|
|
`SELECT MAX(c.a1) FROM c`,
|
|
parsers.SelectStmt{
|
|
SelectItems: []parsers.SelectItem{
|
|
{
|
|
Type: parsers.SelectItemTypeFunctionCall,
|
|
Value: parsers.FunctionCall{
|
|
Type: parsers.FunctionCallAggregateMax,
|
|
Arguments: []interface{}{
|
|
parsers.SelectItem{
|
|
Path: []string{"c", "a1"},
|
|
Type: parsers.SelectItemTypeField,
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
Table: parsers.Table{Value: "c"},
|
|
},
|
|
)
|
|
})
|
|
|
|
t.Run("Should parse function MIN()", func(t *testing.T) {
|
|
testQueryParse(
|
|
t,
|
|
`SELECT MIN(c.a1) FROM c`,
|
|
parsers.SelectStmt{
|
|
SelectItems: []parsers.SelectItem{
|
|
{
|
|
Type: parsers.SelectItemTypeFunctionCall,
|
|
Value: parsers.FunctionCall{
|
|
Type: parsers.FunctionCallAggregateMin,
|
|
Arguments: []interface{}{
|
|
parsers.SelectItem{
|
|
Path: []string{"c", "a1"},
|
|
Type: parsers.SelectItemTypeField,
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
Table: parsers.Table{Value: "c"},
|
|
},
|
|
)
|
|
})
|
|
|
|
t.Run("Should parse function SUM()", func(t *testing.T) {
|
|
testQueryParse(
|
|
t,
|
|
`SELECT SUM(c.a1) FROM c`,
|
|
parsers.SelectStmt{
|
|
SelectItems: []parsers.SelectItem{
|
|
{
|
|
Type: parsers.SelectItemTypeFunctionCall,
|
|
Value: parsers.FunctionCall{
|
|
Type: parsers.FunctionCallAggregateSum,
|
|
Arguments: []interface{}{
|
|
parsers.SelectItem{
|
|
Path: []string{"c", "a1"},
|
|
Type: parsers.SelectItemTypeField,
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
Table: parsers.Table{Value: "c"},
|
|
},
|
|
)
|
|
})
|
|
}
|