jt2594838 commented on code in PR #18533:
URL: https://github.com/apache/iotdb/pull/18533#discussion_r3870348585
##########
iotdb-client/client-cpp/src/session/Session.cpp:
##########
@@ -413,6 +413,83 @@ bool SessionUtils::isTabletContainsSingleDevice(Tablet
tablet) {
return true;
}
+static bool isColumnAllNull(const BitMap& bitMap, size_t rowSize) {
+ if (rowSize == 0) {
+ return false;
+ }
+ if (bitMap.getSize() == rowSize && bitMap.isAllMarked()) {
+ return true;
+ }
+ for (size_t row = 0; row < rowSize; row++) {
+ if (!bitMap.isMarked(row)) {
+ return false;
+ }
+ }
+ return true;
+}
+
+std::shared_ptr<const Tablet> SessionUtils::filterNullColumns(const Tablet&
tablet) {
+ const size_t columnCount = tablet.schemas.size();
+ if (columnCount == 0 || tablet.bitMaps.size() < columnCount) {
+ return std::shared_ptr<const Tablet>(&tablet, [](const Tablet*) {});
+ }
+
+ std::vector<size_t> keptIndices;
+ keptIndices.reserve(columnCount);
+ size_t originalFieldCount = 0;
+ size_t keptFieldCount = 0;
+
+ for (size_t i = 0; i < columnCount; i++) {
+ ColumnCategory category =
+ i < tablet.columnTypes.size() ? tablet.columnTypes[i] :
ColumnCategory::FIELD;
+ bool isField = category == ColumnCategory::FIELD;
+ if (isField) {
+ originalFieldCount++;
+ }
+ bool drop = isField && isColumnAllNull(tablet.bitMaps[i], tablet.rowSize);
+ if (drop) {
+ continue;
+ }
+ keptIndices.push_back(i);
+ if (isField) {
+ keptFieldCount++;
+ }
+ }
+
+ if (keptIndices.size() == columnCount) {
+ return std::shared_ptr<const Tablet>(&tablet, [](const Tablet*) {});
+ }
+ if (originalFieldCount > 0 && keptFieldCount == 0) {
+ return nullptr;
+ }
+ if (keptIndices.empty()) {
+ return nullptr;
+ }
+
+ std::vector<std::pair<std::string, TSDataType::TSDataType>> keptSchemas;
+ std::vector<ColumnCategory> keptColumnTypes;
+ keptSchemas.reserve(keptIndices.size());
+ keptColumnTypes.reserve(keptIndices.size());
+ for (size_t idx : keptIndices) {
+ keptSchemas.push_back(tablet.schemas[idx]);
+ keptColumnTypes.push_back(idx < tablet.columnTypes.size() ?
tablet.columnTypes[idx]
+ :
ColumnCategory::FIELD);
+ }
+
+ auto filteredOut = std::make_shared<Tablet>(tablet.deviceId, keptSchemas,
keptColumnTypes,
+ tablet.maxRowNumber,
tablet.isAligned);
+ filteredOut->deleteColumns();
Review Comment:
Not create-and-delete or copy. May add a constructor for this.
##########
iotdb-client/session/src/main/java/org/apache/iotdb/session/Session.java:
##########
@@ -2849,8 +2857,15 @@ public void insertRelationalTablet(Tablet tablet)
insertRelationalTabletWithLeaderCache(tablet);
} else {
TSInsertTabletReq request = genTSInsertTabletReq(tablet, false, false);
+ if (request == null) {
+ logger.warn(
+ ALL_VALUES_ARE_NULL,
+ tablet.getDeviceId(),
+ tablet.getRowSize() > 0 ? tablet.getTimestamp(0) : null,
+ tablet.getSchemas());
+ return;
+ }
request.setWriteToTable(true);
-
request.setColumnCategories(toEnumOrdinalsAsBytes(tablet.getColumnTypes()));
Review Comment:
Why is thsi removed?
##########
iotdb-client/client-cpp/src/rpc/SessionImpl.h:
##########
@@ -145,7 +145,8 @@ 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 all FIELD columns are null and the insert should be
skipped.
+ static bool buildInsertTabletReq(TSInsertTabletReq& request, Tablet& tablet,
bool sorted);
Review Comment:
For the table model, time-only insertion is allowed.
##########
iotdb-client/client-cpp/src/session/Session.cpp:
##########
@@ -413,6 +413,83 @@ bool SessionUtils::isTabletContainsSingleDevice(Tablet
tablet) {
return true;
}
+static bool isColumnAllNull(const BitMap& bitMap, size_t rowSize) {
+ if (rowSize == 0) {
+ return false;
+ }
+ if (bitMap.getSize() == rowSize && bitMap.isAllMarked()) {
+ return true;
+ }
+ for (size_t row = 0; row < rowSize; row++) {
+ if (!bitMap.isMarked(row)) {
+ return false;
+ }
+ }
+ return true;
+}
Review Comment:
Why is `bitMap.isAllMarked` not enough?
--
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.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]