This is an automated email from the ASF dual-hosted git repository.

rong pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/iotdb.git


The following commit(s) were added to refs/heads/master by this push:
     new eba44b18df [IOTDB-2954] fix influxdb protocol bug found in benchmark 
test of verificationQueryMode (#5594)
eba44b18df is described below

commit eba44b18df4546d124382049926ef2d7743d9e6b
Author: Xieqijun <[email protected]>
AuthorDate: Tue Apr 19 23:58:37 2022 +0800

    [IOTDB-2954] fix influxdb protocol bug found in benchmark test of 
verificationQueryMode (#5594)
    
    Co-authored-by: xieqijun <[email protected]>
---
 .../iotdb/influxdb/session/InfluxDBSession.java    |  6 +--
 .../influxdb/integration/IoTDBInfluxDBIT.java      |  4 +-
 .../db/protocol/influxdb/handler/QueryHandler.java |  4 +-
 .../db/protocol/influxdb/util/JacksonUtils.java    | 44 ++++++++++++++++++++++
 .../db/protocol/influxdb/util/StringUtils.java     |  3 +-
 5 files changed, 53 insertions(+), 8 deletions(-)

diff --git 
a/influxdb-protocol/src/main/java/org/apache/iotdb/influxdb/session/InfluxDBSession.java
 
b/influxdb-protocol/src/main/java/org/apache/iotdb/influxdb/session/InfluxDBSession.java
index 6c4b52d08e..4bee62d86c 100644
--- 
a/influxdb-protocol/src/main/java/org/apache/iotdb/influxdb/session/InfluxDBSession.java
+++ 
b/influxdb-protocol/src/main/java/org/apache/iotdb/influxdb/session/InfluxDBSession.java
@@ -20,6 +20,7 @@
 package org.apache.iotdb.influxdb.session;
 
 import org.apache.iotdb.db.conf.IoTDBDescriptor;
+import org.apache.iotdb.db.protocol.influxdb.util.JacksonUtils;
 import org.apache.iotdb.protocol.influxdb.rpc.thrift.InfluxCloseSessionReq;
 import org.apache.iotdb.protocol.influxdb.rpc.thrift.InfluxCreateDatabaseReq;
 import org.apache.iotdb.protocol.influxdb.rpc.thrift.InfluxDBService;
@@ -35,7 +36,6 @@ import org.apache.iotdb.rpc.RpcUtils;
 import org.apache.iotdb.rpc.StatementExecutionException;
 import org.apache.iotdb.session.Config;
 
-import com.google.gson.Gson;
 import org.apache.thrift.TException;
 import org.apache.thrift.protocol.TBinaryProtocol;
 import org.apache.thrift.protocol.TCompactProtocol;
@@ -182,7 +182,7 @@ public class InfluxDBSession {
     try {
       InfluxQueryResultRsp tsQueryResultRsp = client.query(request);
       RpcUtils.verifySuccess(tsQueryResultRsp.status);
-      return new Gson().fromJson(tsQueryResultRsp.resultJsonString, 
QueryResult.class);
+      return JacksonUtils.json2Bean(tsQueryResultRsp.resultJsonString, 
QueryResult.class);
     } catch (TException e) {
       e.printStackTrace();
       logger.error(e.getMessage());
@@ -191,7 +191,7 @@ public class InfluxDBSession {
           request.setSessionId(sessionId);
           InfluxQueryResultRsp tsQueryResultRsp = client.query(request);
           RpcUtils.verifySuccess(tsQueryResultRsp.status);
-          return new Gson().fromJson(tsQueryResultRsp.resultJsonString, 
QueryResult.class);
+          return JacksonUtils.json2Bean(tsQueryResultRsp.resultJsonString, 
QueryResult.class);
         } catch (TException e1) {
           throw new IoTDBConnectionException(e1);
         }
diff --git 
a/influxdb-protocol/src/test/java/org/apache/iotdb/influxdb/integration/IoTDBInfluxDBIT.java
 
b/influxdb-protocol/src/test/java/org/apache/iotdb/influxdb/integration/IoTDBInfluxDBIT.java
index 079878a915..86c1972faf 100644
--- 
a/influxdb-protocol/src/test/java/org/apache/iotdb/influxdb/integration/IoTDBInfluxDBIT.java
+++ 
b/influxdb-protocol/src/test/java/org/apache/iotdb/influxdb/integration/IoTDBInfluxDBIT.java
@@ -178,7 +178,7 @@ public class IoTDBInfluxDBIT {
     QueryResult result = influxDB.query(query);
     QueryResult.Series series = result.getResults().get(0).getSeries().get(0);
 
-    Object[] retArray = new Object[] {0.0, 99.0, 87.0, 186.0, 2.0, 12.0, 93.0, 
87.0, 99.0};
+    Object[] retArray = new Object[] {0, 99.0, 87.0, 186.0, 2, 12.0, 93.0, 87, 
99};
     for (int i = 0; i < series.getColumns().size(); i++) {
       assertEquals(retArray[i], series.getValues().get(0).get(i));
     }
@@ -194,7 +194,7 @@ public class IoTDBInfluxDBIT {
     QueryResult.Series series = result.getResults().get(0).getSeries().get(0);
 
     Object[] retArray =
-        new Object[] {0.0, 2.0, 87.0, "china", 99.0, 93.0, 93.0, 87.0, 87.0, 
12.0, 6.0, 186.0};
+        new Object[] {0, 2, 87, "china", 99.0, 93.0, 93.0, 87.0, 87, 12.0, 
6.0, 186.0};
     for (int i = 0; i < series.getColumns().size(); i++) {
       assertEquals(retArray[i], series.getValues().get(0).get(i));
     }
diff --git 
a/server/src/main/java/org/apache/iotdb/db/protocol/influxdb/handler/QueryHandler.java
 
b/server/src/main/java/org/apache/iotdb/db/protocol/influxdb/handler/QueryHandler.java
index 0ec2fa1f56..69c9ca4970 100644
--- 
a/server/src/main/java/org/apache/iotdb/db/protocol/influxdb/handler/QueryHandler.java
+++ 
b/server/src/main/java/org/apache/iotdb/db/protocol/influxdb/handler/QueryHandler.java
@@ -35,6 +35,7 @@ import 
org.apache.iotdb.db.protocol.influxdb.operator.InfluxQueryOperator;
 import org.apache.iotdb.db.protocol.influxdb.operator.InfluxSelectComponent;
 import org.apache.iotdb.db.protocol.influxdb.util.FieldUtils;
 import org.apache.iotdb.db.protocol.influxdb.util.FilterUtils;
+import org.apache.iotdb.db.protocol.influxdb.util.JacksonUtils;
 import org.apache.iotdb.db.protocol.influxdb.util.QueryResultUtils;
 import org.apache.iotdb.db.protocol.influxdb.util.StringUtils;
 import org.apache.iotdb.db.qp.constant.FilterConstant;
@@ -61,7 +62,6 @@ import org.apache.iotdb.tsfile.read.expression.IExpression;
 import org.apache.iotdb.tsfile.read.expression.impl.SingleSeriesExpression;
 import org.apache.iotdb.tsfile.read.query.dataset.QueryDataSet;
 
-import com.google.gson.Gson;
 import org.apache.thrift.TException;
 import org.influxdb.InfluxDBException;
 import org.influxdb.dto.QueryResult;
@@ -112,7 +112,7 @@ public class QueryHandler {
                 queryOperator.getSelectComponent(), database, measurement, 
serviceProvider);
       }
       return tsQueryResultRsp
-          .setResultJsonString(new Gson().toJson(queryResult))
+          .setResultJsonString(JacksonUtils.bean2Json(queryResult))
           .setStatus(RpcUtils.getInfluxDBStatus(TSStatusCode.SUCCESS_STATUS));
     } catch (AuthException e) {
       return tsQueryResultRsp.setStatus(
diff --git 
a/server/src/main/java/org/apache/iotdb/db/protocol/influxdb/util/JacksonUtils.java
 
b/server/src/main/java/org/apache/iotdb/db/protocol/influxdb/util/JacksonUtils.java
new file mode 100644
index 0000000000..062c80320f
--- /dev/null
+++ 
b/server/src/main/java/org/apache/iotdb/db/protocol/influxdb/util/JacksonUtils.java
@@ -0,0 +1,44 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.iotdb.db.protocol.influxdb.util;
+
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.databind.ObjectMapper;
+
+import java.io.IOException;
+
+public class JacksonUtils {
+  private static final ObjectMapper mapper = new ObjectMapper();
+
+  public static String bean2Json(Object obj) {
+    try {
+      return mapper.writeValueAsString(obj);
+    } catch (JsonProcessingException e) {
+      return null;
+    }
+  }
+
+  public static <T> T json2Bean(String jsonStr, Class<T> objClass) {
+    try {
+      return mapper.readValue(jsonStr, objClass);
+    } catch (IOException e) {
+      return null;
+    }
+  }
+}
diff --git 
a/server/src/main/java/org/apache/iotdb/db/protocol/influxdb/util/StringUtils.java
 
b/server/src/main/java/org/apache/iotdb/db/protocol/influxdb/util/StringUtils.java
index 39449b63d9..40d588c979 100644
--- 
a/server/src/main/java/org/apache/iotdb/db/protocol/influxdb/util/StringUtils.java
+++ 
b/server/src/main/java/org/apache/iotdb/db/protocol/influxdb/util/StringUtils.java
@@ -32,7 +32,8 @@ public class StringUtils {
    * @return string after processing
    */
   public static String removeQuotation(String str) {
-    if (str.charAt(0) == '"' && str.charAt(str.length() - 1) == '"') {
+    if ((str.charAt(0) == '"' && str.charAt(str.length() - 1) == '"')
+        || str.charAt(0) == '\'' && str.charAt(str.length() - 1) == '\'') {
       return str.substring(1, str.length() - 1);
     }
     return str;

Reply via email to