更新时间:2024-01-25 GMT+08:00
分享

查询SQL列表

功能介绍

该接口用于查询实时SQL列表。

调用方法

请参见如何调用API

URI

POST /v2/{project_id}/clusters/{cluster_id}/dms/queries
表1 路径参数

参数

是否必选

参数类型

描述

project_id

String

项目ID。获取方法,请参见获取项目ID

cluster_id

String

集群ID。获取方法,请参见获取集群ID

请求参数

表2 请求Body参数

参数

是否必选

参数类型

描述

cluster_id

String

集群ID。

project_id

String

项目ID。

offset

String

偏移量,表示从此偏移量开始查询,offset>=0。

limit

String

每页显示的条目数量。

conditions

Array of ListQueriesCondition objects

查询条件数组。

order_by

String

排序字段。

target

String

固定值db_queries。

表3 ListQueriesCondition

参数

是否必选

参数类型

描述

field

String

字段名称。

value

String

字段值。

operator

String

比较方式:

  • String类型参数:
    • =
    • !=
    • like
    • not like
  • int类型参数:
    • =
    • !=
    • >
    • <
    • >=
    • <=
  • boolean类型参数:
    • =
    • !=

响应参数

状态码: 200

表4 响应Body参数

参数

参数类型

描述

code

Integer

响应码。

msg

String

响应信息。

data

ListQueriesData object

响应数据。

count

Integer

总条数。

表5 ListQueriesData

参数

参数类型

描述

queries

Array of ListQueriesDto objects

查询数据列表。

status

ListQueriesStatus object

统计数据。

表6 ListQueriesDto

参数

参数类型

描述

virtual_cluster_id

Integer

虚拟集群ID。

ctime

Long

采集时间。

pid

String

会话id。

inst_name

String

实例名称。

waiting

Boolean

如果后台当前正等待锁则为true。

enqueue

String

工作负载管理资源状态。

warning

String

主要显示如下几类告警信息以及sql自诊断调优相关告警。

query

String

查询语句。

lane

String

快慢车道 (fast or slow)。

db_name

String

数据库名称。

priority

String

job在资源池中的优先级,取值:1,2,4,8(rush、high、medium、low)。

query_id

String

语句执行使用的内部query_id。

query_band

String

用于标示作业类型,可通过guc参数query_band进行设置,默认为空字符串。

job_name

String

这个值是从query_band的字段中取出来的,位置0。

job_inst

String

这个值是从query_band的字段中取出来的,位置1。

user_name

String

连接到后端的用户名。

application_name

String

连接到后端的应用名。

client_address

String

连接到后端的客户端的ip地址。

client_hostname

String

客户端的主机名。

client_port

String

客户端用于与后端通讯的tcp端口号。

start_time

Long

语句执行的开始时间。

block_time

Long

语句执行前的阻塞时间 (单位ms)。

duration

Long

语句已经执行的时间 (单位ms)。

estimate_total_time

Long

语句执行预估总时间 (单位ms)。

estimate_left_time

Long

语句执行预估剩余时间 (单位ms)。

resource_pool

String

用户使用的资源池。

control_group

String

语句所使用的cgroup。

min_peak_memory

Integer

语句在所有dn上的最小内存峰值 (单位mb)。

max_peak_memory

Integer

语句在所有dn上的最大内存峰值 (单位mb)。

average_peak_memory

Integer

语句执行过程中的内存使用平均值 (单位mb)。

memory_skew_percent

Integer

语句在各dn间的内存使用倾斜率。

estimate_memory

Integer

语句预估使用内存 (单位mb)。

spill_info

String

语句在所有dn上的下盘信息。

min_spill_size

Integer

若发生下盘,所有dn上下盘的最小数据量 (单位mb) 默认为0。

max_spill_size

Integer

若发生下盘,所有dn上下盘的最大数据量 (单位mb) 默认为0。

average_spill_size

Integer

若发生下盘,所有dn上下盘的平均数据量 (单位mb) 默认为0。

spill_skew_percent

Integer

若发生下盘,dn间下盘倾斜率。

min_dn_time

Long

语句在所有dn上的最小执行时间 (单位ms)。

max_dn_time

Long

语句在所有dn上的最大执行时间 (单位ms)。

average_dn_time

Long

语句在所有dn上的平均执行时间 (单位ms)。

dntime_skew_percent

Integer

语句在各dn间的执行时间倾斜率。

min_cpu_time

Long

语句在所有dn上的最小cpu时间 (单位ms)。

max_cpu_time

Long

语句在所有dn上的最大cpu时间 (单位ms)。

total_cpu_time

Long

语句在所有dn上的cpu总时间 (单位ms)。

cpu_skew_percent

Integer

语句在各dn间的cpu时间倾斜率。

average_peak_iops

Integer

语句在所有dn上的每秒平均io峰值(列存单位是次/s,行存单位是万次/s)。

iops_skew_percent

Integer

语句在dn间的io倾斜率。

max_peak_iops

Integer

语句在所有dn上的每秒最大io峰值(列存单位是次/s,行存单位是万次/s)。

min_peak_iops

Integer

语句在所有dn上的每秒最小io峰值(列存单位是次/s,行存单位是万次/s)。

query_plan

String

查询计划。

query_status

String

当前查询语句的实时运行状态 (active, idle, idle in transaction, idle in transaction(aborted), fastpath function call, disabled)。

wlm_status

String

当前查询语句在资源池上的运行状态 (pending, running, finished, aborted, active, unknown)。

wlm_attrib

String

语句的属性 (ordinary, simple, complicated, internal)

system_query

Boolean

是否系统查询。

backend_start

Long

该过程开始的时间,即当客户端连接服务器时。

elapsed_time

Long

到目前为止的执行时间。

curr_xact_start

Long

启动当前事务的时间,如果没有事务是活跃的,则为null。如果当前查询是首个事务,则这列等同于query_start列。

state_change

Long

上次状态改变的时间。

query_start

Long

语句执行的开始时间。

query_elapsed_time

Long

语句当前为止的实际执行时间(单位:s)。

表7 ListQueriesStatus

参数

参数类型

描述

average_query_waiting_time

Double

平均查询等待时间。

average_time_consumption_of_queries

Double

平均查询耗时。

average_time_consumption_of_sessions

Double

平均会话耗时。

queries_count

Long

查询数量。

session_count

Long

会话数量。

请求示例

https://{Endpoint}/v2/{project_id}/clusters/{cluster_id}/dms/queries 

{
  "offset" : 0,
  "limit" : 1,
  "cluster_id" : "cluster_id",
  "project_id" : "project_id",
  "conditions" : [ {
    "field" : "userName",
    "value" : "用户名称",
    "operator" : "="
  }, {
    "field" : "applicationName",
    "value" : "应用名称",
    "operator" : "<>"
  }, {
    "field" : "dbName",
    "value" : "数据库名称",
    "operator" : "="
  }, {
    "field" : "resourcePool",
    "value" : "资源池",
    "operator" : "<>"
  }, {
    "field" : "queryStatus",
    "value" : "查询状态",
    "operator" : "="
  }, {
    "field" : "enqueue",
    "value" : "排队状态",
    "operator" : "<>"
  }, {
    "field" : "lane",
    "value" : "快慢车道",
    "operator" : "="
  }, {
    "field" : "instName",
    "value" : "接入CN",
    "operator" : "<>"
  }, {
    "field" : "pid",
    "value" : "会话ID",
    "operator" : "="
  }, {
    "field" : "blockTime",
    "value" : "1",
    "operator" : "="
  }, {
    "field" : "duration",
    "value" : "2",
    "operator" : "<>"
  }, {
    "field" : "minCpuTime",
    "value" : "3",
    "operator" : ">"
  }, {
    "field" : "maxCpuTime",
    "value" : "4",
    "operator" : "<"
  }, {
    "field" : "totalCpuTime",
    "value" : "5",
    "operator" : ">="
  }, {
    "field" : "cpuSkewPercent",
    "value" : "6",
    "operator" : "<="
  }, {
    "field" : "spillInfo",
    "value" : "dn下盘信息",
    "operator" : "="
  }, {
    "field" : "minSpillSize",
    "value" : "7",
    "operator" : "<>"
  }, {
    "field" : "maxSpillSize",
    "value" : "8",
    "operator" : ">"
  }, {
    "field" : "averageSpillSize",
    "value" : "9",
    "operator" : "<"
  }, {
    "field" : "spillSkewPercent",
    "value" : "10",
    "operator" : ">="
  }, {
    "field" : "queryBand",
    "value" : "作业类型",
    "operator" : "<>"
  }, {
    "field" : "jobName",
    "value" : "任务名称",
    "operator" : "="
  }, {
    "field" : "jobInst",
    "value" : "任务实例",
    "operator" : "<>"
  }, {
    "field" : "clientHostname",
    "value" : "主机名称",
    "operator" : "="
  }, {
    "field" : "clientPort",
    "value" : "TCP端口",
    "operator" : "<>"
  }, {
    "field" : "waiting",
    "value" : "是否等待",
    "operator" : "="
  }, {
    "field" : "estimateTotalTime",
    "value" : "11",
    "operator" : "="
  }, {
    "field" : "estimateLeftTime",
    "value" : "12",
    "operator" : "<>"
  }, {
    "field" : "controlGroup",
    "value" : "cgroup",
    "operator" : "like"
  }, {
    "field" : "minPeakMemory",
    "value" : "13",
    "operator" : "="
  }, {
    "field" : "maxPeakMemory",
    "value" : "14",
    "operator" : "<>"
  }, {
    "field" : "averagePeakMemory",
    "value" : "15",
    "operator" : ">"
  }, {
    "field" : "memorySkewPercent",
    "value" : "16",
    "operator" : "<"
  }, {
    "field" : "estimateMemory",
    "value" : "17",
    "operator" : ">="
  }, {
    "field" : "minDnTime",
    "value" : "18",
    "operator" : "<="
  }, {
    "field" : "maxDnTime",
    "value" : "19",
    "operator" : "="
  }, {
    "field" : "averageDnTime",
    "value" : "20",
    "operator" : "<>"
  }, {
    "field" : "dntimeSkewPercent",
    "value" : "21",
    "operator" : ">"
  }, {
    "field" : "warning",
    "value" : "告警",
    "operator" : "="
  }, {
    "field" : "averagePeakIops",
    "value" : "22",
    "operator" : "<>"
  }, {
    "field" : "iopsSkewPercent",
    "value" : "23",
    "operator" : ">"
  }, {
    "field" : "wlmStatus",
    "value" : "语句运行状态",
    "operator" : "="
  }, {
    "field" : "wlmAttrib",
    "value" : "语句属性",
    "operator" : "not like"
  } ],
  "order_by" : "duration asc",
  "target" : "db_queries"
}

响应示例

状态码: 200

{
  "code" : 0,
  "msg" : "OK",
  "count" : 0,
  "data" : {
    "queries" : [ {
      "ctime" : 1699062726000,
      "pid" : "140535026615872",
      "waiting" : false,
      "duration" : 0,
      "enqueue" : "",
      "warning" : "",
      "query" : "WLM fetch collect info from data nodes",
      "lane" : "",
      "priority" : null,
      "virtual_cluster_id" : 0,
      "inst_name" : "cn_5002",
      "db_name" : "postgres",
      "query_id" : "145522562959854219",
      "query_band" : "",
      "job_name" : "",
      "job_inst" : "",
      "user_name" : "Ruby",
      "application_name" : "workload",
      "client_address" : "",
      "client_hostname" : "",
      "client_port" : "",
      "start_time" : 0,
      "block_time" : 0,
      "estimate_total_time" : 0,
      "estimate_left_time" : 0,
      "resource_pool" : "default_pool",
      "control_group" : "",
      "min_peak_memory" : 0,
      "max_peak_memory" : 0,
      "average_peak_memory" : 0,
      "memory_skew_percent" : 0,
      "estimate_memory" : 0,
      "spill_info" : "",
      "min_spill_size" : 0,
      "max_spill_size" : 0,
      "average_spill_size" : 0,
      "spill_skew_percent" : 0,
      "min_dn_time" : 0,
      "max_dn_time" : 0,
      "average_dn_time" : 0,
      "dntime_skew_percent" : 0,
      "min_cpu_time" : 0,
      "max_cpu_time" : 0,
      "total_cpu_time" : 0,
      "cpu_skew_percent" : 0,
      "average_peak_iops" : 0,
      "iops_skew_percent" : 0,
      "max_peak_iops" : 0,
      "min_peak_iops" : 0,
      "query_plan" : null,
      "query_status" : "active",
      "wlm_status" : "",
      "wlm_attrib" : "",
      "system_query" : true,
      "backend_start" : 1698998138,
      "elapsed_time" : 64585,
      "curr_xact_start" : 1699062726,
      "state_change" : 1698998142,
      "query_start" : 1698998142,
      "query_elapsed_time" : -1
    } ],
    "status" : {
      "session_count" : 19,
      "average_time_consumption_of_sessions" : 51297.58,
      "queries_count" : 19,
      "average_time_consumption_of_queries" : 48799.8,
      "average_query_waiting_time" : 0
    }
  }
}

SDK代码示例

SDK代码示例如下。

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
package com.huaweicloud.sdk.test;

import com.huaweicloud.sdk.core.auth.ICredential;
import com.huaweicloud.sdk.core.auth.BasicCredentials;
import com.huaweicloud.sdk.core.exception.ConnectionException;
import com.huaweicloud.sdk.core.exception.RequestTimeoutException;
import com.huaweicloud.sdk.core.exception.ServiceResponseException;
import com.huaweicloud.sdk.dws.v2.region.DwsRegion;
import com.huaweicloud.sdk.dws.v2.*;
import com.huaweicloud.sdk.dws.v2.model.*;

import java.util.List;
import java.util.ArrayList;

public class ListQueriesSolution {

    public static void main(String[] args) {
        // The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security.
        // In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment
        String ak = System.getenv("CLOUD_SDK_AK");
        String sk = System.getenv("CLOUD_SDK_SK");

        ICredential auth = new BasicCredentials()
                .withAk(ak)
                .withSk(sk);

        DwsClient client = DwsClient.newBuilder()
                .withCredential(auth)
                .withRegion(DwsRegion.valueOf("<YOUR REGION>"))
                .build();
        ListQueriesRequest request = new ListQueriesRequest();
        ListQueriesRequestBody body = new ListQueriesRequestBody();
        List<ListQueriesCondition> listbodyConditions = new ArrayList<>();
        listbodyConditions.add(
            new ListQueriesCondition()
                .withField("userName")
                .withValue("用户名称")
                .withOperator("=")
        );
        listbodyConditions.add(
            new ListQueriesCondition()
                .withField("applicationName")
                .withValue("应用名称")
                .withOperator("<>")
        );
        listbodyConditions.add(
            new ListQueriesCondition()
                .withField("dbName")
                .withValue("数据库名称")
                .withOperator("=")
        );
        listbodyConditions.add(
            new ListQueriesCondition()
                .withField("resourcePool")
                .withValue("资源池")
                .withOperator("<>")
        );
        listbodyConditions.add(
            new ListQueriesCondition()
                .withField("queryStatus")
                .withValue("查询状态")
                .withOperator("=")
        );
        listbodyConditions.add(
            new ListQueriesCondition()
                .withField("enqueue")
                .withValue("排队状态")
                .withOperator("<>")
        );
        listbodyConditions.add(
            new ListQueriesCondition()
                .withField("lane")
                .withValue("快慢车道")
                .withOperator("=")
        );
        listbodyConditions.add(
            new ListQueriesCondition()
                .withField("instName")
                .withValue("接入CN")
                .withOperator("<>")
        );
        listbodyConditions.add(
            new ListQueriesCondition()
                .withField("pid")
                .withValue("会话ID")
                .withOperator("=")
        );
        listbodyConditions.add(
            new ListQueriesCondition()
                .withField("blockTime")
                .withValue("1")
                .withOperator("=")
        );
        listbodyConditions.add(
            new ListQueriesCondition()
                .withField("duration")
                .withValue("2")
                .withOperator("<>")
        );
        listbodyConditions.add(
            new ListQueriesCondition()
                .withField("minCpuTime")
                .withValue("3")
                .withOperator(">")
        );
        listbodyConditions.add(
            new ListQueriesCondition()
                .withField("maxCpuTime")
                .withValue("4")
                .withOperator("<")
        );
        listbodyConditions.add(
            new ListQueriesCondition()
                .withField("totalCpuTime")
                .withValue("5")
                .withOperator(">=")
        );
        listbodyConditions.add(
            new ListQueriesCondition()
                .withField("cpuSkewPercent")
                .withValue("6")
                .withOperator("<=")
        );
        listbodyConditions.add(
            new ListQueriesCondition()
                .withField("spillInfo")
                .withValue("dn下盘信息")
                .withOperator("=")
        );
        listbodyConditions.add(
            new ListQueriesCondition()
                .withField("minSpillSize")
                .withValue("7")
                .withOperator("<>")
        );
        listbodyConditions.add(
            new ListQueriesCondition()
                .withField("maxSpillSize")
                .withValue("8")
                .withOperator(">")
        );
        listbodyConditions.add(
            new ListQueriesCondition()
                .withField("averageSpillSize")
                .withValue("9")
                .withOperator("<")
        );
        listbodyConditions.add(
            new ListQueriesCondition()
                .withField("spillSkewPercent")
                .withValue("10")
                .withOperator(">=")
        );
        listbodyConditions.add(
            new ListQueriesCondition()
                .withField("queryBand")
                .withValue("作业类型")
                .withOperator("<>")
        );
        listbodyConditions.add(
            new ListQueriesCondition()
                .withField("jobName")
                .withValue("任务名称")
                .withOperator("=")
        );
        listbodyConditions.add(
            new ListQueriesCondition()
                .withField("jobInst")
                .withValue("任务实例")
                .withOperator("<>")
        );
        listbodyConditions.add(
            new ListQueriesCondition()
                .withField("clientHostname")
                .withValue("主机名称")
                .withOperator("=")
        );
        listbodyConditions.add(
            new ListQueriesCondition()
                .withField("clientPort")
                .withValue("TCP端口")
                .withOperator("<>")
        );
        listbodyConditions.add(
            new ListQueriesCondition()
                .withField("waiting")
                .withValue("是否等待")
                .withOperator("=")
        );
        listbodyConditions.add(
            new ListQueriesCondition()
                .withField("estimateTotalTime")
                .withValue("11")
                .withOperator("=")
        );
        listbodyConditions.add(
            new ListQueriesCondition()
                .withField("estimateLeftTime")
                .withValue("12")
                .withOperator("<>")
        );
        listbodyConditions.add(
            new ListQueriesCondition()
                .withField("controlGroup")
                .withValue("cgroup")
                .withOperator("like")
        );
        listbodyConditions.add(
            new ListQueriesCondition()
                .withField("minPeakMemory")
                .withValue("13")
                .withOperator("=")
        );
        listbodyConditions.add(
            new ListQueriesCondition()
                .withField("maxPeakMemory")
                .withValue("14")
                .withOperator("<>")
        );
        listbodyConditions.add(
            new ListQueriesCondition()
                .withField("averagePeakMemory")
                .withValue("15")
                .withOperator(">")
        );
        listbodyConditions.add(
            new ListQueriesCondition()
                .withField("memorySkewPercent")
                .withValue("16")
                .withOperator("<")
        );
        listbodyConditions.add(
            new ListQueriesCondition()
                .withField("estimateMemory")
                .withValue("17")
                .withOperator(">=")
        );
        listbodyConditions.add(
            new ListQueriesCondition()
                .withField("minDnTime")
                .withValue("18")
                .withOperator("<=")
        );
        listbodyConditions.add(
            new ListQueriesCondition()
                .withField("maxDnTime")
                .withValue("19")
                .withOperator("=")
        );
        listbodyConditions.add(
            new ListQueriesCondition()
                .withField("averageDnTime")
                .withValue("20")
                .withOperator("<>")
        );
        listbodyConditions.add(
            new ListQueriesCondition()
                .withField("dntimeSkewPercent")
                .withValue("21")
                .withOperator(">")
        );
        listbodyConditions.add(
            new ListQueriesCondition()
                .withField("warning")
                .withValue("告警")
                .withOperator("=")
        );
        listbodyConditions.add(
            new ListQueriesCondition()
                .withField("averagePeakIops")
                .withValue("22")
                .withOperator("<>")
        );
        listbodyConditions.add(
            new ListQueriesCondition()
                .withField("iopsSkewPercent")
                .withValue("23")
                .withOperator(">")
        );
        listbodyConditions.add(
            new ListQueriesCondition()
                .withField("wlmStatus")
                .withValue("语句运行状态")
                .withOperator("=")
        );
        listbodyConditions.add(
            new ListQueriesCondition()
                .withField("wlmAttrib")
                .withValue("语句属性")
                .withOperator("not like")
        );
        body.withTarget("db_queries");
        body.withOrderBy("duration asc");
        body.withConditions(listbodyConditions);
        body.withLimit("1");
        body.withOffset("0");
        body.withProjectId("project_id");
        body.withClusterId("cluster_id");
        request.withBody(body);
        try {
            ListQueriesResponse response = client.listQueries(request);
            System.out.println(response.toString());
        } catch (ConnectionException e) {
            e.printStackTrace();
        } catch (RequestTimeoutException e) {
            e.printStackTrace();
        } catch (ServiceResponseException e) {
            e.printStackTrace();
            System.out.println(e.getHttpStatusCode());
            System.out.println(e.getRequestId());
            System.out.println(e.getErrorCode());
            System.out.println(e.getErrorMsg());
        }
    }
}
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
# coding: utf-8

from huaweicloudsdkcore.auth.credentials import BasicCredentials
from huaweicloudsdkdws.v2.region.dws_region import DwsRegion
from huaweicloudsdkcore.exceptions import exceptions
from huaweicloudsdkdws.v2 import *

if __name__ == "__main__":
    # The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security.
    # In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment
    ak = os.getenv("CLOUD_SDK_AK")
    sk = os.getenv("CLOUD_SDK_SK")

    credentials = BasicCredentials(ak, sk) \

    client = DwsClient.new_builder() \
        .with_credentials(credentials) \
        .with_region(DwsRegion.value_of("<YOUR REGION>")) \
        .build()

    try:
        request = ListQueriesRequest()
        listConditionsbody = [
            ListQueriesCondition(
                field="userName",
                value="用户名称",
                operator="="
            ),
            ListQueriesCondition(
                field="applicationName",
                value="应用名称",
                operator="<>"
            ),
            ListQueriesCondition(
                field="dbName",
                value="数据库名称",
                operator="="
            ),
            ListQueriesCondition(
                field="resourcePool",
                value="资源池",
                operator="<>"
            ),
            ListQueriesCondition(
                field="queryStatus",
                value="查询状态",
                operator="="
            ),
            ListQueriesCondition(
                field="enqueue",
                value="排队状态",
                operator="<>"
            ),
            ListQueriesCondition(
                field="lane",
                value="快慢车道",
                operator="="
            ),
            ListQueriesCondition(
                field="instName",
                value="接入CN",
                operator="<>"
            ),
            ListQueriesCondition(
                field="pid",
                value="会话ID",
                operator="="
            ),
            ListQueriesCondition(
                field="blockTime",
                value="1",
                operator="="
            ),
            ListQueriesCondition(
                field="duration",
                value="2",
                operator="<>"
            ),
            ListQueriesCondition(
                field="minCpuTime",
                value="3",
                operator=">"
            ),
            ListQueriesCondition(
                field="maxCpuTime",
                value="4",
                operator="<"
            ),
            ListQueriesCondition(
                field="totalCpuTime",
                value="5",
                operator=">="
            ),
            ListQueriesCondition(
                field="cpuSkewPercent",
                value="6",
                operator="<="
            ),
            ListQueriesCondition(
                field="spillInfo",
                value="dn下盘信息",
                operator="="
            ),
            ListQueriesCondition(
                field="minSpillSize",
                value="7",
                operator="<>"
            ),
            ListQueriesCondition(
                field="maxSpillSize",
                value="8",
                operator=">"
            ),
            ListQueriesCondition(
                field="averageSpillSize",
                value="9",
                operator="<"
            ),
            ListQueriesCondition(
                field="spillSkewPercent",
                value="10",
                operator=">="
            ),
            ListQueriesCondition(
                field="queryBand",
                value="作业类型",
                operator="<>"
            ),
            ListQueriesCondition(
                field="jobName",
                value="任务名称",
                operator="="
            ),
            ListQueriesCondition(
                field="jobInst",
                value="任务实例",
                operator="<>"
            ),
            ListQueriesCondition(
                field="clientHostname",
                value="主机名称",
                operator="="
            ),
            ListQueriesCondition(
                field="clientPort",
                value="TCP端口",
                operator="<>"
            ),
            ListQueriesCondition(
                field="waiting",
                value="是否等待",
                operator="="
            ),
            ListQueriesCondition(
                field="estimateTotalTime",
                value="11",
                operator="="
            ),
            ListQueriesCondition(
                field="estimateLeftTime",
                value="12",
                operator="<>"
            ),
            ListQueriesCondition(
                field="controlGroup",
                value="cgroup",
                operator="like"
            ),
            ListQueriesCondition(
                field="minPeakMemory",
                value="13",
                operator="="
            ),
            ListQueriesCondition(
                field="maxPeakMemory",
                value="14",
                operator="<>"
            ),
            ListQueriesCondition(
                field="averagePeakMemory",
                value="15",
                operator=">"
            ),
            ListQueriesCondition(
                field="memorySkewPercent",
                value="16",
                operator="<"
            ),
            ListQueriesCondition(
                field="estimateMemory",
                value="17",
                operator=">="
            ),
            ListQueriesCondition(
                field="minDnTime",
                value="18",
                operator="<="
            ),
            ListQueriesCondition(
                field="maxDnTime",
                value="19",
                operator="="
            ),
            ListQueriesCondition(
                field="averageDnTime",
                value="20",
                operator="<>"
            ),
            ListQueriesCondition(
                field="dntimeSkewPercent",
                value="21",
                operator=">"
            ),
            ListQueriesCondition(
                field="warning",
                value="告警",
                operator="="
            ),
            ListQueriesCondition(
                field="averagePeakIops",
                value="22",
                operator="<>"
            ),
            ListQueriesCondition(
                field="iopsSkewPercent",
                value="23",
                operator=">"
            ),
            ListQueriesCondition(
                field="wlmStatus",
                value="语句运行状态",
                operator="="
            ),
            ListQueriesCondition(
                field="wlmAttrib",
                value="语句属性",
                operator="not like"
            )
        ]
        request.body = ListQueriesRequestBody(
            target="db_queries",
            order_by="duration asc",
            conditions=listConditionsbody,
            limit="1",
            offset="0",
            project_id="project_id",
            cluster_id="cluster_id"
        )
        response = client.list_queries(request)
        print(response)
    except exceptions.ClientRequestException as e:
        print(e.status_code)
        print(e.request_id)
        print(e.error_code)
        print(e.error_msg)
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
package main

import (
	"fmt"
	"github.com/huaweicloud/huaweicloud-sdk-go-v3/core/auth/basic"
    dws "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/dws/v2"
	"github.com/huaweicloud/huaweicloud-sdk-go-v3/services/dws/v2/model"
    region "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/dws/v2/region"
)

func main() {
    // The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security.
    // In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment
    ak := os.Getenv("CLOUD_SDK_AK")
    sk := os.Getenv("CLOUD_SDK_SK")

    auth := basic.NewCredentialsBuilder().
        WithAk(ak).
        WithSk(sk).
        Build()

    client := dws.NewDwsClient(
        dws.DwsClientBuilder().
            WithRegion(region.ValueOf("<YOUR REGION>")).
            WithCredential(auth).
            Build())

    request := &model.ListQueriesRequest{}
	var listConditionsbody = []model.ListQueriesCondition{
        {
            Field: "userName",
            Value: "用户名称",
            Operator: "=",
        },
        {
            Field: "applicationName",
            Value: "应用名称",
            Operator: "<>",
        },
        {
            Field: "dbName",
            Value: "数据库名称",
            Operator: "=",
        },
        {
            Field: "resourcePool",
            Value: "资源池",
            Operator: "<>",
        },
        {
            Field: "queryStatus",
            Value: "查询状态",
            Operator: "=",
        },
        {
            Field: "enqueue",
            Value: "排队状态",
            Operator: "<>",
        },
        {
            Field: "lane",
            Value: "快慢车道",
            Operator: "=",
        },
        {
            Field: "instName",
            Value: "接入CN",
            Operator: "<>",
        },
        {
            Field: "pid",
            Value: "会话ID",
            Operator: "=",
        },
        {
            Field: "blockTime",
            Value: "1",
            Operator: "=",
        },
        {
            Field: "duration",
            Value: "2",
            Operator: "<>",
        },
        {
            Field: "minCpuTime",
            Value: "3",
            Operator: ">",
        },
        {
            Field: "maxCpuTime",
            Value: "4",
            Operator: "<",
        },
        {
            Field: "totalCpuTime",
            Value: "5",
            Operator: ">=",
        },
        {
            Field: "cpuSkewPercent",
            Value: "6",
            Operator: "<=",
        },
        {
            Field: "spillInfo",
            Value: "dn下盘信息",
            Operator: "=",
        },
        {
            Field: "minSpillSize",
            Value: "7",
            Operator: "<>",
        },
        {
            Field: "maxSpillSize",
            Value: "8",
            Operator: ">",
        },
        {
            Field: "averageSpillSize",
            Value: "9",
            Operator: "<",
        },
        {
            Field: "spillSkewPercent",
            Value: "10",
            Operator: ">=",
        },
        {
            Field: "queryBand",
            Value: "作业类型",
            Operator: "<>",
        },
        {
            Field: "jobName",
            Value: "任务名称",
            Operator: "=",
        },
        {
            Field: "jobInst",
            Value: "任务实例",
            Operator: "<>",
        },
        {
            Field: "clientHostname",
            Value: "主机名称",
            Operator: "=",
        },
        {
            Field: "clientPort",
            Value: "TCP端口",
            Operator: "<>",
        },
        {
            Field: "waiting",
            Value: "是否等待",
            Operator: "=",
        },
        {
            Field: "estimateTotalTime",
            Value: "11",
            Operator: "=",
        },
        {
            Field: "estimateLeftTime",
            Value: "12",
            Operator: "<>",
        },
        {
            Field: "controlGroup",
            Value: "cgroup",
            Operator: "like",
        },
        {
            Field: "minPeakMemory",
            Value: "13",
            Operator: "=",
        },
        {
            Field: "maxPeakMemory",
            Value: "14",
            Operator: "<>",
        },
        {
            Field: "averagePeakMemory",
            Value: "15",
            Operator: ">",
        },
        {
            Field: "memorySkewPercent",
            Value: "16",
            Operator: "<",
        },
        {
            Field: "estimateMemory",
            Value: "17",
            Operator: ">=",
        },
        {
            Field: "minDnTime",
            Value: "18",
            Operator: "<=",
        },
        {
            Field: "maxDnTime",
            Value: "19",
            Operator: "=",
        },
        {
            Field: "averageDnTime",
            Value: "20",
            Operator: "<>",
        },
        {
            Field: "dntimeSkewPercent",
            Value: "21",
            Operator: ">",
        },
        {
            Field: "warning",
            Value: "告警",
            Operator: "=",
        },
        {
            Field: "averagePeakIops",
            Value: "22",
            Operator: "<>",
        },
        {
            Field: "iopsSkewPercent",
            Value: "23",
            Operator: ">",
        },
        {
            Field: "wlmStatus",
            Value: "语句运行状态",
            Operator: "=",
        },
        {
            Field: "wlmAttrib",
            Value: "语句属性",
            Operator: "not like",
        },
    }
	orderByListQueriesRequestBody:= "duration asc"
	request.Body = &model.ListQueriesRequestBody{
		Target: "db_queries",
		OrderBy: &orderByListQueriesRequestBody,
		Conditions: listConditionsbody,
		Limit: "1",
		Offset: "0",
		ProjectId: "project_id",
		ClusterId: "cluster_id",
	}
	response, err := client.ListQueries(request)
	if err == nil {
        fmt.Printf("%+v\n", response)
    } else {
        fmt.Println(err)
    }
}

更多编程语言的SDK代码示例,请参见API Explorer的代码示例页签,可生成自动对应的SDK代码示例。

状态码

状态码

描述

200

查询SQL列表成功。

400

请求错误。

401

鉴权失败。

403

没有操作权限。

404

找不到资源。

500

服务内部错误。

503

服务不可用。

相关文档