zhanglingzhe0820 opened a new issue #2187:
URL: https://github.com/apache/iotdb/issues/2187


   使用如下程序进行写入(Use the following program to write):
   ```
   package org.apache.iotdb;
   
   import java.util.ArrayList;
   import java.util.List;
   import java.util.Random;
   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.tsfile.file.metadata.enums.TSDataType;
   import org.apache.iotdb.tsfile.write.record.Tablet;
   import org.apache.iotdb.tsfile.write.schema.MeasurementSchema;
   
   public class SessionExample {
   
     private static Session session;
     private static final String ROOT_SG1_D1 = "root.sg1.d1";
   
   
     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.sg1");
       } catch (StatementExecutionException e) {
         if (e.getStatusCode() != 
TSStatusCode.PATH_ALREADY_EXIST_ERROR.getStatusCode())
           throw e;
       }
   
       insertTablet();
       session.close();
     }
   
     private static void insertTablet() throws IoTDBConnectionException, 
StatementExecutionException {
       // The schema of measurements of one device
       // only measurementId and data type in MeasurementSchema take effects in 
Tablet
       List<MeasurementSchema> schemaList = new ArrayList<>();
       schemaList.add(new MeasurementSchema("s1", TSDataType.INT64));
   
       Tablet tablet = new Tablet(ROOT_SG1_D1, schemaList, 100);
   
       //Method 1 to add tablet data
       long timestamp = 1;
   
       for (long row = 0; row < 10000; row++) {
         int rowIndex = tablet.rowSize++;
         tablet.addTimestamp(rowIndex, timestamp);
         for (int s = 0; s < 1; s++) {
           long value = new Random().nextLong();
           tablet.addValue(schemaList.get(s).getMeasurementId(), rowIndex, 
value);
         }
         if (tablet.rowSize == tablet.getMaxRowNumber()) {
           session.insertTablet(tablet, true);
           tablet.reset();
           session.executeNonQueryStatement("flush");
         }
         timestamp++;
       }
   
       if (tablet.rowSize != 0) {
         session.insertTablet(tablet);
         tablet.reset();
       }
   
       timestamp = 8322;
   
       for (long row = 0; row < 2400; row++) {
         int rowIndex = tablet.rowSize++;
         tablet.addTimestamp(rowIndex, timestamp);
         for (int s = 0; s < 1; s++) {
           long value = new Random().nextLong();
           tablet.addValue(schemaList.get(s).getMeasurementId(), rowIndex, 
value);
         }
         if (tablet.rowSize == tablet.getMaxRowNumber()) {
           session.insertTablet(tablet, true);
           tablet.reset();
           session.executeNonQueryStatement("flush");
         }
         timestamp++;
       }
   
       if (tablet.rowSize != 0) {
         session.insertTablet(tablet);
         tablet.reset();
       }
   
     }
   
   }
   ```
   
   使用如下SQL进行查询(Use the following SQL to query):
   ```
   select count(*) from root where root.sg1.d1.s1
   ```
   
   报错如下(Get the following error):
   
![image](https://user-images.githubusercontent.com/24886743/101180103-1d4c7680-3686-11eb-98fd-a78b10811248.png)
   


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


Reply via email to