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/09/22 04:39:33 UTC

[GitHub] [incubator-iotdb] qiaojialin 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.

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



##########
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(TSDataType.deserialize((short) 1));
+              field.setIntV(booleanValue ? 1 : 0);
+            }

Review comment:
       Hi, I think we should not change the type of Field. This issue only changes how the getString() method returns data.

##########
File path: session/src/test/java/org/apache/iotdb/session/IoTDBSessionSimpleIT.java
##########
@@ -66,6 +68,44 @@ public void tearDown() throws Exception {
     EnvironmentUtils.cleanEnv();
   }
 
+  @Test
+  public void testBoolFormat() throws IoTDBConnectionException, StatementExecutionException {
+    Map<String, String> map = new HashMap<>();
+    map.put("boolFormat", "number");
+    session = new Session("127.0.0.1", 6667, "root", "root", map);
+    session.open();
+
+    String deviceId = "root.sg1.d1";
+    List<String> measurements = new ArrayList<>();
+    measurements.add("s1");
+    measurements.add("s2");
+    measurements.add("s3");
+    measurements.add("s4");
+
+    List<TSDataType> dataTypes = new ArrayList<>();
+    dataTypes.add(TSDataType.INT64);
+    dataTypes.add(TSDataType.BOOLEAN);
+    dataTypes.add(TSDataType.TEXT);
+    dataTypes.add(TSDataType.TEXT);
+
+    List<Object> values = new ArrayList<>();
+    values.add(311L);
+    values.add(true);
+    values.add("String1");
+    values.add("String2");
+    session.insertRecord(deviceId, 1L, measurements, dataTypes, values);
+
+    String expected = "1";
+    SessionDataSet dataSet = session.executeQueryStatement("select s2 from root.sg1.d1");
+    while (dataSet.hasNext()) {
+      List<Field> fields = dataSet.next().getFields();

Review comment:
       Hi, you could use the SessionDataSet.Iterator()   to get the iterator and use the iterator.getString() that triggers the config.




----------------------------------------------------------------
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