Apache Druid自定义扩展模块-数据解析器

简介: 一.简述 Apache Druid已有的扩展模块很多包括:HDFS存储使用的druid-hdfs-storage,Kafka数据接入使用的druid-kafka-indexing-service,将MySQL做为元数据库使用的mysql-metadata-storage,数据排重使用的druid-datasketches;但有时这些也无法满足我们实际应用场景下的特殊需求,那么必要的二次开发增加自定义的模块就成了必然。

一.简述

Apache Druid已有的扩展模块很多包括:HDFS存储使用的druid-hdfs-storage,Kafka数据接入使用的druid-kafka-indexing-service,将MySQL做为元数据库使用的mysql-metadata-storage,数据排重使用的druid-datasketches;但有时这些也无法满足我们实际应用场景下的个性化需求,那么必要的二次开发增加自定义的模块就成了必然。例如:数据解析器druid-thrift-extensions

二.实现

Ⅰ).创建工程

创建java工程,并在sources目录中添加文件:org.apache.druid.initialization.DruidModule;文件内容如下:

com.yun.druid.data.input.thrift.ThriftExtensionModule

Ⅱ).接口实现

a).ThriftExtensionsModule

ThriftExtensionsModule实现DruidModule接口,并重写getJacksonModules方法;需注册类ThriftInputRowParser.class别名(yun-thrift)

@Override
    public List<? extends Module> getJacksonModules() {
        // TODO Auto-generated method stub
        return Collections.singletonList(
                new SimpleModule("ThriftInputRowParserModule").registerSubtypes(
                        new NamedType(ThriftInputRowParser.class, "yun-thrift")));
    }

b).ThriftInputRowParser

ThriftInputRowParser类实现InputRowParser

接口,并重写 parseBatch方法

@JsonCreator
    public ThriftInputRowParser(
            @JsonProperty("parseSpec") ParseSpec parseSpec,
            @JsonProperty("jarPath") String jarPath,
            @JsonProperty("thriftClassName") String thriftClassName)
    {
        this.jarPath = jarPath;
        this.thriftClassName = thriftClassName;
        
        Preconditions.checkNotNull(thriftClassName, "thrift class name");
        
        this.parseSpec = parseSpec;
        this.demensions = parseSpec.getDimensionsSpec().getDimensionNames();
    }
    
    public List<InputRow> parseBatch(Object input){
        final TBase tbase;
        try {
            
            if(input instanceof ByteBuffer) {
                final byte[] bytes = ((ByteBuffer) input).array();
            }
            
        } catch (Exception e) {
            // TODO: handle exception
        }
        return null;
    }

Ⅲ).自定义逻辑

具体逻辑实现,根据需求重写parseBatch方法中实现

Ⅳ).打包

将该工程打成jar包,命名规则可以是:druid-namesparce-thrift-extension.jar

三.使用

Ⅰ).jar包位置

./apache-druid-0.14.0-incubating/extensions目录,创建druid-namesparce-thrift-extension文件夹;然后将自定义模块工程jar包以及依赖的jar包放到该目录

Ⅱ).导入配置

conf/druid/_common/common.runtime.properties的配置文件中添加如下配置,然后重启角色

druid.extensions.loadList=["druid-histogram", "druid-datasketches", "druid-lookups-cached-global", "druid-kafka-indexing-service", "mysql-metadata-storage", "druid-hdfs-storage", "druid-<namesparce>-thrift-extension"]

Ⅲ).任务中使用

在提交任务的json文件的解析器部分,指定type为自定义的别名;其中,thriftJar、thriftClass和protocol可以不配置

    "parser": {
            "type": "yun-thrift",
            "thriftJar":"druid-<namesparce>-thrift-extension.jar",
            "thriftClass":"com.yun.druid.data.input.thrift.ThriftExtensionModule.class",
            "protocol":"compact",
            "parseSpec": {
                "format": "json",
                "timestampSpec": {
                    "column": "time",
                    "format": "auto"
                },
                "dimensionsSpec": {
                    "dimensions": [
                        "appName",
                        "nodeName"
                    ],
                    "dimensionExclusions": []
                }
            }

Ⅳ).启动任务验证

根据自己的任务配置文件,参考如下启动命令,启动并验证自定义解析器

curl -XPOST -H'Content-Type: application/json' -d @quickstart/tutorial/kafka-streaming.json http://hostname:8081/druid/indexer/v1/supervisor
目录
相关文章
|
21天前
|
XML Java Android开发
Android实现自定义进度条(源码+解析)
Android实现自定义进度条(源码+解析)
50 1
|
22天前
|
存储 缓存 算法
Python中collections模块的deque双端队列:深入解析与应用
在Python的`collections`模块中,`deque`(双端队列)是一个线程安全、快速添加和删除元素的双端队列数据类型。它支持从队列的两端添加和弹出元素,提供了比列表更高的效率,特别是在处理大型数据集时。本文将详细解析`deque`的原理、使用方法以及它在各种场景中的应用。
|
20天前
|
数据挖掘
深入解析ERP系统的人力资源管理模块
深入解析ERP系统的人力资源管理模块
22 1
|
20天前
|
监控 BI
财务智慧:全面解析ERP系统的财务管理模块
财务智慧:全面解析ERP系统的财务管理模块
17 0
|
22天前
|
数据采集 数据挖掘 Python
Python中collections模块的Counter计数器:深入解析与应用
在Python的`collections`模块中,`Counter`是一个强大且实用的工具,它主要用于计数可哈希对象。无论是统计单词出现的频率,还是分析数据集中元素的分布情况,`Counter`都能提供快速且直观的结果。本文将深入解析`Counter`计数器的原理、用法以及它在实际应用中的价值。
|
1月前
|
存储 缓存 负载均衡
【Apache ShenYu源码】如何实现负载均衡模块设计
整个模块为ShenYu提供了什么功能。我们可以看下上文我们提到的工厂对象。/***/核心方法很清晰,我们传入Upsteam列表,通过这个模块的负载均衡算法,负载均衡地返回其中一个对象。这也就是这个模块提供的功能。
18 1
|
1月前
|
XML 数据采集 前端开发
深入解析网页结构解析模块BeautifulSoup
深入解析网页结构解析模块BeautifulSoup
24 0
|
1月前
|
XML Java Apache
Apache Flink自定义 logback xml配置
Apache Flink自定义 logback xml配置
150 0
|
1月前
|
Apache 开发者
揭秘!Apache Hudi社区发展数据盘点
揭秘!Apache Hudi社区发展数据盘点
32 0
|
1月前
|
分布式计算 Java 数据管理
使用Apache Hudi + Amazon EMR进行变化数据捕获(CDC)
使用Apache Hudi + Amazon EMR进行变化数据捕获(CDC)
87 0

推荐镜像

更多