(sql string, args *common.QuerierParams)
| 1002 | } |
| 1003 | |
| 1004 | func (e *CHEngine) QueryWithSql(sql string, args *common.QuerierParams) (*common.Result, *client.Debug, error) { |
| 1005 | sql, callbacks, columnSchemaMap, err := e.ParseWithSql(sql) |
| 1006 | if err != nil { |
| 1007 | log.Error(err) |
| 1008 | return nil, nil, err |
| 1009 | } |
| 1010 | if sql == "" { |
| 1011 | return nil, nil, nil |
| 1012 | } |
| 1013 | |
| 1014 | query_uuid := args.QueryUUID |
| 1015 | debug := &client.Debug{ |
| 1016 | IP: config.Cfg.Clickhouse.Host, |
| 1017 | QueryUUID: query_uuid, |
| 1018 | } |
| 1019 | debug.Sql = sql |
| 1020 | chClient := client.Client{ |
| 1021 | Host: config.Cfg.Clickhouse.Host, |
| 1022 | Port: config.Cfg.Clickhouse.Port, |
| 1023 | UserName: config.Cfg.Clickhouse.User, |
| 1024 | Password: config.Cfg.Clickhouse.Password, |
| 1025 | DB: e.DB, |
| 1026 | Debug: debug, |
| 1027 | Context: e.Context, |
| 1028 | } |
| 1029 | params := &client.QueryParams{ |
| 1030 | Sql: sql, |
| 1031 | UseQueryCache: args.UseQueryCache, |
| 1032 | QueryCacheTTL: args.QueryCacheTTL, |
| 1033 | Callbacks: callbacks, |
| 1034 | QueryUUID: query_uuid, |
| 1035 | ColumnSchemaMap: columnSchemaMap, |
| 1036 | ORGID: args.ORGID, |
| 1037 | } |
| 1038 | rst, err := chClient.DoQuery(params) |
| 1039 | if err != nil { |
| 1040 | log.Error(err) |
| 1041 | return nil, debug, err |
| 1042 | } |
| 1043 | return rst, debug, err |
| 1044 | } |
| 1045 | |
| 1046 | func (e *CHEngine) ParseWithSql(sql string) (string, map[string]func(*common.Result) error, map[string]*common.ColumnSchema, error) { |
| 1047 | checks := checkWithSqlRegexp.FindAllStringSubmatch(sql, -1) |
no test coverage detected