I am trying to learn the process of writing and storing data into Apache IoTDB, and I have a question. Before I stored data in IoTDB, I want to make sure that the time series are already created. I want to know how to ensure that the time series already exists before saving data in Apache IoTDB? Is there any good solution?
Asked
Active
Viewed 15 times
2 Answers
0
Yes, you can do it. So , while writing the data to the IoTDB, you can check whether that storage class exists or not. If it does not exists , you can automatically create on.
def create_storage_group(session, storage_group):
# Check if the storage group exists, if not, create it
query = f"SHOW STORAGE GROUP {storage_group}"
try:
result = session.execute_query_statement(query)
if not result:
session.set_storage_group(storage_group)
except Exception as e:
pass
def create_device(session, device_id, measurements, data_types):
# Check if the device exists, if not, create it
query = f"SHOW TIMESERIES {device_id}"
try:
result = session.execute_query_statement(query)
if not result:
session.create_time_series(device_id, measurements, data_types)
except Exception as e:
pass
So, In the similar way you can check whether the timeseries exists or not.

Utkarsh Kumar
- 17
- 8
0
Before you write data into Apache IoTDB, schema will be automatically created in case time series haven't defined by users themselves. This function can not only solve the problem that entities and measurements are difficult to predict and model in advance under massive time series scenarios, but also provide users with an out-of-the-box writing experience.

Jerry Zhang
- 192
- 3
- 10