SteveYurongSu commented on issue #2124: URL: https://github.com/apache/iotdb/issues/2124#issuecomment-735254132
Hi @bgruenefeld , I tried to reproduce the case you met using the Java session API and the Python client, but both of them worked well on my MacBook. Here is my code, you can have a test on your computer. Let me know if you meet the issue again, then I will do a detail check. :D OS: Mac Big Sur IoTDB Server: 0.11.0 IoTDB Python Client: 0.11.0 (https://pypi.org/project/apache-iotdb/) Python client: ```python from iotdb.Session import Session from iotdb.utils.IoTDBConstants import TSDataType from iotdb.utils.Tablet import Tablet connection = None def open_connection(): global connection try: connection = Session(host="127.0.0.1", port="6667", user='root', password='root') connection.open(False) except Exception as e: print( e ) connection.close() def create_timeseries_data(timestamp, amount): ret = [] for i in range(amount): ret.append([timestamp + i * 900000, 1.3, 1.0]) return ret def save_tablet(device_id, data): global connection measurements_ = [] values = [] data_types_ = [] timestamps = [] measurements_.append("comsumption") measurements_.append("status") data_types_.append(TSDataType.FLOAT) data_types_.append(TSDataType.FLOAT) for datapoint in data: values.append([datapoint[1], datapoint[2]]) timestamps.append(datapoint[0]) tablet_ = Tablet(device_id, measurements_, data_types_, values, timestamps) try: connection.insert_tablet(tablet_) except Exception as e: print('an error occured') print(e) connection.close() def create_data(ts_prefix, amount_timeseries): data = create_timeseries_data(1546300800000, 288) for index in range(1, amount_timeseries): device_id = ts_prefix + str(index) save_tablet(device_id, data) def query(ts_prefix, amount_timeseries): for index in range(1, amount_timeseries): sql = "select count(*) from %s where time >= 1546300800000 and time < 1546560000000" % (ts_prefix + str(index)) session_data_set = connection.execute_query_statement(sql) while session_data_set.has_next(): fields = session_data_set.next().get_fields() print(fields[0].get_long_value(), fields[1].get_long_value()) assert 288 == fields[0].get_long_value() and 288 == fields[1].get_long_value() session_data_set.close_operation_handle() if __name__ == "__main__": ts_prefix = "root.storagegroup.city.device" open_connection() create_data(ts_prefix, 1000) query(ts_prefix, 1000) connection.close() print("All executions done!!") ``` Java session: ```java import java.util.ArrayList; import java.util.List; import org.apache.iotdb.rpc.IoTDBConnectionException; import org.apache.iotdb.rpc.StatementExecutionException; import org.apache.iotdb.rpc.TSStatusCode; import org.apache.iotdb.session.Session; import org.apache.iotdb.session.SessionDataSet; import org.apache.iotdb.tsfile.file.metadata.enums.CompressionType; import org.apache.iotdb.tsfile.file.metadata.enums.TSDataType; import org.apache.iotdb.tsfile.file.metadata.enums.TSEncoding; public class SessionExample { private static Session session; public static void main(String[] args) throws IoTDBConnectionException, StatementExecutionException { session = new Session("127.0.0.1", 6667, "root", "root"); session.open(false); try { session.setStorageGroup("root.storagegroup"); } catch (StatementExecutionException e) { if (e.getStatusCode() != TSStatusCode.PATH_ALREADY_EXIST_ERROR.getStatusCode()) { throw e; } } createTimeseries(); insertRecords(); query(); session.close(); } private static void createTimeseries() throws IoTDBConnectionException, StatementExecutionException { for (int i = 1; i <= 1000; ++i) { String path = "root.storagegroup.city.device"; if (i < 10) { path += "000"; } else if (i < 100) { path += "00"; } else if (i < 1000) { path += "0"; } path += i; String comsumption = path + ".comsumption"; if (!session.checkTimeseriesExists(comsumption)) { session.createTimeseries(comsumption, TSDataType.FLOAT, TSEncoding.GORILLA, CompressionType.SNAPPY); } System.out.println(comsumption); String status = path + ".status"; if (!session.checkTimeseriesExists(status)) { session.createTimeseries(status, TSDataType.FLOAT, TSEncoding.GORILLA, CompressionType.SNAPPY); } System.out.println(status); } } private static void insertRecords() throws IoTDBConnectionException, StatementExecutionException { for (int i = 1; i <= 1000; ++i) { String deviceId = "root.storagegroup.city.device"; if (i < 10) { deviceId += "000"; } else if (i < 100) { deviceId += "00"; } else if (i < 1000) { deviceId += "0"; } deviceId += i; List<String> measurements = new ArrayList<>(); measurements.add("comsumption"); measurements.add("status"); List<String> deviceIds = new ArrayList<>(); List<List<String>> measurementsList = new ArrayList<>(); List<List<Object>> valuesList = new ArrayList<>(); List<Long> timestamps = new ArrayList<>(); List<List<TSDataType>> typesList = new ArrayList<>(); for (long time = 1546300800000L; time < 1546560000000L; time += 900000L) { List<Object> values = new ArrayList<>(); List<TSDataType> types = new ArrayList<>(); values.add(1.3f); values.add(1.0f); types.add(TSDataType.FLOAT); types.add(TSDataType.FLOAT); deviceIds.add(deviceId); measurementsList.add(measurements); timestamps.add(time); typesList.add(types); valuesList.add(values); } session.insertRecords(deviceIds, timestamps, measurementsList, typesList, valuesList); } } private static void query() throws IoTDBConnectionException, StatementExecutionException { for (int i = 1; i <= 1000; ++i) { String deviceId = "root.storagegroup.city.device"; if (i < 10) { deviceId += "000"; } else if (i < 100) { deviceId += "00"; } else if (i < 1000) { deviceId += "0"; } deviceId += i; SessionDataSet dataSet = session.executeQueryStatement(String.format( "select count(comsumption), count(status) from %s where time >= 1546300800000 and time < 1546560000000", deviceId)); System.out.println(dataSet.getColumnNames()); while (dataSet.hasNext()) { System.out.println(dataSet.next()); } dataSet.closeOperationHandle(); } } } ``` ---------------------------------------------------------------- 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: [email protected]
