From 56e9d4e2b36c6d691e296b2c5759718e7ef76556 Mon Sep 17 00:00:00 2001 From: Jialin Qiao Date: Thu, 7 Nov 2019 16:14:06 +0800 Subject: [PATCH] fix auto create bool type (#534) --- .../assembly/resources/conf/iotdb-engine.properties | 2 +- .../org/apache/iotdb/db/utils/TypeInferenceUtils.java | 10 ++++++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/server/src/assembly/resources/conf/iotdb-engine.properties b/server/src/assembly/resources/conf/iotdb-engine.properties index 3d45d57b60..44d69fe899 100644 --- a/server/src/assembly/resources/conf/iotdb-engine.properties +++ b/server/src/assembly/resources/conf/iotdb-engine.properties @@ -330,7 +330,7 @@ watermark_method=GroupBasedLSBMethod(embed_row_cycle=2,embed_lsb_num=5) #################### # Whether creating schema automatically is enabled -enable_auto_create_schema=false +enable_auto_create_schema=true # Storage group level when creating schema automatically is enabled # e.g. root.sg0.d1.s2 diff --git a/server/src/main/java/org/apache/iotdb/db/utils/TypeInferenceUtils.java b/server/src/main/java/org/apache/iotdb/db/utils/TypeInferenceUtils.java index 934bc8ce03..63c79a3125 100644 --- a/server/src/main/java/org/apache/iotdb/db/utils/TypeInferenceUtils.java +++ b/server/src/main/java/org/apache/iotdb/db/utils/TypeInferenceUtils.java @@ -19,6 +19,7 @@ package org.apache.iotdb.db.utils; +import org.apache.iotdb.db.qp.constant.SQLConstant; import org.apache.iotdb.tsfile.file.metadata.enums.TSDataType; public class TypeInferenceUtils { @@ -27,7 +28,7 @@ public class TypeInferenceUtils { } - public static boolean isNumber(String s) { + static boolean isNumber(String s) { try { Double.parseDouble(s); } catch (NumberFormatException e) { @@ -36,11 +37,16 @@ public class TypeInferenceUtils { return true; } + private static boolean isBoolean(String s) { + return s.equalsIgnoreCase(SQLConstant.BOOLEN_TRUE) || s + .equalsIgnoreCase(SQLConstant.BOOLEN_FALSE); + } + /** * Get predicted DataType of the given value */ public static TSDataType getPredictedDataType(Object value) { - if (value instanceof Boolean) { + if (value instanceof Boolean || (value instanceof String && isBoolean((String) value))) { return TSDataType.BOOLEAN; } else if (value instanceof Number || (value instanceof String && isNumber((String) value))) { String v = String.valueOf(value); -- GitLab