iotdb icon indicating copy to clipboard operation
iotdb copied to clipboard

[Bug] Custom Pipe Processor Plugin can not get the all insert data values

Open xiaochangg opened this issue 8 months ago • 13 comments

Search before asking

  • [x] I searched in the issues and found nothing similar.

Version

the version is 2.0.5

Describe the bug and provide the minimal reproduce step

my table is: create database testdb2; CREATE TABLE gwy6l(time TIMESTAMP TIME,measurementname STRING TAG,type STRING ATTRIBUTE,value STRING FIELD,status INT64 FIELD,source_time INT64 FIELD,server_time INT64 FIELD);

the custom pipe processor plugin is:

Image

show pipeplugins is:

Image

my pipe create cmd is: CREATE PIPE task2742_outer_98785855 WITH SOURCE ('source'='iotdb-source','source.inclusion' = 'data.insert,data.delete', 'source.history.enable' = 'false', 'source.mode.streaming' = 'true') WITH PROCESSOR ('processor' = 'SYNC_IOTDB_IOTDBTABLE_11') WITH SINK ('sink' = 'do-nothing-sink')

insert into data and find in /logs/log_datanode_all.log is:

Image

i can get the insert data , but the data is not complete.

logger.info("tablet schemas:{}",tablet.getSchemas()); logger.info("tablet columnsTypes:{}",tablet.getColumnTypes());

the print log
:[[measurementname,STRING,PLAIN,,LZ4], [server_time,INT64,TS_2DIFF,,LZ4], [source_time,INT64,TS_2DIFF,,LZ4], [status,INT64,TS_2DIFF,,LZ4], [value,STRING,PLAIN,,LZ4]]

not contains the type field ,the type field columnCategory is attribute ,

What did you expect to see?

i want to get the field value(the field is attribute ) from custom pipe processor ,

What did you see instead?

the pipe task should config ? i can get the field value . the field columnCategory is attribute .

Anything else?

No response

Are you willing to submit a PR?

  • [ ] I'm willing to submit a PR!

xiaochangg avatar Mar 25 '26 06:03 xiaochangg

in the custom pipe processor ,i can not get the type field value , the type field category is attribute Image

xiaochangg avatar Mar 25 '26 07:03 xiaochangg

Well, the method in the PIPE processor only captures data from the DataRegion BY DESIGN.

The attribute is defined as part of the metadata instead of the data. It will not even go into the DataRegion, let alone be captured by the PIPE.

It is recommended to query the attribute from the attribute cache with the DeviceId (table name + tags).

jt2594838 avatar Mar 26 '26 02:03 jt2594838

The simplest query logic may be using:

      LocalExecutionPlanner.getInstance()
          .metadata
          .indexScan(
              new QualifiedObjectName(<database>, <table>),
              Collections.emptyList(),
              Arrays.asList(<yourAttributes>),
              new MPPQueryContext(new QueryId("Processor query")));

And it will return Map<String, List>, ignore the key (database, for tree view), and the List is all you needed.

Caideyipi avatar Mar 26 '26 02:03 Caideyipi

new QueryId("Processor query") What parameters should I pass, or is it a fixed value(Processor query), time,or tags field value?

xiaochangg avatar Mar 26 '26 02:03 xiaochangg

QueryId can be and arbitary value, or even just QueryId.MOCK_QUERY_ID. Of course you can also use Coordinator.createQueryId() here

Caideyipi avatar Mar 26 '26 03:03 Caideyipi

Since the queryId may occur in the log when the attribute query fails, you can also use a self-defined querId for debugging purposes.

jt2594838 avatar Mar 26 '26 03:03 jt2594838

Can you give an example? my table data is:

Image

table desc

Image

in pipe processor : Map<String, List> stringListMap = LocalExecutionPlanner.getInstance().metadata.indexScan(new QualifiedObjectName("testdb","gwy6l" ), Collections.emptyList(), Arrays.asList("type"), new MPPQueryContext(new QueryId("Processor query")));

new QueryId("device_016_0") ?

xiaochangg avatar Mar 26 '26 03:03 xiaochangg

I would suggest appending the name of your processor to the front ("SYNC_IOTDB_IOTDBTABLE_11_<database>_<table>"), so that you may know easily from the log if something went wrong.

jt2594838 avatar Mar 26 '26 03:03 jt2594838

i does not understand what you mean , LocalExecutionPlanner.getInstance().metadata.indexScan(new QualifiedObjectName("testdb","gwy6l" ), Collections.emptyList(), Arrays.asList("type"), new MPPQueryContext(new QueryId("Processor query"))); What environment does this code snippet need to run in?

Image

run it ,the printstack is

Image

What I want is to get the attribute info in the pipe processor?

if use SYNC_IOTDB_IOTDBTABLE_11__

the error message id : CustomProcessorToFile customize error :Invalid id SYNC_IOTDB_IOTDBTABLE_11_testdb2_gwy6l

xiaochangg avatar Mar 26 '26 06:03 xiaochangg

i have got it get it by using it this way:

SessionInfo sessionInfo = new SessionInfo( 9999L, // sessionId:随便给一个唯一 long 即可(Pipe内部用) userName, // userName:默认超级管理员 root ZoneId.systemDefault(), // 时区:必须传,用系统默认就行 dbName, IClientSession.SqlDialect.TABLE // 重点:你用的是表模型,必须是 TABLE 模式! ); TEndPoint localDataBlockEndpoint = new TEndPoint("127.0.0.1", port); TEndPoint localInternalEndpoint = new TEndPoint("127.0.0.1", 10730); MPPQueryContext queryContext = new MPPQueryContext( "pipe query", // 随便写一个SQL QueryId.MOCK_QUERY_ID, sessionInfo, localDataBlockEndpoint, localInternalEndpoint );

queryContext.setSession(sessionInfo);

Map<String, List> stringListMap = LocalExecutionPlanner.getInstance() .metadata.indexScan(new QualifiedObjectName(sid, oriTableName), Collections.emptyList(), Arrays.asList("type","type2"),queryContext);

for (String key : stringListMap.keySet()) { List entryList = stringListMap.get(key); for (DeviceEntry entry : entryList) { String deviceId = entry.getDeviceID().toString(); if (attributeKeyCache.containsKey(deviceId)){ continue; }

    Binary[] attributeColumnValues = entry.getAttributeColumnValues();
    StringBuilder s = new StringBuilder();
    for(Binary binary : attributeColumnValues) {
        s.append(",").append(binary.toString());
    }
    attributeKeyCache.put(deviceId,s.substring(1));
}

}

xiaochangg avatar Mar 26 '26 09:03 xiaochangg

Congratulations.

Since customize is only called during the initialization of Pipe, if the attribute is changed during runtime, you may put the above logic in process instead. However, it may introduce a higher cost because the query is performed with every insertion.

jt2594838 avatar Mar 27 '26 01:03 jt2594838

I get the data in the customize method and put it into the cache map for the first time. the cache map expired 5min. when cache expired . then load the attribute data to cache .

xiaochangg avatar Mar 27 '26 07:03 xiaochangg

This has a small issue, but it's acceptable.

xiaochangg avatar Mar 27 '26 07:03 xiaochangg