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