Skip to content

Commit

Permalink
refactor: revise some codes as feedbacks and add test case in es expr…
Browse files Browse the repository at this point in the history
… test
  • Loading branch information
Muhammad Luthfi Fahlevi committed Aug 21, 2024
1 parent a550154 commit c3fb143
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 2 deletions.
1 change: 1 addition & 0 deletions compass.yaml.example
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ worker:
sync_job_timeout: 15m
index_job_timeout: 5s
delete_job_timeout: 5s
max_attempt_retry: 3

client:
host: localhost:8081
Expand Down
2 changes: 1 addition & 1 deletion internal/server/v1beta1/asset.go
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,7 @@ func (server *APIServer) DeleteAssets(ctx context.Context, req *compassv1beta1.D
return nil, err
}
defer func() {
server.logger.Warn("delete assets",
server.logger.Warn("delete assets by query",
"the number of affected rows is", affectedRows,
"query delete", req.QueryExpr,
"dry run", req.DryRun)
Expand Down
8 changes: 8 additions & 0 deletions pkg/queryexpr/es_expr_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package queryexpr_test

import (
"fmt"
"testing"
"time"

"github.com/goto/compass/pkg/queryexpr"
)
Expand Down Expand Up @@ -66,6 +68,12 @@ func TestESExpr_ToQuery(t *testing.T) {
want: `{"query":{"term":{"bool_identifier":false}}}`,
wantErr: false,
},
{
name: "complex query expression that can directly produce a value regarding time",
expr: queryexpr.ESExpr(`refreshed_at <= (now() - duration('1h'))`),
want: fmt.Sprintf(`{"query":{"range":{"refreshed_at":{"lte":"%v"}}}}`, time.Now().Add(-1*time.Hour).Format(time.RFC3339)),
wantErr: false,
},
{
name: "complex query expression that can NOT directly produce a value",
expr: queryexpr.ESExpr(`service in filter(assets, .Service startsWith "T")`),
Expand Down
2 changes: 1 addition & 1 deletion pkg/queryexpr/sql_expr.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ func (s SQLExpr) String() string {
return string(s)
}

// ToQuery default
// ToQuery default: convert to be SQL query
func (s SQLExpr) ToQuery() (string, error) {
queryExprParsed, err := getTreeNodeFromQueryExpr(s.String())
if err != nil {
Expand Down

0 comments on commit c3fb143

Please sign in to comment.