You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@iotdb.apache.org by GitBox <gi...@apache.org> on 2020/08/31 02:33:13 UTC

[GitHub] [incubator-iotdb] HTHou commented on a change in pull request #1642: In Session, the JDBC module can set the Boolean return data type to 0/1 or true/false.

HTHou commented on a change in pull request #1642:
URL: https://github.com/apache/incubator-iotdb/pull/1642#discussion_r479850893



##########
File path: jdbc/src/main/java/org/apache/iotdb/jdbc/Utils.java
##########
@@ -43,6 +47,20 @@ static IoTDBConnectionParams parseUrl(String url, Properties info)
     Matcher matcher = null;
     if (url.startsWith(Config.IOTDB_URL_PREFIX)) {
       String subURL = url.substring(Config.IOTDB_URL_PREFIX.length());
+      Map<String,String> paramKV = new HashMap<>();
+      if (subURL.contains(PARAMS_SEPARATION)){
+        int separationIndex = subURL.indexOf(PARAMS_SEPARATION);
+        String[] parameters = subURL.substring(separationIndex+1).split(PARAMS_JOIN);
+        subURL = subURL.substring(0, separationIndex);
+        for (int i=0; i<parameters.length; i++){
+          String[] kv = parameters[i].split(PARAMS_ASSIGNMENT);
+          if (kv.length<2){

Review comment:
       ```suggestion
             if (kv.length < 2) {
   ```

##########
File path: jdbc/src/main/java/org/apache/iotdb/jdbc/Utils.java
##########
@@ -43,6 +47,20 @@ static IoTDBConnectionParams parseUrl(String url, Properties info)
     Matcher matcher = null;
     if (url.startsWith(Config.IOTDB_URL_PREFIX)) {
       String subURL = url.substring(Config.IOTDB_URL_PREFIX.length());
+      Map<String,String> paramKV = new HashMap<>();
+      if (subURL.contains(PARAMS_SEPARATION)){

Review comment:
       ```suggestion
         if (subURL.contains(PARAMS_SEPARATION)) {
   ```

##########
File path: jdbc/src/main/java/org/apache/iotdb/jdbc/Utils.java
##########
@@ -43,6 +47,20 @@ static IoTDBConnectionParams parseUrl(String url, Properties info)
     Matcher matcher = null;
     if (url.startsWith(Config.IOTDB_URL_PREFIX)) {
       String subURL = url.substring(Config.IOTDB_URL_PREFIX.length());
+      Map<String,String> paramKV = new HashMap<>();
+      if (subURL.contains(PARAMS_SEPARATION)){
+        int separationIndex = subURL.indexOf(PARAMS_SEPARATION);
+        String[] parameters = subURL.substring(separationIndex+1).split(PARAMS_JOIN);
+        subURL = subURL.substring(0, separationIndex);
+        for (int i=0; i<parameters.length; i++){

Review comment:
       ```suggestion
           for (int i = 0; i < parameters.length; i++) {
   ```

##########
File path: cli/src/main/java/org/apache/iotdb/cli/WinCli.java
##########
@@ -120,6 +120,12 @@ private static void serve() {
       host = checkRequiredArg(HOST_ARGS, HOST_NAME, commandLine, false, host);
       port = checkRequiredArg(PORT_ARGS, PORT_NAME, commandLine, false, port);
       username = checkRequiredArg(USERNAME_ARGS, USERNAME_NAME, commandLine, true, null);
+
+      boolFormat = checkRequiredArg(BOOL_FORMAT_ARGS,BOOL_FORMAT_ARGS,commandLine,false, boolFormat);

Review comment:
       ```suggestion
         boolFormat = checkRequiredArg(BOOL_FORMAT_ARGS, BOOL_FORMAT_ARGS, commandLine, false, boolFormat);
   ```

##########
File path: cli/src/main/java/org/apache/iotdb/cli/Cli.java
##########
@@ -115,6 +115,11 @@ private static void serve() {
       port = checkRequiredArg(PORT_ARGS, PORT_NAME, commandLine, false, port);
       username = checkRequiredArg(USERNAME_ARGS, USERNAME_NAME, commandLine, true, null);
 
+      boolFormat = checkRequiredArg(BOOL_FORMAT_ARGS,BOOL_FORMAT_ARGS,commandLine,false, boolFormat);
+      if (NUMBER.equals(boolFormat)){

Review comment:
       ```suggestion
         boolFormat = checkRequiredArg(BOOL_FORMAT_ARGS, BOOL_FORMAT_ARGS, commandLine, false, boolFormat);
         if (NUMBER.equals(boolFormat)) {
   ```

##########
File path: session/src/main/java/org/apache/iotdb/session/SessionDataSet.java
##########
@@ -93,7 +93,12 @@ private RowRecord constructRowRecordFromValueArray() throws StatementExecutionEx
         switch (dataType) {
           case BOOLEAN:
             boolean booleanValue = BytesUtils.bytesToBool(valueBytes);
-            field.setBoolV(booleanValue);
+            if (org.apache.iotdb.rpc.Config.boolFormat== org.apache.iotdb.rpc.Config.Constant.BOOLEAN){
+              field.setBoolV(booleanValue);
+            }else{
+              field = new Field(ioTDBRpcDataSet.columnTypeDeduplicatedList.get(1));
+              field.setLongV(booleanValue?1:0);
+            }

Review comment:
       ```suggestion
               if (org.apache.iotdb.rpc.Config.boolFormat == org.apache.iotdb.rpc.Config.Constant.BOOLEAN) {
                 field.setBoolV(booleanValue);
               } else {
                 field = new Field(ioTDBRpcDataSet.columnTypeDeduplicatedList.get(1));
                 field.setLongV(booleanValue ? 1 : 0);
               }
   ```

##########
File path: jdbc/src/main/java/org/apache/iotdb/jdbc/Utils.java
##########
@@ -43,6 +47,20 @@ static IoTDBConnectionParams parseUrl(String url, Properties info)
     Matcher matcher = null;
     if (url.startsWith(Config.IOTDB_URL_PREFIX)) {
       String subURL = url.substring(Config.IOTDB_URL_PREFIX.length());
+      Map<String,String> paramKV = new HashMap<>();
+      if (subURL.contains(PARAMS_SEPARATION)){
+        int separationIndex = subURL.indexOf(PARAMS_SEPARATION);
+        String[] parameters = subURL.substring(separationIndex+1).split(PARAMS_JOIN);

Review comment:
       ```suggestion
           String[] parameters = subURL.substring(separationIndex + 1).split(PARAMS_JOIN);
   ```

##########
File path: jdbc/src/main/java/org/apache/iotdb/jdbc/Utils.java
##########
@@ -43,6 +47,20 @@ static IoTDBConnectionParams parseUrl(String url, Properties info)
     Matcher matcher = null;
     if (url.startsWith(Config.IOTDB_URL_PREFIX)) {
       String subURL = url.substring(Config.IOTDB_URL_PREFIX.length());
+      Map<String,String> paramKV = new HashMap<>();
+      if (subURL.contains(PARAMS_SEPARATION)){
+        int separationIndex = subURL.indexOf(PARAMS_SEPARATION);
+        String[] parameters = subURL.substring(separationIndex+1).split(PARAMS_JOIN);
+        subURL = subURL.substring(0, separationIndex);
+        for (int i=0; i<parameters.length; i++){
+          String[] kv = parameters[i].split(PARAMS_ASSIGNMENT);
+          if (kv.length<2){
+            continue;
+          }
+          paramKV.put(kv[0],kv[1]);

Review comment:
       ```suggestion
             paramKV.put(kv[0], kv[1]);
   ```

##########
File path: service-rpc/src/main/java/org/apache/iotdb/rpc/Config.java
##########
@@ -0,0 +1,42 @@
+package org.apache.iotdb.rpc;
+
+
+/**
+ * @author chenPeng
+ * @version 1.0.0
+ * @ClassName Config.java
+ * @Description TODO
+ * @createTime 2020年08月19日 22:26:00
+ */
+public class Config {

Review comment:
       Also, please update the rpc change list md doc if you make a change in rpc module.

##########
File path: jdbc/src/main/java/org/apache/iotdb/jdbc/IoTDBConnection.java
##########
@@ -76,6 +76,10 @@ public IoTDBConnection(String url, Properties info) throws SQLException, TTransp
     }
     params = Utils.parseUrl(url, info);
 
+    String boolFormat = params.getParams().get(org.apache.iotdb.jdbc.Config.PARAMS_BOOL_FORMAT);
+    if (Config.Constant.NUMBER.getType().equals(boolFormat)){

Review comment:
       ```suggestion
       if (Config.Constant.NUMBER.getType().equals(boolFormat)) {
   ```

##########
File path: service-rpc/src/main/java/org/apache/iotdb/rpc/IoTDBRpcDataSet.java
##########
@@ -391,7 +391,12 @@ public String getValueByName(String columnName) throws StatementExecutionExcepti
   public String getString(int index, TSDataType tsDataType, byte[][] values) {
     switch (tsDataType) {
       case BOOLEAN:
-        return String.valueOf(BytesUtils.bytesToBool(values[index]));
+        boolean result = BytesUtils.bytesToBool(values[index]);
+        if (Config.boolFormat== Config.Constant.BOOLEAN){
+          return String.valueOf(result);
+        }else{
+          return String.valueOf(result?1:0);
+        }

Review comment:
       ```suggestion
           if (Config.boolFormat == Config.Constant.BOOLEAN) {
             return String.valueOf(result);
           } else {
             return String.valueOf(result ? 1 : 0);
           }
   ```

##########
File path: service-rpc/src/main/java/org/apache/iotdb/rpc/Config.java
##########
@@ -0,0 +1,42 @@
+package org.apache.iotdb.rpc;
+
+
+/**
+ * @author chenPeng
+ * @version 1.0.0
+ * @ClassName Config.java
+ * @Description TODO
+ * @createTime 2020年08月19日 22:26:00
+ */
+public class Config {

Review comment:
       Please reformat this class and avoid use Chinese in Javadoc. 

##########
File path: session/src/main/java/org/apache/iotdb/session/Session.java
##########
@@ -172,8 +193,13 @@ private synchronized void open(boolean enableRPCCompression, int connectionTimeo
     }
     isClosed = false;
 
+    String boolFormat = params.get(Config.PARAMS_BOOL_FORMAT);
+    if (org.apache.iotdb.rpc.Config.Constant.NUMBER.getType().equals(boolFormat)){

Review comment:
       ```suggestion
       if (org.apache.iotdb.rpc.Config.Constant.NUMBER.getType().equals(boolFormat)) {
   ```




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org