You are viewing a plain text version of this content. The canonical link for it is here.
Posted to reviews@iotdb.apache.org by GitBox <gi...@apache.org> on 2021/07/12 19:52:10 UTC

[GitHub] [iotdb] zyk990424 commented on pull request #3540: [To rel/0.12][IOTDB-1482] Fix Count Timeseries and Count Devices with Template Bug

zyk990424 commented on pull request #3540:
URL: https://github.com/apache/iotdb/pull/3540#issuecomment-878377232


   > Hi, I have tested to execute count devices and count timeseries with template. Count devices works good, but count timeseries throws a NPE.
   > In session example,
   > 
   > ```java
   >   public static void main(String[] args)
   >       throws IoTDBConnectionException, StatementExecutionException {
   >     session = new Session(LOCAL_HOST, 6667, "root", "root");
   >     session.open(false);
   > 
   >     // set session fetchSize
   >     session.setFetchSize(10000);
   > 
   >     try {
   >       session.setStorageGroup("root.sg1");
   >     } catch (StatementExecutionException e) {
   >       if (e.getStatusCode() != TSStatusCode.PATH_ALREADY_EXIST_ERROR.getStatusCode()) {
   >         throw e;
   >       }
   >     }
   > 
   >     createTemplate();
   >     insertRecord();
   >     session.close();
   >   }
   > 
   >   private static void createTemplate()
   >       throws IoTDBConnectionException, StatementExecutionException {
   >     List<List<String>> measurementList = new ArrayList<>();
   >     measurementList.add(Collections.singletonList("s1"));
   >     measurementList.add(Collections.singletonList("s2"));
   >     measurementList.add(Collections.singletonList("s3"));
   > 
   >     List<List<TSDataType>> dataTypeList = new ArrayList<>();
   >     dataTypeList.add(Collections.singletonList(TSDataType.INT64));
   >     dataTypeList.add(Collections.singletonList(TSDataType.INT64));
   >     dataTypeList.add(Collections.singletonList(TSDataType.INT64));
   > 
   >     List<List<TSEncoding>> encodingList = new ArrayList<>();
   >     encodingList.add(Collections.singletonList(TSEncoding.RLE));
   >     encodingList.add(Collections.singletonList(TSEncoding.RLE));
   >     encodingList.add(Collections.singletonList(TSEncoding.RLE));
   > 
   >     List<CompressionType> compressionTypes = new ArrayList<>();
   >     for (int i = 0; i < 3; i++) {
   >       compressionTypes.add(CompressionType.SNAPPY);
   >     }
   >     List<String> schemaNames = new ArrayList<>();
   >     schemaNames.add("s1");
   >     schemaNames.add("s2");
   >     schemaNames.add("s3");
   > 
   >     session.createSchemaTemplate(
   >         "template1", schemaNames, measurementList, dataTypeList, encodingList, compressionTypes);
   >     session.setSchemaTemplate("template1", "root.sg1");
   >   }
   > 
   >   private static void insertRecord() throws IoTDBConnectionException, StatementExecutionException {
   >     String deviceId = ROOT_SG1_D1;
   >     List<String> measurements = new ArrayList<>();
   >     List<TSDataType> types = new ArrayList<>();
   >     measurements.add("s1");
   >     measurements.add("s2");
   >     measurements.add("s3");
   >     types.add(TSDataType.INT64);
   >     types.add(TSDataType.INT64);
   >     types.add(TSDataType.INT64);
   > 
   >     for (long time = 0; time < 100; time++) {
   >       List<Object> values = new ArrayList<>();
   >       values.add(1L);
   >       values.add(2L);
   >       values.add(3L);
   >       session.insertRecord(deviceId, time, measurements, types, values);
   >     }
   >   }
   > ```
   > 
   > After running the code, I execute the count devices and count timeseries in CLI
   > 
   > ```sql
   > IoTDB> show devices
   > +-----------+
   > |    devices|
   > +-----------+
   > |root.sg1.d1|
   > +-----------+
   > Total line number = 1
   > It costs 0.005s
   > IoTDB> count timeseries
   > Msg: 500: [INTERNAL_SERVER_ERROR] Exception occurred while executing executeStatement. null
   > ```
   > 
   > The log on server shows
   > 
   > ```
   > 22:44:28.714 [pool-8-IoTDB-RPC-Client-2] ERROR org.apache.iotdb.db.service.TSServiceImpl - [INTERNAL_SERVER_ERROR] Exception occurred while executing executeStatement. 
   > java.lang.NullPointerException: null
   > 	at org.apache.iotdb.db.metadata.MTree.getCount(MTree.java:944)
   > 	at org.apache.iotdb.db.metadata.MTree.getCount(MTree.java:947)
   > 	at org.apache.iotdb.db.metadata.MTree.getCount(MTree.java:947)
   > 	at org.apache.iotdb.db.metadata.MTree.getAllTimeseriesCount(MTree.java:910)
   > 	at org.apache.iotdb.db.metadata.MManager.getAllTimeseriesCount(MManager.java:790)
   > 	at org.apache.iotdb.db.qp.executor.PlanExecutor.getPathsNum(PlanExecutor.java:673)
   > 	at org.apache.iotdb.db.qp.executor.PlanExecutor.processCountTimeSeries(PlanExecutor.java:690)
   > 	at org.apache.iotdb.db.qp.executor.PlanExecutor.processShowQuery(PlanExecutor.java:573)
   > 	at org.apache.iotdb.db.qp.executor.PlanExecutor.processQuery(PlanExecutor.java:229)
   > 	at org.apache.iotdb.db.service.TSServiceImpl.createQueryDataSet(TSServiceImpl.java:1211)
   > 	at org.apache.iotdb.db.service.TSServiceImpl.internalExecuteQueryStatement(TSServiceImpl.java:796)
   > 	at org.apache.iotdb.db.service.TSServiceImpl.executeStatement(TSServiceImpl.java:655)
   > 	at org.apache.iotdb.service.rpc.thrift.TSIService$Processor$executeStatement.getResult(TSIService.java:2373)
   > 	at org.apache.iotdb.service.rpc.thrift.TSIService$Processor$executeStatement.getResult(TSIService.java:1)
   > 	at org.apache.thrift.ProcessFunction.process(ProcessFunction.java:38)
   > 	at org.apache.thrift.TBaseProcessor.process(TBaseProcessor.java:38)
   > 	at org.apache.thrift.server.TThreadPoolServer$WorkerProcess.run(TThreadPoolServer.java:248)
   > 	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
   > 	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
   > 	at java.base/java.lang.Thread.run(Thread.java:834)
   > ```
   
   The is becasue the deviceNode's template is null and it is using the upperTemplate on SGNode. Therefore, the getDeviceTemplate  method  should be replaced with getUpperTemplate method while checking the schema num.


-- 
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.

To unsubscribe, e-mail: reviews-unsubscribe@iotdb.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org