Skip to content

Commit

Permalink
change native queries to collection
Browse files Browse the repository at this point in the history
  • Loading branch information
hgiasac committed Oct 11, 2024
1 parent 7e677c7 commit 49b26b4
Show file tree
Hide file tree
Showing 13 changed files with 599 additions and 612 deletions.
5 changes: 3 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,11 @@ ci-build-configuration: clean

.PHONY: build-supergraph-test
build-supergraph-test:
docker compose up -d --build
cd tests/engine && \
ddn connector-link update prometheus --add-all-resources --subgraph ./app/subgraph.yaml && \
ddn supergraph build local && \
docker compose up -d --build engine
ddn supergraph build local
docker compose up -d --build engine

.PHONY: generate-api-types
generate-api-types:
Expand Down
18 changes: 0 additions & 18 deletions connector/internal/collection.go
Original file line number Diff line number Diff line change
Expand Up @@ -397,21 +397,3 @@ func (qce *QueryCollectionExecutor) evalValueComparisonCondition(operator *schem
func (qce *QueryCollectionExecutor) getComparisonValue(input schema.ComparisonValue) (any, error) {
return getComparisonValue(input, qce.Variables)
}

func getComparisonValue(input schema.ComparisonValue, variables map[string]any) (any, error) {
if len(input) == 0 {
return nil, nil
}

switch v := input.Interface().(type) {
case *schema.ComparisonValueScalar:
return v.Value, nil
case *schema.ComparisonValueVariable:
if value, ok := variables[v.Name]; ok {
return value, nil
}
return nil, fmt.Errorf("variable %s does not exist", v.Name)
default:
return nil, fmt.Errorf("invalid comparison value: %v", input)
}
}
47 changes: 29 additions & 18 deletions connector/internal/collection_request.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ type CollectionRequest struct {
Timestamp schema.ComparisonValue
Start schema.ComparisonValue
End schema.ComparisonValue
OrderBy []ColumnOrder
Value *schema.ExpressionBinaryComparisonOperator
LabelExpressions map[string]*LabelExpression
Functions []KeyValue
OrderBy []ColumnOrder
}

// EvalCollectionRequest evaluates the requested collection data of the query request
Expand Down Expand Up @@ -67,24 +67,11 @@ func EvalCollectionRequest(request *schema.QueryRequest, arguments map[string]an
}
}

if request.Query.OrderBy != nil {
for _, elem := range request.Query.OrderBy.Elements {
switch target := elem.Target.Interface().(type) {
case *schema.OrderByColumn:
if slices.Contains([]string{metadata.LabelsKey, metadata.ValuesKey}, target.Name) {
return nil, fmt.Errorf("ordering by `%s` is unsupported", target.Name)
}

orderBy := ColumnOrder{
Name: target.Name,
Descending: elem.OrderDirection == schema.OrderDirectionDesc,
}
result.OrderBy = append(result.OrderBy, orderBy)
default:
return nil, fmt.Errorf("support ordering by column only, got: %v", elem.Target)
}
}
orderBy, err := evalCollectionOrderBy(request.Query.OrderBy)
if err != nil {
return nil, err
}
result.OrderBy = orderBy
return result, nil
}

Expand Down Expand Up @@ -142,3 +129,27 @@ func (pr *CollectionRequest) evalQueryPredicate(expression schema.Expression) er

return nil
}

func evalCollectionOrderBy(orderBy *schema.OrderBy) ([]ColumnOrder, error) {
var results []ColumnOrder
if orderBy == nil {
return results, nil
}
for _, elem := range orderBy.Elements {
switch target := elem.Target.Interface().(type) {
case *schema.OrderByColumn:
if slices.Contains([]string{metadata.LabelsKey, metadata.ValuesKey}, target.Name) {
return nil, fmt.Errorf("ordering by `%s` is unsupported", target.Name)
}

orderBy := ColumnOrder{
Name: target.Name,
Descending: elem.OrderDirection == schema.OrderDirectionDesc,
}
results = append(results, orderBy)
default:
return nil, fmt.Errorf("support ordering by column only, got: %v", elem.Target)
}
}
return results, nil
}
Loading

0 comments on commit 49b26b4

Please sign in to comment.