Influx提供多条语句的同时查询(Multiple queries):
curl -G 'http://localhost:8086/query?pretty=true' --data-urlencode "db=mydb" --data-urlencode "q=SELECT \"value\" FROM \"cpu_load_short\" WHERE \"region\"='us-west';SELECT count(\"value\") FROM \"cpu_load_short\" WHERE \"region\"='us-west'"
就是说我一次请求可以同时执行多条sql,官网明确说明只要每个sql中间用分号(;)隔开就好。
获取信息的代码:
public void getTest(){
RestTemplate restTemplate=new RestTemplate();
String url="http://localhost:8086/query?pretty=true&q=select * from pkk;select count(*) from pkk&db=mydb";
String points=restTemplate.getForObject(url,String.class);
System.out.println("points:"+points);
}
返回的信息:
points:{
"results": [
{
"statement_id": 0,
"series": [
{
"name": "pkk",
"columns": [
"time",
"address",
"age",
"name"
],
"values": [
[
"2017-07-28T01:32:03.378554614Z",
"shanghai",
21,
"pangkun1"
],
[
"2017-07-28T01:32:03.378554614Z",
"shanghai",
23,
"pangkun3"
],
[
"2017-07-28T01:32:03.378554614Z",
"shanghai",
22,
"pangkun2"
]
]
}
]
}
]
}
这里可以看出上边返回的只有第一条查询语句的结果,第二条根本就没有执行,或者执行后根本就没返回。
同样的sql在InfluxDB的web端可以正常返回数据,但是放到代码中就是查询不出结果。
所以我判断问题应该是出在两条sql的连接处–分号,仔细查看curl中的url是说要encode的,现在看下web端执行成功的url:
http://localhost:8086/query?q=select+*+from+pkk%3Bselect+count(*)+from+pkk&db=mydb
通过抓包,或者直接在浏览器中执行我代码中的URL:
http://localhost:8086/query?pretty=true&q=select%20*%20from%20pkk;select%20count(*)%20from%20pkk&db=mydb
仔细对比可以发现自己执行的url中的分号(;)并没有没加密处理,在网上搜索可以看到其对应的编码为%3B。
所以,现在的问题是sping的resttemplate没有对分号进行处理。解决方案&