MCPcopy Create free account
hub / github.com/deepflowio/deepflow / DoQuery

Method DoQuery

server/querier/engine/clickhouse/client/client.go:117–229  ·  view source on GitHub ↗
(params *QueryParams)

Source from the content-addressed store, hash-verified

115}
116
117func (c *Client) DoQuery(params *QueryParams) (result *common.Result, err error) {
118 sqlstr, callbacks, query_uuid, columnSchemaMap, simpleSql := params.Sql, params.Callbacks, params.QueryUUID, params.ColumnSchemaMap, params.SimpleSql
119 queryCacheStr := ""
120 if params.UseQueryCache {
121 queryCacheStr = " SETTINGS use_query_cache = true"
122 if version > ctrCommon.CLICK_HOUSE_VERSION {
123 queryCacheStr += ", query_cache_nondeterministic_function_handling = 'save'"
124 } else {
125 queryCacheStr += ", query_cache_store_results_of_queries_with_nondeterministic_functions = 1"
126 }
127 if params.QueryCacheTTL != "" {
128 queryCacheStr += fmt.Sprintf(", query_cache_ttl = %s", params.QueryCacheTTL)
129 }
130 sqlstr += queryCacheStr
131 }
132 // ORGID
133 if !simpleSql && params.ORGID != common.DEFAULT_ORG_ID && params.ORGID != "" {
134 orgIDInt, err := strconv.Atoi(params.ORGID)
135 if err != nil {
136 return nil, err
137 }
138 sqlstr = strings.ReplaceAll(sqlstr, "flow_tag", fmt.Sprintf("%04d_flow_tag", orgIDInt))
139 }
140 // live view
141 if version > ctrCommon.CLICK_HOUSE_VERSION {
142 sqlstr = strings.ReplaceAll(sqlstr, "app_label_live_view", "app_label_map")
143 sqlstr = strings.ReplaceAll(sqlstr, "target_label_live_view", "target_label_map")
144 }
145
146 err = c.Init(query_uuid)
147 if err != nil {
148 return nil, err
149 }
150 defer c.Close()
151
152 start := time.Now()
153 ctx := c.Context
154 if c.Context == nil {
155 ctx = context.Background()
156 }
157 rows, err := c.connection.Query(ctx, sqlstr)
158 c.Debug.Sql = sqlstr
159 if err != nil {
160 log.Errorf("query clickhouse Error: %s, sql: %s, query_uuid: %s", err, sqlstr, c.Debug.QueryUUID)
161 c.Debug.Error = fmt.Sprintf("%s", err)
162 return nil, err
163 }
164 defer rows.Close()
165 columns := rows.ColumnTypes()
166 resColumns := len(columns)
167 columnNames := make([]interface{}, 0, len(columns))
168 var columnSchemas common.ColumnSchemas // FIXME: Slice growth should be avoided.
169 // 获取列名和列类型
170 for _, column := range columns {
171 columnNames = append(columnNames, column.Name())
172 if schema, ok := columnSchemaMap[column.Name()]; ok {
173 columnSchemas = append(columnSchemas, schema)
174 } else {

Callers 11

TransCustomBizFilterFunction · 0.95
GetRemoteReadFilterFunction · 0.95
SimpleExecuteFunction · 0.95
ExecuteQueryMethod · 0.95
QuerySlimitSqlMethod · 0.95
QueryWithSqlMethod · 0.95
GetExtMetricsFunction · 0.95
GenerateMapFunction · 0.95
GetExtTablesFunction · 0.95

Calls 13

InitMethod · 0.95
CloseMethod · 0.95
TransTypeFunction · 0.85
NewMethod · 0.80
NextMethod · 0.80
WriteCkMethod · 0.80
QueryMethod · 0.65
CloseMethod · 0.65
NameMethod · 0.65
ErrorMethod · 0.65
ErrorfMethod · 0.45
ScanMethod · 0.45

Tested by

no test coverage detected