mirror of
https://github.com/pikami/cosmium.git
synced 2025-02-08 17:06:45 +00:00
Added support for table alias; Make AS keyword optional #9
This commit is contained in:
parent
e080888c20
commit
8657c48fc8
@ -17,6 +17,7 @@ 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,6 +4,7 @@ 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) {
|
||||||
@ -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"
|
"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) {
|
||||||
@ -17,7 +18,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{Value: "c"},
|
Table: parsers.Table{SelectItem: testutils.SelectItem_Path("c")},
|
||||||
JoinItems: []parsers.JoinItem{
|
JoinItems: []parsers.JoinItem{
|
||||||
{
|
{
|
||||||
Table: parsers.Table{
|
Table: parsers.Table{
|
||||||
@ -40,7 +41,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{Value: "c"},
|
Table: parsers.Table{SelectItem: testutils.SelectItem_Path("c")},
|
||||||
JoinItems: []parsers.JoinItem{
|
JoinItems: []parsers.JoinItem{
|
||||||
{
|
{
|
||||||
Table: parsers.Table{
|
Table: parsers.Table{
|
||||||
|
@ -4,6 +4,7 @@ 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) {
|
||||||
@ -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", "id"}},
|
||||||
{Path: []string{"c", "pk"}},
|
{Path: []string{"c", "pk"}},
|
||||||
},
|
},
|
||||||
Table: parsers.Table{Value: "c"},
|
Table: parsers.Table{SelectItem: testutils.SelectItem_Path("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{Value: "c"},
|
Table: parsers.Table{SelectItem: testutils.SelectItem_Path("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{Value: "c"},
|
Table: parsers.Table{SelectItem: testutils.SelectItem_Path("c")},
|
||||||
Filters: parsers.SelectItem{
|
Filters: parsers.SelectItem{
|
||||||
Type: parsers.SelectItemTypeFunctionCall,
|
Type: parsers.SelectItemTypeFunctionCall,
|
||||||
Value: parsers.FunctionCall{
|
Value: parsers.FunctionCall{
|
||||||
@ -125,9 +125,8 @@ func Test_Parse(t *testing.T) {
|
|||||||
},
|
},
|
||||||
Table: parsers.Table{
|
Table: parsers.Table{
|
||||||
Value: "c",
|
Value: "c",
|
||||||
SelectItem: parsers.SelectItem{
|
SelectItem: testutils.SelectItem_Path("c", "tags"),
|
||||||
Path: []string{"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
|
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)
|
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{
|
||||||
@ -243,13 +251,13 @@ SubQuerySelectItem <- subQuery:SubQuery asClause:(ws alias:AsClause { return ali
|
|||||||
return selectItem, nil
|
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)
|
return makeJoin(table, column)
|
||||||
} / Join ws subQuery:SubQuerySelectItem {
|
} / Join ws subQuery:SubQuerySelectItem {
|
||||||
return makeJoin(nil, subQuery)
|
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
|
return []interface{}{offset.(parsers.Constant).Value, limit.(parsers.Constant).Value}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -317,7 +325,11 @@ SelectItem <- selectItem:(SubQuerySelectItem / Literal / FunctionCall / SelectAr
|
|||||||
return itemResult, nil
|
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 {
|
DotFieldAccess <- "." id:Identifier {
|
||||||
return id, nil
|
return id, nil
|
||||||
@ -373,6 +385,8 @@ As <- "AS"i
|
|||||||
|
|
||||||
From <- "FROM"i
|
From <- "FROM"i
|
||||||
|
|
||||||
|
In <- "IN"i
|
||||||
|
|
||||||
Join <- "JOIN"i
|
Join <- "JOIN"i
|
||||||
|
|
||||||
Exists <- "EXISTS"i
|
Exists <- "EXISTS"i
|
||||||
@ -387,6 +401,8 @@ 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
|
||||||
}
|
}
|
||||||
@ -700,7 +716,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"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{})...))
|
return createFunctionCall(parsers.FunctionCallIn, append([]interface{}{ex1, ex2}, others.([]interface{})...))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4,6 +4,7 @@ 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) {
|
||||||
@ -17,7 +18,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{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", "id"}},
|
||||||
{Path: []string{"c", "@param"}},
|
{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{
|
SelectItems: []parsers.SelectItem{
|
||||||
{Path: []string{"c", "id"}},
|
{Path: []string{"c", "id"}},
|
||||||
},
|
},
|
||||||
Table: parsers.Table{Value: "c"},
|
Table: parsers.Table{SelectItem: testutils.SelectItem_Path("c")},
|
||||||
Distinct: true,
|
Distinct: true,
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
@ -58,7 +59,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{Value: "c"},
|
Table: parsers.Table{SelectItem: testutils.SelectItem_Path("c")},
|
||||||
Count: 1,
|
Count: 1,
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
@ -72,7 +73,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{Value: "c"},
|
Table: parsers.Table{SelectItem: testutils.SelectItem_Path("c")},
|
||||||
Count: 5,
|
Count: 5,
|
||||||
Offset: 3,
|
Offset: 3,
|
||||||
},
|
},
|
||||||
@ -87,7 +88,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{Value: "c"},
|
Table: parsers.Table{SelectItem: testutils.SelectItem_Path("c")},
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
@ -100,7 +101,20 @@ 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{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"
|
"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) {
|
||||||
@ -22,7 +23,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{Value: "cc"},
|
Table: parsers.Table{SelectItem: testutils.SelectItem_Path("cc")},
|
||||||
SelectItems: []parsers.SelectItem{
|
SelectItems: []parsers.SelectItem{
|
||||||
{Path: []string{"cc", "info"}, IsTopLevel: true},
|
{Path: []string{"cc", "info"}, IsTopLevel: true},
|
||||||
},
|
},
|
||||||
@ -42,9 +43,7 @@ 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{
|
Table: parsers.Table{SelectItem: testutils.SelectItem_Path("c")},
|
||||||
Value: "c",
|
|
||||||
},
|
|
||||||
JoinItems: []parsers.JoinItem{
|
JoinItems: []parsers.JoinItem{
|
||||||
{
|
{
|
||||||
Table: parsers.Table{
|
Table: parsers.Table{
|
||||||
@ -55,13 +54,12 @@ 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{
|
||||||
{Path: []string{"tag", "name"}},
|
testutils.SelectItem_Path("tag", "name"),
|
||||||
},
|
},
|
||||||
Table: parsers.Table{
|
Table: parsers.Table{
|
||||||
Value: "tag",
|
Value: "tag",
|
||||||
SelectItem: parsers.SelectItem{
|
SelectItem: testutils.SelectItem_Path("c", "tags"),
|
||||||
Path: []string{"c", "tags"},
|
IsInSelect: true,
|
||||||
},
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -82,10 +80,10 @@ func Test_Parse_SubQuery(t *testing.T) {
|
|||||||
WHERE hasTags`,
|
WHERE hasTags`,
|
||||||
parsers.SelectStmt{
|
parsers.SelectStmt{
|
||||||
SelectItems: []parsers.SelectItem{
|
SelectItems: []parsers.SelectItem{
|
||||||
{Path: []string{"c", "id"}},
|
testutils.SelectItem_Path("c", "id"),
|
||||||
},
|
},
|
||||||
Table: parsers.Table{
|
Table: parsers.Table{
|
||||||
Value: "c",
|
SelectItem: testutils.SelectItem_Path("c"),
|
||||||
},
|
},
|
||||||
JoinItems: []parsers.JoinItem{
|
JoinItems: []parsers.JoinItem{
|
||||||
{
|
{
|
||||||
@ -100,13 +98,12 @@ 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{
|
||||||
{Path: []string{"tag", "name"}},
|
testutils.SelectItem_Path("tag", "name"),
|
||||||
},
|
},
|
||||||
Table: parsers.Table{
|
Table: parsers.Table{
|
||||||
Value: "tag",
|
Value: "tag",
|
||||||
SelectItem: parsers.SelectItem{
|
SelectItem: testutils.SelectItem_Path("c", "tags"),
|
||||||
Path: []string{"c", "tags"},
|
IsInSelect: true,
|
||||||
},
|
|
||||||
},
|
},
|
||||||
Exists: true,
|
Exists: true,
|
||||||
},
|
},
|
||||||
|
@ -4,6 +4,7 @@ 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) {
|
||||||
@ -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{
|
Filters: parsers.SelectItem{
|
||||||
Type: parsers.SelectItemTypeFunctionCall,
|
Type: parsers.SelectItemTypeFunctionCall,
|
||||||
Value: parsers.FunctionCall{
|
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{
|
Filters: parsers.SelectItem{
|
||||||
Type: parsers.SelectItemTypeFunctionCall,
|
Type: parsers.SelectItemTypeFunctionCall,
|
||||||
Value: parsers.FunctionCall{
|
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{
|
Filters: parsers.SelectItem{
|
||||||
Type: parsers.SelectItemTypeFunctionCall,
|
Type: parsers.SelectItemTypeFunctionCall,
|
||||||
Value: parsers.FunctionCall{
|
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{
|
Filters: parsers.SelectItem{
|
||||||
Type: parsers.SelectItemTypeFunctionCall,
|
Type: parsers.SelectItemTypeFunctionCall,
|
||||||
Value: parsers.FunctionCall{
|
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{
|
Filters: parsers.SelectItem{
|
||||||
Type: parsers.SelectItemTypeFunctionCall,
|
Type: parsers.SelectItemTypeFunctionCall,
|
||||||
Value: parsers.FunctionCall{
|
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{
|
Filters: parsers.SelectItem{
|
||||||
Type: parsers.SelectItemTypeFunctionCall,
|
Type: parsers.SelectItemTypeFunctionCall,
|
||||||
Value: parsers.FunctionCall{
|
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{
|
Filters: parsers.SelectItem{
|
||||||
Type: parsers.SelectItemTypeFunctionCall,
|
Type: parsers.SelectItemTypeFunctionCall,
|
||||||
Value: parsers.FunctionCall{
|
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{
|
Filters: parsers.SelectItem{
|
||||||
Type: parsers.SelectItemTypeFunctionCall,
|
Type: parsers.SelectItemTypeFunctionCall,
|
||||||
Value: parsers.FunctionCall{
|
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{
|
Filters: parsers.SelectItem{
|
||||||
Type: parsers.SelectItemTypeFunctionCall,
|
Type: parsers.SelectItemTypeFunctionCall,
|
||||||
Value: parsers.FunctionCall{
|
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{
|
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{Value: "c"},
|
Table: parsers.Table{SelectItem: testutils.SelectItem_Path("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{Value: "c"},
|
Table: parsers.Table{SelectItem: testutils.SelectItem_Path("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{Value: "c"},
|
Table: parsers.Table{SelectItem: testutils.SelectItem_Path("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{Value: "c"},
|
Table: parsers.Table{SelectItem: testutils.SelectItem_Path("c")},
|
||||||
Filters: parsers.LogicalExpression{
|
Filters: parsers.LogicalExpression{
|
||||||
Expressions: []interface{}{
|
Expressions: []interface{}{
|
||||||
parsers.ComparisonExpression{
|
parsers.ComparisonExpression{
|
||||||
|
@ -5,6 +5,7 @@ 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) {
|
||||||
@ -38,7 +39,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{Value: "c"},
|
Table: parsers.Table{SelectItem: testutils.SelectItem_Path("c")},
|
||||||
},
|
},
|
||||||
mockData,
|
mockData,
|
||||||
[]memoryexecutor.RowType{
|
[]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,
|
mockData,
|
||||||
[]memoryexecutor.RowType{
|
[]memoryexecutor.RowType{
|
||||||
@ -99,7 +100,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{Value: "c"},
|
Table: parsers.Table{SelectItem: testutils.SelectItem_Path("c")},
|
||||||
},
|
},
|
||||||
mockData,
|
mockData,
|
||||||
[]memoryexecutor.RowType{
|
[]memoryexecutor.RowType{
|
||||||
@ -132,7 +133,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{Value: "c"},
|
Table: parsers.Table{SelectItem: testutils.SelectItem_Path("c")},
|
||||||
},
|
},
|
||||||
mockData,
|
mockData,
|
||||||
[]memoryexecutor.RowType{
|
[]memoryexecutor.RowType{
|
||||||
@ -165,7 +166,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{Value: "c"},
|
Table: parsers.Table{SelectItem: testutils.SelectItem_Path("c")},
|
||||||
},
|
},
|
||||||
mockData,
|
mockData,
|
||||||
[]memoryexecutor.RowType{
|
[]memoryexecutor.RowType{
|
||||||
@ -198,7 +199,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{Value: "c"},
|
Table: parsers.Table{SelectItem: testutils.SelectItem_Path("c")},
|
||||||
},
|
},
|
||||||
mockData,
|
mockData,
|
||||||
[]memoryexecutor.RowType{
|
[]memoryexecutor.RowType{
|
||||||
|
@ -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,
|
mockData,
|
||||||
[]memoryexecutor.RowType{
|
[]memoryexecutor.RowType{
|
||||||
@ -356,7 +356,7 @@ func Test_Execute_ArrayFunctions(t *testing.T) {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Table: parsers.Table{Value: "c"},
|
Table: parsers.Table{SelectItem: testutils.SelectItem_Path("c")},
|
||||||
},
|
},
|
||||||
mockData,
|
mockData,
|
||||||
[]memoryexecutor.RowType{
|
[]memoryexecutor.RowType{
|
||||||
@ -392,7 +392,7 @@ func Test_Execute_ArrayFunctions(t *testing.T) {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Table: parsers.Table{Value: "c"},
|
Table: parsers.Table{SelectItem: testutils.SelectItem_Path("c")},
|
||||||
},
|
},
|
||||||
mockData,
|
mockData,
|
||||||
[]memoryexecutor.RowType{
|
[]memoryexecutor.RowType{
|
||||||
@ -430,7 +430,7 @@ func Test_Execute_ArrayFunctions(t *testing.T) {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Table: parsers.Table{Value: "c"},
|
Table: parsers.Table{SelectItem: testutils.SelectItem_Path("c")},
|
||||||
},
|
},
|
||||||
mockData,
|
mockData,
|
||||||
[]memoryexecutor.RowType{
|
[]memoryexecutor.RowType{
|
||||||
@ -468,7 +468,7 @@ func Test_Execute_ArrayFunctions(t *testing.T) {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Table: parsers.Table{Value: "c"},
|
Table: parsers.Table{SelectItem: testutils.SelectItem_Path("c")},
|
||||||
},
|
},
|
||||||
mockData,
|
mockData,
|
||||||
[]memoryexecutor.RowType{
|
[]memoryexecutor.RowType{
|
||||||
|
@ -5,6 +5,7 @@ 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) {
|
||||||
@ -33,7 +34,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{Value: "c"},
|
Table: parsers.Table{SelectItem: testutils.SelectItem_Path("c")},
|
||||||
JoinItems: []parsers.JoinItem{
|
JoinItems: []parsers.JoinItem{
|
||||||
{
|
{
|
||||||
Table: parsers.Table{
|
Table: parsers.Table{
|
||||||
@ -62,7 +63,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{Value: "c"},
|
Table: parsers.Table{SelectItem: testutils.SelectItem_Path("c")},
|
||||||
JoinItems: []parsers.JoinItem{
|
JoinItems: []parsers.JoinItem{
|
||||||
{
|
{
|
||||||
Table: parsers.Table{
|
Table: parsers.Table{
|
||||||
|
@ -6,6 +6,7 @@ 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) {
|
||||||
@ -261,7 +262,7 @@ func testMathFunctionExecute(
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
Table: parsers.Table{Value: "c"},
|
Table: parsers.Table{SelectItem: testutils.SelectItem_Path("c")},
|
||||||
},
|
},
|
||||||
data,
|
data,
|
||||||
expectedData,
|
expectedData,
|
||||||
|
@ -80,10 +80,15 @@ 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,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -93,7 +98,11 @@ 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 {
|
||||||
@ -104,6 +113,20 @@ 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}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -310,18 +333,7 @@ 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 := selectItem.Alias
|
destinationName := resolveDestinationColumnName(selectItem, index, r.parameters)
|
||||||
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)
|
||||||
}
|
}
|
||||||
@ -329,6 +341,23 @@ 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{Value: "c"},
|
Table: parsers.Table{SelectItem: testutils.SelectItem_Path("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{Value: "c"},
|
Table: parsers.Table{SelectItem: testutils.SelectItem_Path("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{Value: "c"},
|
Table: parsers.Table{SelectItem: testutils.SelectItem_Path("c")},
|
||||||
Filters: parsers.SelectItem{
|
Filters: parsers.SelectItem{
|
||||||
Type: parsers.SelectItemTypeFunctionCall,
|
Type: parsers.SelectItemTypeFunctionCall,
|
||||||
Value: parsers.FunctionCall{
|
Value: parsers.FunctionCall{
|
||||||
@ -138,9 +138,8 @@ func Test_Execute(t *testing.T) {
|
|||||||
},
|
},
|
||||||
Table: parsers.Table{
|
Table: parsers.Table{
|
||||||
Value: "c",
|
Value: "c",
|
||||||
SelectItem: parsers.SelectItem{
|
SelectItem: testutils.SelectItem_Path("c", "tags"),
|
||||||
Path: []string{"c", "tags"},
|
IsInSelect: true,
|
||||||
},
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
mockData,
|
mockData,
|
||||||
|
@ -5,6 +5,7 @@ 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) {
|
||||||
@ -23,7 +24,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{Value: "c"},
|
Table: parsers.Table{SelectItem: testutils.SelectItem_Path("c")},
|
||||||
},
|
},
|
||||||
mockData,
|
mockData,
|
||||||
[]memoryexecutor.RowType{
|
[]memoryexecutor.RowType{
|
||||||
@ -43,7 +44,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{Value: "c"},
|
Table: parsers.Table{SelectItem: testutils.SelectItem_Path("c")},
|
||||||
Parameters: map[string]interface{}{
|
Parameters: map[string]interface{}{
|
||||||
"@param": "pk",
|
"@param": "pk",
|
||||||
},
|
},
|
||||||
@ -65,7 +66,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{Value: "c"},
|
Table: parsers.Table{SelectItem: testutils.SelectItem_Path("c")},
|
||||||
Distinct: true,
|
Distinct: true,
|
||||||
},
|
},
|
||||||
mockData,
|
mockData,
|
||||||
@ -84,7 +85,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{Value: "c"},
|
Table: parsers.Table{SelectItem: testutils.SelectItem_Path("c")},
|
||||||
Count: 1,
|
Count: 1,
|
||||||
},
|
},
|
||||||
mockData,
|
mockData,
|
||||||
@ -102,7 +103,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{Value: "c"},
|
Table: parsers.Table{SelectItem: testutils.SelectItem_Path("c")},
|
||||||
Count: 2,
|
Count: 2,
|
||||||
Offset: 1,
|
Offset: 1,
|
||||||
OrderExpressions: []parsers.OrderExpression{
|
OrderExpressions: []parsers.OrderExpression{
|
||||||
@ -127,7 +128,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{Value: "c"},
|
Table: parsers.Table{SelectItem: testutils.SelectItem_Path("c")},
|
||||||
},
|
},
|
||||||
mockData,
|
mockData,
|
||||||
[]memoryexecutor.RowType{
|
[]memoryexecutor.RowType{
|
||||||
@ -146,7 +147,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{Value: "c"},
|
Table: parsers.Table{SelectItem: testutils.SelectItem_Path("c")},
|
||||||
},
|
},
|
||||||
mockData,
|
mockData,
|
||||||
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,
|
mockData,
|
||||||
[]memoryexecutor.RowType{
|
[]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,
|
mockData,
|
||||||
[]memoryexecutor.RowType{
|
[]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,
|
mockData,
|
||||||
[]memoryexecutor.RowType{
|
[]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,
|
mockData,
|
||||||
[]memoryexecutor.RowType{
|
[]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,
|
mockData,
|
||||||
[]memoryexecutor.RowType{
|
[]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,
|
mockData,
|
||||||
[]memoryexecutor.RowType{
|
[]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,
|
mockData,
|
||||||
[]memoryexecutor.RowType{
|
[]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,
|
mockData,
|
||||||
[]memoryexecutor.RowType{
|
[]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,
|
mockData,
|
||||||
[]memoryexecutor.RowType{
|
[]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,
|
mockData,
|
||||||
[]memoryexecutor.RowType{
|
[]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,
|
mockData,
|
||||||
[]memoryexecutor.RowType{
|
[]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,
|
mockData,
|
||||||
[]memoryexecutor.RowType{
|
[]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,
|
mockData,
|
||||||
[]memoryexecutor.RowType{
|
[]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,
|
mockData,
|
||||||
[]memoryexecutor.RowType{
|
[]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,
|
mockData,
|
||||||
[]memoryexecutor.RowType{
|
[]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,
|
mockData,
|
||||||
[]memoryexecutor.RowType{
|
[]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,
|
mockData,
|
||||||
[]memoryexecutor.RowType{
|
[]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,
|
mockData,
|
||||||
[]memoryexecutor.RowType{
|
[]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,
|
mockData,
|
||||||
[]memoryexecutor.RowType{
|
[]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,
|
mockData,
|
||||||
[]memoryexecutor.RowType{
|
[]memoryexecutor.RowType{
|
||||||
|
@ -5,6 +5,7 @@ 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) {
|
||||||
@ -41,7 +42,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{Value: "cc"},
|
Table: parsers.Table{SelectItem: testutils.SelectItem_Path("cc")},
|
||||||
SelectItems: []parsers.SelectItem{
|
SelectItems: []parsers.SelectItem{
|
||||||
{Path: []string{"cc", "info"}, IsTopLevel: true},
|
{Path: []string{"cc", "info"}, IsTopLevel: true},
|
||||||
},
|
},
|
||||||
@ -66,9 +67,7 @@ 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{
|
Table: parsers.Table{SelectItem: testutils.SelectItem_Path("c")},
|
||||||
Value: "c",
|
|
||||||
},
|
|
||||||
JoinItems: []parsers.JoinItem{
|
JoinItems: []parsers.JoinItem{
|
||||||
{
|
{
|
||||||
Table: parsers.Table{
|
Table: parsers.Table{
|
||||||
@ -79,13 +78,12 @@ 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{
|
||||||
{Path: []string{"tag", "name"}},
|
testutils.SelectItem_Path("tag", "name"),
|
||||||
},
|
},
|
||||||
Table: parsers.Table{
|
Table: parsers.Table{
|
||||||
Value: "tag",
|
Value: "tag",
|
||||||
SelectItem: parsers.SelectItem{
|
SelectItem: testutils.SelectItem_Path("c", "tags"),
|
||||||
Path: []string{"c", "tags"},
|
IsInSelect: true,
|
||||||
},
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
@ -107,10 +105,10 @@ func Test_Execute_SubQuery(t *testing.T) {
|
|||||||
t,
|
t,
|
||||||
parsers.SelectStmt{
|
parsers.SelectStmt{
|
||||||
SelectItems: []parsers.SelectItem{
|
SelectItems: []parsers.SelectItem{
|
||||||
{Path: []string{"c", "id"}},
|
testutils.SelectItem_Path("c", "id"),
|
||||||
},
|
},
|
||||||
Table: parsers.Table{
|
Table: parsers.Table{
|
||||||
Value: "c",
|
SelectItem: testutils.SelectItem_Path("c"),
|
||||||
},
|
},
|
||||||
JoinItems: []parsers.JoinItem{
|
JoinItems: []parsers.JoinItem{
|
||||||
{
|
{
|
||||||
@ -125,13 +123,12 @@ 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{
|
||||||
{Path: []string{"tag", "name"}},
|
testutils.SelectItem_Path("tag", "name"),
|
||||||
},
|
},
|
||||||
Table: parsers.Table{
|
Table: parsers.Table{
|
||||||
Value: "tag",
|
Value: "tag",
|
||||||
SelectItem: parsers.SelectItem{
|
SelectItem: testutils.SelectItem_Path("c", "tags"),
|
||||||
Path: []string{"c", "tags"},
|
IsInSelect: true,
|
||||||
},
|
|
||||||
},
|
},
|
||||||
Exists: true,
|
Exists: true,
|
||||||
},
|
},
|
||||||
|
@ -6,6 +6,7 @@ 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) {
|
||||||
@ -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,
|
mockData,
|
||||||
[]memoryexecutor.RowType{
|
[]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,
|
mockData,
|
||||||
[]memoryexecutor.RowType{
|
[]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,
|
mockData,
|
||||||
[]memoryexecutor.RowType{
|
[]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,
|
mockData,
|
||||||
[]memoryexecutor.RowType{
|
[]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,
|
mockData,
|
||||||
[]memoryexecutor.RowType{
|
[]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,
|
mockData,
|
||||||
[]memoryexecutor.RowType{
|
[]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,
|
mockData,
|
||||||
[]memoryexecutor.RowType{
|
[]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,
|
mockData,
|
||||||
[]memoryexecutor.RowType{
|
[]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,
|
mockData,
|
||||||
[]memoryexecutor.RowType{
|
[]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,
|
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{Value: "c"},
|
Table: parsers.Table{SelectItem: testutils.SelectItem_Path("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{Value: "c"},
|
Table: parsers.Table{SelectItem: testutils.SelectItem_Path("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{Value: "c"},
|
Table: parsers.Table{SelectItem: testutils.SelectItem_Path("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{Value: "c"},
|
Table: parsers.Table{SelectItem: testutils.SelectItem_Path("c")},
|
||||||
Filters: parsers.LogicalExpression{
|
Filters: parsers.LogicalExpression{
|
||||||
Operation: parsers.LogicalExpressionTypeAnd,
|
Operation: parsers.LogicalExpressionTypeAnd,
|
||||||
Expressions: []interface{}{
|
Expressions: []interface{}{
|
||||||
|
@ -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