(params *QueryParams)
| 115 | } |
| 116 | |
| 117 | func (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 { |
no test coverage detected