dremio AbstractRecordReader 简单说明一

AbstractRecordReader 在dremio 实现了不同存储的数据读取处理,还是比较重要的,毕竟dremio 主要还是查询

AbstractRecordReader接口定义

AbstractRecordReader 实现了RecordReader接口,当然AbstractRecordReader 还是抽象类,业务使用是由具体子类处理的,不同场景会用不同的
具体reader,比如jdbc 有自己的,mongo 也有自己的,对于读取到的数据我们是需要到一个OutputMutator 的(可以进行schema 的修改),具体从
接口定义也可以看到

 

 

 

实现子类

只包含了部分内部的,对于外部插件的没有包含(比如mongo,jdbc。。。)

存储插件对于AbstractRecordReader 的使用

  • InformationSchemaRecordReader
    简单以InformationSchemaRecordReader 为例说明
    首先是需要一个ProducerOperator.Creator 的,此类实现reader 以及schema fetcher 以及InfoSchemaStoragePlugin 存储扩展的关联
    ProducerOperator
 
public class InfoSchemaScanCreator implements ProducerOperator.Creator<InfoSchemaSubScan>{
 
  @Override
  public ProducerOperator create(FragmentExecutionContext fec, OperatorContext context, InfoSchemaSubScan config) throws ExecutionSetupException {
    final InformationSchemaTable table = config.getTable();
    final InfoSchemaStoragePlugin plugin = fec.getStoragePlugin(config.getPluginId());
    final String catalogName =
        context.getOptions().getOption(ExecConstants.USE_LEGACY_CATALOG_NAME)
            ? InfoSchemaConstants.IS_LEGACY_CATALOG_NAME
            : InfoSchemaConstants.IS_CATALOG_NAME;
    // 关联存储插件以及reader
    final RecordReader reader = new InformationSchemaRecordReader(context, config.getColumns(),
        plugin.getSabotContext().getInformationSchemaServiceBlockingStub(), table,
        catalogName, config.getProps().getUserName(), config.getQuery(), context.getOptions().getOption(PlannerSettings.FULL_NESTED_SCHEMA_SUPPORT));
    return new ScanOperator(config, context, RecordReaderIterator.from(reader));
  }
}

具体读取处理,依赖了rpc 服务InformationSchemaServiceBlockingStub,然后进行schema 数据的获取
对于不同schema 表的数据使用了不同的表createTableWriter 方法,会在setup 进行初始化,数据会到一个writer 中

 
  private TableWriter<?> createTableWriter()  
 @Override
  public void setup(OutputMutator output) {
    context = Context.current().withCancellation();
    context.run(() -> {
      tableWriter = createTableWriter();
      tableWriter.init(output);
    });
  }

InformationSchema 包含的writer 实现

 

 

OutputMutator

  • 作用
    允许record reader 可以修改当前的schema 的能力,同时将处理进行了抽象,可以确保以不同顺序共享相同列定义的新 RecordReader
    不会为下游消费者生成模式更改事件(schema 变动对于dremio 影响比较大)
  • 实现子类

包含了测试,采样,以及向量容器

说明

AbstractRecordReader 的执行依赖Operator,reader 数据会到一个中间的writer 中(不同存储插件的具体实现会不一样)以上是结合InformationSchemaRecordReader 的一个简单说明,实际上还是很复杂的

参考资料

https://github.com/dremio/dremio-oss/blob/d41cb52143b6b0289fc8ed4d970bfcf410a669e8/sabot/kernel/src/main/java/com/dremio/exec/store/ischema/writers/TableWriter.java
https://github.com/dremio/dremio-oss/blob/d41cb52143b6b0289fc8ed4d970bfcf410a669e8/sabot/kernel/src/main/java/com/dremio/exec/store/ischema/InformationSchemaRecordReader.java
https://github.com/dremio/dremio-oss/blob/d41cb52143b6b0289fc8ed4d970bfcf410a669e8/sabot/kernel/src/main/java/com/dremio/exec/store/ischema/InfoSchemaStoragePlugin.java
https://github.com/dremio/dremio-oss/blob/d41cb52143b6b0289fc8ed4d970bfcf410a669e8/sabot/vector-tools/src/main/java/com/dremio/sabot/op/scan/OutputMutator.java
https://www.cnblogs.com/rongfengliang/p/16799983.html

posted on 2022-10-17 17:32  荣锋亮  阅读(26)  评论(0编辑  收藏  举报

导航