iotdb icon indicating copy to clipboard operation
iotdb copied to clipboard

Subscription: support table-model column-filter for topics

Open VGalaxies opened this issue 5 months ago • 3 comments

Purpose

Add a column-filter topic attribute for table-model subscriptions so a topic can restrict which columns consumers receive, based on column metadata, applied uniformly across historical, real-time pipe, and IoTConsensus WAL paths.

What

  • New optional topic attribute column-filter (table-model only); unset == true. Restricted boolean predicate over column-metadata fields aligned with information_schema.columns: database, table_name, column_name, datatype, category. Supports =/!=, IN, LIKE, REGEXP, IS [NOT] NULL, AND/OR/NOT.
  • Independent ColumnFilter.g4 grammar (decoupled from the query grammar) producing the reused relational AST nodes; a whitelist validator rejects unsupported syntax/fields.
  • Resolved to a per-(database, table) column set at CREATE/ALTER (and on re-bind) against the current schema, cached per topic on the DataNode and used for O(1) runtime pruning. TAG columns are retained; ATTRIBUTE columns are not transmittable.
  • Applied in all paths: IoTConsensus WAL converter, pipe tablet batch, and TsFile reseal (prune at tablet granularity; raw TsFile passthrough kept only when the filter is trivial).
  • timeSelected propagated as an optional, backward-compatible per-table flag on the poll response (defaults to exposing time for old consumers).
  • ALTER TOPIC hot-refreshes the cached matcher (no converter rebuild; in-flight not reprocessed).
  • Removed the legacy consensus-only column regex attribute.

Tests

  • Unit: parser/validator/evaluator, binder, tablet pruner, topic config, poll response, record handler.
  • Integration (table model): live/snapshot, record & TsFile, multi-consumer-group, historical+ realtime consistency, ALTER rebind, empty-result progress, snapshot semantics, custom time column, altered data type, tree-view source-column binding, attribute drop, 1C3D cluster ALTER-after-owner-transfer, DataNode restart re-snapshot, invalid-expression rejection, permission.

Notes

  • The column-filter bound set is a non-persisted snapshot: stable between binds, re-derived from the current schema on CREATE/ALTER/restart/owner-transfer; not frozen for the topic lifetime.
  • Tree-model topics are unaffected.

VGalaxies avatar Jun 12 '26 17:06 VGalaxies

Codecov Report

:x: Patch coverage is 69.09227% with 412 lines in your changes missing coverage. Please review. :white_check_mark: Project coverage is 42.19%. Comparing base (71cb6e6) to head (b7188f2). :warning: Report is 8 commits behind head on master.

Files with missing lines Patch % Lines
.../event/batch/SubscriptionPipeTabletEventBatch.java 0.00% 82 Missing :warning:
...db/subscription/agent/SubscriptionBrokerAgent.java 19.35% 50 Missing :warning:
...che/iotdb/confignode/manager/ProcedureManager.java 33.33% 28 Missing :warning:
...vent/response/SubscriptionEventTabletResponse.java 0.00% 28 Missing :warning:
.../plan/execution/config/TableConfigTaskVisitor.java 4.00% 24 Missing :warning:
...on/consumer/base/AbstractSubscriptionConsumer.java 0.00% 16 Missing :warning:
...on/broker/consensus/ConsensusPrefetchingQueue.java 70.37% 16 Missing :warning:
.../subscription/columnfilter/ColumnFilterParser.java 88.52% 14 Missing :warning:
...ad/evolvable/batch/PipeTabletEventTsFileBatch.java 56.00% 11 Missing :warning:
...otdb/db/schemaengine/table/DataNodeTableCache.java 0.00% 11 Missing :warning:
... and 22 more
Additional details and impacted files
@@             Coverage Diff              @@
##             master   #17936      +/-   ##
============================================
+ Coverage     41.81%   42.19%   +0.38%     
  Complexity      318      318              
============================================
  Files          5296     5306      +10     
  Lines        373384   375004    +1620     
  Branches      48210    48507     +297     
============================================
+ Hits         156134   158238    +2104     
+ Misses       217250   216766     -484     

:umbrella: View full report in Codecov by Harness.
:loudspeaker: Have feedback on the report? Share it here.

:rocket: New features to boost your workflow:
  • :snowflake: Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

codecov[bot] avatar Jun 12 '26 18:06 codecov[bot]

Findings

  1. Valid REGEXP/string literals are rejected before parsing
    ColumnFilterParser.java#L139-L153
    validateUnsupportedSyntax scans the raw expression and rejects <, >, and + before tokenization, but it does not
    skip quoted string literals. As a result, valid filters such as column_name REGEXP "s[0-9]+", column_name = "a+b", or column_name LIKE "a>%" fail at topic creation time. This should either ignore characters inside quoted strings
    or let the grammar/parser reject unsupported operators.

  2. A time-only filter drops all rows for tagless tables
    ColumnFilterBinder.java#L67-L75, TabletColumnPruner.java#L78-L94
    A filter like column_name = "time" only sets timeSelected; it does not add any selected physical tablet column. For a table without TAG columns, TabletColumnPruner then sees an empty selected column set and returns null, so
    consumers receive no rows. IoTDB table model allows tagless tables such as CREATE TABLE t (s1 INT64 FIELD), so this is a valid case. The implementation should either support time-only tablets or reject this unsupported shape during bind/validation.

Caideyipi avatar Jun 15 '26 07:06 Caideyipi

Quality Gate Failed Quality Gate failed

Failed conditions
B Reliability Rating on New Code (required ≥ A)

See analysis details on SonarQube Cloud

💡 Need a hand with PR review? Try Gitar by Sonar!

sonarqubecloud[bot] avatar Jul 10 '26 04:07 sonarqubecloud[bot]