dremio 存储插件之StoragePluginRulesFactory 类简单说明

StoragePluginRulesFactory 是dremio 为了分离每个插件的规则,我们存储插件可以包含自己的规则工厂,具体使用到StoragePluginRulesFactory
的包含了CatalogServiceImpl,SqlHandlerConfig,实际都会到sql 执行的handler 中

系统内置实现

 

 

集成使用

主要是CatalogServiceImpl.java 中,其他执行部分通过间接引用

 
public RuleSet getStorageRules(OptimizerRulesContext context, PlannerPhase phase) {
    final ImmutableSet.Builder<RelOptRule> rules = ImmutableSet.builder();
    final Set<SourceType> types = new HashSet<>();
 
    try {
      for (ManagedStoragePlugin plugin : getPlugins().managed()) {
        // we want to check state without acquiring a read lock
        if (plugin.getState().getStatus() == SourceState.SourceStatus.bad) {
          // we shouldn't consider rules for misbehaving plugins.
          continue;
        }
 
        StoragePluginId pluginId;
        try {
          // getId has a check for plugin state
          pluginId = plugin.getId();
        } catch (UserException e) {
          if (e.getErrorType() == ErrorType.SOURCE_BAD_STATE) {
            // we shouldn't consider rules for misbehaving plugins.
            continue;
          }
          throw e;
        }
 
        StoragePluginRulesFactory factory = plugin.getRulesFactory();
        if(factory != null) {
          // add instance level rules.
          rules.addAll(factory.getRules(context, phase, pluginId));
 
          // add type level rules.
          if(types.add(pluginId.getType())) {
            rules.addAll(factory.getRules(context, phase, pluginId.getType()));
          }
        }
      }
    } catch (InstantiationException | IllegalAccessException e) {
      throw UserException.validationError(e).message("Failure getting plugin rules.").build(logger);
    }
 
    ImmutableSet<RelOptRule> rulesSet = rules.build();
    return RuleSets.ofList(rulesSet);
  }

SqlHandlerConfig 对于规则的使用 SqlHandlerConfig.java 间接也是通过执行上下文使用的CatalogService

 public RuleSet getRules(PlannerPhase phase) {
    return PlannerPhase.mergedRuleSets(
        context.getInjectedRules(phase),
        phase.getRules(context),
        context.getCatalogService().getStorageRules(context, phase));
  }

说明

dremio StoragePluginRulesFactory 还是比较强大的,扩展了dremio sql 处理能力,是一个很不错的扩展点 尤其我们需要开发自己的存储扩展的时候

参考资料

https://github.com/dremio/dremio-oss/blob/d41cb52143b6b0289fc8ed4d970bfcf410a669e8/sabot/kernel/src/main/java/com/dremio/exec/catalog/CatalogServiceImpl.java
https://github.com/dremio/dremio-oss/blob/d41cb52143b6b0289fc8ed4d970bfcf410a669e8/sabot/kernel/src/main/java/com/dremio/exec/planner/sql/handlers/SqlHandlerConfig.java
https://github.com/dremio/dremio-oss/blob/d41cb52143b6b0289fc8ed4d970bfcf410a669e8/sabot/kernel/src/main/java/com/dremio/exec/store/StoragePlugin.java

posted on   荣锋亮  阅读(25)  评论(0编辑  收藏  举报

相关博文:
阅读排行:
· 全程不用写代码,我用AI程序员写了一个飞机大战
· DeepSeek 开源周回顾「GitHub 热点速览」
· 记一次.NET内存居高不下排查解决与启示
· MongoDB 8.0这个新功能碉堡了,比商业数据库还牛
· .NET10 - 预览版1新功能体验(一)
历史上的今天:
2020-10-21 使用properties-maven-plugin管理配置
2020-10-21 The Fault in Our JARs: Why We Stopped Building Fat JARs
2019-10-21 space-cloud 学习一 基本试用
2018-10-21 dbt macro 说明
2018-10-21 构建一个dbt 数据库适配器
2018-10-21 dbt 包的构建
2018-10-21 dbt 生产环境使用

导航

< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5
点击右上角即可分享
微信分享提示