mirror of
https://github.com/pikami/cosmium.git
synced 2025-06-07 16:10:23 +01:00
Compare commits
4 Commits
e080888c20
...
887d456ad4
Author | SHA1 | Date | |
---|---|---|---|
|
887d456ad4 | ||
|
da1566875b | ||
|
3fee3bc816 | ||
|
8657c48fc8 |
@ -7,18 +7,21 @@ import (
|
||||
)
|
||||
|
||||
type ApiServer struct {
|
||||
stopServer chan interface{}
|
||||
isActive bool
|
||||
router *gin.Engine
|
||||
config config.ServerConfig
|
||||
stopServer chan interface{}
|
||||
onServerShutdown chan interface{}
|
||||
isActive bool
|
||||
router *gin.Engine
|
||||
config config.ServerConfig
|
||||
}
|
||||
|
||||
func NewApiServer(dataRepository *repositories.DataRepository, config config.ServerConfig) *ApiServer {
|
||||
stopChan := make(chan interface{})
|
||||
onServerShutdownChan := make(chan interface{})
|
||||
|
||||
apiServer := &ApiServer{
|
||||
stopServer: stopChan,
|
||||
config: config,
|
||||
stopServer: stopChan,
|
||||
onServerShutdown: onServerShutdownChan,
|
||||
config: config,
|
||||
}
|
||||
|
||||
apiServer.CreateRouter(dataRepository)
|
||||
@ -32,4 +35,5 @@ func (s *ApiServer) GetRouter() *gin.Engine {
|
||||
|
||||
func (s *ApiServer) Stop() {
|
||||
s.stopServer <- true
|
||||
<-s.onServerShutdown
|
||||
}
|
||||
|
@ -5,6 +5,7 @@ import (
|
||||
"fmt"
|
||||
"net/http"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/pikami/cosmium/api/handlers"
|
||||
@ -86,7 +87,7 @@ func (s *ApiServer) CreateRouter(repository *repositories.DataRepository) {
|
||||
s.router = router
|
||||
}
|
||||
|
||||
func (s *ApiServer) Start() {
|
||||
func (s *ApiServer) Start() error {
|
||||
listenAddress := fmt.Sprintf(":%d", s.config.Port)
|
||||
s.isActive = true
|
||||
|
||||
@ -95,6 +96,8 @@ func (s *ApiServer) Start() {
|
||||
Handler: s.router.Handler(),
|
||||
}
|
||||
|
||||
errChan := make(chan error, 1)
|
||||
|
||||
go func() {
|
||||
<-s.stopServer
|
||||
logger.InfoLn("Shutting down server...")
|
||||
@ -102,35 +105,40 @@ func (s *ApiServer) Start() {
|
||||
if err != nil {
|
||||
logger.ErrorLn("Failed to shutdown server:", err)
|
||||
}
|
||||
s.onServerShutdown <- true
|
||||
}()
|
||||
|
||||
go func() {
|
||||
var err error
|
||||
if s.config.DisableTls {
|
||||
logger.Infof("Listening and serving HTTP on %s\n", server.Addr)
|
||||
err := server.ListenAndServe()
|
||||
if err != nil && err != http.ErrServerClosed {
|
||||
logger.ErrorLn("Failed to start HTTP server:", err)
|
||||
}
|
||||
s.isActive = false
|
||||
err = server.ListenAndServe()
|
||||
} else if s.config.TLS_CertificatePath != "" && s.config.TLS_CertificateKey != "" {
|
||||
logger.Infof("Listening and serving HTTPS on %s\n", server.Addr)
|
||||
err := server.ListenAndServeTLS(
|
||||
err = server.ListenAndServeTLS(
|
||||
s.config.TLS_CertificatePath,
|
||||
s.config.TLS_CertificateKey)
|
||||
if err != nil && err != http.ErrServerClosed {
|
||||
logger.ErrorLn("Failed to start HTTPS server:", err)
|
||||
}
|
||||
s.isActive = false
|
||||
} else {
|
||||
tlsConfig := tlsprovider.GetDefaultTlsConfig()
|
||||
server.TLSConfig = tlsConfig
|
||||
|
||||
logger.Infof("Listening and serving HTTPS on %s\n", server.Addr)
|
||||
err := server.ListenAndServeTLS("", "")
|
||||
if err != nil && err != http.ErrServerClosed {
|
||||
logger.ErrorLn("Failed to start HTTPS server:", err)
|
||||
}
|
||||
s.isActive = false
|
||||
err = server.ListenAndServeTLS("", "")
|
||||
}
|
||||
|
||||
if err != nil && err != http.ErrServerClosed {
|
||||
logger.ErrorLn("Failed to start server:", err)
|
||||
errChan <- err
|
||||
} else {
|
||||
errChan <- nil
|
||||
}
|
||||
s.isActive = false
|
||||
}()
|
||||
|
||||
select {
|
||||
case err := <-errChan:
|
||||
return err
|
||||
case <-time.After(50 * time.Millisecond):
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
@ -19,7 +19,10 @@ func main() {
|
||||
})
|
||||
|
||||
server := api.NewApiServer(repository, configuration)
|
||||
server.Start()
|
||||
err := server.Start()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
waitForExit(server, repository, configuration)
|
||||
}
|
||||
|
@ -204,6 +204,15 @@ Cosmium strives to support the core features of Cosmos DB, including:
|
||||
| IS_PRIMITIVE | Yes |
|
||||
| IS_STRING | Yes |
|
||||
|
||||
### Document Batch Requests
|
||||
|
||||
| Operation | Implemented |
|
||||
| --------- | ----------- |
|
||||
| Create | No |
|
||||
| Update | No |
|
||||
| Delete | No |
|
||||
| Read | No |
|
||||
|
||||
## Known Differences
|
||||
|
||||
While Cosmium aims to replicate the behavior of Cosmos DB as closely as possible, there are certain differences and limitations to be aware of:
|
||||
|
@ -17,6 +17,7 @@ type SelectStmt struct {
|
||||
type Table struct {
|
||||
Value string
|
||||
SelectItem SelectItem
|
||||
IsInSelect bool
|
||||
}
|
||||
|
||||
type JoinItem struct {
|
||||
|
@ -4,6 +4,7 @@ import (
|
||||
"testing"
|
||||
|
||||
"github.com/pikami/cosmium/parsers"
|
||||
testutils "github.com/pikami/cosmium/test_utils"
|
||||
)
|
||||
|
||||
func Test_Parse_AggregateFunctions(t *testing.T) {
|
||||
@ -27,7 +28,7 @@ func Test_Parse_AggregateFunctions(t *testing.T) {
|
||||
},
|
||||
},
|
||||
},
|
||||
Table: parsers.Table{Value: "c"},
|
||||
Table: parsers.Table{SelectItem: testutils.SelectItem_Path("c")},
|
||||
},
|
||||
)
|
||||
})
|
||||
@ -51,7 +52,7 @@ func Test_Parse_AggregateFunctions(t *testing.T) {
|
||||
},
|
||||
},
|
||||
},
|
||||
Table: parsers.Table{Value: "c"},
|
||||
Table: parsers.Table{SelectItem: testutils.SelectItem_Path("c")},
|
||||
},
|
||||
)
|
||||
})
|
||||
@ -75,7 +76,7 @@ func Test_Parse_AggregateFunctions(t *testing.T) {
|
||||
},
|
||||
},
|
||||
},
|
||||
Table: parsers.Table{Value: "c"},
|
||||
Table: parsers.Table{SelectItem: testutils.SelectItem_Path("c")},
|
||||
},
|
||||
)
|
||||
})
|
||||
@ -99,7 +100,7 @@ func Test_Parse_AggregateFunctions(t *testing.T) {
|
||||
},
|
||||
},
|
||||
},
|
||||
Table: parsers.Table{Value: "c"},
|
||||
Table: parsers.Table{SelectItem: testutils.SelectItem_Path("c")},
|
||||
},
|
||||
)
|
||||
})
|
||||
@ -123,7 +124,7 @@ func Test_Parse_AggregateFunctions(t *testing.T) {
|
||||
},
|
||||
},
|
||||
},
|
||||
Table: parsers.Table{Value: "c"},
|
||||
Table: parsers.Table{SelectItem: testutils.SelectItem_Path("c")},
|
||||
},
|
||||
)
|
||||
})
|
||||
|
@ -32,7 +32,7 @@ func Test_Parse_ArrayFunctions(t *testing.T) {
|
||||
},
|
||||
},
|
||||
},
|
||||
Table: parsers.Table{Value: "c"},
|
||||
Table: parsers.Table{SelectItem: testutils.SelectItem_Path("c")},
|
||||
},
|
||||
)
|
||||
})
|
||||
@ -58,7 +58,7 @@ func Test_Parse_ArrayFunctions(t *testing.T) {
|
||||
},
|
||||
},
|
||||
},
|
||||
Table: parsers.Table{Value: "c"},
|
||||
Table: parsers.Table{SelectItem: testutils.SelectItem_Path("c")},
|
||||
},
|
||||
)
|
||||
})
|
||||
@ -87,7 +87,7 @@ func Test_Parse_ArrayFunctions(t *testing.T) {
|
||||
},
|
||||
},
|
||||
},
|
||||
Table: parsers.Table{Value: "c"},
|
||||
Table: parsers.Table{SelectItem: testutils.SelectItem_Path("c")},
|
||||
},
|
||||
)
|
||||
})
|
||||
@ -116,7 +116,7 @@ func Test_Parse_ArrayFunctions(t *testing.T) {
|
||||
},
|
||||
},
|
||||
},
|
||||
Table: parsers.Table{Value: "c"},
|
||||
Table: parsers.Table{SelectItem: testutils.SelectItem_Path("c")},
|
||||
},
|
||||
)
|
||||
})
|
||||
@ -145,7 +145,7 @@ func Test_Parse_ArrayFunctions(t *testing.T) {
|
||||
},
|
||||
},
|
||||
},
|
||||
Table: parsers.Table{Value: "c"},
|
||||
Table: parsers.Table{SelectItem: testutils.SelectItem_Path("c")},
|
||||
},
|
||||
)
|
||||
})
|
||||
@ -169,7 +169,7 @@ func Test_Parse_ArrayFunctions(t *testing.T) {
|
||||
},
|
||||
},
|
||||
},
|
||||
Table: parsers.Table{Value: "c"},
|
||||
Table: parsers.Table{SelectItem: testutils.SelectItem_Path("c")},
|
||||
},
|
||||
)
|
||||
})
|
||||
@ -195,7 +195,7 @@ func Test_Parse_ArrayFunctions(t *testing.T) {
|
||||
},
|
||||
},
|
||||
},
|
||||
Table: parsers.Table{Value: "c"},
|
||||
Table: parsers.Table{SelectItem: testutils.SelectItem_Path("c")},
|
||||
},
|
||||
)
|
||||
})
|
||||
@ -223,7 +223,7 @@ func Test_Parse_ArrayFunctions(t *testing.T) {
|
||||
},
|
||||
},
|
||||
},
|
||||
Table: parsers.Table{Value: "c"},
|
||||
Table: parsers.Table{SelectItem: testutils.SelectItem_Path("c")},
|
||||
},
|
||||
)
|
||||
})
|
||||
@ -251,7 +251,7 @@ func Test_Parse_ArrayFunctions(t *testing.T) {
|
||||
},
|
||||
},
|
||||
},
|
||||
Table: parsers.Table{Value: "c"},
|
||||
Table: parsers.Table{SelectItem: testutils.SelectItem_Path("c")},
|
||||
},
|
||||
)
|
||||
})
|
||||
|
@ -4,6 +4,7 @@ import (
|
||||
"testing"
|
||||
|
||||
"github.com/pikami/cosmium/parsers"
|
||||
testutils "github.com/pikami/cosmium/test_utils"
|
||||
)
|
||||
|
||||
func Test_Parse_Join(t *testing.T) {
|
||||
@ -17,7 +18,7 @@ func Test_Parse_Join(t *testing.T) {
|
||||
{Path: []string{"c", "id"}},
|
||||
{Path: []string{"c", "pk"}},
|
||||
},
|
||||
Table: parsers.Table{Value: "c"},
|
||||
Table: parsers.Table{SelectItem: testutils.SelectItem_Path("c")},
|
||||
JoinItems: []parsers.JoinItem{
|
||||
{
|
||||
Table: parsers.Table{
|
||||
@ -40,7 +41,7 @@ func Test_Parse_Join(t *testing.T) {
|
||||
SelectItems: []parsers.SelectItem{
|
||||
{Path: []string{"cc"}, IsTopLevel: true},
|
||||
},
|
||||
Table: parsers.Table{Value: "c"},
|
||||
Table: parsers.Table{SelectItem: testutils.SelectItem_Path("c")},
|
||||
JoinItems: []parsers.JoinItem{
|
||||
{
|
||||
Table: parsers.Table{
|
||||
|
@ -4,6 +4,7 @@ import (
|
||||
"testing"
|
||||
|
||||
"github.com/pikami/cosmium/parsers"
|
||||
testutils "github.com/pikami/cosmium/test_utils"
|
||||
)
|
||||
|
||||
func Test_Execute_MathFunctions(t *testing.T) {
|
||||
@ -644,7 +645,7 @@ func testMathFunctionParse(
|
||||
},
|
||||
},
|
||||
},
|
||||
Table: parsers.Table{Value: expectedTable},
|
||||
Table: parsers.Table{SelectItem: testutils.SelectItem_Path(expectedTable)},
|
||||
},
|
||||
)
|
||||
}
|
||||
|
@ -49,7 +49,7 @@ func Test_Parse(t *testing.T) {
|
||||
{Path: []string{"c", "id"}},
|
||||
{Path: []string{"c", "pk"}},
|
||||
},
|
||||
Table: parsers.Table{Value: "c"},
|
||||
Table: parsers.Table{SelectItem: testutils.SelectItem_Path("c")},
|
||||
OrderExpressions: []parsers.OrderExpression{
|
||||
{
|
||||
SelectItem: parsers.SelectItem{Path: []string{"c", "id"}},
|
||||
@ -73,7 +73,7 @@ func Test_Parse(t *testing.T) {
|
||||
{Path: []string{"c", "id"}},
|
||||
{Path: []string{"c", "pk"}},
|
||||
},
|
||||
Table: parsers.Table{Value: "c"},
|
||||
Table: parsers.Table{SelectItem: testutils.SelectItem_Path("c")},
|
||||
GroupBy: []parsers.SelectItem{
|
||||
{Path: []string{"c", "id"}},
|
||||
{Path: []string{"c", "pk"}},
|
||||
@ -93,7 +93,7 @@ func Test_Parse(t *testing.T) {
|
||||
Type: parsers.SelectItemTypeField,
|
||||
},
|
||||
},
|
||||
Table: parsers.Table{Value: "c"},
|
||||
Table: parsers.Table{SelectItem: testutils.SelectItem_Path("c")},
|
||||
Filters: parsers.SelectItem{
|
||||
Type: parsers.SelectItemTypeFunctionCall,
|
||||
Value: parsers.FunctionCall{
|
||||
@ -124,10 +124,9 @@ func Test_Parse(t *testing.T) {
|
||||
},
|
||||
},
|
||||
Table: parsers.Table{
|
||||
Value: "c",
|
||||
SelectItem: parsers.SelectItem{
|
||||
Path: []string{"c", "tags"},
|
||||
},
|
||||
Value: "c",
|
||||
SelectItem: testutils.SelectItem_Path("c", "tags"),
|
||||
IsInSelect: true,
|
||||
},
|
||||
},
|
||||
)
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -204,14 +204,22 @@ TopClause <- Top ws count:Integer {
|
||||
return count, nil
|
||||
}
|
||||
|
||||
FromClause <- From ws table:TableName selectItem:(ws "IN"i ws column:SelectItem { return column, nil })? {
|
||||
FromClause <- From ws table:TableName selectItem:(ws In ws column:SelectItem { return column, nil }) {
|
||||
tableTyped := table.(parsers.Table)
|
||||
|
||||
if selectItem != nil {
|
||||
tableTyped.SelectItem = selectItem.(parsers.SelectItem)
|
||||
tableTyped.IsInSelect = true
|
||||
}
|
||||
|
||||
return tableTyped, nil
|
||||
} / From ws column:SelectItem {
|
||||
tableSelectItem := column.(parsers.SelectItem)
|
||||
table := parsers.Table{
|
||||
Value: tableSelectItem.Alias,
|
||||
SelectItem: tableSelectItem,
|
||||
}
|
||||
return table, nil
|
||||
} / From ws subQuery:SubQuerySelectItem {
|
||||
subQueryTyped := subQuery.(parsers.SelectItem)
|
||||
table := parsers.Table{
|
||||
@ -243,13 +251,13 @@ SubQuerySelectItem <- subQuery:SubQuery asClause:(ws alias:AsClause { return ali
|
||||
return selectItem, nil
|
||||
}
|
||||
|
||||
JoinClause <- Join ws table:TableName ws "IN"i ws column:SelectItem {
|
||||
JoinClause <- Join ws table:TableName ws In ws column:SelectItem {
|
||||
return makeJoin(table, column)
|
||||
} / Join ws subQuery:SubQuerySelectItem {
|
||||
return makeJoin(nil, subQuery)
|
||||
}
|
||||
|
||||
OffsetClause <- "OFFSET"i ws offset:IntegerLiteral ws "LIMIT"i ws limit:IntegerLiteral {
|
||||
OffsetClause <- Offset ws offset:IntegerLiteral ws "LIMIT"i ws limit:IntegerLiteral {
|
||||
return []interface{}{offset.(parsers.Constant).Value, limit.(parsers.Constant).Value}, nil
|
||||
}
|
||||
|
||||
@ -317,7 +325,11 @@ SelectItem <- selectItem:(SubQuerySelectItem / Literal / FunctionCall / SelectAr
|
||||
return itemResult, nil
|
||||
}
|
||||
|
||||
AsClause <- ws As ws alias:Identifier { return alias, nil }
|
||||
AsClause <- (ws As)? ws !ExcludedKeywords alias:Identifier {
|
||||
return alias, nil
|
||||
}
|
||||
|
||||
ExcludedKeywords <- Select / Top / As / From / In / Join / Exists / Where / And / Or / GroupBy / OrderBy / Offset
|
||||
|
||||
DotFieldAccess <- "." id:Identifier {
|
||||
return id, nil
|
||||
@ -373,6 +385,8 @@ As <- "AS"i
|
||||
|
||||
From <- "FROM"i
|
||||
|
||||
In <- "IN"i
|
||||
|
||||
Join <- "JOIN"i
|
||||
|
||||
Exists <- "EXISTS"i
|
||||
@ -387,6 +401,8 @@ GroupBy <- "GROUP"i ws "BY"i
|
||||
|
||||
OrderBy <- "ORDER"i ws "BY"i
|
||||
|
||||
Offset <- "OFFSET"i
|
||||
|
||||
ComparisonOperator <- ("=" / "!=" / "<" / "<=" / ">" / ">=") {
|
||||
return string(c.text), nil
|
||||
}
|
||||
@ -700,7 +716,7 @@ MathNumberBinExpression <- "NumberBin"i ws "(" ws ex1:SelectItem others:(ws ","
|
||||
MathPiExpression <- "PI"i ws "(" ws ")" { return createFunctionCall(parsers.FunctionCallMathPi, []interface{}{}) }
|
||||
MathRandExpression <- "RAND"i ws "(" ws ")" { return createFunctionCall(parsers.FunctionCallMathRand, []interface{}{}) }
|
||||
|
||||
InFunction <- ex1:SelectProperty ws "IN"i ws "(" ws ex2:SelectItem others:(ws "," ws ex:SelectItem { return ex, nil })* ws ")" {
|
||||
InFunction <- ex1:SelectProperty ws In ws "(" ws ex2:SelectItem others:(ws "," ws ex:SelectItem { return ex, nil })* ws ")" {
|
||||
return createFunctionCall(parsers.FunctionCallIn, append([]interface{}{ex1, ex2}, others.([]interface{})...))
|
||||
}
|
||||
|
||||
|
@ -4,6 +4,7 @@ import (
|
||||
"testing"
|
||||
|
||||
"github.com/pikami/cosmium/parsers"
|
||||
testutils "github.com/pikami/cosmium/test_utils"
|
||||
)
|
||||
|
||||
func Test_Parse_Select(t *testing.T) {
|
||||
@ -17,7 +18,7 @@ func Test_Parse_Select(t *testing.T) {
|
||||
{Path: []string{"c", "id"}},
|
||||
{Path: []string{"c", "pk"}},
|
||||
},
|
||||
Table: parsers.Table{Value: "c"},
|
||||
Table: parsers.Table{SelectItem: testutils.SelectItem_Path("c")},
|
||||
},
|
||||
)
|
||||
})
|
||||
@ -31,7 +32,7 @@ func Test_Parse_Select(t *testing.T) {
|
||||
{Path: []string{"c", "id"}},
|
||||
{Path: []string{"c", "@param"}},
|
||||
},
|
||||
Table: parsers.Table{Value: "c"},
|
||||
Table: parsers.Table{SelectItem: testutils.SelectItem_Path("c")},
|
||||
},
|
||||
)
|
||||
})
|
||||
@ -44,7 +45,7 @@ func Test_Parse_Select(t *testing.T) {
|
||||
SelectItems: []parsers.SelectItem{
|
||||
{Path: []string{"c", "id"}},
|
||||
},
|
||||
Table: parsers.Table{Value: "c"},
|
||||
Table: parsers.Table{SelectItem: testutils.SelectItem_Path("c")},
|
||||
Distinct: true,
|
||||
},
|
||||
)
|
||||
@ -58,7 +59,7 @@ func Test_Parse_Select(t *testing.T) {
|
||||
SelectItems: []parsers.SelectItem{
|
||||
{Path: []string{"c", "id"}},
|
||||
},
|
||||
Table: parsers.Table{Value: "c"},
|
||||
Table: parsers.Table{SelectItem: testutils.SelectItem_Path("c")},
|
||||
Count: 1,
|
||||
},
|
||||
)
|
||||
@ -72,7 +73,7 @@ func Test_Parse_Select(t *testing.T) {
|
||||
SelectItems: []parsers.SelectItem{
|
||||
{Path: []string{"c", "id"}},
|
||||
},
|
||||
Table: parsers.Table{Value: "c"},
|
||||
Table: parsers.Table{SelectItem: testutils.SelectItem_Path("c")},
|
||||
Count: 5,
|
||||
Offset: 3,
|
||||
},
|
||||
@ -87,7 +88,7 @@ func Test_Parse_Select(t *testing.T) {
|
||||
SelectItems: []parsers.SelectItem{
|
||||
{Path: []string{"c", "id"}, IsTopLevel: true},
|
||||
},
|
||||
Table: parsers.Table{Value: "c"},
|
||||
Table: parsers.Table{SelectItem: testutils.SelectItem_Path("c")},
|
||||
},
|
||||
)
|
||||
})
|
||||
@ -100,7 +101,20 @@ func Test_Parse_Select(t *testing.T) {
|
||||
SelectItems: []parsers.SelectItem{
|
||||
{Path: []string{"c"}, IsTopLevel: true},
|
||||
},
|
||||
Table: parsers.Table{Value: "c"},
|
||||
Table: parsers.Table{SelectItem: testutils.SelectItem_Path("c")},
|
||||
},
|
||||
)
|
||||
})
|
||||
|
||||
t.Run("Should parse SELECT c", func(t *testing.T) {
|
||||
testQueryParse(
|
||||
t,
|
||||
`SELECT c FROM c`,
|
||||
parsers.SelectStmt{
|
||||
SelectItems: []parsers.SelectItem{
|
||||
{Path: []string{"c"}, IsTopLevel: false},
|
||||
},
|
||||
Table: parsers.Table{SelectItem: testutils.SelectItem_Path("c")},
|
||||
},
|
||||
)
|
||||
})
|
||||
@ -120,7 +134,27 @@ func Test_Parse_Select(t *testing.T) {
|
||||
},
|
||||
},
|
||||
},
|
||||
Table: parsers.Table{Value: "c"},
|
||||
Table: parsers.Table{SelectItem: testutils.SelectItem_Path("c")},
|
||||
},
|
||||
)
|
||||
})
|
||||
|
||||
t.Run("Should parse SELECT with alias", func(t *testing.T) {
|
||||
testQueryParse(
|
||||
t,
|
||||
`SELECT
|
||||
c.id AS aliasWithAs,
|
||||
c.pk aliasWithoutAs
|
||||
FROM root c`,
|
||||
parsers.SelectStmt{
|
||||
SelectItems: []parsers.SelectItem{
|
||||
{Alias: "aliasWithAs", Path: []string{"c", "id"}},
|
||||
{Alias: "aliasWithoutAs", Path: []string{"c", "pk"}},
|
||||
},
|
||||
Table: parsers.Table{
|
||||
Value: "c",
|
||||
SelectItem: parsers.SelectItem{Alias: "c", Path: []string{"root"}},
|
||||
},
|
||||
},
|
||||
)
|
||||
})
|
||||
@ -140,7 +174,7 @@ func Test_Parse_Select(t *testing.T) {
|
||||
},
|
||||
},
|
||||
},
|
||||
Table: parsers.Table{Value: "c"},
|
||||
Table: parsers.Table{SelectItem: testutils.SelectItem_Path("c")},
|
||||
},
|
||||
)
|
||||
})
|
||||
|
@ -30,7 +30,7 @@ func Test_Execute_StringFunctions(t *testing.T) {
|
||||
},
|
||||
},
|
||||
},
|
||||
Table: parsers.Table{Value: "c"},
|
||||
Table: parsers.Table{SelectItem: testutils.SelectItem_Path("c")},
|
||||
},
|
||||
)
|
||||
})
|
||||
@ -56,7 +56,7 @@ func Test_Execute_StringFunctions(t *testing.T) {
|
||||
},
|
||||
},
|
||||
},
|
||||
Table: parsers.Table{Value: "c"},
|
||||
Table: parsers.Table{SelectItem: testutils.SelectItem_Path("c")},
|
||||
},
|
||||
)
|
||||
})
|
||||
@ -85,7 +85,7 @@ func Test_Execute_StringFunctions(t *testing.T) {
|
||||
},
|
||||
},
|
||||
},
|
||||
Table: parsers.Table{Value: "c"},
|
||||
Table: parsers.Table{SelectItem: testutils.SelectItem_Path("c")},
|
||||
},
|
||||
)
|
||||
})
|
||||
@ -111,7 +111,7 @@ func Test_Execute_StringFunctions(t *testing.T) {
|
||||
},
|
||||
},
|
||||
},
|
||||
Table: parsers.Table{Value: "c"},
|
||||
Table: parsers.Table{SelectItem: testutils.SelectItem_Path("c")},
|
||||
},
|
||||
)
|
||||
})
|
||||
@ -137,7 +137,7 @@ func Test_Execute_StringFunctions(t *testing.T) {
|
||||
},
|
||||
},
|
||||
},
|
||||
Table: parsers.Table{Value: "c"},
|
||||
Table: parsers.Table{SelectItem: testutils.SelectItem_Path("c")},
|
||||
},
|
||||
)
|
||||
})
|
||||
@ -163,7 +163,7 @@ func Test_Execute_StringFunctions(t *testing.T) {
|
||||
},
|
||||
},
|
||||
},
|
||||
Table: parsers.Table{Value: "c"},
|
||||
Table: parsers.Table{SelectItem: testutils.SelectItem_Path("c")},
|
||||
},
|
||||
)
|
||||
})
|
||||
@ -189,7 +189,7 @@ func Test_Execute_StringFunctions(t *testing.T) {
|
||||
},
|
||||
},
|
||||
},
|
||||
Table: parsers.Table{Value: "c"},
|
||||
Table: parsers.Table{SelectItem: testutils.SelectItem_Path("c")},
|
||||
},
|
||||
)
|
||||
})
|
||||
@ -213,7 +213,7 @@ func Test_Execute_StringFunctions(t *testing.T) {
|
||||
},
|
||||
},
|
||||
},
|
||||
Table: parsers.Table{Value: "c"},
|
||||
Table: parsers.Table{SelectItem: testutils.SelectItem_Path("c")},
|
||||
},
|
||||
)
|
||||
})
|
||||
@ -237,7 +237,7 @@ func Test_Execute_StringFunctions(t *testing.T) {
|
||||
},
|
||||
},
|
||||
},
|
||||
Table: parsers.Table{Value: "c"},
|
||||
Table: parsers.Table{SelectItem: testutils.SelectItem_Path("c")},
|
||||
},
|
||||
)
|
||||
})
|
||||
@ -261,7 +261,7 @@ func Test_Execute_StringFunctions(t *testing.T) {
|
||||
},
|
||||
},
|
||||
},
|
||||
Table: parsers.Table{Value: "c"},
|
||||
Table: parsers.Table{SelectItem: testutils.SelectItem_Path("c")},
|
||||
},
|
||||
)
|
||||
})
|
||||
@ -286,7 +286,7 @@ func Test_Execute_StringFunctions(t *testing.T) {
|
||||
},
|
||||
},
|
||||
},
|
||||
Table: parsers.Table{Value: "c"},
|
||||
Table: parsers.Table{SelectItem: testutils.SelectItem_Path("c")},
|
||||
},
|
||||
)
|
||||
})
|
||||
@ -310,7 +310,7 @@ func Test_Execute_StringFunctions(t *testing.T) {
|
||||
},
|
||||
},
|
||||
},
|
||||
Table: parsers.Table{Value: "c"},
|
||||
Table: parsers.Table{SelectItem: testutils.SelectItem_Path("c")},
|
||||
},
|
||||
)
|
||||
})
|
||||
@ -334,7 +334,7 @@ func Test_Execute_StringFunctions(t *testing.T) {
|
||||
},
|
||||
},
|
||||
},
|
||||
Table: parsers.Table{Value: "c"},
|
||||
Table: parsers.Table{SelectItem: testutils.SelectItem_Path("c")},
|
||||
},
|
||||
)
|
||||
})
|
||||
@ -360,7 +360,7 @@ func Test_Execute_StringFunctions(t *testing.T) {
|
||||
},
|
||||
},
|
||||
},
|
||||
Table: parsers.Table{Value: "c"},
|
||||
Table: parsers.Table{SelectItem: testutils.SelectItem_Path("c")},
|
||||
},
|
||||
)
|
||||
})
|
||||
@ -385,7 +385,7 @@ func Test_Execute_StringFunctions(t *testing.T) {
|
||||
},
|
||||
},
|
||||
},
|
||||
Table: parsers.Table{Value: "c"},
|
||||
Table: parsers.Table{SelectItem: testutils.SelectItem_Path("c")},
|
||||
},
|
||||
)
|
||||
})
|
||||
@ -409,7 +409,7 @@ func Test_Execute_StringFunctions(t *testing.T) {
|
||||
},
|
||||
},
|
||||
},
|
||||
Table: parsers.Table{Value: "c"},
|
||||
Table: parsers.Table{SelectItem: testutils.SelectItem_Path("c")},
|
||||
},
|
||||
)
|
||||
})
|
||||
@ -434,7 +434,7 @@ func Test_Execute_StringFunctions(t *testing.T) {
|
||||
},
|
||||
},
|
||||
},
|
||||
Table: parsers.Table{Value: "c"},
|
||||
Table: parsers.Table{SelectItem: testutils.SelectItem_Path("c")},
|
||||
},
|
||||
)
|
||||
})
|
||||
@ -458,7 +458,7 @@ func Test_Execute_StringFunctions(t *testing.T) {
|
||||
},
|
||||
},
|
||||
},
|
||||
Table: parsers.Table{Value: "c"},
|
||||
Table: parsers.Table{SelectItem: testutils.SelectItem_Path("c")},
|
||||
},
|
||||
)
|
||||
})
|
||||
@ -484,7 +484,7 @@ func Test_Execute_StringFunctions(t *testing.T) {
|
||||
},
|
||||
},
|
||||
},
|
||||
Table: parsers.Table{Value: "c"},
|
||||
Table: parsers.Table{SelectItem: testutils.SelectItem_Path("c")},
|
||||
},
|
||||
)
|
||||
})
|
||||
@ -508,7 +508,7 @@ func Test_Execute_StringFunctions(t *testing.T) {
|
||||
},
|
||||
},
|
||||
},
|
||||
Table: parsers.Table{Value: "c"},
|
||||
Table: parsers.Table{SelectItem: testutils.SelectItem_Path("c")},
|
||||
},
|
||||
)
|
||||
})
|
||||
|
@ -4,6 +4,7 @@ import (
|
||||
"testing"
|
||||
|
||||
"github.com/pikami/cosmium/parsers"
|
||||
testutils "github.com/pikami/cosmium/test_utils"
|
||||
)
|
||||
|
||||
func Test_Parse_SubQuery(t *testing.T) {
|
||||
@ -22,7 +23,7 @@ func Test_Parse_SubQuery(t *testing.T) {
|
||||
Alias: "c",
|
||||
Type: parsers.SelectItemTypeSubQuery,
|
||||
Value: parsers.SelectStmt{
|
||||
Table: parsers.Table{Value: "cc"},
|
||||
Table: parsers.Table{SelectItem: testutils.SelectItem_Path("cc")},
|
||||
SelectItems: []parsers.SelectItem{
|
||||
{Path: []string{"cc", "info"}, IsTopLevel: true},
|
||||
},
|
||||
@ -42,9 +43,7 @@ func Test_Parse_SubQuery(t *testing.T) {
|
||||
{Path: []string{"c", "id"}},
|
||||
{Path: []string{"cc", "name"}},
|
||||
},
|
||||
Table: parsers.Table{
|
||||
Value: "c",
|
||||
},
|
||||
Table: parsers.Table{SelectItem: testutils.SelectItem_Path("c")},
|
||||
JoinItems: []parsers.JoinItem{
|
||||
{
|
||||
Table: parsers.Table{
|
||||
@ -55,13 +54,12 @@ func Test_Parse_SubQuery(t *testing.T) {
|
||||
Type: parsers.SelectItemTypeSubQuery,
|
||||
Value: parsers.SelectStmt{
|
||||
SelectItems: []parsers.SelectItem{
|
||||
{Path: []string{"tag", "name"}},
|
||||
testutils.SelectItem_Path("tag", "name"),
|
||||
},
|
||||
Table: parsers.Table{
|
||||
Value: "tag",
|
||||
SelectItem: parsers.SelectItem{
|
||||
Path: []string{"c", "tags"},
|
||||
},
|
||||
Value: "tag",
|
||||
SelectItem: testutils.SelectItem_Path("c", "tags"),
|
||||
IsInSelect: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
@ -82,10 +80,10 @@ func Test_Parse_SubQuery(t *testing.T) {
|
||||
WHERE hasTags`,
|
||||
parsers.SelectStmt{
|
||||
SelectItems: []parsers.SelectItem{
|
||||
{Path: []string{"c", "id"}},
|
||||
testutils.SelectItem_Path("c", "id"),
|
||||
},
|
||||
Table: parsers.Table{
|
||||
Value: "c",
|
||||
SelectItem: testutils.SelectItem_Path("c"),
|
||||
},
|
||||
JoinItems: []parsers.JoinItem{
|
||||
{
|
||||
@ -100,13 +98,12 @@ func Test_Parse_SubQuery(t *testing.T) {
|
||||
Type: parsers.SelectItemTypeSubQuery,
|
||||
Value: parsers.SelectStmt{
|
||||
SelectItems: []parsers.SelectItem{
|
||||
{Path: []string{"tag", "name"}},
|
||||
testutils.SelectItem_Path("tag", "name"),
|
||||
},
|
||||
Table: parsers.Table{
|
||||
Value: "tag",
|
||||
SelectItem: parsers.SelectItem{
|
||||
Path: []string{"c", "tags"},
|
||||
},
|
||||
Value: "tag",
|
||||
SelectItem: testutils.SelectItem_Path("c", "tags"),
|
||||
IsInSelect: true,
|
||||
},
|
||||
Exists: true,
|
||||
},
|
||||
|
@ -4,6 +4,7 @@ import (
|
||||
"testing"
|
||||
|
||||
"github.com/pikami/cosmium/parsers"
|
||||
testutils "github.com/pikami/cosmium/test_utils"
|
||||
)
|
||||
|
||||
func Test_Execute_TypeCheckingFunctions(t *testing.T) {
|
||||
@ -27,7 +28,7 @@ func Test_Execute_TypeCheckingFunctions(t *testing.T) {
|
||||
},
|
||||
},
|
||||
},
|
||||
Table: parsers.Table{Value: "c"},
|
||||
Table: parsers.Table{SelectItem: testutils.SelectItem_Path("c")},
|
||||
Filters: parsers.SelectItem{
|
||||
Type: parsers.SelectItemTypeFunctionCall,
|
||||
Value: parsers.FunctionCall{
|
||||
@ -63,7 +64,7 @@ func Test_Execute_TypeCheckingFunctions(t *testing.T) {
|
||||
},
|
||||
},
|
||||
},
|
||||
Table: parsers.Table{Value: "c"},
|
||||
Table: parsers.Table{SelectItem: testutils.SelectItem_Path("c")},
|
||||
Filters: parsers.SelectItem{
|
||||
Type: parsers.SelectItemTypeFunctionCall,
|
||||
Value: parsers.FunctionCall{
|
||||
@ -99,7 +100,7 @@ func Test_Execute_TypeCheckingFunctions(t *testing.T) {
|
||||
},
|
||||
},
|
||||
},
|
||||
Table: parsers.Table{Value: "c"},
|
||||
Table: parsers.Table{SelectItem: testutils.SelectItem_Path("c")},
|
||||
Filters: parsers.SelectItem{
|
||||
Type: parsers.SelectItemTypeFunctionCall,
|
||||
Value: parsers.FunctionCall{
|
||||
@ -135,7 +136,7 @@ func Test_Execute_TypeCheckingFunctions(t *testing.T) {
|
||||
},
|
||||
},
|
||||
},
|
||||
Table: parsers.Table{Value: "c"},
|
||||
Table: parsers.Table{SelectItem: testutils.SelectItem_Path("c")},
|
||||
Filters: parsers.SelectItem{
|
||||
Type: parsers.SelectItemTypeFunctionCall,
|
||||
Value: parsers.FunctionCall{
|
||||
@ -171,7 +172,7 @@ func Test_Execute_TypeCheckingFunctions(t *testing.T) {
|
||||
},
|
||||
},
|
||||
},
|
||||
Table: parsers.Table{Value: "c"},
|
||||
Table: parsers.Table{SelectItem: testutils.SelectItem_Path("c")},
|
||||
Filters: parsers.SelectItem{
|
||||
Type: parsers.SelectItemTypeFunctionCall,
|
||||
Value: parsers.FunctionCall{
|
||||
@ -207,7 +208,7 @@ func Test_Execute_TypeCheckingFunctions(t *testing.T) {
|
||||
},
|
||||
},
|
||||
},
|
||||
Table: parsers.Table{Value: "c"},
|
||||
Table: parsers.Table{SelectItem: testutils.SelectItem_Path("c")},
|
||||
Filters: parsers.SelectItem{
|
||||
Type: parsers.SelectItemTypeFunctionCall,
|
||||
Value: parsers.FunctionCall{
|
||||
@ -243,7 +244,7 @@ func Test_Execute_TypeCheckingFunctions(t *testing.T) {
|
||||
},
|
||||
},
|
||||
},
|
||||
Table: parsers.Table{Value: "c"},
|
||||
Table: parsers.Table{SelectItem: testutils.SelectItem_Path("c")},
|
||||
Filters: parsers.SelectItem{
|
||||
Type: parsers.SelectItemTypeFunctionCall,
|
||||
Value: parsers.FunctionCall{
|
||||
@ -279,7 +280,7 @@ func Test_Execute_TypeCheckingFunctions(t *testing.T) {
|
||||
},
|
||||
},
|
||||
},
|
||||
Table: parsers.Table{Value: "c"},
|
||||
Table: parsers.Table{SelectItem: testutils.SelectItem_Path("c")},
|
||||
Filters: parsers.SelectItem{
|
||||
Type: parsers.SelectItemTypeFunctionCall,
|
||||
Value: parsers.FunctionCall{
|
||||
@ -315,7 +316,7 @@ func Test_Execute_TypeCheckingFunctions(t *testing.T) {
|
||||
},
|
||||
},
|
||||
},
|
||||
Table: parsers.Table{Value: "c"},
|
||||
Table: parsers.Table{SelectItem: testutils.SelectItem_Path("c")},
|
||||
Filters: parsers.SelectItem{
|
||||
Type: parsers.SelectItemTypeFunctionCall,
|
||||
Value: parsers.FunctionCall{
|
||||
@ -351,7 +352,7 @@ func Test_Execute_TypeCheckingFunctions(t *testing.T) {
|
||||
},
|
||||
},
|
||||
},
|
||||
Table: parsers.Table{Value: "c"},
|
||||
Table: parsers.Table{SelectItem: testutils.SelectItem_Path("c")},
|
||||
Filters: parsers.SelectItem{
|
||||
Type: parsers.SelectItemTypeFunctionCall,
|
||||
Value: parsers.FunctionCall{
|
||||
|
@ -19,7 +19,7 @@ func Test_Parse_Were(t *testing.T) {
|
||||
SelectItems: []parsers.SelectItem{
|
||||
{Path: []string{"c", "id"}},
|
||||
},
|
||||
Table: parsers.Table{Value: "c"},
|
||||
Table: parsers.Table{SelectItem: testutils.SelectItem_Path("c")},
|
||||
Filters: parsers.ComparisonExpression{
|
||||
Operation: "=",
|
||||
Left: parsers.SelectItem{Path: []string{"c", "isCool"}},
|
||||
@ -42,7 +42,7 @@ func Test_Parse_Were(t *testing.T) {
|
||||
{Path: []string{"c", "_rid"}},
|
||||
{Path: []string{"c", "_ts"}},
|
||||
},
|
||||
Table: parsers.Table{Value: "c"},
|
||||
Table: parsers.Table{SelectItem: testutils.SelectItem_Path("c")},
|
||||
Filters: parsers.LogicalExpression{
|
||||
Operation: parsers.LogicalExpressionTypeOr,
|
||||
Expressions: []interface{}{
|
||||
@ -72,7 +72,7 @@ func Test_Parse_Were(t *testing.T) {
|
||||
SelectItems: []parsers.SelectItem{
|
||||
{Path: []string{"c", "id"}},
|
||||
},
|
||||
Table: parsers.Table{Value: "c"},
|
||||
Table: parsers.Table{SelectItem: testutils.SelectItem_Path("c")},
|
||||
Filters: parsers.LogicalExpression{
|
||||
Operation: parsers.LogicalExpressionTypeAnd,
|
||||
Expressions: []interface{}{
|
||||
@ -114,7 +114,7 @@ func Test_Parse_Were(t *testing.T) {
|
||||
AND c.param=@param_id1`,
|
||||
parsers.SelectStmt{
|
||||
SelectItems: []parsers.SelectItem{{Path: []string{"c", "id"}, Alias: ""}},
|
||||
Table: parsers.Table{Value: "c"},
|
||||
Table: parsers.Table{SelectItem: testutils.SelectItem_Path("c")},
|
||||
Filters: parsers.LogicalExpression{
|
||||
Expressions: []interface{}{
|
||||
parsers.ComparisonExpression{
|
||||
|
@ -5,6 +5,7 @@ import (
|
||||
|
||||
"github.com/pikami/cosmium/parsers"
|
||||
memoryexecutor "github.com/pikami/cosmium/query_executors/memory_executor"
|
||||
testutils "github.com/pikami/cosmium/test_utils"
|
||||
)
|
||||
|
||||
func Test_Execute_AggregateFunctions(t *testing.T) {
|
||||
@ -38,7 +39,7 @@ func Test_Execute_AggregateFunctions(t *testing.T) {
|
||||
GroupBy: []parsers.SelectItem{
|
||||
{Path: []string{"c", "key"}},
|
||||
},
|
||||
Table: parsers.Table{Value: "c"},
|
||||
Table: parsers.Table{SelectItem: testutils.SelectItem_Path("c")},
|
||||
},
|
||||
mockData,
|
||||
[]memoryexecutor.RowType{
|
||||
@ -67,7 +68,7 @@ func Test_Execute_AggregateFunctions(t *testing.T) {
|
||||
},
|
||||
},
|
||||
},
|
||||
Table: parsers.Table{Value: "c"},
|
||||
Table: parsers.Table{SelectItem: testutils.SelectItem_Path("c")},
|
||||
},
|
||||
mockData,
|
||||
[]memoryexecutor.RowType{
|
||||
@ -99,7 +100,7 @@ func Test_Execute_AggregateFunctions(t *testing.T) {
|
||||
GroupBy: []parsers.SelectItem{
|
||||
{Path: []string{"c", "key"}},
|
||||
},
|
||||
Table: parsers.Table{Value: "c"},
|
||||
Table: parsers.Table{SelectItem: testutils.SelectItem_Path("c")},
|
||||
},
|
||||
mockData,
|
||||
[]memoryexecutor.RowType{
|
||||
@ -132,7 +133,7 @@ func Test_Execute_AggregateFunctions(t *testing.T) {
|
||||
GroupBy: []parsers.SelectItem{
|
||||
{Path: []string{"c", "key"}},
|
||||
},
|
||||
Table: parsers.Table{Value: "c"},
|
||||
Table: parsers.Table{SelectItem: testutils.SelectItem_Path("c")},
|
||||
},
|
||||
mockData,
|
||||
[]memoryexecutor.RowType{
|
||||
@ -165,7 +166,7 @@ func Test_Execute_AggregateFunctions(t *testing.T) {
|
||||
GroupBy: []parsers.SelectItem{
|
||||
{Path: []string{"c", "key"}},
|
||||
},
|
||||
Table: parsers.Table{Value: "c"},
|
||||
Table: parsers.Table{SelectItem: testutils.SelectItem_Path("c")},
|
||||
},
|
||||
mockData,
|
||||
[]memoryexecutor.RowType{
|
||||
@ -198,7 +199,7 @@ func Test_Execute_AggregateFunctions(t *testing.T) {
|
||||
GroupBy: []parsers.SelectItem{
|
||||
{Path: []string{"c", "key"}},
|
||||
},
|
||||
Table: parsers.Table{Value: "c"},
|
||||
Table: parsers.Table{SelectItem: testutils.SelectItem_Path("c")},
|
||||
},
|
||||
mockData,
|
||||
[]memoryexecutor.RowType{
|
||||
|
@ -220,7 +220,7 @@ func (r rowContext) partialMatch(item interface{}, exprToSearch interface{}) boo
|
||||
}
|
||||
|
||||
for _, key := range exprValue.MapKeys() {
|
||||
if itemValue.MapIndex(key).Interface() != exprValue.MapIndex(key).Interface() {
|
||||
if !reflect.DeepEqual(itemValue.MapIndex(key).Interface(), exprValue.MapIndex(key).Interface()) {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
@ -42,7 +42,7 @@ func Test_Execute_ArrayFunctions(t *testing.T) {
|
||||
},
|
||||
},
|
||||
},
|
||||
Table: parsers.Table{Value: "c"},
|
||||
Table: parsers.Table{SelectItem: testutils.SelectItem_Path("c")},
|
||||
},
|
||||
mockData,
|
||||
[]memoryexecutor.RowType{
|
||||
@ -59,10 +59,11 @@ func Test_Execute_ArrayFunctions(t *testing.T) {
|
||||
parsers.SelectStmt{
|
||||
Parameters: map[string]interface{}{
|
||||
"@categories": []interface{}{"coats", "jackets", "sweatshirts"},
|
||||
"@objectArray": []interface{}{map[string]interface{}{"category": "shirts", "color": "blue"}},
|
||||
"@fullMatchObject": map[string]interface{}{"category": "shirts", "color": "blue"},
|
||||
"@objectArray": []interface{}{map[string]interface{}{"category": "shirts", "color": "blue", "nestedObject": map[string]interface{}{"size": "M"}}},
|
||||
"@fullMatchObject": map[string]interface{}{"category": "shirts", "color": "blue", "nestedObject": map[string]interface{}{"size": "M"}},
|
||||
"@partialMatchObject": map[string]interface{}{"category": "shirts"},
|
||||
"@missingPartialMatchObject": map[string]interface{}{"category": "shorts", "color": "blue"},
|
||||
"@nestedPartialMatchObject": map[string]interface{}{"nestedObject": map[string]interface{}{"size": "M"}},
|
||||
},
|
||||
SelectItems: []parsers.SelectItem{
|
||||
{
|
||||
@ -133,17 +134,30 @@ func Test_Execute_ArrayFunctions(t *testing.T) {
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
Alias: "ContainsNestedPartialMatchObject",
|
||||
Type: parsers.SelectItemTypeFunctionCall,
|
||||
Value: parsers.FunctionCall{
|
||||
Type: parsers.FunctionCallArrayContains,
|
||||
Arguments: []interface{}{
|
||||
testutils.SelectItem_Constant_Parameter("@objectArray"),
|
||||
testutils.SelectItem_Constant_Parameter("@nestedPartialMatchObject"),
|
||||
testutils.SelectItem_Constant_Bool(true),
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
[]memoryexecutor.RowType{map[string]interface{}{"id": "123"}},
|
||||
[]memoryexecutor.RowType{
|
||||
map[string]interface{}{
|
||||
"ContainsItem": true,
|
||||
"MissingItem": false,
|
||||
"ContainsFullMatchObject": true,
|
||||
"MissingFullMatchObject": false,
|
||||
"ContainsPartialMatchObject": true,
|
||||
"MissingPartialMatchObject": false,
|
||||
"ContainsItem": true,
|
||||
"MissingItem": false,
|
||||
"ContainsFullMatchObject": true,
|
||||
"MissingFullMatchObject": false,
|
||||
"ContainsPartialMatchObject": true,
|
||||
"MissingPartialMatchObject": false,
|
||||
"ContainsNestedPartialMatchObject": true,
|
||||
},
|
||||
},
|
||||
)
|
||||
@ -356,7 +370,7 @@ func Test_Execute_ArrayFunctions(t *testing.T) {
|
||||
},
|
||||
},
|
||||
},
|
||||
Table: parsers.Table{Value: "c"},
|
||||
Table: parsers.Table{SelectItem: testutils.SelectItem_Path("c")},
|
||||
},
|
||||
mockData,
|
||||
[]memoryexecutor.RowType{
|
||||
@ -392,7 +406,7 @@ func Test_Execute_ArrayFunctions(t *testing.T) {
|
||||
},
|
||||
},
|
||||
},
|
||||
Table: parsers.Table{Value: "c"},
|
||||
Table: parsers.Table{SelectItem: testutils.SelectItem_Path("c")},
|
||||
},
|
||||
mockData,
|
||||
[]memoryexecutor.RowType{
|
||||
@ -430,7 +444,7 @@ func Test_Execute_ArrayFunctions(t *testing.T) {
|
||||
},
|
||||
},
|
||||
},
|
||||
Table: parsers.Table{Value: "c"},
|
||||
Table: parsers.Table{SelectItem: testutils.SelectItem_Path("c")},
|
||||
},
|
||||
mockData,
|
||||
[]memoryexecutor.RowType{
|
||||
@ -468,7 +482,7 @@ func Test_Execute_ArrayFunctions(t *testing.T) {
|
||||
},
|
||||
},
|
||||
},
|
||||
Table: parsers.Table{Value: "c"},
|
||||
Table: parsers.Table{SelectItem: testutils.SelectItem_Path("c")},
|
||||
},
|
||||
mockData,
|
||||
[]memoryexecutor.RowType{
|
||||
|
@ -5,6 +5,7 @@ import (
|
||||
|
||||
"github.com/pikami/cosmium/parsers"
|
||||
memoryexecutor "github.com/pikami/cosmium/query_executors/memory_executor"
|
||||
testutils "github.com/pikami/cosmium/test_utils"
|
||||
)
|
||||
|
||||
func Test_Execute_Joins(t *testing.T) {
|
||||
@ -33,7 +34,7 @@ func Test_Execute_Joins(t *testing.T) {
|
||||
{Path: []string{"c", "id"}},
|
||||
{Path: []string{"cc", "name"}},
|
||||
},
|
||||
Table: parsers.Table{Value: "c"},
|
||||
Table: parsers.Table{SelectItem: testutils.SelectItem_Path("c")},
|
||||
JoinItems: []parsers.JoinItem{
|
||||
{
|
||||
Table: parsers.Table{
|
||||
@ -62,7 +63,7 @@ func Test_Execute_Joins(t *testing.T) {
|
||||
SelectItems: []parsers.SelectItem{
|
||||
{Path: []string{"cc"}, IsTopLevel: true},
|
||||
},
|
||||
Table: parsers.Table{Value: "c"},
|
||||
Table: parsers.Table{SelectItem: testutils.SelectItem_Path("c")},
|
||||
JoinItems: []parsers.JoinItem{
|
||||
{
|
||||
Table: parsers.Table{
|
||||
|
@ -6,6 +6,7 @@ import (
|
||||
|
||||
"github.com/pikami/cosmium/parsers"
|
||||
memoryexecutor "github.com/pikami/cosmium/query_executors/memory_executor"
|
||||
testutils "github.com/pikami/cosmium/test_utils"
|
||||
)
|
||||
|
||||
func Test_Execute_MathFunctions(t *testing.T) {
|
||||
@ -261,7 +262,7 @@ func testMathFunctionExecute(
|
||||
},
|
||||
},
|
||||
},
|
||||
Table: parsers.Table{Value: "c"},
|
||||
Table: parsers.Table{SelectItem: testutils.SelectItem_Path("c")},
|
||||
},
|
||||
data,
|
||||
expectedData,
|
||||
|
@ -80,10 +80,15 @@ func resolveFrom(query parsers.SelectStmt, doc RowType) []rowContext {
|
||||
initialTableName = query.Table.Value
|
||||
}
|
||||
|
||||
if initialTableName == "" {
|
||||
initialTableName = resolveDestinationColumnName(query.Table.SelectItem, 0, query.Parameters)
|
||||
}
|
||||
|
||||
initialRow = rowContext{
|
||||
parameters: query.Parameters,
|
||||
tables: map[string]RowType{
|
||||
initialTableName: doc,
|
||||
"$root": doc,
|
||||
},
|
||||
}
|
||||
}
|
||||
@ -93,15 +98,33 @@ func resolveFrom(query parsers.SelectStmt, doc RowType) []rowContext {
|
||||
if destinationTableName == "" {
|
||||
destinationTableName = query.Table.Value
|
||||
}
|
||||
|
||||
selectValue := initialRow.parseArray(query.Table.SelectItem)
|
||||
rowContexts := make([]rowContext, len(selectValue))
|
||||
for i, newRowData := range selectValue {
|
||||
rowContexts[i].parameters = initialRow.parameters
|
||||
rowContexts[i].tables = copyMap(initialRow.tables)
|
||||
rowContexts[i].tables[destinationTableName] = newRowData
|
||||
if destinationTableName == "" {
|
||||
destinationTableName = resolveDestinationColumnName(query.Table.SelectItem, 0, initialRow.parameters)
|
||||
}
|
||||
return rowContexts
|
||||
|
||||
if query.Table.IsInSelect || query.Table.SelectItem.Type == parsers.SelectItemTypeSubQuery {
|
||||
selectValue := initialRow.parseArray(query.Table.SelectItem)
|
||||
rowContexts := make([]rowContext, len(selectValue))
|
||||
for i, newRowData := range selectValue {
|
||||
rowContexts[i].parameters = initialRow.parameters
|
||||
rowContexts[i].tables = copyMap(initialRow.tables)
|
||||
rowContexts[i].tables[destinationTableName] = newRowData
|
||||
}
|
||||
return rowContexts
|
||||
}
|
||||
|
||||
if len(query.Table.SelectItem.Path) > 0 {
|
||||
sourceTableName := query.Table.SelectItem.Path[0]
|
||||
sourceTableData := initialRow.tables[sourceTableName]
|
||||
if sourceTableData == nil {
|
||||
// When source table is not found, assume it's root document
|
||||
initialRow.tables[sourceTableName] = initialRow.tables["$root"]
|
||||
}
|
||||
}
|
||||
|
||||
newRowData := initialRow.resolveSelectItem(query.Table.SelectItem)
|
||||
initialRow.tables[destinationTableName] = newRowData
|
||||
return []rowContext{initialRow}
|
||||
}
|
||||
|
||||
return []rowContext{initialRow}
|
||||
@ -310,18 +333,7 @@ func (r rowContext) applyProjection(selectItems []parsers.SelectItem) RowType {
|
||||
// Construct a new row based on the selected columns
|
||||
row := make(map[string]interface{})
|
||||
for index, selectItem := range selectItems {
|
||||
destinationName := selectItem.Alias
|
||||
if destinationName == "" {
|
||||
if len(selectItem.Path) > 0 {
|
||||
destinationName = selectItem.Path[len(selectItem.Path)-1]
|
||||
} else {
|
||||
destinationName = fmt.Sprintf("$%d", index+1)
|
||||
}
|
||||
|
||||
if destinationName[0] == '@' {
|
||||
destinationName = r.parameters[destinationName].(string)
|
||||
}
|
||||
}
|
||||
destinationName := resolveDestinationColumnName(selectItem, index, r.parameters)
|
||||
|
||||
row[destinationName] = r.resolveSelectItem(selectItem)
|
||||
}
|
||||
@ -329,6 +341,23 @@ func (r rowContext) applyProjection(selectItems []parsers.SelectItem) RowType {
|
||||
return row
|
||||
}
|
||||
|
||||
func resolveDestinationColumnName(selectItem parsers.SelectItem, itemIndex int, queryParameters map[string]interface{}) string {
|
||||
if selectItem.Alias != "" {
|
||||
return selectItem.Alias
|
||||
}
|
||||
|
||||
destinationName := fmt.Sprintf("$%d", itemIndex+1)
|
||||
if len(selectItem.Path) > 0 {
|
||||
destinationName = selectItem.Path[len(selectItem.Path)-1]
|
||||
}
|
||||
|
||||
if destinationName[0] == '@' {
|
||||
destinationName = queryParameters[destinationName].(string)
|
||||
}
|
||||
|
||||
return destinationName
|
||||
}
|
||||
|
||||
func (r rowContext) resolveSelectItem(selectItem parsers.SelectItem) interface{} {
|
||||
if selectItem.Type == parsers.SelectItemTypeArray {
|
||||
return r.selectItem_SelectItemTypeArray(selectItem)
|
||||
|
@ -50,7 +50,7 @@ func Test_Execute(t *testing.T) {
|
||||
{Path: []string{"c", "id"}},
|
||||
{Path: []string{"c", "pk"}},
|
||||
},
|
||||
Table: parsers.Table{Value: "c"},
|
||||
Table: parsers.Table{SelectItem: testutils.SelectItem_Path("c")},
|
||||
OrderExpressions: []parsers.OrderExpression{
|
||||
{
|
||||
SelectItem: parsers.SelectItem{Path: []string{"c", "pk"}},
|
||||
@ -79,7 +79,7 @@ func Test_Execute(t *testing.T) {
|
||||
SelectItems: []parsers.SelectItem{
|
||||
{Path: []string{"c", "pk"}},
|
||||
},
|
||||
Table: parsers.Table{Value: "c"},
|
||||
Table: parsers.Table{SelectItem: testutils.SelectItem_Path("c")},
|
||||
GroupBy: []parsers.SelectItem{
|
||||
{Path: []string{"c", "pk"}},
|
||||
},
|
||||
@ -102,7 +102,7 @@ func Test_Execute(t *testing.T) {
|
||||
Type: parsers.SelectItemTypeField,
|
||||
},
|
||||
},
|
||||
Table: parsers.Table{Value: "c"},
|
||||
Table: parsers.Table{SelectItem: testutils.SelectItem_Path("c")},
|
||||
Filters: parsers.SelectItem{
|
||||
Type: parsers.SelectItemTypeFunctionCall,
|
||||
Value: parsers.FunctionCall{
|
||||
@ -137,10 +137,9 @@ func Test_Execute(t *testing.T) {
|
||||
},
|
||||
},
|
||||
Table: parsers.Table{
|
||||
Value: "c",
|
||||
SelectItem: parsers.SelectItem{
|
||||
Path: []string{"c", "tags"},
|
||||
},
|
||||
Value: "c",
|
||||
SelectItem: testutils.SelectItem_Path("c", "tags"),
|
||||
IsInSelect: true,
|
||||
},
|
||||
},
|
||||
mockData,
|
||||
|
@ -5,6 +5,7 @@ import (
|
||||
|
||||
"github.com/pikami/cosmium/parsers"
|
||||
memoryexecutor "github.com/pikami/cosmium/query_executors/memory_executor"
|
||||
testutils "github.com/pikami/cosmium/test_utils"
|
||||
)
|
||||
|
||||
func Test_Execute_Select(t *testing.T) {
|
||||
@ -23,7 +24,7 @@ func Test_Execute_Select(t *testing.T) {
|
||||
{Path: []string{"c", "id"}},
|
||||
{Path: []string{"c", "pk"}},
|
||||
},
|
||||
Table: parsers.Table{Value: "c"},
|
||||
Table: parsers.Table{SelectItem: testutils.SelectItem_Path("c")},
|
||||
},
|
||||
mockData,
|
||||
[]memoryexecutor.RowType{
|
||||
@ -43,7 +44,7 @@ func Test_Execute_Select(t *testing.T) {
|
||||
{Path: []string{"c", "id"}},
|
||||
{Path: []string{"c", "@param"}},
|
||||
},
|
||||
Table: parsers.Table{Value: "c"},
|
||||
Table: parsers.Table{SelectItem: testutils.SelectItem_Path("c")},
|
||||
Parameters: map[string]interface{}{
|
||||
"@param": "pk",
|
||||
},
|
||||
@ -65,7 +66,7 @@ func Test_Execute_Select(t *testing.T) {
|
||||
SelectItems: []parsers.SelectItem{
|
||||
{Path: []string{"c", "pk"}},
|
||||
},
|
||||
Table: parsers.Table{Value: "c"},
|
||||
Table: parsers.Table{SelectItem: testutils.SelectItem_Path("c")},
|
||||
Distinct: true,
|
||||
},
|
||||
mockData,
|
||||
@ -84,7 +85,7 @@ func Test_Execute_Select(t *testing.T) {
|
||||
{Path: []string{"c", "id"}},
|
||||
{Path: []string{"c", "pk"}},
|
||||
},
|
||||
Table: parsers.Table{Value: "c"},
|
||||
Table: parsers.Table{SelectItem: testutils.SelectItem_Path("c")},
|
||||
Count: 1,
|
||||
},
|
||||
mockData,
|
||||
@ -102,7 +103,7 @@ func Test_Execute_Select(t *testing.T) {
|
||||
{Path: []string{"c", "id"}},
|
||||
{Path: []string{"c", "pk"}},
|
||||
},
|
||||
Table: parsers.Table{Value: "c"},
|
||||
Table: parsers.Table{SelectItem: testutils.SelectItem_Path("c")},
|
||||
Count: 2,
|
||||
Offset: 1,
|
||||
OrderExpressions: []parsers.OrderExpression{
|
||||
@ -127,7 +128,7 @@ func Test_Execute_Select(t *testing.T) {
|
||||
SelectItems: []parsers.SelectItem{
|
||||
{Path: []string{"c", "id"}, IsTopLevel: true},
|
||||
},
|
||||
Table: parsers.Table{Value: "c"},
|
||||
Table: parsers.Table{SelectItem: testutils.SelectItem_Path("c")},
|
||||
},
|
||||
mockData,
|
||||
[]memoryexecutor.RowType{
|
||||
@ -146,7 +147,7 @@ func Test_Execute_Select(t *testing.T) {
|
||||
SelectItems: []parsers.SelectItem{
|
||||
{Path: []string{"c"}, IsTopLevel: true},
|
||||
},
|
||||
Table: parsers.Table{Value: "c"},
|
||||
Table: parsers.Table{SelectItem: testutils.SelectItem_Path("c")},
|
||||
},
|
||||
mockData,
|
||||
mockData,
|
||||
@ -167,7 +168,7 @@ func Test_Execute_Select(t *testing.T) {
|
||||
},
|
||||
},
|
||||
},
|
||||
Table: parsers.Table{Value: "c"},
|
||||
Table: parsers.Table{SelectItem: testutils.SelectItem_Path("c")},
|
||||
},
|
||||
mockData,
|
||||
[]memoryexecutor.RowType{
|
||||
@ -193,7 +194,7 @@ func Test_Execute_Select(t *testing.T) {
|
||||
},
|
||||
},
|
||||
},
|
||||
Table: parsers.Table{Value: "c"},
|
||||
Table: parsers.Table{SelectItem: testutils.SelectItem_Path("c")},
|
||||
},
|
||||
mockData,
|
||||
[]memoryexecutor.RowType{
|
||||
|
@ -40,7 +40,7 @@ func Test_Execute_StringFunctions(t *testing.T) {
|
||||
},
|
||||
},
|
||||
},
|
||||
Table: parsers.Table{Value: "c"},
|
||||
Table: parsers.Table{SelectItem: testutils.SelectItem_Path("c")},
|
||||
},
|
||||
mockData,
|
||||
[]memoryexecutor.RowType{
|
||||
@ -76,7 +76,7 @@ func Test_Execute_StringFunctions(t *testing.T) {
|
||||
},
|
||||
},
|
||||
},
|
||||
Table: parsers.Table{Value: "c"},
|
||||
Table: parsers.Table{SelectItem: testutils.SelectItem_Path("c")},
|
||||
},
|
||||
mockData,
|
||||
[]memoryexecutor.RowType{
|
||||
@ -112,7 +112,7 @@ func Test_Execute_StringFunctions(t *testing.T) {
|
||||
},
|
||||
},
|
||||
},
|
||||
Table: parsers.Table{Value: "c"},
|
||||
Table: parsers.Table{SelectItem: testutils.SelectItem_Path("c")},
|
||||
},
|
||||
mockData,
|
||||
[]memoryexecutor.RowType{
|
||||
@ -148,7 +148,7 @@ func Test_Execute_StringFunctions(t *testing.T) {
|
||||
},
|
||||
},
|
||||
},
|
||||
Table: parsers.Table{Value: "c"},
|
||||
Table: parsers.Table{SelectItem: testutils.SelectItem_Path("c")},
|
||||
},
|
||||
mockData,
|
||||
[]memoryexecutor.RowType{
|
||||
@ -184,7 +184,7 @@ func Test_Execute_StringFunctions(t *testing.T) {
|
||||
},
|
||||
},
|
||||
},
|
||||
Table: parsers.Table{Value: "c"},
|
||||
Table: parsers.Table{SelectItem: testutils.SelectItem_Path("c")},
|
||||
},
|
||||
mockData,
|
||||
[]memoryexecutor.RowType{
|
||||
@ -220,7 +220,7 @@ func Test_Execute_StringFunctions(t *testing.T) {
|
||||
},
|
||||
},
|
||||
},
|
||||
Table: parsers.Table{Value: "c"},
|
||||
Table: parsers.Table{SelectItem: testutils.SelectItem_Path("c")},
|
||||
},
|
||||
mockData,
|
||||
[]memoryexecutor.RowType{
|
||||
@ -256,7 +256,7 @@ func Test_Execute_StringFunctions(t *testing.T) {
|
||||
},
|
||||
},
|
||||
},
|
||||
Table: parsers.Table{Value: "c"},
|
||||
Table: parsers.Table{SelectItem: testutils.SelectItem_Path("c")},
|
||||
},
|
||||
mockData,
|
||||
[]memoryexecutor.RowType{
|
||||
@ -290,7 +290,7 @@ func Test_Execute_StringFunctions(t *testing.T) {
|
||||
},
|
||||
},
|
||||
},
|
||||
Table: parsers.Table{Value: "c"},
|
||||
Table: parsers.Table{SelectItem: testutils.SelectItem_Path("c")},
|
||||
},
|
||||
mockData,
|
||||
[]memoryexecutor.RowType{
|
||||
@ -325,7 +325,7 @@ func Test_Execute_StringFunctions(t *testing.T) {
|
||||
},
|
||||
},
|
||||
},
|
||||
Table: parsers.Table{Value: "c"},
|
||||
Table: parsers.Table{SelectItem: testutils.SelectItem_Path("c")},
|
||||
},
|
||||
mockData,
|
||||
[]memoryexecutor.RowType{
|
||||
@ -359,7 +359,7 @@ func Test_Execute_StringFunctions(t *testing.T) {
|
||||
},
|
||||
},
|
||||
},
|
||||
Table: parsers.Table{Value: "c"},
|
||||
Table: parsers.Table{SelectItem: testutils.SelectItem_Path("c")},
|
||||
},
|
||||
mockData,
|
||||
[]memoryexecutor.RowType{
|
||||
@ -393,7 +393,7 @@ func Test_Execute_StringFunctions(t *testing.T) {
|
||||
},
|
||||
},
|
||||
},
|
||||
Table: parsers.Table{Value: "c"},
|
||||
Table: parsers.Table{SelectItem: testutils.SelectItem_Path("c")},
|
||||
},
|
||||
mockData,
|
||||
[]memoryexecutor.RowType{
|
||||
@ -429,7 +429,7 @@ func Test_Execute_StringFunctions(t *testing.T) {
|
||||
},
|
||||
},
|
||||
},
|
||||
Table: parsers.Table{Value: "c"},
|
||||
Table: parsers.Table{SelectItem: testutils.SelectItem_Path("c")},
|
||||
},
|
||||
mockData,
|
||||
[]memoryexecutor.RowType{
|
||||
@ -464,7 +464,7 @@ func Test_Execute_StringFunctions(t *testing.T) {
|
||||
},
|
||||
},
|
||||
},
|
||||
Table: parsers.Table{Value: "c"},
|
||||
Table: parsers.Table{SelectItem: testutils.SelectItem_Path("c")},
|
||||
},
|
||||
mockData,
|
||||
[]memoryexecutor.RowType{
|
||||
@ -498,7 +498,7 @@ func Test_Execute_StringFunctions(t *testing.T) {
|
||||
},
|
||||
},
|
||||
},
|
||||
Table: parsers.Table{Value: "c"},
|
||||
Table: parsers.Table{SelectItem: testutils.SelectItem_Path("c")},
|
||||
},
|
||||
mockData,
|
||||
[]memoryexecutor.RowType{
|
||||
@ -533,7 +533,7 @@ func Test_Execute_StringFunctions(t *testing.T) {
|
||||
},
|
||||
},
|
||||
},
|
||||
Table: parsers.Table{Value: "c"},
|
||||
Table: parsers.Table{SelectItem: testutils.SelectItem_Path("c")},
|
||||
},
|
||||
mockData,
|
||||
[]memoryexecutor.RowType{
|
||||
@ -567,7 +567,7 @@ func Test_Execute_StringFunctions(t *testing.T) {
|
||||
},
|
||||
},
|
||||
},
|
||||
Table: parsers.Table{Value: "c"},
|
||||
Table: parsers.Table{SelectItem: testutils.SelectItem_Path("c")},
|
||||
},
|
||||
mockData,
|
||||
[]memoryexecutor.RowType{
|
||||
@ -603,7 +603,7 @@ func Test_Execute_StringFunctions(t *testing.T) {
|
||||
},
|
||||
},
|
||||
},
|
||||
Table: parsers.Table{Value: "c"},
|
||||
Table: parsers.Table{SelectItem: testutils.SelectItem_Path("c")},
|
||||
},
|
||||
mockData,
|
||||
[]memoryexecutor.RowType{
|
||||
@ -637,7 +637,7 @@ func Test_Execute_StringFunctions(t *testing.T) {
|
||||
},
|
||||
},
|
||||
},
|
||||
Table: parsers.Table{Value: "c"},
|
||||
Table: parsers.Table{SelectItem: testutils.SelectItem_Path("c")},
|
||||
},
|
||||
mockData,
|
||||
[]memoryexecutor.RowType{
|
||||
|
@ -5,6 +5,7 @@ import (
|
||||
|
||||
"github.com/pikami/cosmium/parsers"
|
||||
memoryexecutor "github.com/pikami/cosmium/query_executors/memory_executor"
|
||||
testutils "github.com/pikami/cosmium/test_utils"
|
||||
)
|
||||
|
||||
func Test_Execute_SubQuery(t *testing.T) {
|
||||
@ -41,7 +42,7 @@ func Test_Execute_SubQuery(t *testing.T) {
|
||||
Alias: "c",
|
||||
Type: parsers.SelectItemTypeSubQuery,
|
||||
Value: parsers.SelectStmt{
|
||||
Table: parsers.Table{Value: "cc"},
|
||||
Table: parsers.Table{SelectItem: testutils.SelectItem_Path("cc")},
|
||||
SelectItems: []parsers.SelectItem{
|
||||
{Path: []string{"cc", "info"}, IsTopLevel: true},
|
||||
},
|
||||
@ -66,9 +67,7 @@ func Test_Execute_SubQuery(t *testing.T) {
|
||||
{Path: []string{"c", "id"}},
|
||||
{Path: []string{"cc", "name"}},
|
||||
},
|
||||
Table: parsers.Table{
|
||||
Value: "c",
|
||||
},
|
||||
Table: parsers.Table{SelectItem: testutils.SelectItem_Path("c")},
|
||||
JoinItems: []parsers.JoinItem{
|
||||
{
|
||||
Table: parsers.Table{
|
||||
@ -79,13 +78,12 @@ func Test_Execute_SubQuery(t *testing.T) {
|
||||
Type: parsers.SelectItemTypeSubQuery,
|
||||
Value: parsers.SelectStmt{
|
||||
SelectItems: []parsers.SelectItem{
|
||||
{Path: []string{"tag", "name"}},
|
||||
testutils.SelectItem_Path("tag", "name"),
|
||||
},
|
||||
Table: parsers.Table{
|
||||
Value: "tag",
|
||||
SelectItem: parsers.SelectItem{
|
||||
Path: []string{"c", "tags"},
|
||||
},
|
||||
Value: "tag",
|
||||
SelectItem: testutils.SelectItem_Path("c", "tags"),
|
||||
IsInSelect: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
@ -107,10 +105,10 @@ func Test_Execute_SubQuery(t *testing.T) {
|
||||
t,
|
||||
parsers.SelectStmt{
|
||||
SelectItems: []parsers.SelectItem{
|
||||
{Path: []string{"c", "id"}},
|
||||
testutils.SelectItem_Path("c", "id"),
|
||||
},
|
||||
Table: parsers.Table{
|
||||
Value: "c",
|
||||
SelectItem: testutils.SelectItem_Path("c"),
|
||||
},
|
||||
JoinItems: []parsers.JoinItem{
|
||||
{
|
||||
@ -125,13 +123,12 @@ func Test_Execute_SubQuery(t *testing.T) {
|
||||
Type: parsers.SelectItemTypeSubQuery,
|
||||
Value: parsers.SelectStmt{
|
||||
SelectItems: []parsers.SelectItem{
|
||||
{Path: []string{"tag", "name"}},
|
||||
testutils.SelectItem_Path("tag", "name"),
|
||||
},
|
||||
Table: parsers.Table{
|
||||
Value: "tag",
|
||||
SelectItem: parsers.SelectItem{
|
||||
Path: []string{"c", "tags"},
|
||||
},
|
||||
Value: "tag",
|
||||
SelectItem: testutils.SelectItem_Path("c", "tags"),
|
||||
IsInSelect: true,
|
||||
},
|
||||
Exists: true,
|
||||
},
|
||||
|
@ -6,6 +6,7 @@ import (
|
||||
|
||||
"github.com/pikami/cosmium/parsers"
|
||||
memoryexecutor "github.com/pikami/cosmium/query_executors/memory_executor"
|
||||
testutils "github.com/pikami/cosmium/test_utils"
|
||||
)
|
||||
|
||||
func Test_Execute_TypeCheckingFunctions(t *testing.T) {
|
||||
@ -40,7 +41,7 @@ func Test_Execute_TypeCheckingFunctions(t *testing.T) {
|
||||
},
|
||||
},
|
||||
},
|
||||
Table: parsers.Table{Value: "c"},
|
||||
Table: parsers.Table{SelectItem: testutils.SelectItem_Path("c")},
|
||||
},
|
||||
mockData,
|
||||
[]memoryexecutor.RowType{
|
||||
@ -76,7 +77,7 @@ func Test_Execute_TypeCheckingFunctions(t *testing.T) {
|
||||
},
|
||||
},
|
||||
},
|
||||
Table: parsers.Table{Value: "c"},
|
||||
Table: parsers.Table{SelectItem: testutils.SelectItem_Path("c")},
|
||||
},
|
||||
mockData,
|
||||
[]memoryexecutor.RowType{
|
||||
@ -112,7 +113,7 @@ func Test_Execute_TypeCheckingFunctions(t *testing.T) {
|
||||
},
|
||||
},
|
||||
},
|
||||
Table: parsers.Table{Value: "c"},
|
||||
Table: parsers.Table{SelectItem: testutils.SelectItem_Path("c")},
|
||||
},
|
||||
mockData,
|
||||
[]memoryexecutor.RowType{
|
||||
@ -148,7 +149,7 @@ func Test_Execute_TypeCheckingFunctions(t *testing.T) {
|
||||
},
|
||||
},
|
||||
},
|
||||
Table: parsers.Table{Value: "c"},
|
||||
Table: parsers.Table{SelectItem: testutils.SelectItem_Path("c")},
|
||||
},
|
||||
mockData,
|
||||
[]memoryexecutor.RowType{
|
||||
@ -184,7 +185,7 @@ func Test_Execute_TypeCheckingFunctions(t *testing.T) {
|
||||
},
|
||||
},
|
||||
},
|
||||
Table: parsers.Table{Value: "c"},
|
||||
Table: parsers.Table{SelectItem: testutils.SelectItem_Path("c")},
|
||||
},
|
||||
mockData,
|
||||
[]memoryexecutor.RowType{
|
||||
@ -220,7 +221,7 @@ func Test_Execute_TypeCheckingFunctions(t *testing.T) {
|
||||
},
|
||||
},
|
||||
},
|
||||
Table: parsers.Table{Value: "c"},
|
||||
Table: parsers.Table{SelectItem: testutils.SelectItem_Path("c")},
|
||||
},
|
||||
mockData,
|
||||
[]memoryexecutor.RowType{
|
||||
@ -256,7 +257,7 @@ func Test_Execute_TypeCheckingFunctions(t *testing.T) {
|
||||
},
|
||||
},
|
||||
},
|
||||
Table: parsers.Table{Value: "c"},
|
||||
Table: parsers.Table{SelectItem: testutils.SelectItem_Path("c")},
|
||||
},
|
||||
mockData,
|
||||
[]memoryexecutor.RowType{
|
||||
@ -292,7 +293,7 @@ func Test_Execute_TypeCheckingFunctions(t *testing.T) {
|
||||
},
|
||||
},
|
||||
},
|
||||
Table: parsers.Table{Value: "c"},
|
||||
Table: parsers.Table{SelectItem: testutils.SelectItem_Path("c")},
|
||||
},
|
||||
mockData,
|
||||
[]memoryexecutor.RowType{
|
||||
@ -328,7 +329,7 @@ func Test_Execute_TypeCheckingFunctions(t *testing.T) {
|
||||
},
|
||||
},
|
||||
},
|
||||
Table: parsers.Table{Value: "c"},
|
||||
Table: parsers.Table{SelectItem: testutils.SelectItem_Path("c")},
|
||||
},
|
||||
mockData,
|
||||
[]memoryexecutor.RowType{
|
||||
@ -364,7 +365,7 @@ func Test_Execute_TypeCheckingFunctions(t *testing.T) {
|
||||
},
|
||||
},
|
||||
},
|
||||
Table: parsers.Table{Value: "c"},
|
||||
Table: parsers.Table{SelectItem: testutils.SelectItem_Path("c")},
|
||||
},
|
||||
mockData,
|
||||
[]memoryexecutor.RowType{
|
||||
|
@ -23,7 +23,7 @@ func Test_Execute_Where(t *testing.T) {
|
||||
SelectItems: []parsers.SelectItem{
|
||||
{Path: []string{"c", "id"}},
|
||||
},
|
||||
Table: parsers.Table{Value: "c"},
|
||||
Table: parsers.Table{SelectItem: testutils.SelectItem_Path("c")},
|
||||
Filters: parsers.ComparisonExpression{
|
||||
Operation: "=",
|
||||
Left: parsers.SelectItem{Path: []string{"c", "isCool"}},
|
||||
@ -46,7 +46,7 @@ func Test_Execute_Where(t *testing.T) {
|
||||
SelectItems: []parsers.SelectItem{
|
||||
{Path: []string{"c", "id"}},
|
||||
},
|
||||
Table: parsers.Table{Value: "c"},
|
||||
Table: parsers.Table{SelectItem: testutils.SelectItem_Path("c")},
|
||||
Filters: parsers.ComparisonExpression{
|
||||
Operation: "=",
|
||||
Left: parsers.SelectItem{Path: []string{"c", "id"}},
|
||||
@ -71,7 +71,7 @@ func Test_Execute_Where(t *testing.T) {
|
||||
{Path: []string{"c", "id"}},
|
||||
{Path: []string{"c", "_self"}, Alias: "self"},
|
||||
},
|
||||
Table: parsers.Table{Value: "c"},
|
||||
Table: parsers.Table{SelectItem: testutils.SelectItem_Path("c")},
|
||||
Filters: parsers.LogicalExpression{
|
||||
Operation: parsers.LogicalExpressionTypeAnd,
|
||||
Expressions: []interface{}{
|
||||
@ -102,7 +102,7 @@ func Test_Execute_Where(t *testing.T) {
|
||||
SelectItems: []parsers.SelectItem{
|
||||
{Path: []string{"c", "id"}},
|
||||
},
|
||||
Table: parsers.Table{Value: "c"},
|
||||
Table: parsers.Table{SelectItem: testutils.SelectItem_Path("c")},
|
||||
Filters: parsers.LogicalExpression{
|
||||
Operation: parsers.LogicalExpressionTypeAnd,
|
||||
Expressions: []interface{}{
|
||||
|
@ -25,6 +25,7 @@ const (
|
||||
ResponseFailedToParseRequest = 103
|
||||
ResponseServerInstanceAlreadyExists = 104
|
||||
ResponseServerInstanceNotFound = 105
|
||||
ResponseFailedToStartServer = 106
|
||||
|
||||
ResponseRepositoryNotFound = 200
|
||||
ResponseRepositoryConflict = 201
|
||||
|
@ -1,8 +1,12 @@
|
||||
package main
|
||||
|
||||
/*
|
||||
#include <stdlib.h>
|
||||
*/
|
||||
import "C"
|
||||
import (
|
||||
"encoding/json"
|
||||
"unsafe"
|
||||
|
||||
"github.com/pikami/cosmium/api"
|
||||
"github.com/pikami/cosmium/api/config"
|
||||
@ -33,7 +37,10 @@ func CreateServerInstance(serverName *C.char, configurationJSON *C.char) int {
|
||||
})
|
||||
|
||||
server := api.NewApiServer(repository, configuration)
|
||||
server.Start()
|
||||
err = server.Start()
|
||||
if err != nil {
|
||||
return ResponseFailedToStartServer
|
||||
}
|
||||
|
||||
addInstance(serverNameStr, &ServerInstance{
|
||||
server: server,
|
||||
@ -87,4 +94,9 @@ func LoadServerInstanceState(serverName *C.char, stateJSON *C.char) int {
|
||||
return ResponseServerInstanceNotFound
|
||||
}
|
||||
|
||||
//export FreeMemory
|
||||
func FreeMemory(ptr *C.char) {
|
||||
C.free(unsafe.Pointer(ptr))
|
||||
}
|
||||
|
||||
func main() {}
|
||||
|
@ -51,3 +51,9 @@ func SelectItem_Constant_Parameter(name string) parsers.SelectItem {
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func SelectItem_Path(path ...string) parsers.SelectItem {
|
||||
return parsers.SelectItem{
|
||||
Path: path,
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user