mirror of https://github.com/pikami/cosmium.git
Implement UPPER/LOWER; minor Fixes
This commit is contained in:
parent
f37c664c1a
commit
f356f26d26
1
go.mod
1
go.mod
|
@ -6,6 +6,7 @@ require (
|
|||
github.com/Azure/azure-sdk-for-go/sdk/azcore v1.9.2
|
||||
github.com/Azure/azure-sdk-for-go/sdk/data/azcosmos v0.3.6
|
||||
github.com/gin-gonic/gin v1.9.1
|
||||
github.com/google/uuid v1.1.1
|
||||
github.com/stretchr/testify v1.8.4
|
||||
)
|
||||
|
||||
|
|
|
@ -1,14 +1,15 @@
|
|||
package repositories
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/google/uuid"
|
||||
repositorymodels "github.com/pikami/cosmium/internal/repository_models"
|
||||
structhidrators "github.com/pikami/cosmium/internal/struct_hidrators"
|
||||
)
|
||||
|
||||
var collections = []repositorymodels.Collection{
|
||||
{ID: "db1"},
|
||||
{ID: "db2"},
|
||||
}
|
||||
var collections = []repositorymodels.Collection{}
|
||||
|
||||
func GetAllCollections(databaseId string) ([]repositorymodels.Collection, repositorymodels.RepositoryStatus) {
|
||||
dbCollections := make([]repositorymodels.Collection, 0)
|
||||
|
@ -52,6 +53,9 @@ func CreateCollection(databaseId string, newCollection repositorymodels.Collecti
|
|||
|
||||
newCollection = structhidrators.Hidrate(newCollection).(repositorymodels.Collection)
|
||||
|
||||
newCollection.TimeStamp = time.Now().Unix()
|
||||
newCollection.UniqueID = uuid.New().String()
|
||||
newCollection.ETag = fmt.Sprintf("\"%s\"", newCollection.UniqueID)
|
||||
newCollection.Internals = struct{ DatabaseId string }{
|
||||
DatabaseId: databaseId,
|
||||
}
|
||||
|
|
|
@ -1,6 +1,12 @@
|
|||
package repositories
|
||||
|
||||
import repositorymodels "github.com/pikami/cosmium/internal/repository_models"
|
||||
import (
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/google/uuid"
|
||||
repositorymodels "github.com/pikami/cosmium/internal/repository_models"
|
||||
)
|
||||
|
||||
var databases = []repositorymodels.Database{
|
||||
{ID: "db1"},
|
||||
|
@ -39,6 +45,9 @@ func CreateDatabase(newDatabase repositorymodels.Database) repositorymodels.Repo
|
|||
}
|
||||
}
|
||||
|
||||
newDatabase.TimeStamp = time.Now().Unix()
|
||||
newDatabase.UniqueID = uuid.New().String()
|
||||
newDatabase.ETag = fmt.Sprintf("\"%s\"", newDatabase.UniqueID)
|
||||
databases = append(databases, newDatabase)
|
||||
return repositorymodels.StatusOk
|
||||
}
|
||||
|
|
|
@ -1,9 +1,12 @@
|
|||
package repositories
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"log"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/google/uuid"
|
||||
repositorymodels "github.com/pikami/cosmium/internal/repository_models"
|
||||
"github.com/pikami/cosmium/parsers"
|
||||
"github.com/pikami/cosmium/parsers/nosql"
|
||||
|
@ -93,6 +96,9 @@ func CreateDocument(databaseId string, collectionId string, document map[string]
|
|||
partitionKeyValue = append(partitionKeyValue, val.(string))
|
||||
}
|
||||
|
||||
document["_ts"] = time.Now().Unix()
|
||||
document["_rid"] = uuid.New().String()
|
||||
document["_etag"] = fmt.Sprintf("\"%s\"", document["_rid"])
|
||||
document["_internal"] = map[string]interface{}{
|
||||
"databaseId": databaseId,
|
||||
"collectionId": collectionId,
|
||||
|
|
|
@ -1,7 +1,10 @@
|
|||
package repositorymodels
|
||||
|
||||
type Database struct {
|
||||
ID string `json:"id"`
|
||||
ID string `json:"id"`
|
||||
TimeStamp int64 `json:"_ts"`
|
||||
UniqueID string `json:"_rid"`
|
||||
ETag string `json:"_etag"`
|
||||
}
|
||||
|
||||
type RepositoryStatus int
|
||||
|
@ -17,10 +20,10 @@ type Collection struct {
|
|||
ID string `json:"id"`
|
||||
IndexingPolicy CollectionIndexingPolicy `json:"indexingPolicy"`
|
||||
PartitionKey CollectionPartitionKey `json:"partitionKey"`
|
||||
Rid string `json:"_rid"`
|
||||
Ts int `json:"_ts"`
|
||||
UniqueID string `json:"_rid"`
|
||||
TimeStamp int64 `json:"_ts"`
|
||||
Self string `json:"_self"`
|
||||
Etag string `json:"_etag"`
|
||||
ETag string `json:"_etag"`
|
||||
Docs string `json:"_docs"`
|
||||
Sprocs string `json:"_sprocs"`
|
||||
Triggers string `json:"_triggers"`
|
||||
|
|
|
@ -20,10 +20,10 @@ var defaultCollection repositorymodels.Collection = repositorymodels.Collection{
|
|||
Kind: "Hash",
|
||||
Version: 2,
|
||||
},
|
||||
Rid: "nFFFFFFFFFF=",
|
||||
Ts: 0,
|
||||
UniqueID: "nFFFFFFFFFF=",
|
||||
TimeStamp: 0,
|
||||
Self: "",
|
||||
Etag: "\"00000000-0000-0000-0000-000000000000\"",
|
||||
ETag: "\"00000000-0000-0000-0000-000000000000\"",
|
||||
Docs: "docs/",
|
||||
Sprocs: "sprocs/",
|
||||
Triggers: "triggers/",
|
||||
|
|
|
@ -89,6 +89,8 @@ const (
|
|||
FunctionCallIndexOf FunctionCallType = "IndexOf"
|
||||
FunctionCallToString FunctionCallType = "ToString"
|
||||
FunctionCallIn FunctionCallType = "In"
|
||||
FunctionCallUpper FunctionCallType = "Upper"
|
||||
FunctionCallLower FunctionCallType = "Lower"
|
||||
)
|
||||
|
||||
type FunctionCall struct {
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -312,6 +312,16 @@ StringFunctions <- StringEqualsExpression
|
|||
/ ToStringExpression
|
||||
/ ConcatExpression
|
||||
/ ThreeArgumentStringFunctionExpression
|
||||
/ UpperExpression
|
||||
/ LowerExpression
|
||||
|
||||
UpperExpression <- "UPPER"i ws "(" ex:SelectItem ")" {
|
||||
return parsers.FunctionCall{Type: parsers.FunctionCallUpper, Arguments: []interface{}{ex}}, nil
|
||||
}
|
||||
|
||||
LowerExpression <- "LOWER"i ws "(" ex:SelectItem ")" {
|
||||
return parsers.FunctionCall{Type: parsers.FunctionCallLower, Arguments: []interface{}{ex}}, nil
|
||||
}
|
||||
|
||||
StringEqualsExpression <- StringEquals ws "(" ws ex1:SelectItem ws "," ws ex2:SelectItem ws ignoreCase:("," ws boolean:SelectItem { return boolean, nil })? ")" {
|
||||
return parsers.FunctionCall{Type: parsers.FunctionCallStringEquals, Arguments: []interface{}{ex1, ex2, ignoreCase}}, nil
|
||||
|
|
|
@ -288,4 +288,52 @@ func Test_Execute_StringFunctions(t *testing.T) {
|
|||
},
|
||||
)
|
||||
})
|
||||
|
||||
t.Run("Should parse function UPPER()", func(t *testing.T) {
|
||||
testQueryParse(
|
||||
t,
|
||||
`SELECT UPPER(c.id) FROM c`,
|
||||
parsers.SelectStmt{
|
||||
SelectItems: []parsers.SelectItem{
|
||||
{
|
||||
Type: parsers.SelectItemTypeFunctionCall,
|
||||
Value: parsers.FunctionCall{
|
||||
Type: parsers.FunctionCallUpper,
|
||||
Arguments: []interface{}{
|
||||
parsers.SelectItem{
|
||||
Path: []string{"c", "id"},
|
||||
Type: parsers.SelectItemTypeField,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
Table: parsers.Table{Value: "c"},
|
||||
},
|
||||
)
|
||||
})
|
||||
|
||||
t.Run("Should parse function LOWER()", func(t *testing.T) {
|
||||
testQueryParse(
|
||||
t,
|
||||
`SELECT LOWER(c.id) FROM c`,
|
||||
parsers.SelectStmt{
|
||||
SelectItems: []parsers.SelectItem{
|
||||
{
|
||||
Type: parsers.SelectItemTypeFunctionCall,
|
||||
Value: parsers.FunctionCall{
|
||||
Type: parsers.FunctionCallLower,
|
||||
Arguments: []interface{}{
|
||||
parsers.SelectItem{
|
||||
Path: []string{"c", "id"},
|
||||
Type: parsers.SelectItemTypeField,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
Table: parsers.Table{Value: "c"},
|
||||
},
|
||||
)
|
||||
})
|
||||
}
|
||||
|
|
|
@ -190,6 +190,10 @@ func getFieldValue(field parsers.SelectItem, queryParameters map[string]interfac
|
|||
return strings_IndexOf(typedValue.Arguments, queryParameters, row)
|
||||
case parsers.FunctionCallToString:
|
||||
return strings_ToString(typedValue.Arguments, queryParameters, row)
|
||||
case parsers.FunctionCallUpper:
|
||||
return strings_Upper(typedValue.Arguments, queryParameters, row)
|
||||
case parsers.FunctionCallLower:
|
||||
return strings_Lower(typedValue.Arguments, queryParameters, row)
|
||||
case parsers.FunctionCallIsDefined:
|
||||
return typeChecking_IsDefined(typedValue.Arguments, queryParameters, row)
|
||||
case parsers.FunctionCallIn:
|
||||
|
|
|
@ -101,6 +101,16 @@ func strings_ToString(arguments []interface{}, queryParameters map[string]interf
|
|||
return convertToString(value)
|
||||
}
|
||||
|
||||
func strings_Upper(arguments []interface{}, queryParameters map[string]interface{}, row RowType) string {
|
||||
value := getFieldValue(arguments[0].(parsers.SelectItem), queryParameters, row)
|
||||
return strings.ToUpper(convertToString(value))
|
||||
}
|
||||
|
||||
func strings_Lower(arguments []interface{}, queryParameters map[string]interface{}, row RowType) string {
|
||||
value := getFieldValue(arguments[0].(parsers.SelectItem), queryParameters, row)
|
||||
return strings.ToLower(convertToString(value))
|
||||
}
|
||||
|
||||
func getBoolFlag(arguments []interface{}, queryParameters map[string]interface{}, row RowType) bool {
|
||||
ignoreCase := false
|
||||
if len(arguments) > 2 && arguments[2] != nil {
|
||||
|
@ -117,10 +127,10 @@ func parseString(argument interface{}, queryParameters map[string]interface{}, r
|
|||
exItem := argument.(parsers.SelectItem)
|
||||
ex := getFieldValue(exItem, queryParameters, row)
|
||||
if str1, ok := ex.(string); ok {
|
||||
fmt.Println("StringEquals got parameters of wrong type")
|
||||
return str1
|
||||
}
|
||||
|
||||
fmt.Println("StringEquals got parameters of wrong type")
|
||||
return ""
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue