本文将详细介绍 Apache IoTDB 如何实现数据的导入和查询功能,包括自动导入 CSV 格式数据、使用 SQL 语句写入数据以及基本查询和聚合查询等。
以实际工业应用场景为例,我们提供了一个测试用的 CSV 格式数据表格,该表格记录了某集团高山风机的轮毂温度数据。
Apache IoTDB 提供了 CSV 工具,可以将 CSV 格式的数据导入数据库中。具体步骤如下:
import-csv.sh -h -p -u -pw -f [-fd <./failedDirectory>]
-f
指定要导入的数据文件。-fd
指定保存失败文件的目录(可选)。除了导入 CSV 数据,还可以使用 SQL 语句创建和写入时间序列数据。
create timeseries root.BHSFC.Q1.W003.speed FLOAT encoding=RLE
insert into root.BHSFC.Q1.W003(timestamp, speed) values(1657468800000, 1)
insert into root.ln1.wf01(time, status, temperature) aligned values(1657468800000, 0, 1)
select from
语句查询select WROT_HubTmp from root.BHSFC.Q1.W002
select * from root.BHSFC.** limit 10
select last WROT_HubTmp from root.BHSFC.Q1.W002
where
语句查询select WROT_HubTmp from root.BHSFC.Q1.W002 where time < 2022-01-12
select last WROT_HubTmp from root.BHSFC.Q1.W002 where time >= 2022-1-14T00:00:00
select WROT_HubTmp from root.BHSFC.Q1.W002 where WROT_HubTmp > 20
select count(WROT_HubTmp) from root.BHSFC.Q1.W002
select count(*) from root.**
select MAX_VALUE(*) from root.BHSFC.Q1.W002
select AVG(*) from root.BHSFC.Q1.W002
select count(*) from root.BHSFC.Q1.W002 where time > 2022-01-13T00:00:00
select count(*) from root.** group by level = 2
select AVG(*) from root.BHSFC.Q1.W002 group by ([2022-1-14T00:00:00,2022-1-15T00:00:00),1d)
select max_value (*) from root.BHSFC.Q1.W002 group by ([2022-1-11T00:00:00,2022-1-15T00:00:00),1d)
select WROT_HubTmp from root.BHSFC.Q1.W002 where time = 2022-01-16T00:00:00 fill(previous)
select avg(*) from root.BHSFC.Q1.W002 group by ([2022-1-11T00:00:00,2022-1-15T00:00:00),6h,12h) fill (linear)
select WROT_HubTmp from root.BHSFC.Q1.W002 where time = 2022-01-16T00:00:00 fill(15)
通过本文,我们详细了解了 Apache IoTDB 的数据导入和查询功能,包括如何导入 CSV 数据、使用 SQL 语句写入和查询数据,以及如何进行聚合查询和控制空值填充。这些功能为时间序列数据的处理提供了强大的支持。