dremio 读取 jsonl 格式支持

实际上属于dremio 社区一个问题,内部实际上是dremio 对于格式化插件支持的问题, 不少是基于文件格式硬编码的,尽管
我们可以自定义格式化插件,但是对于已经支持的就有点不是很方便了,可以直接复用现有的,以下说明下修改以及处理

直接修改JSONFormatPlugin 代码支持jsonl

  • 参考如下
    FormatCreator.java
public static Map<String, FormatPluginConfig> getDefaultFormats() {
  Map<String, FormatPluginConfig> defaultFormats = new TreeMap<>();
  defaultFormats.put("csv", createTextFormatPlugin(false, ",", Lists.newArrayList("csv")));
  defaultFormats.put("csvh", createTextFormatPlugin(true, ",", Lists.newArrayList("csvh")));
  defaultFormats.put("tsv", createTextFormatPlugin(false, "\t", Lists.newArrayList("tsv")));
  defaultFormats.put("psv", createTextFormatPlugin(false, "|", Lists.newArrayList("psv", "tbl")));
  defaultFormats.put("txt", createTextFormatPlugin(false, "\u0000", Lists.newArrayList("txt")));
  TextFormatConfig psva = createTextFormatPlugin(false, "|", Lists.newArrayList("psva", "tbla"));
  psva.autoGenerateColumnNames = true;
  defaultFormats.put("psva", psva);
 
  defaultFormats.put("parquet", new ParquetFormatConfig());
  defaultFormats.put("json", new JSONFormatPlugin.JSONFormatConfig());
  defaultFormats.put("jsonl", new JSONFormatPlugin.JSONFormatConfig());
  defaultFormats.put("dremarrow1", new ArrowFormatPluginConfig());
  defaultFormats.put("iceberg", new IcebergFormatConfig());
  defaultFormats.put("delta", new DeltaLakeFormatConfig());
  defaultFormats.put("xls", new ExcelFormatPluginConfig(true));
  defaultFormats.put("excel", new ExcelFormatPluginConfig(false));
  return defaultFormats;
}

JSONFormatPlugin.java

public static class JSONFormatConfig implements FormatPluginConfig {
 
  public List<String> extensions = ImmutableList.of("json","jsonl");
  private static final List<String> DEFAULT_EXTS = ImmutableList.of("json","jsonl");
  .....

基于标准格式化插件模式

实际上就是复制JSONFormatPlugin的代码,自己修改,然后编译一个,复制到dremio的classpath 中

构建以及替换

方法就比较多了,可以是直接jar class 替换的,也可以是按照标准jar 文件存放的

  • class 替换的参考命令
jar uf dremio-sabot-kernel-25.0.0-202404051521110861-ed9515a8.jar   com/dremio/exec/store/dfs/FormatCreator.class
jar uf dremio-sabot-kernel-25.0.0-202404051521110861-ed9515a8.jar   com/dremio/exec/store/easy/json/JSONFormatPlugin\$JSONFormatConfig.class
  • 标准格式化插件模式
    直接放到dremio jars 目录就行了

参考效果

  • s3 数据存储

  • 通过修改表元数据进行自动提升
    自动提升就会使用到格式化插件
ALTER TABLE s3.dalong.appdemo REFRESH METADATA AUTO PROMOTION

效果

  • 查询

说明

以上是一个简单说明,实际上对于格式化插件的开发基本套路也是这样的

参考资料

https://jsonlines.org/
https://www.atatus.com/glossary/jsonl/
https://www.cnblogs.com/rongfengliang/p/18141296

posted on 2024-05-02 11:31  荣锋亮  阅读(4)  评论(0编辑  收藏  举报

导航