Updated on 2024-04-18 GMT+08:00

Querying the SQL List

Function

This API is used to query the real-time SQL list.

Call Method

For details, see Calling APIs.

URI

POST /v2/{project_id}/clusters/{cluster_id}/dms/queries
Table 1 URI parameters

Parameter

Mandatory

Type

Description

project_id

Yes

String

Project ID. For details about how to obtain the ID, see Obtaining Project ID.

cluster_id

Yes

String

Cluster ID. For details about how to obtain the ID, see Obtaining the Cluster ID.

Request Parameters

Table 2 Request body parameters

Parameter

Mandatory

Type

Description

cluster_id

Yes

String

Cluster ID

project_id

Yes

String

Project ID

offset

Yes

String

Offset from which the query starts, which is greater or equal to 0.

limit

Yes

String

Number of records displayed per page

conditions

Yes

Array of ListQueriesCondition objects

Search criteria

order_by

No

String

Sorting field

target

Yes

String

The value is fixed at db_queries.

Table 3 ListQueriesCondition

Parameter

Mandatory

Type

Description

field

Yes

String

Field name

value

Yes

String

Field value

operator

Yes

String

Comparison mode.

  • For string parameters:
    • =
    • !=
    • like
    • not like
  • For int parameters:
    • =
    • !=
    • >
    • <
    • >=
    • <=
  • For boolean parameters:
    • =
    • !=

Response Parameters

Status code: 200

Table 4 Response body parameters

Parameter

Type

Description

code

Integer

Response code

msg

String

Response message

data

ListQueriesData object

Response data

count

Integer

Total records

Table 5 ListQueriesData

Parameter

Type

Description

queries

Array of ListQueriesDto objects

Queried data object list

status

ListQueriesStatus object

Statistical data

Table 6 ListQueriesDto

Parameter

Type

Description

virtual_cluster_id

Integer

Virtual cluster ID

ctime

Long

Collection time

pid

String

Session ID

inst_name

String

Instance name

waiting

Boolean

Whether the backend is currently waiting on a lock. If yes, the value is true.

enqueue

String

Workload management resource status

warning

String

Warnings related to SQL self-diagnosis and tuning

query

String

Query statement

lane

String

Fast or slow lane.

db_name

String

Database name

priority

String

Priority of a job in the resource pool. The value can be 1, 2, 4, or 8 (rush, high, medium, or low).

query_id

String

Internal query_id used for statement execution

query_band

String

Job type, which can be set using the guc parameter query_band. The default value is a null string.

job_name

String

The value is obtained from the query_band field. The position is 0.

job_inst

String

The value is obtained from the query_band field. The position is 1.

user_name

String

Username used for connecting to the backend

application_name

String

Name of the application that is connected to the backend.

client_address

String

IP address of the client connected to this backend.

client_hostname

String

Host name of the client.

client_port

String

TCP port number used by a client to communicate with the backend

start_time

Long

Time when a statement starts to be executed

block_time

Long

Block time before the statement is executed. The unit is ms.

duration

Long

Duration that a statement has been executed. The unit is ms.

estimate_total_time

Long

Estimated execution time of a statement. The unit is ms.

estimate_left_time

Long

Estimated remaining time of statement execution. The unit is ms.

resource_pool

String

Resource pool used by the user

control_group

String

Cgroup used by the statement.

min_peak_memory

Integer

Minimum memory peak of a statement across all DNs. The unit is MB.

max_peak_memory

Integer

Maximum memory peak of a statement across all DNs. The unit is MB.

average_peak_memory

Integer

Average memory usage during statement execution. The unit is MB.

memory_skew_percent

Integer

Memory usage skew of a statement among DNs.

estimate_memory

Integer

Estimated memory used by a statement. The unit is MB.

spill_info

String

Information about the statement spilling to disks on all DNs.

min_spill_size

Integer

Minimum spilled data among all DNs when a spill occurs, in MB. The default value is 0.

max_spill_size

Integer

Maximum spilled data among all DNs when a spill occurs, in MB. The default value is 0.

average_spill_size

Integer

Average spilled data among all DNs when a spill occurs, in MB. The default value is 0.

spill_skew_percent

Integer

DN spill skew.

min_dn_time

Long

Minimum execution time of a statement across all DNs. The unit is ms.

max_dn_time

Long

Minimum execution time of a statement across all DNs. The unit is ms.

average_dn_time

Long

Average execution time of a statement across all DNs. The unit is ms.

dntime_skew_percent

Integer

Execution time skew of a statement among DNs.

min_cpu_time

Long

Minimum CPU time of a statement across all DNs. The unit is milliseconds.

max_cpu_time

Long

Maximum CPU time of a statement across all DNs. The unit is milliseconds.

total_cpu_time

Long

Total CPU time of a statement across all DNs. The unit is milliseconds.

cpu_skew_percent

Integer

CPU time skew of a statement among DNs.

average_peak_iops

Integer

Average IOPS peak of a statement across all DNs. It is counted by ones in a column-store table and by ten thousands in a row-store table.

iops_skew_percent

Integer

I/O skew of a statement among DNs.

max_peak_iops

Integer

Maximum IOPS peak of a statement across all DNs. It is counted by ones in a column-store table and by ten thousands in a row-store table.

min_peak_iops

Integer

Minimum IOPS peak of a statement across all DNs. It is counted by ones in a column-store table and by ten thousands in a row-store table.

query_plan

String

Query Plan

query_status

String

Real-time running status (active, idle, idle in transaction, idle in transaction(aborted), fastpath function call, disabled) of the current query statement.

wlm_status

String

Running status (pending, running, finished, aborted, active, unknown) of the current query statement in the resource pool.

wlm_attrib

String

Statement attribute (ordinary, simple, complicated, internal)

system_query

Boolean

Whether a query is a system query

backend_start

Long

Time when this process was started, that is, when the client connected to the server

elapsed_time

Long

Execution time so far.

curr_xact_start

Long

Time when the current transaction was started (NULL if no transactions are active). If the current query is the first of its transaction, the value of this column is the same as that of the query_start column.

state_change

Long

Time when the status was changed in the previous time

query_start

Long

Time when a statement starts to be executed

query_elapsed_time

Long

Actual execution duration of the statement, in seconds.

Table 7 ListQueriesStatus

Parameter

Type

Description

average_query_waiting_time

Double

Average query wait time

average_time_consumption_of_queries

Double

Average query duration

average_time_consumption_of_sessions

Double

Average session duration

queries_count

Long

Number of records to be queried.

session_count

Long

Sessions

Example Request

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": " User Name",
    "operator" : "="
  }, {
    "field" : "applicationName",
"value": "Application Name",
    "operator" : "<>"
  }, {
    "field" : "dbName",
"value": "Database name",
    "operator" : "="
  }, {
    "field" : "resourcePool",
"value": "Resource Pool",
    "operator" : "<>"
  }, {
    "field" : "queryStatus",
"value": "Query status",
    "operator" : "="
  }, {
    "field" : "enqueue",
"value": "Queuing status",
    "operator" : "<>"
  }, {
    "field" : "lane",
"value": "Fast and slow lane",
    "operator" : "="
  }, {
    "field" : "instName",
"value": "Access CN",
    "operator" : "<>"
  }, {
    "field" : "pid",
"value": "Session 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 spill information",
    "operator" : "="
  }, {
    "field" : "minSpillSize",
    "value" : "7",
    "operator" : "<>"
  }, {
    "field" : "maxSpillSize",
    "value" : "8",
    "operator" : ">"
  }, {
    "field" : "averageSpillSize",
    "value" : "9",
    "operator" : "<"
  }, {
    "field" : "spillSkewPercent",
    "value" : "10",
    "operator" : ">="
  }, {
    "field" : "queryBand",
"value": "Job type",
    "operator" : "<>"
  }, {
    "field" : "jobName",
"value": " Task name",
    "operator" : "="
  }, {
    "field" : "jobInst",
"value": "Task instance",
    "operator" : "<>"
  }, {
    "field" : "clientHostname",
"value": "Host name",
    "operator" : "="
  }, {
    "field" : "clientPort",
"value": "TCP port",
    "operator" : "<>"
  }, {
    "field" : "waiting",
"value": "Wait",
    "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": "Alarm",
    "operator" : "="
  }, {
    "field" : "averagePeakIops",
    "value" : "22",
    "operator" : "<>"
  }, {
    "field" : "iopsSkewPercent",
    "value" : "23",
    "operator" : ">"
  }, {
    "field" : "wlmStatus",
"value": "Statement running status",
    "operator" : "="
  }, {
    "field" : "wlmAttrib",
"value": "Statement attribute",
    "operator" : "not like"
  } ],
  "order_by" : "duration asc",
  "target" : "db_queries"
}

Example Response

Status code: 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 Sample Code

The sample code is as follows:

  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 ("User_name")
                .withOperator("=")
        );
        listbodyConditions.add(
            new ListQueriesCondition()
                .withField("applicationName")
.withValue ("Application_name")
                .withOperator("<>")
        );
        listbodyConditions.add(
            new ListQueriesCondition()
                .withField("dbName")
.withValue ("Database_name")
                .withOperator("=")
        );
        listbodyConditions.add(
            new ListQueriesCondition()
                .withField("resourcePool")
.withValue ("Resource_pool")
                .withOperator("<>")
        );
        listbodyConditions.add(
            new ListQueriesCondition()
                .withField("queryStatus")
.withValue ("Query_status")
                .withOperator("=")
        );
        listbodyConditions.add(
            new ListQueriesCondition()
                .withField("enqueue")
.withValue ("Queuing_status")
                .withOperator("<>")
        );
        listbodyConditions.add(
            new ListQueriesCondition()
                .withField("lane")
.withValue ("Fast/slow_lane")
                .withOperator("=")
        );
        listbodyConditions.add(
            new ListQueriesCondition()
                .withField("instName")
.withValue ("Access_CN")
                .withOperator("<>")
        );
        listbodyConditions.add(
            new ListQueriesCondition()
                .withField("pid")
.withValue ("Session_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_spilling_information")
                .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 ("Job_type")
                .withOperator("<>")
        );
        listbodyConditions.add(
            new ListQueriesCondition()
                .withField("jobName")
.withValue ("Task_name")
                .withOperator("=")
        );
        listbodyConditions.add(
            new ListQueriesCondition()
                .withField("jobInst")
.withValue ("Task_instance")
                .withOperator("<>")
        );
        listbodyConditions.add(
            new ListQueriesCondition()
                .withField("clientHostname")
.withValue ("Host_name")
                .withOperator("=")
        );
        listbodyConditions.add(
            new ListQueriesCondition()
                .withField("clientPort")
.withValue ("TCP_port")
                .withOperator("<>")
        );
        listbodyConditions.add(
            new ListQueriesCondition()
                .withField("waiting")
.withValue ("Wait_or_not")
                .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 ("Alarm")
                .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 ("Statement_running_status")
                .withOperator("=")
        );
        listbodyConditions.add(
            new ListQueriesCondition()
                .withField("wlmAttrib")
.withValue ("Statement_attribute")
                .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="User_name",
                operator="="
            ),
            ListQueriesCondition(
                field="applicationName",
value="Application_name",
                operator="<>"
            ),
            ListQueriesCondition(
                field="dbName",
value="Database_name",
                operator="="
            ),
            ListQueriesCondition(
                field="resourcePool",
value="Resource_pool",
                operator="<>"
            ),
            ListQueriesCondition(
                field="queryStatus",
value="Query_status",
                operator="="
            ),
            ListQueriesCondition(
                field="enqueue",
value="Queuing_status",
                operator="<>"
            ),
            ListQueriesCondition(
                field="lane",
value="Fast/Slow_lane",
                operator="="
            ),
            ListQueriesCondition(
                field="instName",
value="Connected_CN",
                operator="<>"
            ),
            ListQueriesCondition(
                field="pid",
value="Session_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_spilling_information",
                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="Job_type",
                operator="<>"
            ),
            ListQueriesCondition(
                field="jobName",
value="Task_name",
                operator="="
            ),
            ListQueriesCondition(
                field="jobInst",
value="Task_instance",
                operator="<>"
            ),
            ListQueriesCondition(
                field="clientHostname",
value="Host_name",
                operator="="
            ),
            ListQueriesCondition(
                field="clientPort",
value="TCP_port",
                operator="<>"
            ),
            ListQueriesCondition(
                field="waiting",
value="Wait_or_not",
                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="Alarm",
                operator="="
            ),
            ListQueriesCondition(
                field="averagePeakIops",
                value="22",
                operator="<>"
            ),
            ListQueriesCondition(
                field="iopsSkewPercent",
                value="23",
                operator=">"
            ),
            ListQueriesCondition(
                field="wlmStatus",
value="Statement_running_status",
                operator="="
            ),
            ListQueriesCondition(
                field="wlmAttrib",
value="Statement_attribute",
                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: "User_name",
            Operator: "=",
        },
        {
            Field: "applicationName",
Value: "Application_name",
            Operator: "<>",
        },
        {
            Field: "dbName",
Value: "Database_name",
            Operator: "=",
        },
        {
            Field: "resourcePool",
Value: "Resource_pool",
            Operator: "<>",
        },
        {
            Field: "queryStatus",
Value: "Query_status",
            Operator: "=",
        },
        {
            Field: "enqueue",
Value: "Queuing_status",
            Operator: "<>",
        },
        {
            Field: "lane",
Value: "Fast/Slow_lane",
            Operator: "=",
        },
        {
            Field: "instName",
Value: "Connected_CN",
            Operator: "<>",
        },
        {
            Field: "pid",
Value: "Session_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_spilling_information",
            Operator: "=",
        },
        {
            Field: "minSpillSize",
            Value: "7",
            Operator: "<>",
        },
        {
            Field: "maxSpillSize",
            Value: "8",
            Operator: ">",
        },
        {
            Field: "averageSpillSize",
            Value: "9",
            Operator: "<",
        },
        {
            Field: "spillSkewPercent",
            Value: "10",
            Operator: ">=",
        },
        {
            Field: "queryBand",
Value: "Job_type",
            Operator: "<>",
        },
        {
            Field: "jobName",
Value: "Task_name",
            Operator: "=",
        },
        {
            Field: "jobInst",
Value: "Task_instance",
            Operator: "<>",
        },
        {
            Field: "clientHostname",
Value: "Host_name",
            Operator: "=",
        },
        {
            Field: "clientPort",
Value: "TCP_port",
            Operator: "<>",
        },
        {
            Field: "waiting",
Value: "Wait_or_not",
            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: "Alarm",
            Operator: "=",
        },
        {
            Field: "averagePeakIops",
            Value: "22",
            Operator: "<>",
        },
        {
            Field: "iopsSkewPercent",
            Value: "23",
            Operator: ">",
        },
        {
            Field: "wlmStatus",
Value: "Statement_running_status",
            Operator: "=",
        },
        {
            Field: "wlmAttrib",
Value: "Statement_attribute",
            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)
    }
}

For more SDK sample codes of programming languages, visit API Explorer and click the Sample Code tab. Example codes can be automatically generated.

Status Code

Status Code

Description

200

The SQL list is queried successfully.

400

Request error.

401

Authentication failed.

403

You do not have required permissions.

404

No resources found.

500

Internal server error.

503

Service unavailable.