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 544956b commit 8586788
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: "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: "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: "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) 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) 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 @@ -156,6 +156,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 8586788

Please sign in to comment.