Skip to content

Commit

Permalink
feat: exist function supports non-resource tags
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaochaoren1 authored and SongZhen0704 committed Oct 9, 2024
1 parent 6406501 commit 481d7e1
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
3 changes: 3 additions & 0 deletions server/querier/engine/clickhouse/clickhouse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,9 @@ var (
}, {
input: "SELECT chost_id_0 from l4_flow_log WHERE NOT exist(chost_0) LIMIT 1",
output: []string{"SELECT if(l3_device_type_0=1,l3_device_id_0, 0) AS `chost_id_0` FROM flow_log.`l4_flow_log` PREWHERE NOT (l3_device_type_0=1) LIMIT 1"},
}, {
input: "SELECT response_code from l4_flow_log WHERE exist(response_code) LIMIT 1",
output: []string{"SELECT response_code FROM flow_log.`l4_flow_log` PREWHERE ((isNotNull(response_code))) LIMIT 1"},
}, {
input: "SELECT `cloud.tag.xx_0` from l4_flow_log WHERE NOT exist(`cloud.tag.xx_0`) LIMIT 1",
output: []string{"SELECT if(if(l3_device_type_0=1, dictGet('flow_tag.chost_cloud_tag_map', 'value', (toUInt64(l3_device_id_0),'xx')), '')!='',if(l3_device_type_0=1, dictGet('flow_tag.chost_cloud_tag_map', 'value', (toUInt64(l3_device_id_0),'xx')), ''), dictGet('flow_tag.pod_ns_cloud_tag_map', 'value', (toUInt64(pod_ns_id_0),'xx')) ) AS `cloud.tag.xx_0` FROM flow_log.`l4_flow_log` PREWHERE NOT (((toUInt64(l3_device_id_0) GLOBAL IN (SELECT id FROM flow_tag.chost_cloud_tag_map WHERE key='xx') AND l3_device_type_0=1) OR (toUInt64(pod_ns_id_0) GLOBAL IN (SELECT id FROM flow_tag.pod_ns_cloud_tag_map WHERE key='xx')))) LIMIT 1"},
Expand Down
8 changes: 8 additions & 0 deletions server/querier/engine/clickhouse/filter.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,14 @@ func TransWhereTagFunction(db, table string, name string, args []string) (filter
} else {
filter = resourceInfo.ResourceName + "_id" + suffix + "!=0"
}
} else {
// non-resource tags
engine := &CHEngine{DB: db, Table: table}
notNullExpr, ok := GetNotNullFilter(resource, engine)
if !ok {
return
}
filter = notNullExpr.(*view.Expr).Value
}
}
return
Expand Down

0 comments on commit 481d7e1

Please sign in to comment.