The Traffic API provides SQL-based search syntax for various query scenarios.
URL
sql?query=SELECT brand, COUNT(*) FROM phone GROUP BY (brand)&&kvpair=trace:INFO;formatType:json
-
This URL omits request header parameters and encoding.
-
This URL omits the application host address.
-
For query parameter definitions and examples, see the Query parameters section.
Request protocol
HTTP
Request method
GET
Supported format
JSON
Signature mechanism
Calculate the authorization signature as follows
|
Parameter |
Type |
Description |
|
accessUserName |
String |
The username. Find it on the Instance Details > Network Information page. |
|
accessPassWord |
String |
The password. Change it on the Instance Details > Network Information page. |
import com.aliyun.darabonba.encode.Encoder;
import com.aliyun.darabonbastring.Client;
public class GenerateAuthorization {
public static void main(String[] args) throws Exception {
String accessUserName = "username";
String accessPassWord = "password";
String realmStr = "" + accessUserName + ":" + accessPassWord + "";
String authorization = Encoder.base64EncodeToString(Client.toBytes(realmStr, "UTF-8"));
System.out.println(authorization);
}
}
The following example shows the expected authorization output.
cm9vdDp******mdhbA==
Add the `Basic` prefix to the authorization parameter in HTTP requests.
Example:
authorization: Basic cm9vdDp******mdhbA==
Query parameters
|
Parameter |
Type |
Required |
Description |
|
query clause |
String |
Yes |
For more information, see query clause. |
|
kvpairs clause |
String |
No |
For more information, see kvpair clause. |
Query parameter usage
-
query: Use the query clause to write a complete SQL statement.
Response parameters
|
Parameter |
Type |
Description |
|
total_time |
String |
The record ID of the query. Use this ID for troubleshooting. |
|
covered_percent |
The coverage percentage. |
|
|
row_count |
int |
curl example
curl --location --request GET 'http://ha-cn-*******.public.ha.aliyuncs.com/query?sql=query=select * from index_hdf%26%26kvpair=trace:INFO;format:full_json' \
--header 'authorization: Basic ******************' \
--header 'host: ha-cn-*******.public.ha.aliyuncs.com'
-
The example uses a public network endpoint. For more information, see Network Information.
Search example
Normal response
{
"total_time": 4.557,
"covered_percent": 1.0,
"row_count": 1,
"format_type": "full_json",
"search_info": {},
"trace": [],
"sql_result": {
"data": [
[
1
]
],
"column_name": [
"id"
],
"column_type": [
"int64"
]
},
"error_info": {
"ErrorCode": 0,
"Error": "ERROR_NONE",
"Message": ""
}
}
Error response
{
"total_time": 15.96,
"covered_percent": 0.0,
"row_count": 0,
"format_type": "full_json",
"search_info": {},
"trace": [],
"sql_result": {
"data": [],
"column_name": [],
"column_type": []
},
"error_info": {
"ErrorCode": 8010,
"Error": "call sql plan service failed.",
"Message": "failed to get sql plan, error message is [IQUAN_EC_INTERNAL_ERROR] internal error : SQL validation failed. From line 1, column 15 to line 1, column 23: Object 'index_hdf' not found\nFrom line 1, column 15 to line 1, column 23: Object 'index_hdf' not found\norg.apache.flink.table.api.ValidationException: SQL validation failed. From line 1, column 15 to line 1, column 23: Object 'index_hdf' not found\n\tat org.apache.flink.table.planner.calcite.FlinkPlannerImpl.org$apache$flink$table$planner$calcite$FlinkPlannerImpl$$validate(FlinkPlannerImpl.scala:149)\n\tat org.apache.flink.table.planner.calcite.FlinkPlannerImpl.validate(FlinkPlannerImpl.scala:108)\n\tat org.apache.flink.table.planner.delegation.ParserImpl.validate(ParserImpl.java:91)\n\tat com.taobao.search.iquan.core.api.impl.SqlQueryableImpl$SqlWorkFlow.validateSql(SqlQueryableImpl.java:646)\n\tat com.taobao.search.iquan.core.api.impl.SqlQueryableImpl$SqlWorkFlow.process(SqlQueryableImpl.java:392)\n\tat com.taobao.search.iquan.core.api.impl.SqlQueryableImpl.select(SqlQueryableImpl.java:134)\n\tat com.taobao.search.iquan.client.common.service.SqlQueryService.sqlQuery(SqlQueryService.java:89)\n\tat com.taobao.search.iquan.client.IquanClient.sqlQuery(IquanClient.java:79)\nCaused by: org.apache.calcite.runtime.CalciteContextException: From line 1, column 15 to line 1, column 23: Object 'index_hdf' not found\n\tat sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)\n\tat sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)\n\tat sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)\n\tat java.lang.reflect.Constructor.newInstance(Constructor.java:422)\n\tat org.apache.calcite.runtime.Resources$ExInstWithCause.ex(Resources.java:467)\n\tat org.apache.calcite.sql.SqlUtil.newContextException(SqlUtil.java:883)\n\tat org.apache.calcite.sql.SqlUtil.newContextException(SqlUtil.java:868)\n\tat org.apache.calcite.sql.validate.SqlValidatorImpl.newValidationError(SqlValidatorImpl.java:5032)\n\tat org.apache.calcite.sql.validate.IdentifierNamespace.resolveImpl(IdentifierNamespace.java:179)\n\tat org.apache.calcite.sql.validate.IdentifierNamespace.validateImpl(IdentifierNamespace.java:184)\n\tat org.apache.calcite.sql.validate.AbstractNamespace.validate(AbstractNamespace.java:84)\n\tat org.apache.calcite.sql.validate.SqlValidatorImpl.validateNamespace(SqlValidatorImpl.java:1067)\n\tat org.apache.calcite.sql.validate.SqlValidatorImpl.validateQuery(SqlValidatorImpl.java:1041)\n\tat org.apache.calcite.sql.validate.SqlValidatorImpl.validateFrom(SqlValidatorImpl.java:3202)\n\tat org.apache.calcite.sql.validate.SqlValidatorImpl.validateFrom(SqlValidatorImpl.java:3187)\n\tat org.apache.calcite.sql.validate.SqlValidatorImpl.validateSelect(SqlValidatorImpl.java:3450)\n\tat org.apache.calcite.sql.validate.SelectNamespace.validateImpl(SelectNamespace.java:60)\n\tat org.apache.calcite.sql.validate.AbstractNamespace.validate(AbstractNamespace.java:84)\n\tat org.apache.calcite.sql.validate.SqlValidatorImpl.validateNamespace(SqlValidatorImpl.java:1067)\n\tat org.apache.calcite.sql.validate.SqlValidatorImpl.validateQuery(SqlValidatorImpl.java:1041)\n\tat org.apache.calcite.sql.SqlSelect.validate(SqlSelect.java:232)\n\tat org.apache.calcite.sql.validate.SqlValidatorImpl.validateScopedExpression(SqlValidatorImpl.java:1016)\n\tat org.apache.calcite.sql.validate.SqlValidatorImpl.validate(SqlValidatorImpl.java:724)\n\tat org.apache.flink.table.planner.calcite.FlinkPlannerImpl.org$apache$flink$table$planner$calcite$FlinkPlannerImpl$$validate(FlinkPlannerImpl.scala:144)\n\t... 7 more\nCaused by: org.apache.calcite.sql.validate.SqlValidatorException: Object 'index_hdf' not found\n\tat sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)\n\tat sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)\n\tat sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)\n\tat java.lang.reflect.Constructor.newInstance(Constructor.java:422)\n\tat org.apache.calcite.runtime.Resources$ExInstWithCause.ex(Resources.java:467)\n\tat org.apache.calcite.runtime.Resources$ExInst.ex(Resources.java:560)\n\t... 26 more\n"
}
}
Notes
-
If the query length exceeds 30 KB, use the RESTful API for search processing.