• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

apache / iotdb / #9950

29 Aug 2023 06:53AM UTC coverage: 47.678% (-0.05%) from 47.724%
#9950

push

travis_ci

web-flow
[To rel/1.2] Feature add insertRecords method to rest service (#10838)

Co-authored-by: Cloudwise_Luke <282583553@qq.com>

177 of 177 new or added lines in 7 files covered. (100.0%)

80115 of 168032 relevant lines covered (47.68%)

0.48 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/iotdb-core/datanode/src/main/java/org/apache/iotdb/db/protocol/rest/utils/InsertRowDataUtils.java
1
/*
2
 * Licensed to the Apache Software Foundation (ASF) under one or more
3
 * contributor license agreements.  See the NOTICE file distributed with
4
 * this work for additional information regarding copyright ownership.
5
 * The ASF licenses this file to You under the Apache License, Version 2.0
6
 * (the "License"); you may not use this file except in compliance with
7
 * the License.  You may obtain a copy of the License at
8
 *
9
 *      http://www.apache.org/licenses/LICENSE-2.0
10
 *
11
 * Unless required by applicable law or agreed to in writing, software
12
 * distributed under the License is distributed on an "AS IS" BASIS,
13
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
 * See the License for the specific language governing permissions and
15
 * limitations under the License.
16
 */
17

18
package org.apache.iotdb.db.protocol.rest.utils;
19

20
import org.apache.iotdb.rpc.IoTDBConnectionException;
21
import org.apache.iotdb.rpc.NoValidValueException;
22
import org.apache.iotdb.tsfile.file.metadata.enums.TSDataType;
23
import org.apache.iotdb.tsfile.utils.Binary;
24

25
import java.nio.charset.StandardCharsets;
26
import java.util.List;
27

28
import static org.apache.iotdb.session.Session.MSG_UNSUPPORTED_DATA_TYPE;
29

30
public class InsertRowDataUtils {
×
31

32
  private static final String ALL_INSERT_DATA_IS_NULL = "All inserted data is null.";
33

34
  public static void filterNullValueAndMeasurement(
35
      List<String> deviceIds,
36
      List<Long> times,
37
      List<List<String>> measurementsList,
38
      List<List<Object>> valuesList,
39
      List<List<TSDataType>> typesList) {
40
    for (int i = valuesList.size() - 1; i >= 0; i--) {
×
41
      List<Object> values = valuesList.get(i);
×
42
      List<String> measurements = measurementsList.get(i);
×
43
      List<TSDataType> types = typesList.get(i);
×
44
      boolean isAllValuesNull = getValuesIsEmpty(measurements, types, values);
×
45
      if (isAllValuesNull) {
×
46
        valuesList.remove(i);
×
47
        measurementsList.remove(i);
×
48
        deviceIds.remove(i);
×
49
        times.remove(i);
×
50
        typesList.remove(i);
×
51
      }
52
    }
53
    if (valuesList.isEmpty()) {
×
54
      throw new NoValidValueException(ALL_INSERT_DATA_IS_NULL);
×
55
    }
56
  }
×
57

58
  private static boolean getValuesIsEmpty(
59
      List<String> measurementsList, List<TSDataType> types, List<Object> valuesList) {
60
    for (int i = valuesList.size() - 1; i >= 0; i--) {
×
61
      if (valuesList.get(i) == null) {
×
62
        valuesList.remove(i);
×
63
        measurementsList.remove(i);
×
64
        types.remove(i);
×
65
      }
66
    }
67
    return valuesList.isEmpty();
×
68
  }
69

70
  public static List<Object> reGenValues(List<TSDataType> types, List<Object> values)
71
      throws IoTDBConnectionException {
72
    for (int i = 0; i < values.size(); i++) {
×
73
      if (values.get(i) == null) {
×
74
        continue;
×
75
      }
76
      Object val = values.get(i);
×
77
      switch (types.get(i)) {
×
78
        case BOOLEAN:
79
        case INT32:
80
          break;
×
81
        case INT64:
82
          if (val instanceof Number) {
×
83
            values.set(i, ((Number) val).longValue());
×
84
          }
85
          break;
86
        case FLOAT:
87
          if (val instanceof Number) {
×
88
            values.set(i, ((Number) val).floatValue());
×
89
          }
90
          break;
91
        case DOUBLE:
92
          if (val instanceof Number) {
×
93
            values.set(i, ((Number) val).doubleValue());
×
94
          }
95
          break;
96
        case TEXT:
97
          values.set(i, new Binary(val.toString().getBytes(StandardCharsets.UTF_8)));
×
98
          break;
×
99
        default:
100
          throw new IoTDBConnectionException(MSG_UNSUPPORTED_DATA_TYPE + types.get(i));
×
101
      }
102
    }
103
    return values;
×
104
  }
105
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc