org.apache.iotdb.session.util.SessionUtils Maven / Gradle / Ivy
/*
* 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.session.util;
import org.apache.iotdb.common.rpc.thrift.TEndPoint;
import org.apache.iotdb.rpc.IoTDBConnectionException;
import org.apache.iotdb.tsfile.common.conf.TSFileConfig;
import org.apache.iotdb.tsfile.exception.write.UnSupportedDataTypeException;
import org.apache.iotdb.tsfile.file.metadata.enums.TSDataType;
import org.apache.iotdb.tsfile.utils.Binary;
import org.apache.iotdb.tsfile.utils.BitMap;
import org.apache.iotdb.tsfile.utils.BytesUtils;
import org.apache.iotdb.tsfile.utils.ReadWriteIOUtils;
import org.apache.iotdb.tsfile.write.record.Tablet;
import org.apache.iotdb.tsfile.write.schema.MeasurementSchema;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.nio.ByteBuffer;
import java.util.ArrayList;
import java.util.List;
import static org.apache.iotdb.session.Session.MSG_UNSUPPORTED_DATA_TYPE;
public class SessionUtils {
private static final Logger logger = LoggerFactory.getLogger(SessionUtils.class);
private static final byte TYPE_NULL = -2;
public static ByteBuffer getTimeBuffer(Tablet tablet) {
ByteBuffer timeBuffer = ByteBuffer.allocate(tablet.getTimeBytesSize());
for (int i = 0; i < tablet.rowSize; i++) {
timeBuffer.putLong(tablet.timestamps[i]);
}
timeBuffer.flip();
return timeBuffer;
}
@SuppressWarnings("squid:S3776") // Suppress high Cognitive Complexity warning
public static ByteBuffer getValueBuffer(Tablet tablet) {
ByteBuffer valueBuffer = ByteBuffer.allocate(tablet.getTotalValueOccupation());
for (int i = 0; i < tablet.getSchemas().size(); i++) {
MeasurementSchema schema = tablet.getSchemas().get(i);
getValueBufferOfDataType(schema.getType(), tablet, i, valueBuffer);
}
if (tablet.bitMaps != null) {
for (BitMap bitMap : tablet.bitMaps) {
boolean columnHasNull = bitMap != null && !bitMap.isAllUnmarked();
valueBuffer.put(BytesUtils.boolToByte(columnHasNull));
if (columnHasNull) {
byte[] bytes = bitMap.getByteArray();
for (int j = 0; j < tablet.rowSize / Byte.SIZE + 1; j++) {
valueBuffer.put(bytes[j]);
}
}
}
}
valueBuffer.flip();
return valueBuffer;
}
public static ByteBuffer getValueBuffer(List types, List