Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2164,6 +2164,7 @@ public void testQueryAllDataType() throws IoTDBConnectionException, StatementExe
tablet.addValue("s8", 0, new Binary(new byte[] {1}));
tablet.addValue("s9", 0, "string_value");
tablet.addValue("s10", 0, DateUtils.parseIntToLocalDate(20250403));
tablet.addValue("s11", 0, 1L);

try (ISession session = EnvFactory.getEnv().getSessionConnection()) {
session.insertTablet(tablet);
Expand Down Expand Up @@ -2193,8 +2194,8 @@ public void testQueryAllDataType() throws IoTDBConnectionException, StatementExe
assertEquals("string_value", iterator.getString("root.sg.d1.s9"));
assertFalse(iterator.isNull("root.sg.d1.s10"));
assertEquals(DateUtils.parseIntToLocalDate(20250403), iterator.getDate("root.sg.d1.s10"));
assertTrue(iterator.isNull("root.sg.d1.s11"));
assertNull(iterator.getTimestamp("root.sg.d1.s11"));
assertFalse(iterator.isNull("root.sg.d1.s11"));
assertEquals(new Timestamp(1), iterator.getTimestamp("root.sg.d1.s11"));

assertEquals(new Timestamp(0), iterator.getTimestamp("Time"));
assertFalse(iterator.isNull("Time"));
Expand Down
1 change: 1 addition & 0 deletions iotdb-client/client-cpp/src/include/Common.h
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,7 @@ class BitMap {
bool isMarked(size_t position) const;
bool isAllUnmarked() const;
bool isAllMarked() const;
bool isRangeAllMarked(size_t start, size_t length) const;
const std::vector<char>& getByteArray() const;
size_t getSize() const;

Expand Down
50 changes: 28 additions & 22 deletions iotdb-client/client-cpp/src/include/Session.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,12 +99,21 @@ template <typename T, typename Target> void safe_cast(const T& value, Target& ta
*
*/
class Tablet {
friend class SessionUtils;

private:
static const int DEFAULT_ROW_SIZE = 1024;

void createColumns();
void deleteColumns();

struct WithoutValueColumnsTag {};

Tablet(const std::string& deviceId,
const std::vector<std::pair<std::string, TSDataType::TSDataType>>& schemas,
const std::vector<ColumnCategory> columnTypes, size_t maxRowNumber, bool isAligned,
WithoutValueColumnsTag);

public:
std::string deviceId; // deviceId of this tablet
std::vector<std::pair<std::string, TSDataType::TSDataType>> schemas;
Expand Down Expand Up @@ -160,31 +169,18 @@ class Tablet {
const std::vector<std::pair<std::string, TSDataType::TSDataType>>& schemas,
const std::vector<ColumnCategory> columnTypes, size_t maxRowNumber,
bool _isAligned = false)
: deviceId(deviceId), schemas(schemas), columnTypes(columnTypes), maxRowNumber(maxRowNumber),
isAligned(_isAligned) {
// create timestamp column
timestamps.resize(maxRowNumber);
// create value columns
values.resize(schemas.size());
: Tablet(deviceId, schemas, columnTypes, maxRowNumber, _isAligned, WithoutValueColumnsTag{}) {
createColumns();
// init tagColumnIndexes
for (size_t i = 0; i < this->columnTypes.size(); i++) {
if (this->columnTypes[i] == ColumnCategory::TAG) {
tagColumnIndexes.push_back(i);
}
}
// create bitMaps
bitMaps.resize(schemas.size());
for (size_t i = 0; i < schemas.size(); i++) {
bitMaps[i].resize(maxRowNumber);
}
// create schemaNameIndex
for (size_t i = 0; i < schemas.size(); i++) {
schemaNameIndex[schemas[i].first] = i;
}
this->rowSize = 0;
}

/**
* Create a tablet with metadata and bitmaps only; value columns are filled by the caller.
*/
static std::shared_ptr<Tablet> createWithoutValueColumns(
const std::string& deviceId,
const std::vector<std::pair<std::string, TSDataType::TSDataType>>& schemas,
const std::vector<ColumnCategory>& columnTypes, size_t maxRowNumber, bool isAligned = false);

Tablet(const Tablet& other)
: deviceId(other.deviceId), schemas(other.schemas), schemaNameIndex(other.schemaNameIndex),
columnTypes(other.columnTypes), timestamps(other.timestamps),
Expand Down Expand Up @@ -431,6 +427,16 @@ class SessionUtils {
static std::string getValue(const Tablet& tablet);

static bool isTabletContainsSingleDevice(Tablet tablet);

/**
* Drop entirely-null FIELD columns within [0, rowSize). TAG/ATTRIBUTE are kept.
* Does not mutate {@code tablet}.
*
* @return non-owning pointer to {@code tablet} if nothing to drop; a new tablet if filtered;
* nullptr if no columns remain. Table-model TAG / ATTRIBUTE columns are kept even when
* every FIELD column is null.
*/
static std::shared_ptr<const Tablet> filterNullColumns(const Tablet& tablet);
};

class TemplateNode {
Expand Down
4 changes: 3 additions & 1 deletion iotdb-client/client-cpp/src/rpc/SessionImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,9 @@ class Session::Impl {
void handleRedirection(const std::string& deviceId, TEndPoint endPoint);
void handleRedirection(const std::shared_ptr<storage::IDeviceID>& deviceId, TEndPoint endPoint);

static void buildInsertTabletReq(TSInsertTabletReq& request, Tablet& tablet, bool sorted);
// Returns false when filtering leaves no columns (tree-model all-null FIELD tablet).
// Table-model inserts may keep TAG / ATTRIBUTE columns when all FIELD columns are null.
static bool buildInsertTabletReq(TSInsertTabletReq& request, Tablet& tablet, bool sorted);
void insertTablet(TSInsertTabletReq request);
void insertRelationalTabletOnce(
const std::unordered_map<std::shared_ptr<SessionConnection>, Tablet>& relationalTabletGroup,
Expand Down
38 changes: 30 additions & 8 deletions iotdb-client/client-cpp/src/session/Common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -323,18 +323,40 @@ bool BitMap::isAllUnmarked() const {
}

bool BitMap::isAllMarked() const {
size_t j;
for (j = 0; j < size >> 3; j++) {
if (bits[j] != (char)0XFF) {
return false;
}
return isRangeAllMarked(0, size);
}

bool BitMap::isRangeAllMarked(size_t start, size_t length) const {
// size_t addition can wrap; short-circuit so `size - start` is only used when
// start <= size. Out-of-range matches mark()/isMarked(): return false.
if (start > size || length > size - start) {
return false;
}
for (j = 0; j < size % 8; j++) {
if ((bits[size >> 3] & ((char)1 << j)) == 0) {
if (length == 0) {
return true;
}

const size_t end = start + length;
const size_t firstByte = start >> 3;
const size_t lastByte = (end - 1) >> 3;
if (firstByte == lastByte) {
const unsigned char mask = static_cast<unsigned char>(((1U << length) - 1U) << (start & 7U));
return (static_cast<unsigned char>(bits[firstByte]) & mask) == mask;
}

const unsigned char firstMask = static_cast<unsigned char>((0xFFU << (start & 7U)) & 0xFFU);
if ((static_cast<unsigned char>(bits[firstByte]) & firstMask) != firstMask) {
return false;
}
for (size_t index = firstByte + 1; index < lastByte; index++) {
if (static_cast<unsigned char>(bits[index]) != 0xFFU) {
return false;
}
}
return true;
const size_t lastBitCount = end & 7U;
const unsigned char lastMask =
lastBitCount == 0 ? 0xFFU : static_cast<unsigned char>((1U << lastBitCount) - 1U);
return (static_cast<unsigned char>(bits[lastByte]) & lastMask) == lastMask;
}

const std::vector<char>& BitMap::getByteArray() const {
Expand Down
Loading
Loading