You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@iotdb.apache.org by ha...@apache.org on 2022/09/14 09:40:56 UTC

[iotdb] branch master updated: Add cases for Data Type Conversion Function in UserGuide (#7309)

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

haonan 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 3a6efcac95 Add cases for Data Type Conversion Function in UserGuide (#7309)
3a6efcac95 is described below

commit 3a6efcac95c828ccb48be8033bd195a8cacc0f2f
Author: 肖志红 <73...@users.noreply.github.com>
AuthorDate: Wed Sep 14 17:40:49 2022 +0800

    Add cases for Data Type Conversion Function in UserGuide (#7309)
---
 docs/UserGuide/Query-Data/Select-Expression.md    | 63 +++++++++++++++++++++++
 docs/zh/UserGuide/Query-Data/Select-Expression.md | 61 ++++++++++++++++++++++
 2 files changed, 124 insertions(+)

diff --git a/docs/UserGuide/Query-Data/Select-Expression.md b/docs/UserGuide/Query-Data/Select-Expression.md
index 5b5f7da815..5932d162e1 100644
--- a/docs/UserGuide/Query-Data/Select-Expression.md
+++ b/docs/UserGuide/Query-Data/Select-Expression.md
@@ -413,9 +413,72 @@ The IoTDB currently supports 6 data types, including INT32, INT64 ,FLOAT, DOUBLE
 
 #### Notes
 1. The value of type BOOLEAN is `true`, when data is converted to BOOLEAN if INT32 and INT64 are not 0, FLOAT and DOUBLE are not 0.0, TEXT is not empty string or "false", otherwise `false`.    
+
+```
+IoTDB> show timeseries root.sg.d1.*;
++-------------+-----+-------------+--------+--------+-----------+----+----------+
+|   timeseries|alias|storage group|dataType|encoding|compression|tags|attributes|
++-------------+-----+-------------+--------+--------+-----------+----+----------+
+|root.sg.d1.s3| null|      root.sg|   FLOAT|     RLE|     SNAPPY|null|      null|
+|root.sg.d1.s4| null|      root.sg|  DOUBLE|     RLE|     SNAPPY|null|      null|
+|root.sg.d1.s5| null|      root.sg|    TEXT|   PLAIN|     SNAPPY|null|      null|
+|root.sg.d1.s6| null|      root.sg| BOOLEAN|     RLE|     SNAPPY|null|      null|
+|root.sg.d1.s1| null|      root.sg|   INT32|     RLE|     SNAPPY|null|      null|
+|root.sg.d1.s2| null|      root.sg|   INT64|     RLE|     SNAPPY|null|      null|
++-------------+-----+-------------+--------+--------+-----------+----+----------+
+Total line number = 6
+It costs 0.006s
+IoTDB> select * from root.sg.d1;
++-----------------------------+-------------+-------------+-------------+-------------+-------------+-------------+
+|                         Time|root.sg.d1.s3|root.sg.d1.s4|root.sg.d1.s5|root.sg.d1.s6|root.sg.d1.s1|root.sg.d1.s2|
++-----------------------------+-------------+-------------+-------------+-------------+-------------+-------------+
+|1970-01-01T08:00:00.001+08:00|          1.1|          1.1|         test|        false|            1|            1|
+|1970-01-01T08:00:00.002+08:00|         -2.2|         -2.2|        false|         true|           -2|           -2|
+|1970-01-01T08:00:00.003+08:00|          0.0|          0.0|         true|         true|            0|            0|
++-----------------------------+-------------+-------------+-------------+-------------+-------------+-------------+
+Total line number = 3
+It costs 0.009s
+IoTDB> select cast(s1, 'type'='BOOLEAN'), cast(s2, 'type'='BOOLEAN'), cast(s3, 'type'='BOOLEAN'), cast(s4, 'type'='BOOLEAN'), cast(s5, 'type'='BOOLEAN') from root.sg.d1;
++-----------------------------+-------------------------------------+-------------------------------------+-------------------------------------+-------------------------------------+-------------------------------------+
+|                         Time|cast(root.sg.d1.s1, "type"="BOOLEAN")|cast(root.sg.d1.s2, "type"="BOOLEAN")|cast(root.sg.d1.s3, "type"="BOOLEAN")|cast(root.sg.d1.s4, "type"="BOOLEAN")|cast(root.sg.d1.s5, "type"="BOOLEAN")|
++-----------------------------+-------------------------------------+-------------------------------------+-------------------------------------+-------------------------------------+-------------------------------------+
+|1970-01-01T08:00:00.001+08:00|                                 true|                                 true|                                 true|                                 true|                                 true|
+|1970-01-01T08:00:00.002+08:00|                                 true|                                 true|                                 true|                                 true|                                false|
+|1970-01-01T08:00:00.003+08:00|                                false|                                false|                                false|                                false|                                 true|
++-----------------------------+-------------------------------------+-------------------------------------+-------------------------------------+-------------------------------------+-------------------------------------+
+Total line number = 3
+It costs 0.012s
+```
+
 2. The value of type INT32, INT64, FLOAT, DOUBLE are 1 or 1.0 and TEXT is "true", when BOOLEAN data is true, otherwise 0, 0.0 or "false".  
+
+```
+IoTDB> select cast(s6, 'type'='INT32'), cast(s6, 'type'='INT64'), cast(s6, 'type'='FLOAT'), cast(s6, 'type'='DOUBLE'), cast(s6, 'type'='TEXT') from root.sg.d1;
++-----------------------------+-----------------------------------+-----------------------------------+-----------------------------------+------------------------------------+----------------------------------+
+|                         Time|cast(root.sg.d1.s6, "type"="INT32")|cast(root.sg.d1.s6, "type"="INT64")|cast(root.sg.d1.s6, "type"="FLOAT")|cast(root.sg.d1.s6, "type"="DOUBLE")|cast(root.sg.d1.s6, "type"="TEXT")|
++-----------------------------+-----------------------------------+-----------------------------------+-----------------------------------+------------------------------------+----------------------------------+
+|1970-01-01T08:00:00.001+08:00|                                  0|                                  0|                                0.0|                                 0.0|                             false|
+|1970-01-01T08:00:00.002+08:00|                                  1|                                  1|                                1.0|                                 1.0|                              true|
+|1970-01-01T08:00:00.003+08:00|                                  1|                                  1|                                1.0|                                 1.0|                              true|
++-----------------------------+-----------------------------------+-----------------------------------+-----------------------------------+------------------------------------+----------------------------------+
+Total line number = 3
+It costs 0.016s
+```
+
 3. When TEXT is converted to INT32, INT64, or FLOAT, the TEXT is first converted to DOUBLE and then to the corresponding type, which may cause loss of precision. It will skip directly if the data can not be converted.
 
+```
+IoTDB> select cast(s5, 'type'='INT32'), cast(s5, 'type'='INT64'), cast(s5, 'type'='FLOAT') from root.sg.d1;
++----+-----------------------------------+-----------------------------------+-----------------------------------+
+|Time|cast(root.sg.d1.s5, "type"="INT32")|cast(root.sg.d1.s5, "type"="INT64")|cast(root.sg.d1.s5, "type"="FLOAT")|
++----+-----------------------------------+-----------------------------------+-----------------------------------+
++----+-----------------------------------+-----------------------------------+-----------------------------------+
+Empty set.
+It costs 0.005s
+```
+
+
+
 #### Syntax
 Example data:
 ```
diff --git a/docs/zh/UserGuide/Query-Data/Select-Expression.md b/docs/zh/UserGuide/Query-Data/Select-Expression.md
index 7ad430966c..62d9445df9 100644
--- a/docs/zh/UserGuide/Query-Data/Select-Expression.md
+++ b/docs/zh/UserGuide/Query-Data/Select-Expression.md
@@ -417,10 +417,71 @@ It costs 0.005s
 
 1.当INT32、INT64类型的值不为0时,FLOAT与DOUBLE类型的值不为0.0时,TEXT类型不为空字符串或者"false"时,转换为BOOLEAN类型时值为true,否则为false。
 
+```
+IoTDB> show timeseries root.sg.d1.*;
++-------------+-----+-------------+--------+--------+-----------+----+----------+
+|   timeseries|alias|storage group|dataType|encoding|compression|tags|attributes|
++-------------+-----+-------------+--------+--------+-----------+----+----------+
+|root.sg.d1.s3| null|      root.sg|   FLOAT|     RLE|     SNAPPY|null|      null|
+|root.sg.d1.s4| null|      root.sg|  DOUBLE|     RLE|     SNAPPY|null|      null|
+|root.sg.d1.s5| null|      root.sg|    TEXT|   PLAIN|     SNAPPY|null|      null|
+|root.sg.d1.s6| null|      root.sg| BOOLEAN|     RLE|     SNAPPY|null|      null|
+|root.sg.d1.s1| null|      root.sg|   INT32|     RLE|     SNAPPY|null|      null|
+|root.sg.d1.s2| null|      root.sg|   INT64|     RLE|     SNAPPY|null|      null|
++-------------+-----+-------------+--------+--------+-----------+----+----------+
+Total line number = 6
+It costs 0.006s
+IoTDB> select * from root.sg.d1;
++-----------------------------+-------------+-------------+-------------+-------------+-------------+-------------+
+|                         Time|root.sg.d1.s3|root.sg.d1.s4|root.sg.d1.s5|root.sg.d1.s6|root.sg.d1.s1|root.sg.d1.s2|
++-----------------------------+-------------+-------------+-------------+-------------+-------------+-------------+
+|1970-01-01T08:00:00.001+08:00|          1.1|          1.1|         test|        false|            1|            1|
+|1970-01-01T08:00:00.002+08:00|         -2.2|         -2.2|        false|         true|           -2|           -2|
+|1970-01-01T08:00:00.003+08:00|          0.0|          0.0|         true|         true|            0|            0|
++-----------------------------+-------------+-------------+-------------+-------------+-------------+-------------+
+Total line number = 3
+It costs 0.009s
+IoTDB> select cast(s1, 'type'='BOOLEAN'), cast(s2, 'type'='BOOLEAN'), cast(s3, 'type'='BOOLEAN'), cast(s4, 'type'='BOOLEAN'), cast(s5, 'type'='BOOLEAN') from root.sg.d1;
++-----------------------------+-------------------------------------+-------------------------------------+-------------------------------------+-------------------------------------+-------------------------------------+
+|                         Time|cast(root.sg.d1.s1, "type"="BOOLEAN")|cast(root.sg.d1.s2, "type"="BOOLEAN")|cast(root.sg.d1.s3, "type"="BOOLEAN")|cast(root.sg.d1.s4, "type"="BOOLEAN")|cast(root.sg.d1.s5, "type"="BOOLEAN")|
++-----------------------------+-------------------------------------+-------------------------------------+-------------------------------------+-------------------------------------+-------------------------------------+
+|1970-01-01T08:00:00.001+08:00|                                 true|                                 true|                                 true|                                 true|                                 true|
+|1970-01-01T08:00:00.002+08:00|                                 true|                                 true|                                 true|                                 true|                                false|
+|1970-01-01T08:00:00.003+08:00|                                false|                                false|                                false|                                false|                                 true|
++-----------------------------+-------------------------------------+-------------------------------------+-------------------------------------+-------------------------------------+-------------------------------------+
+Total line number = 3
+It costs 0.012s
+```
+
 2.当BOOLEAN类型的值为true时,转换为INT32与INT64类型的值为1,转换为FLOAT或者DOUBLE类型时值为1.0,转换为TEXT类型时值为"true"。当BOOLEAN类型的值为false时,转换为INT32与INT64类型的值为0,转换为FLOAT或者DOUBLE类型时值为0.0,转换为TEXT类型时值为"false"。  
 
+```
+IoTDB> select cast(s6, 'type'='INT32'), cast(s6, 'type'='INT64'), cast(s6, 'type'='FLOAT'), cast(s6, 'type'='DOUBLE'), cast(s6, 'type'='TEXT') from root.sg.d1;
++-----------------------------+-----------------------------------+-----------------------------------+-----------------------------------+------------------------------------+----------------------------------+
+|                         Time|cast(root.sg.d1.s6, "type"="INT32")|cast(root.sg.d1.s6, "type"="INT64")|cast(root.sg.d1.s6, "type"="FLOAT")|cast(root.sg.d1.s6, "type"="DOUBLE")|cast(root.sg.d1.s6, "type"="TEXT")|
++-----------------------------+-----------------------------------+-----------------------------------+-----------------------------------+------------------------------------+----------------------------------+
+|1970-01-01T08:00:00.001+08:00|                                  0|                                  0|                                0.0|                                 0.0|                             false|
+|1970-01-01T08:00:00.002+08:00|                                  1|                                  1|                                1.0|                                 1.0|                              true|
+|1970-01-01T08:00:00.003+08:00|                                  1|                                  1|                                1.0|                                 1.0|                              true|
++-----------------------------+-----------------------------------+-----------------------------------+-----------------------------------+------------------------------------+----------------------------------+
+Total line number = 3
+It costs 0.016s
+```
+
 3.当TEXT类型转换为INT32、INT64、FLOAT类型时,会先将TEXT类型的数据转换为DOUBLE类型,然后再转换为对应的类型,此时可能会存在损失精度的问题。如果无法转换的话则直接跳过。
 
+```
+IoTDB> select cast(s5, 'type'='INT32'), cast(s5, 'type'='INT64'), cast(s5, 'type'='FLOAT') from root.sg.d1;
++----+-----------------------------------+-----------------------------------+-----------------------------------+
+|Time|cast(root.sg.d1.s5, "type"="INT32")|cast(root.sg.d1.s5, "type"="INT64")|cast(root.sg.d1.s5, "type"="FLOAT")|
++----+-----------------------------------+-----------------------------------+-----------------------------------+
++----+-----------------------------------+-----------------------------------+-----------------------------------+
+Empty set.
+It costs 0.009s
+```
+
+
+
 ##### 演示
 测试数据:
 ```