Added support for array selects

This commit is contained in:
Pijus Kamandulis
2024-02-13 21:57:33 +02:00
parent e89f2e5611
commit 5d2b21dc46
7 changed files with 513 additions and 295 deletions

View File

@@ -84,6 +84,14 @@ func evaluateFilters(expr ExpressionType, row RowType) bool {
}
func getFieldValue(field parsers.SelectItem, row RowType) interface{} {
if field.Type == parsers.SelectItemTypeArray {
arrayValue := make([]interface{}, 0)
for _, selectItem := range field.SelectItems {
arrayValue = append(arrayValue, getFieldValue(selectItem, row))
}
return arrayValue
}
value := row
for _, pathSegment := range field.Path[1:] {
if nestedValue, ok := value.(map[string]interface{}); ok {

View File

@@ -62,6 +62,30 @@ func Test_Execute(t *testing.T) {
)
})
t.Run("Should execute SELECT array", func(t *testing.T) {
testQueryExecute(
t,
parsers.SelectStmt{
SelectItems: []parsers.SelectItem{
{
Alias: "arr",
Type: parsers.SelectItemTypeArray,
SelectItems: []parsers.SelectItem{
{Path: []string{"c", "id"}},
{Path: []string{"c", "pk"}},
},
},
},
Table: parsers.Table{Value: "c"},
},
mockData,
[]memoryexecutor.RowType{
map[string]interface{}{"arr": []interface{}{"12345", 123}},
map[string]interface{}{"arr": []interface{}{"67890", 456}},
},
)
})
t.Run("Should execute SELECT with single WHERE condition", func(t *testing.T) {
testQueryExecute(
t,