Skip to content

Filter all-null FIELD columns before tablet insert in Java/C++/Python… - #18533

Open
hongzhi-gao wants to merge 1 commit into
apache:masterfrom
hongzhi-gao:feature/client-filter-null-col
Open

Filter all-null FIELD columns before tablet insert in Java/C++/Python…#18533
hongzhi-gao wants to merge 1 commit into
apache:masterfrom
hongzhi-gao:feature/client-filter-null-col

Conversation

@hongzhi-gao

Copy link
Copy Markdown
Contributor

Description

Before inserting a Tablet, drop FIELD columns that are entirely null within [0, rowSize). TAG / ATTRIBUTE columns are always kept. This avoids shipping unused measurement columns when the client schema is wide but each batch only fills a subset of fields.

Behavior

  • If nothing needs to be dropped, return the original Tablet (no copy).
  • If some FIELD columns are dropped, return a new Tablet with only the kept columns.
  • If every FIELD column is null, skip the insert (return null / empty and log a warning where applicable).
  • Does not mutate the caller-owned Tablet.

Multi-language clients

Aligned the same logic in Java / C++ / Python Session insert tablet paths (insertTablet / insertTablets / aligned / relational where applicable). C API goes through the C++ Session, so no separate implementation.

Design notes

  • Logic lives in SessionUtils.filterNullColumns (Java / C++) and filter_null_columns (Python), and is invoked when building insert requests after sort.
  • C++ returns std::shared_ptr<const Tablet> (non-owning empty deleter for the original tablet; owning shared_ptr for a filtered copy) instead of a raw pointer + out-parameter.

This PR has:

  • been self-reviewed.
  • added unit tests or modified existing tests to cover new code paths, ensuring the threshold for code coverage.
  • added documentation for new or modified features or behaviors.
  • added integration tests.
  • been tested in a test IoTDB cluster.

Key changed/added classes (or packages if there are too many classes) in this PR
  • org.apache.iotdb.session.util.SessionUtils
  • org.apache.iotdb.session.Session
  • iotdb-client/client-cpp SessionUtils::filterNullColumns / Session
  • iotdb.utils.SessionUtils (Python)
  • Unit tests: SessionUtilsTest (Java), sessionUtilsTest (C++), test_session_utils.py (Python)

… clients

Skip or shrink tablets that only contain null FIELD values so insert paths
avoid shipping unused measurement columns across languages.
Comment on lines +148 to +149
// Returns false when all FIELD columns are null and the insert should be skipped.
static bool buildInsertTabletReq(TSInsertTabletReq& request, Tablet& tablet, bool sorted);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the table model, time-only insertion is allowed.

Comment on lines +416 to +429
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;
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is bitMap.isAllMarked not enough?

Comment on lines +479 to +481
auto filteredOut = std::make_shared<Tablet>(tablet.deviceId, keptSchemas, keptColumnTypes,
tablet.maxRowNumber, tablet.isAligned);
filteredOut->deleteColumns();

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not create-and-delete or copy. May add a constructor for this.

return;
}
request.setWriteToTable(true);
request.setColumnCategories(toEnumOrdinalsAsBytes(tablet.getColumnTypes()));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is thsi removed?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants