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/01/18 12:50:40 UTC

[GitHub] [iotdb] neuyilan edited a comment on pull request #2454: [IOTDB-1099] Optimize insertablets logic in cluster module

neuyilan edited a comment on pull request #2454:
URL: https://github.com/apache/iotdb/pull/2454#issuecomment-762230593


   The test code is shown as below, and when called `insertTabletsSecondFailed()`, the following error will be occurred because of datatype not match.
   ![image](https://user-images.githubusercontent.com/6237070/104917585-90a80e80-59ce-11eb-87ed-6170783a4904.png)
   
   
   /*
    * Licensed to the Apache Software Foundation (ASF) under one
    * or more contributor license agreements.  See the NOTICE file
    * distributed with this work for additional information
    * regarding copyright ownership.  The ASF licenses this file
    * to you under the Apache License, Version 2.0 (the
    * "License"); you may not use this file except in compliance
    * with the License.  You may obtain a copy of the License at
    *
    *     http://www.apache.org/licenses/LICENSE-2.0
    *
    * Unless required by applicable law or agreed to in writing,
    * software distributed under the License is distributed on an
    * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
    * KIND, either express or implied.  See the License for the
    * specific language governing permissions and limitations
    * under the License.
    */
   package org.apache.iotdb;
   
   import java.util.ArrayList;
   import java.util.HashMap;
   import java.util.List;
   import java.util.Map;
   import java.util.Random;
   import org.apache.iotdb.rpc.IoTDBConnectionException;
   import org.apache.iotdb.rpc.StatementExecutionException;
   import org.apache.iotdb.session.Session;
   import org.apache.iotdb.session.SessionDataSet;
   import org.apache.iotdb.tsfile.file.metadata.enums.TSDataType;
   import org.apache.iotdb.tsfile.utils.Binary;
   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", 55560, "root", "root");
       session.open(false);
   
       //set session fetchSize
       session.setFetchSize(10000);
   
       insertTabletsFirstSuccess();
       insertTabletsSecondFailed();
       query();
       session.close();
     }
   
   
     private static void query() throws IoTDBConnectionException, StatementExecutionException {
       SessionDataSet dataSet = session.executeQueryStatement("select * from root");
       System.out.println(dataSet.getColumnNames());
       dataSet.setFetchSize(1024); // default is 10000
       while (dataSet.hasNext()) {
         System.out.println(dataSet.next());
       }
   
       dataSet.closeOperationHandle();
     }
   
     private static void insertTabletsFirstSuccess()
         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));
       schemaList.add(new MeasurementSchema("s2", TSDataType.INT64));
       schemaList.add(new MeasurementSchema("s3", TSDataType.INT64));
   
       Tablet tablet1 = new Tablet(ROOT_SG1_D1, schemaList, 100);
       Tablet tablet2 = new Tablet("root.sg1.d2", schemaList, 100);
       Tablet tablet3 = new Tablet("root.sg1.d3", schemaList, 100);
   
       Map<String, Tablet> tabletMap = new HashMap<>();
       tabletMap.put(ROOT_SG1_D1, tablet1);
       tabletMap.put("root.sg1.d2", tablet2);
       tabletMap.put("root.sg1.d3", tablet3);
   
       //Method 1 to add tablet data
       long timestamp = System.currentTimeMillis();
       for (long row = 0; row < 100; row++) {
         int row1 = tablet1.rowSize++;
         int row2 = tablet2.rowSize++;
         int row3 = tablet3.rowSize++;
         tablet1.addTimestamp(row1, timestamp);
         tablet2.addTimestamp(row2, timestamp);
         tablet3.addTimestamp(row3, timestamp);
         for (int i = 0; i < 3; i++) {
           long value = new Random().nextLong();
   
           tablet1.addValue(schemaList.get(i).getMeasurementId(), row1, value);
           tablet2.addValue(schemaList.get(i).getMeasurementId(), row2, value);
           tablet3.addValue(schemaList.get(i).getMeasurementId(), row3, value);
         }
         if (tablet1.rowSize == tablet1.getMaxRowNumber()) {
           session.insertTablets(tabletMap, true);
           tablet1.reset();
           tablet2.reset();
           tablet3.reset();
         }
         timestamp++;
       }
   
       if (tablet1.rowSize != 0) {
         session.insertTablets(tabletMap, true);
         tablet1.reset();
         tablet2.reset();
         tablet3.reset();
       }
     }
   
     private static void insertTabletsSecondFailed()
         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));
       schemaList.add(new MeasurementSchema("s2", TSDataType.INT64));
       schemaList.add(new MeasurementSchema("s3", TSDataType.TEXT));
   
       Tablet tablet1 = new Tablet(ROOT_SG1_D1, schemaList, 100);
       Tablet tablet2 = new Tablet("root.sg1.d2", schemaList, 100);
       Tablet tablet3 = new Tablet("root.sg1.d3", schemaList, 100);
   
       Map<String, Tablet> tabletMap = new HashMap<>();
       tabletMap.put(ROOT_SG1_D1, tablet1);
       tabletMap.put("root.sg1.d2", tablet2);
       tabletMap.put("root.sg1.d3", tablet3);
   
       //Method 1 to add tablet data
       long timestamp = System.currentTimeMillis();
       for (long row = 0; row < 100; row++) {
         int row1 = tablet1.rowSize++;
         int row2 = tablet2.rowSize++;
         int row3 = tablet3.rowSize++;
         tablet1.addTimestamp(row1, timestamp);
         tablet2.addTimestamp(row2, timestamp);
         tablet3.addTimestamp(row3, timestamp);
         for (int i = 0; i < 3; i++) {
           long value = new Random().nextLong();
   
           if (i == 2) {
             Binary b = new Binary(value + "-str");
             tablet1.addValue(schemaList.get(i).getMeasurementId(), row1, b);
             tablet2.addValue(schemaList.get(i).getMeasurementId(), row2, b);
             tablet3.addValue(schemaList.get(i).getMeasurementId(), row3, b);
           } else {
             tablet1.addValue(schemaList.get(i).getMeasurementId(), row1, value);
             tablet2.addValue(schemaList.get(i).getMeasurementId(), row2, value);
             tablet3.addValue(schemaList.get(i).getMeasurementId(), row3, value);
           }
         }
         if (tablet1.rowSize == tablet1.getMaxRowNumber()) {
           session.insertTablets(tabletMap, true);
           tablet1.reset();
           tablet2.reset();
           tablet3.reset();
         }
         timestamp++;
       }
   
       if (tablet1.rowSize != 0) {
         session.insertTablets(tabletMap, true);
         tablet1.reset();
         tablet2.reset();
         tablet3.reset();
       }
     }
   }
   
   
   


----------------------------------------------------------------
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:
users@infra.apache.org