Custom Parser SDK
Kylin supports custom parsing of Kafka data through the SDK.
Setting up the development environment
Create a Project
- Use Maven to manage project dependencies

Modify the pom.xml file
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.10.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.3.0</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<finalName>${artifactId}</finalName>
<artifactSet>
<excludes>
<exclude>org.apache.kylin:kylin-streaming-sdk</exclude>
<exclude>org.projectlombok:*</exclude>
<exclude>org.apache.commons:*</exclude>
<exclude>com.fasterxml.jackson.core:*</exclude>
<exclude>com.google.guava:*</exclude>
<exclude>org.slf4j:*</exclude>
</excludes>
</artifactSet>
<filters>
<filter>
<artifact>*:*</artifact>
<excludes>
<exclude>META-INF/*.SF</exclude>
<exclude>META-INF/*.DSA</exclude>
<exclude>META-INF/*.RSA</exclude>
<exclude>javax/annotation/**</exclude>
</excludes>
</filter>
</filters>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
Import SDK
Copy ${KYLIN_HOME}/server/jars/kylin-streaming-sdk-{version}.jar.
Create a new lib directory in the project root directory. And put the SDK Jar into the lib directory.

Load the SDK dependencies into the project
<properties>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<noop.version>1</noop.version>
</properties>
<dependencies>
<dependency>
<groupId>org.apache.kylin</groupId>
<artifactId>kylin-streaming-sdk</artifactId>
<version>${noop.version}</version>
<scope>system</scope>
<systemPath>${project.basedir}/lib/kylin-streaming-sdk-{version}.jar</systemPath>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-slf4j-impl</artifactId>
<version>2.18.0</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.10</version>
</dependency>
</dependencies>
Implement a custom parser
- Create a new parser class,
XXXParser extends AbstractDataParser<ByteBuffer>. Override parse(ByteBuffer input), Parse a single piece of data within a method, returnMap<Field Name, Field Value>.- If there are initialization actions that need to be done while the instance resolver class is in use, do so in a parameterless construct.
Override before()if an initialization action is required before each data is parsed.- If an exception is thrown during the parsing of a single piece of data, the data will be considered dirty during the build and the construction of this piece of data will be skipped.
- To check data after each piece of data is processed,
Override after(). - Create
${project.basedir}/src/resources/META-INF/services/org.apache.kylin.parser.AbstractDataParserfile, and each of the parser class's class path to fill them.

Demo Parser
pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.apache.kylin</groupId>
<artifactId>custom-parser-demo</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<maven.compiler.source>8</maven.compiler.source>
<maven.compiler.target>8</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<noop.version>1</noop.version>
</properties>
<dependencies>
<!-- SDK -->
<dependency>
<groupId>org.apache.kylin</groupId>
<artifactId>kylin-streaming-sdk</artifactId>
<version>${noop.version}</version>
<scope>system</scope>
<systemPath>${project.basedir}/lib/kylin-streaming-sdk-5.0.0-SNAPSHOT.jar</systemPath>
</dependency>
<!-- Json -->
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.14.0</version>
</dependency>
<!-- CSV -->
<dependency>
<groupId>com.opencsv</groupId>
<artifactId>opencsv</artifactId>
<version>5.7.1</version>
<exclusions>
<exclusion>
<groupId>commons-collections</groupId>
<artifactId>commons-collections</artifactId>
</exclusion>
</exclusions>
</dependency>
<!-- Others -->
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.24</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>31.1-jre</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-slf4j-impl</artifactId>
<version>2.18.0</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.10</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.10.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.3.0</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<finalName>${artifactId}</finalName>
<artifactSet>
<excludes>
<exclude>org.apache.kylin:kylin-streaming-sdk</exclude>
<exclude>org.projectlombok:*</exclude>
<exclude>org.apache.commons:*</exclude>
<exclude>com.fasterxml.jackson.core:*</exclude>
<exclude>com.google.guava:*</exclude>
<exclude>org.slf4j:*</exclude>
<exclude>org.apache.logging.log4j:*</exclude>
</excludes>
</artifactSet>
<filters>
<filter>
<artifact>*:*</artifact>
<excludes>
<exclude>META-INF/*.SF</exclude>
<exclude>META-INF/*.DSA</exclude>
<exclude>META-INF/*.RSA</exclude>
<exclude>javax/annotation/**</exclude>
</excludes>
</filter>
</filters>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>