This is an automated email from the ASF dual-hosted git repository.
dockerzhang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/inlong.git
The following commit(s) were added to refs/heads/master by this push:
new 1b800932b0 [INLONG-9596][Sort] Support row way of sort InLong message
tlog-kv format (#9620)
1b800932b0 is described below
commit 1b800932b0e46b0ed9a916360cbd626a929ab214
Author: baomingyu <[email protected]>
AuthorDate: Mon Jan 29 12:21:08 2024 +0800
[INLONG-9596][Sort] Support row way of sort InLong message tlog-kv format
(#9620)
---
.../format-row/format-inlongmsg-tlogkv/pom.xml | 130 +++++++++
.../formats/inlongmsgtlogkv/InLongMsgTlogKv.java | 95 ++++++
.../InLongMsgTlogKvFormatDeserializer.java | 320 +++++++++++++++++++++
.../InLongMsgTlogKvFormatFactory.java | 163 +++++++++++
.../InLongMsgTlogKvMixedFormatConverter.java | 163 +++++++++++
.../InLongMsgTlogKvMixedFormatDeserializer.java | 233 +++++++++++++++
.../inlongmsgtlogkv/InLongMsgTlogKvUtils.java | 157 ++++++++++
.../inlongmsgtlogkv/InLongMsgTlogKvValidator.java | 44 +++
.../org.apache.flink.table.factories.TableFactory | 16 ++
.../InLongMsgTlogKvFormatDeserializerTest.java | 213 ++++++++++++++
.../InLongMsgTlogKvFormatFactoryTest.java | 125 ++++++++
.../inlongmsgtlogkv/InLongMsgTlogKvTest.java | 112 ++++++++
.../src/test/resources/log4j-test.properties | 27 ++
inlong-sort/sort-formats/format-row/pom.xml | 1 +
14 files changed, 1799 insertions(+)
diff --git
a/inlong-sort/sort-formats/format-row/format-inlongmsg-tlogkv/pom.xml
b/inlong-sort/sort-formats/format-row/format-inlongmsg-tlogkv/pom.xml
new file mode 100644
index 0000000000..5ebdc105f4
--- /dev/null
+++ b/inlong-sort/sort-formats/format-row/format-inlongmsg-tlogkv/pom.xml
@@ -0,0 +1,130 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+Licensed to the Apache Software Foundation (ASF) under one
+or more contributor license agreements. See the NOTICE file
+distributed with this work for additional information
+regarding copyright ownership. The ASF licenses this file
+to you under the Apache License, Version 2.0 (the
+"License"); you may not use this file except in compliance
+with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing,
+software distributed under the License is distributed on an
+"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+KIND, either express or implied. See the License for the
+specific language governing permissions and limitations
+under the License.
+-->
+<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/maven-v4_0_0.xsd">
+
+ <modelVersion>4.0.0</modelVersion>
+
+ <parent>
+ <groupId>org.apache.inlong</groupId>
+ <artifactId>format-row</artifactId>
+ <version>1.11.0-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>sort-format-inlongmsg-tlogkv</artifactId>
+
+ <packaging>jar</packaging>
+ <name>Apache InLong - Sort Format-InLongMsg-TLogKV</name>
+
+ <properties>
+
<inlong.root.dir>${project.parent.parent.parent.parent.basedir}</inlong.root.dir>
+ </properties>
+
+ <dependencies>
+
+ <!-- core dependencies -->
+
+ <dependency>
+ <groupId>org.apache.inlong</groupId>
+ <artifactId>sort-format-common</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.inlong</groupId>
+ <artifactId>sort-format-base</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.inlong</groupId>
+ <artifactId>sort-format-inlongmsg-base</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.xerial.snappy</groupId>
+ <artifactId>snappy-java</artifactId>
+ <version>${snappy.version}</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.flink</groupId>
+ <artifactId>flink-shaded-jackson</artifactId>
+ <version>${flink.jackson.version}</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.flink</groupId>
+ <artifactId>flink-core</artifactId>
+ <version>${flink.version}</version>
+ <scope>provided</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.flink</groupId>
+ <artifactId>flink-table-common</artifactId>
+ <version>${flink.version}</version>
+ <scope>provided</scope>
+ </dependency>
+
+ <!-- test dependencies -->
+
+ <dependency>
+ <groupId>org.apache.flink</groupId>
+ <artifactId>flink-table-common</artifactId>
+ <version>${flink.version}</version>
+ <type>test-jar</type>
+ <scope>test</scope>
+ </dependency>
+
+ </dependencies>
+
+ <profiles>
+ <!-- Create SQL Client uber jars by default -->
+ <profile>
+ <id>sql-jars</id>
+ <activation>
+ <property>
+ <name>!skipSqlJars</name>
+ </property>
+ </activation>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-jar-plugin</artifactId>
+ <executions>
+ <execution>
+ <goals>
+ <goal>jar</goal>
+ </goals>
+ <phase>package</phase>
+ <configuration>
+ <classifier>sql-jar</classifier>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+ </profile>
+ </profiles>
+</project>
diff --git
a/inlong-sort/sort-formats/format-row/format-inlongmsg-tlogkv/src/main/java/org/apache/inlong/sort/formats/inlongmsgtlogkv/InLongMsgTlogKv.java
b/inlong-sort/sort-formats/format-row/format-inlongmsg-tlogkv/src/main/java/org/apache/inlong/sort/formats/inlongmsgtlogkv/InLongMsgTlogKv.java
new file mode 100644
index 0000000000..eb7ec66d35
--- /dev/null
+++
b/inlong-sort/sort-formats/format-row/format-inlongmsg-tlogkv/src/main/java/org/apache/inlong/sort/formats/inlongmsgtlogkv/InLongMsgTlogKv.java
@@ -0,0 +1,95 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.inlong.sort.formats.inlongmsgtlogkv;
+
+import org.apache.inlong.sort.formats.base.TextFormatDescriptor;
+import org.apache.inlong.sort.formats.inlongmsg.InLongMsgUtils;
+
+import static org.apache.flink.util.Preconditions.checkNotNull;
+import static
org.apache.inlong.sort.formats.base.TableFormatConstants.FORMAT_DELIMITER;
+import static
org.apache.inlong.sort.formats.base.TableFormatConstants.FORMAT_ENTRY_DELIMITER;
+import static
org.apache.inlong.sort.formats.base.TableFormatConstants.FORMAT_KV_DELIMITER;
+
+/**
+ * Format descriptor for InLongMsgTlogKVs.
+ */
+public class InLongMsgTlogKv extends TextFormatDescriptor<InLongMsgTlogKv> {
+
+ public static final String FORMAT_TYPE_VALUE = "inlong-msg-tlogkv";
+
+ public InLongMsgTlogKv() {
+ super(FORMAT_TYPE_VALUE, 1);
+ }
+
+ /**
+ * Sets the delimiter character (',' by default).
+ *
+ * @param delimiter the field delimiter character.
+ * @return The instance which has delimiter set.
+ */
+ public InLongMsgTlogKv delimiter(char delimiter) {
+ internalProperties.putCharacter(FORMAT_DELIMITER, delimiter);
+ return this;
+ }
+
+ /**
+ * Sets the entry delimiter character ('&' by default).
+ *
+ * @param delimiter the entry delimiter character.
+ * @return The instance which has delimiter set.
+ */
+ public InLongMsgTlogKv entryDelimiter(char delimiter) {
+ internalProperties.putCharacter(FORMAT_ENTRY_DELIMITER, delimiter);
+ return this;
+ }
+
+ /**
+ * Sets the kv delimiter character ('=' by default).
+ *
+ * @param delimiter the kv delimiter character.
+ * @return The instance which has delimiter set.
+ */
+ public InLongMsgTlogKv kvDelimiter(char delimiter) {
+ internalProperties.putCharacter(FORMAT_KV_DELIMITER, delimiter);
+ return this;
+ }
+
+ /**
+ * Sets the name of the time field.
+ *
+ * @param timeFieldName The name of the time field.
+ * @return The instance which has time field name set.
+ */
+ public InLongMsgTlogKv timeFieldName(String timeFieldName) {
+ checkNotNull(timeFieldName);
+ internalProperties.putString(InLongMsgUtils.FORMAT_TIME_FIELD_NAME,
timeFieldName);
+ return this;
+ }
+
+ /**
+ * Sets the name of the attributes field.
+ *
+ * @param attributesFieldName The name of the attributes field.
+ * @return The instance which has attributes field name set.
+ */
+ public InLongMsgTlogKv attributesFieldName(String attributesFieldName) {
+ checkNotNull(attributesFieldName);
+
internalProperties.putString(InLongMsgUtils.FORMAT_ATTRIBUTES_FIELD_NAME,
attributesFieldName);
+ return this;
+ }
+}
diff --git
a/inlong-sort/sort-formats/format-row/format-inlongmsg-tlogkv/src/main/java/org/apache/inlong/sort/formats/inlongmsgtlogkv/InLongMsgTlogKvFormatDeserializer.java
b/inlong-sort/sort-formats/format-row/format-inlongmsg-tlogkv/src/main/java/org/apache/inlong/sort/formats/inlongmsgtlogkv/InLongMsgTlogKvFormatDeserializer.java
new file mode 100644
index 0000000000..19a82503fa
--- /dev/null
+++
b/inlong-sort/sort-formats/format-row/format-inlongmsg-tlogkv/src/main/java/org/apache/inlong/sort/formats/inlongmsgtlogkv/InLongMsgTlogKvFormatDeserializer.java
@@ -0,0 +1,320 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.inlong.sort.formats.inlongmsgtlogkv;
+
+import org.apache.inlong.sort.formats.base.TextFormatBuilder;
+import org.apache.inlong.sort.formats.common.RowFormatInfo;
+import
org.apache.inlong.sort.formats.inlongmsg.AbstractInLongMsgFormatDeserializer;
+import org.apache.inlong.sort.formats.inlongmsg.FailureHandler;
+import org.apache.inlong.sort.formats.inlongmsg.InLongMsgBody;
+import org.apache.inlong.sort.formats.inlongmsg.InLongMsgHead;
+import org.apache.inlong.sort.formats.inlongmsg.InLongMsgUtils;
+
+import org.apache.flink.api.common.typeinfo.TypeInformation;
+import org.apache.flink.table.descriptors.DescriptorProperties;
+import org.apache.flink.types.Row;
+
+import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
+
+import java.util.Collections;
+import java.util.List;
+import java.util.Objects;
+
+import static
org.apache.inlong.sort.formats.base.TableFormatConstants.DEFAULT_DELIMITER;
+import static
org.apache.inlong.sort.formats.base.TableFormatConstants.DEFAULT_ENTRY_DELIMITER;
+import static
org.apache.inlong.sort.formats.base.TableFormatConstants.DEFAULT_KV_DELIMITER;
+import static
org.apache.inlong.sort.formats.base.TableFormatConstants.FORMAT_DELIMITER;
+import static
org.apache.inlong.sort.formats.base.TableFormatConstants.FORMAT_ENTRY_DELIMITER;
+import static
org.apache.inlong.sort.formats.base.TableFormatConstants.FORMAT_KV_DELIMITER;
+import static
org.apache.inlong.sort.formats.inlongmsg.InLongMsgUtils.DEFAULT_ATTRIBUTES_FIELD_NAME;
+import static
org.apache.inlong.sort.formats.inlongmsg.InLongMsgUtils.DEFAULT_TIME_FIELD_NAME;
+import static
org.apache.inlong.sort.formats.inlongmsg.InLongMsgUtils.FORMAT_ATTRIBUTES_FIELD_NAME;
+import static
org.apache.inlong.sort.formats.inlongmsg.InLongMsgUtils.FORMAT_TIME_FIELD_NAME;
+import static
org.apache.inlong.sort.formats.inlongmsgtlogkv.InLongMsgTlogKvUtils.DEFAULT_INLONGMSG_TLOGKV_CHARSET;
+
+/**
+ * The deserializer for the records in InLongMsgTlogKV format.
+ */
+public final class InLongMsgTlogKvFormatDeserializer extends
AbstractInLongMsgFormatDeserializer {
+
+ private static final long serialVersionUID = 1L;
+
+ /**
+ * Format information describing the result type.
+ */
+ @Nonnull
+ private final RowFormatInfo rowFormatInfo;
+
+ /**
+ * The name of the time field.
+ */
+ @Nullable
+ private final String timeFieldName;
+
+ /**
+ * The name of the attributes field.
+ */
+ @Nullable
+ private final String attributesFieldName;
+
+ /**
+ * The charset of the text.
+ */
+ @Nonnull
+ private final String charset;
+
+ /**
+ * The delimiter between fields.
+ */
+ @Nonnull
+ private final Character delimiter;
+
+ /**
+ * The delimiter between entries.
+ */
+ @Nonnull
+ private final Character entryDelimiter;
+
+ /**
+ * The delimiter between key and value.
+ */
+ @Nonnull
+ private final Character kvDelimiter;
+
+ /**
+ * Escape character. Null if escaping is disabled.
+ */
+ @Nullable
+ private final Character escapeChar;
+
+ /**
+ * Quote character. Null if quoting is disabled.
+ */
+ @Nullable
+ private final Character quoteChar;
+
+ /**
+ * The literal represented null values, default "".
+ */
+ @Nullable
+ private final String nullLiteral;
+
+ public InLongMsgTlogKvFormatDeserializer(
+ @Nonnull RowFormatInfo rowFormatInfo,
+ @Nullable String timeFieldName,
+ @Nullable String attributesFieldName,
+ @Nonnull String charset,
+ @Nonnull Character delimiter,
+ @Nonnull Character entryDelimiter,
+ @Nonnull Character kvDelimiter,
+ @Nullable Character escapeChar,
+ @Nullable Character quoteChar,
+ @Nullable String nullLiteral,
+ @Nonnull Boolean ignoreErrors) {
+ this(
+ rowFormatInfo,
+ timeFieldName,
+ attributesFieldName,
+ charset,
+ delimiter,
+ entryDelimiter,
+ kvDelimiter,
+ escapeChar,
+ quoteChar,
+ nullLiteral,
+ InLongMsgUtils.getDefaultExceptionHandler(ignoreErrors));
+ }
+
+ public InLongMsgTlogKvFormatDeserializer(
+ @Nonnull RowFormatInfo rowFormatInfo,
+ @Nullable String timeFieldName,
+ @Nullable String attributesFieldName,
+ @Nonnull String charset,
+ @Nonnull Character delimiter,
+ @Nonnull Character entryDelimiter,
+ @Nonnull Character kvDelimiter,
+ @Nullable Character escapeChar,
+ @Nullable Character quoteChar,
+ @Nullable String nullLiteral,
+ @Nonnull FailureHandler failureHandler) {
+ super(failureHandler);
+
+ this.rowFormatInfo = rowFormatInfo;
+ this.timeFieldName = timeFieldName;
+ this.attributesFieldName = attributesFieldName;
+ this.charset = charset;
+ this.delimiter = delimiter;
+ this.entryDelimiter = entryDelimiter;
+ this.kvDelimiter = kvDelimiter;
+ this.escapeChar = escapeChar;
+ this.quoteChar = quoteChar;
+ this.nullLiteral = nullLiteral;
+ }
+
+ @Override
+ public TypeInformation<Row> getProducedType() {
+ return
InLongMsgUtils.decorateRowTypeWithNeededHeadFields(timeFieldName,
attributesFieldName, rowFormatInfo);
+ }
+
+ @Override
+ protected InLongMsgHead parseHead(String attr) throws Exception {
+ return InLongMsgTlogKvUtils.parseHead(attr);
+ }
+
+ @Override
+ protected List<InLongMsgBody> parseBodyList(byte[] bytes) throws Exception
{
+ return Collections.singletonList(
+ InLongMsgTlogKvUtils.parseBody(
+ bytes,
+ charset,
+ delimiter,
+ entryDelimiter,
+ kvDelimiter,
+ escapeChar,
+ quoteChar));
+ }
+
+ @Override
+ protected List<Row> convertRows(InLongMsgHead head, InLongMsgBody body)
throws Exception {
+ Row dataRow =
+ InLongMsgTlogKvUtils.deserializeRow(
+ rowFormatInfo,
+ nullLiteral,
+ head.getPredefinedFields(),
+ body.getEntries());
+
+ Row row = InLongMsgUtils.decorateRowWithNeededHeadFields(
+ timeFieldName,
+ attributesFieldName,
+ head.getTime(),
+ head.getAttributes(),
+ dataRow);
+
+ return Collections.singletonList(row);
+ }
+
+ /**
+ * The builder for {@link InLongMsgTlogKvFormatDeserializer}.
+ */
+ public static class Builder extends TextFormatBuilder<Builder> {
+
+ private String timeFieldName = DEFAULT_TIME_FIELD_NAME;
+ private String attributesFieldName = DEFAULT_ATTRIBUTES_FIELD_NAME;
+ private Character delimiter = DEFAULT_DELIMITER;
+ private Character entryDelimiter = DEFAULT_ENTRY_DELIMITER;
+ private Character kvDelimiter = DEFAULT_KV_DELIMITER;
+
+ public Builder(RowFormatInfo rowFormatInfo) {
+ super(rowFormatInfo);
+
+ this.charset = DEFAULT_INLONGMSG_TLOGKV_CHARSET;
+ }
+
+ public Builder setTimeFieldName(String timeFieldName) {
+ this.timeFieldName = timeFieldName;
+ return this;
+ }
+
+ public Builder setAttributesFieldName(String attributesFieldName) {
+ this.attributesFieldName = attributesFieldName;
+ return this;
+ }
+
+ public Builder setDelimiter(Character delimiter) {
+ this.delimiter = delimiter;
+ return this;
+ }
+
+ public Builder setEntryDelimiter(Character entryDelimiter) {
+ this.entryDelimiter = entryDelimiter;
+ return this;
+ }
+
+ public Builder setKvDelimiter(Character kvDelimiter) {
+ this.kvDelimiter = kvDelimiter;
+ return this;
+ }
+
+ public Builder configure(DescriptorProperties descriptorProperties) {
+ super.configure(descriptorProperties);
+
+ descriptorProperties.getOptionalString(FORMAT_TIME_FIELD_NAME)
+ .ifPresent(this::setTimeFieldName);
+
descriptorProperties.getOptionalString(FORMAT_ATTRIBUTES_FIELD_NAME)
+ .ifPresent(this::setAttributesFieldName);
+ descriptorProperties.getOptionalCharacter(FORMAT_DELIMITER)
+ .ifPresent(this::setDelimiter);
+ descriptorProperties.getOptionalCharacter(FORMAT_ENTRY_DELIMITER)
+ .ifPresent(this::setEntryDelimiter);
+ descriptorProperties.getOptionalCharacter(FORMAT_KV_DELIMITER)
+ .ifPresent(this::setKvDelimiter);
+
+ return this;
+ }
+
+ public InLongMsgTlogKvFormatDeserializer build() {
+ return new InLongMsgTlogKvFormatDeserializer(
+ rowFormatInfo,
+ timeFieldName,
+ attributesFieldName,
+ charset,
+ delimiter,
+ entryDelimiter,
+ kvDelimiter,
+ escapeChar,
+ quoteChar,
+ nullLiteral,
+ ignoreErrors);
+ }
+ }
+
+ @Override
+ public boolean equals(Object object) {
+ if (this == object) {
+ return true;
+ }
+
+ if (object == null || getClass() != object.getClass()) {
+ return false;
+ }
+
+ if (!super.equals(object)) {
+ return false;
+ }
+
+ InLongMsgTlogKvFormatDeserializer that =
(InLongMsgTlogKvFormatDeserializer) object;
+ return rowFormatInfo.equals(that.rowFormatInfo) &&
+ Objects.equals(timeFieldName, that.timeFieldName) &&
+ Objects.equals(attributesFieldName, that.attributesFieldName)
&&
+ charset.equals(that.charset) &&
+ delimiter.equals(that.delimiter) &&
+ entryDelimiter.equals(that.entryDelimiter) &&
+ kvDelimiter.equals(that.kvDelimiter) &&
+ Objects.equals(escapeChar, that.escapeChar) &&
+ Objects.equals(quoteChar, that.quoteChar) &&
+ Objects.equals(nullLiteral, that.nullLiteral);
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(super.hashCode(), rowFormatInfo, timeFieldName,
+ attributesFieldName, charset, delimiter, entryDelimiter,
kvDelimiter,
+ escapeChar, quoteChar, nullLiteral);
+ }
+}
diff --git
a/inlong-sort/sort-formats/format-row/format-inlongmsg-tlogkv/src/main/java/org/apache/inlong/sort/formats/inlongmsgtlogkv/InLongMsgTlogKvFormatFactory.java
b/inlong-sort/sort-formats/format-row/format-inlongmsg-tlogkv/src/main/java/org/apache/inlong/sort/formats/inlongmsgtlogkv/InLongMsgTlogKvFormatFactory.java
new file mode 100644
index 0000000000..0dbf0723ee
--- /dev/null
+++
b/inlong-sort/sort-formats/format-row/format-inlongmsg-tlogkv/src/main/java/org/apache/inlong/sort/formats/inlongmsgtlogkv/InLongMsgTlogKvFormatFactory.java
@@ -0,0 +1,163 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.inlong.sort.formats.inlongmsgtlogkv;
+
+import org.apache.inlong.sort.formats.base.TableFormatDeserializer;
+import
org.apache.inlong.sort.formats.base.TableFormatDeserializer.TableFormatContext;
+import org.apache.inlong.sort.formats.base.TableFormatDeserializerFactory;
+import org.apache.inlong.sort.formats.common.RowFormatInfo;
+import
org.apache.inlong.sort.formats.inlongmsg.AbstractInLongMsgMixedFormatConverter;
+import
org.apache.inlong.sort.formats.inlongmsg.AbstractInLongMsgMixedFormatDeserializer;
+import
org.apache.inlong.sort.formats.inlongmsg.InLongMsgMixedFormatConverterValidator;
+import
org.apache.inlong.sort.formats.inlongmsg.InLongMsgMixedFormatDeserializerValidator;
+import org.apache.inlong.sort.formats.inlongmsg.InLongMsgMixedFormatFactory;
+
+import org.apache.flink.table.descriptors.DescriptorProperties;
+import org.apache.flink.table.factories.TableFormatFactoryBase;
+import org.apache.flink.types.Row;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+import static
org.apache.inlong.sort.formats.base.TableFormatConstants.FORMAT_CHARSET;
+import static
org.apache.inlong.sort.formats.base.TableFormatConstants.FORMAT_DELIMITER;
+import static
org.apache.inlong.sort.formats.base.TableFormatConstants.FORMAT_ENTRY_DELIMITER;
+import static
org.apache.inlong.sort.formats.base.TableFormatConstants.FORMAT_ESCAPE_CHARACTER;
+import static
org.apache.inlong.sort.formats.base.TableFormatConstants.FORMAT_IGNORE_ERRORS;
+import static
org.apache.inlong.sort.formats.base.TableFormatConstants.FORMAT_KV_DELIMITER;
+import static
org.apache.inlong.sort.formats.base.TableFormatConstants.FORMAT_NULL_LITERAL;
+import static
org.apache.inlong.sort.formats.base.TableFormatConstants.FORMAT_QUOTE_CHARACTER;
+import static
org.apache.inlong.sort.formats.base.TableFormatConstants.FORMAT_SCHEMA;
+import static
org.apache.inlong.sort.formats.inlongmsg.InLongMsgUtils.FORMAT_ATTRIBUTES_FIELD_NAME;
+import static
org.apache.inlong.sort.formats.inlongmsg.InLongMsgUtils.FORMAT_TIME_FIELD_NAME;
+import static
org.apache.inlong.sort.formats.inlongmsg.InLongMsgUtils.getDataRowFormatInfo;
+import static
org.apache.inlong.sort.formats.inlongmsgtlogkv.InLongMsgTlogKv.FORMAT_TYPE_VALUE;
+
+/**
+ * Table format factory for providing configured instances of
InLongMsgTlogKv-to-row
+ * serializer and deserializer.
+ */
+public final class InLongMsgTlogKvFormatFactory
+ extends
+ TableFormatFactoryBase<Row>
+ implements
+ TableFormatDeserializerFactory,
+ InLongMsgMixedFormatFactory {
+
+ public InLongMsgTlogKvFormatFactory() {
+ super(FORMAT_TYPE_VALUE, 1, false);
+ }
+
+ @Override
+ public List<String> supportedFormatProperties() {
+ final List<String> properties = new ArrayList<>();
+ properties.add(FORMAT_CHARSET);
+ properties.add(FORMAT_DELIMITER);
+ properties.add(FORMAT_ENTRY_DELIMITER);
+ properties.add(FORMAT_KV_DELIMITER);
+ properties.add(FORMAT_ESCAPE_CHARACTER);
+ properties.add(FORMAT_QUOTE_CHARACTER);
+ properties.add(FORMAT_NULL_LITERAL);
+ properties.add(FORMAT_IGNORE_ERRORS);
+ properties.add(FORMAT_SCHEMA);
+ properties.add(FORMAT_TIME_FIELD_NAME);
+ properties.add(FORMAT_ATTRIBUTES_FIELD_NAME);
+ return properties;
+ }
+
+ @Override
+ public InLongMsgTlogKvFormatDeserializer createFormatDeserializer(
+ Map<String, String> properties) {
+ final DescriptorProperties descriptorProperties =
+ new DescriptorProperties(true);
+ descriptorProperties.putProperties(properties);
+
+ InLongMsgTlogKvValidator validator = new InLongMsgTlogKvValidator();
+ validator.validate(descriptorProperties);
+
+ RowFormatInfo rowFormatInfo =
getDataRowFormatInfo(descriptorProperties);
+
+ InLongMsgTlogKvFormatDeserializer.Builder builder =
+ new InLongMsgTlogKvFormatDeserializer.Builder(rowFormatInfo);
+ builder.configure(descriptorProperties);
+
+ return builder.build();
+ }
+
+ @Override
+ public TableFormatDeserializer createFormatDeserializer(TableFormatContext
context) {
+ TableFormatDeserializer deserializer =
+ createFormatDeserializer(context.getFormatProperties());
+ deserializer.init(context);
+ return deserializer;
+ }
+
+ @Override
+ public InLongMsgTlogKvMixedFormatDeserializer
createMixedFormatDeserializer(
+ Map<String, String> properties) {
+ final DescriptorProperties descriptorProperties =
+ new DescriptorProperties(true);
+ descriptorProperties.putProperties(properties);
+
+ InLongMsgMixedFormatDeserializerValidator validator =
+ new InLongMsgMixedFormatDeserializerValidator();
+ validator.validate(descriptorProperties);
+
+ InLongMsgTlogKvMixedFormatDeserializer.Builder builder =
+ new InLongMsgTlogKvMixedFormatDeserializer.Builder();
+ builder.configure(descriptorProperties);
+
+ return builder.build();
+ }
+
+ @Override
+ public AbstractInLongMsgMixedFormatConverter createMixedFormatConverter(
+ AbstractInLongMsgMixedFormatConverter.TableFormatContext context) {
+ return createMixedFormatConverter(context.getFormatProperties());
+ }
+
+ @Override
+ public AbstractInLongMsgMixedFormatDeserializer
createMixedFormatDeserializer(
+ TableFormatContext context) {
+ InLongMsgTlogKvMixedFormatDeserializer deserializer =
+ createMixedFormatDeserializer(context.getFormatProperties());
+ deserializer.init(context);
+ return deserializer;
+ }
+
+ @Override
+ public InLongMsgTlogKvMixedFormatConverter createMixedFormatConverter(
+ Map<String, String> properties) {
+ final DescriptorProperties descriptorProperties =
+ new DescriptorProperties(true);
+ descriptorProperties.putProperties(properties);
+
+ InLongMsgMixedFormatConverterValidator validator =
+ new InLongMsgMixedFormatConverterValidator();
+ validator.validate(descriptorProperties);
+
+ RowFormatInfo rowFormatInfo =
getDataRowFormatInfo(descriptorProperties);
+
+ InLongMsgTlogKvMixedFormatConverter.Builder builder =
+ new InLongMsgTlogKvMixedFormatConverter.Builder(rowFormatInfo);
+ builder.configure(descriptorProperties);
+
+ return builder.build();
+ }
+}
diff --git
a/inlong-sort/sort-formats/format-row/format-inlongmsg-tlogkv/src/main/java/org/apache/inlong/sort/formats/inlongmsgtlogkv/InLongMsgTlogKvMixedFormatConverter.java
b/inlong-sort/sort-formats/format-row/format-inlongmsg-tlogkv/src/main/java/org/apache/inlong/sort/formats/inlongmsgtlogkv/InLongMsgTlogKvMixedFormatConverter.java
new file mode 100644
index 0000000000..2892dfc755
--- /dev/null
+++
b/inlong-sort/sort-formats/format-row/format-inlongmsg-tlogkv/src/main/java/org/apache/inlong/sort/formats/inlongmsgtlogkv/InLongMsgTlogKvMixedFormatConverter.java
@@ -0,0 +1,163 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.inlong.sort.formats.inlongmsgtlogkv;
+
+import org.apache.inlong.sort.formats.common.RowFormatInfo;
+import
org.apache.inlong.sort.formats.inlongmsg.AbstractInLongMsgMixedFormatConverter;
+import
org.apache.inlong.sort.formats.inlongmsg.InLongMsgMixedFormatConverterBuilder;
+import org.apache.inlong.sort.formats.inlongmsg.InLongMsgUtils;
+
+import org.apache.flink.api.common.typeinfo.TypeInformation;
+import org.apache.flink.types.Row;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
+
+import java.sql.Timestamp;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+import java.util.Objects;
+
+/**
+ * Converter used to deserialize a mixed row in InLongMsg-TlogKV format.
+ */
+public class InLongMsgTlogKvMixedFormatConverter extends
AbstractInLongMsgMixedFormatConverter {
+
+ private static final long serialVersionUID = 1L;
+
+ private static final Logger LOG = LoggerFactory.getLogger(
+ InLongMsgTlogKvMixedFormatConverter.class);
+
+ /**
+ * The schema of the rows.
+ */
+ @Nonnull
+ private final RowFormatInfo rowFormatInfo;
+
+ /**
+ * The name of the time field.
+ */
+ @Nullable
+ private final String timeFieldName;
+
+ /**
+ * The name of the attributes field.
+ */
+ @Nullable
+ private final String attributesFieldName;
+
+ /**
+ * The literal representing null values.
+ */
+ @Nullable
+ private final String nullLiteral;
+
+ public InLongMsgTlogKvMixedFormatConverter(
+ @Nonnull RowFormatInfo rowFormatInfo,
+ @Nullable String timeFieldName,
+ @Nullable String attributesFieldName,
+ @Nullable String nullLiteral,
+ boolean ignoreErrors) {
+ super(ignoreErrors);
+
+ this.rowFormatInfo = rowFormatInfo;
+ this.timeFieldName = timeFieldName;
+ this.attributesFieldName = attributesFieldName;
+ this.nullLiteral = nullLiteral;
+ }
+
+ @Override
+ public TypeInformation<Row> getProducedType() {
+ return
InLongMsgUtils.decorateRowTypeWithNeededHeadFields(timeFieldName,
attributesFieldName, rowFormatInfo);
+ }
+
+ @Override
+ public List<Row> convertRows(
+ Map<String, String> attributes,
+ byte[] data,
+ String tid,
+ Timestamp time,
+ List<String> predefinedFields,
+ List<String> fields,
+ Map<String, String> entries) throws Exception {
+ Row dataRow =
+ InLongMsgTlogKvUtils.deserializeRow(
+ rowFormatInfo,
+ nullLiteral,
+ predefinedFields,
+ entries);
+
+ Row row = InLongMsgUtils.decorateRowWithNeededHeadFields(
+ timeFieldName,
+ attributesFieldName,
+ time,
+ attributes,
+ dataRow);
+
+ return Collections.singletonList(row);
+ }
+
+ /**
+ * The builder for {@link InLongMsgTlogKvMixedFormatConverter}.
+ */
+ public static class Builder extends InLongMsgMixedFormatConverterBuilder {
+
+ public Builder(RowFormatInfo rowFormatInfo) {
+ super(rowFormatInfo);
+ }
+
+ public InLongMsgTlogKvMixedFormatConverter build() {
+ return new InLongMsgTlogKvMixedFormatConverter(
+ rowFormatInfo,
+ timeFieldName,
+ attributesFieldName,
+ nullLiteral,
+ ignoreErrors);
+ }
+ }
+
+ @Override
+ public boolean equals(Object object) {
+ if (this == object) {
+ return true;
+ }
+
+ if (object == null || getClass() != object.getClass()) {
+ return false;
+ }
+
+ if (!super.equals(object)) {
+ return false;
+ }
+
+ InLongMsgTlogKvMixedFormatConverter that =
(InLongMsgTlogKvMixedFormatConverter) object;
+ return rowFormatInfo.equals(that.rowFormatInfo) &&
+ Objects.equals(timeFieldName, that.timeFieldName) &&
+ Objects.equals(attributesFieldName, that.attributesFieldName)
&&
+ Objects.equals(nullLiteral, that.nullLiteral);
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(super.hashCode(), rowFormatInfo, timeFieldName,
attributesFieldName,
+ nullLiteral);
+ }
+}
diff --git
a/inlong-sort/sort-formats/format-row/format-inlongmsg-tlogkv/src/main/java/org/apache/inlong/sort/formats/inlongmsgtlogkv/InLongMsgTlogKvMixedFormatDeserializer.java
b/inlong-sort/sort-formats/format-row/format-inlongmsg-tlogkv/src/main/java/org/apache/inlong/sort/formats/inlongmsgtlogkv/InLongMsgTlogKvMixedFormatDeserializer.java
new file mode 100644
index 0000000000..bccba0276f
--- /dev/null
+++
b/inlong-sort/sort-formats/format-row/format-inlongmsg-tlogkv/src/main/java/org/apache/inlong/sort/formats/inlongmsgtlogkv/InLongMsgTlogKvMixedFormatDeserializer.java
@@ -0,0 +1,233 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.inlong.sort.formats.inlongmsgtlogkv;
+
+import
org.apache.inlong.sort.formats.inlongmsg.AbstractInLongMsgMixedFormatDeserializer;
+import org.apache.inlong.sort.formats.inlongmsg.FailureHandler;
+import org.apache.inlong.sort.formats.inlongmsg.InLongMsgBody;
+import org.apache.inlong.sort.formats.inlongmsg.InLongMsgHead;
+import
org.apache.inlong.sort.formats.inlongmsg.InLongMsgTextMixedFormatDeserializerBuilder;
+import org.apache.inlong.sort.formats.inlongmsg.InLongMsgUtils;
+
+import org.apache.flink.api.common.typeinfo.TypeInformation;
+import org.apache.flink.table.descriptors.DescriptorProperties;
+import org.apache.flink.types.Row;
+
+import javax.annotation.Nonnull;
+import javax.annotation.Nullable;
+
+import java.util.Collections;
+import java.util.List;
+import java.util.Objects;
+
+import static
org.apache.inlong.sort.formats.base.TableFormatConstants.DEFAULT_DELIMITER;
+import static
org.apache.inlong.sort.formats.base.TableFormatConstants.DEFAULT_ENTRY_DELIMITER;
+import static
org.apache.inlong.sort.formats.base.TableFormatConstants.DEFAULT_KV_DELIMITER;
+import static
org.apache.inlong.sort.formats.base.TableFormatConstants.FORMAT_DELIMITER;
+import static
org.apache.inlong.sort.formats.base.TableFormatConstants.FORMAT_ENTRY_DELIMITER;
+import static
org.apache.inlong.sort.formats.base.TableFormatConstants.FORMAT_KV_DELIMITER;
+import static
org.apache.inlong.sort.formats.inlongmsgtlogkv.InLongMsgTlogKvUtils.DEFAULT_INLONGMSG_TLOGKV_CHARSET;
+
+/**
+ * The deserializer for the records in InLongMsgTlogKV format.
+ */
+public final class InLongMsgTlogKvMixedFormatDeserializer
+ extends
+ AbstractInLongMsgMixedFormatDeserializer {
+
+ private static final long serialVersionUID = 1L;
+
+ /**
+ * The charset of the text.
+ */
+ @Nonnull
+ private final String charset;
+
+ /**
+ * The delimiter between fields.
+ */
+ @Nonnull
+ private final Character delimiter;
+
+ /**
+ * The delimiter between entries.
+ */
+ @Nonnull
+ private final Character entryDelimiter;
+
+ /**
+ * The delimiter between key and value.
+ */
+ @Nonnull
+ private final Character kvDelimiter;
+
+ /**
+ * Escape character. Null if escaping is disabled.
+ */
+ @Nullable
+ private final Character escapeChar;
+
+ /**
+ * Quote character. Null if quoting is disabled.
+ */
+ @Nullable
+ private final Character quoteChar;
+
+ public InLongMsgTlogKvMixedFormatDeserializer(
+ @Nonnull String charset,
+ @Nonnull Character delimiter,
+ @Nonnull Character entryDelimiter,
+ @Nonnull Character kvDelimiter,
+ @Nullable Character escapeChar,
+ @Nullable Character quoteChar,
+ @Nonnull Boolean ignoreErrors) {
+ this(charset, delimiter, entryDelimiter, kvDelimiter, escapeChar,
quoteChar,
+ InLongMsgUtils.getDefaultExceptionHandler(ignoreErrors));
+ }
+
+ public InLongMsgTlogKvMixedFormatDeserializer(
+ @Nonnull String charset,
+ @Nonnull Character delimiter,
+ @Nonnull Character entryDelimiter,
+ @Nonnull Character kvDelimiter,
+ @Nullable Character escapeChar,
+ @Nullable Character quoteChar,
+ @Nonnull FailureHandler failureHandler) {
+ super(failureHandler);
+
+ this.charset = charset;
+ this.delimiter = delimiter;
+ this.entryDelimiter = entryDelimiter;
+ this.kvDelimiter = kvDelimiter;
+ this.escapeChar = escapeChar;
+ this.quoteChar = quoteChar;
+ }
+
+ @Override
+ public TypeInformation<Row> getProducedType() {
+ return InLongMsgUtils.MIXED_ROW_TYPE;
+ }
+
+ @Override
+ protected InLongMsgHead parseHead(String attr) throws Exception {
+ return InLongMsgTlogKvUtils.parseHead(attr);
+ }
+
+ @Override
+ protected List<InLongMsgBody> parseBodyList(byte[] bytes) throws Exception
{
+ return Collections.singletonList(
+ InLongMsgTlogKvUtils.parseBody(
+ bytes,
+ charset,
+ delimiter,
+ entryDelimiter,
+ kvDelimiter,
+ escapeChar,
+ quoteChar));
+ }
+
+ @Override
+ protected List<Row> convertRows(InLongMsgHead head, InLongMsgBody body)
throws Exception {
+ Row row = InLongMsgUtils.buildMixedRow(head, body, body.getTid());
+ return Collections.singletonList(row);
+ }
+
+ /**
+ * The builder for {@link InLongMsgTlogKvMixedFormatDeserializer}.
+ */
+ public static class Builder extends
InLongMsgTextMixedFormatDeserializerBuilder<Builder> {
+
+ private Character delimiter = DEFAULT_DELIMITER;
+ private Character entryDelimiter = DEFAULT_ENTRY_DELIMITER;
+ private Character kvDelimiter = DEFAULT_KV_DELIMITER;
+
+ public Builder() {
+ super();
+ this.charset = DEFAULT_INLONGMSG_TLOGKV_CHARSET;
+ }
+
+ public Builder setDelimiter(Character delimiter) {
+ this.delimiter = delimiter;
+ return this;
+ }
+
+ public Builder setEntryDelimiter(Character entryDelimiter) {
+ this.entryDelimiter = entryDelimiter;
+ return this;
+ }
+
+ public Builder setKvDelimiter(Character kvDelimiter) {
+ this.kvDelimiter = kvDelimiter;
+ return this;
+ }
+
+ @Override
+ public Builder configure(DescriptorProperties descriptorProperties) {
+ super.configure(descriptorProperties);
+
+ descriptorProperties.getOptionalCharacter(FORMAT_DELIMITER)
+ .ifPresent(this::setDelimiter);
+ descriptorProperties.getOptionalCharacter(FORMAT_ENTRY_DELIMITER)
+ .ifPresent(this::setEntryDelimiter);
+ descriptorProperties.getOptionalCharacter(FORMAT_KV_DELIMITER)
+ .ifPresent(this::setKvDelimiter);
+
+ return this;
+ }
+
+ public InLongMsgTlogKvMixedFormatDeserializer build() {
+ return new InLongMsgTlogKvMixedFormatDeserializer(
+ charset,
+ delimiter,
+ entryDelimiter,
+ kvDelimiter,
+ escapeChar,
+ quoteChar,
+ ignoreErrors);
+ }
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) {
+ return true;
+ }
+
+ if (o == null || getClass() != o.getClass()) {
+ return false;
+ }
+
+ if (!super.equals(o)) {
+ return false;
+ }
+
+ InLongMsgTlogKvMixedFormatDeserializer that =
(InLongMsgTlogKvMixedFormatDeserializer) o;
+ return delimiter.equals(that.delimiter) &&
+ entryDelimiter.equals(that.entryDelimiter) &&
+ kvDelimiter.equals(that.kvDelimiter) &&
+ charset.equals(that.charset) &&
+ Objects.equals(escapeChar, that.escapeChar) &&
+ Objects.equals(quoteChar, that.quoteChar);
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(super.hashCode(), delimiter, entryDelimiter,
+ kvDelimiter, charset, escapeChar, quoteChar);
+ }
+}
diff --git
a/inlong-sort/sort-formats/format-row/format-inlongmsg-tlogkv/src/main/java/org/apache/inlong/sort/formats/inlongmsgtlogkv/InLongMsgTlogKvUtils.java
b/inlong-sort/sort-formats/format-row/format-inlongmsg-tlogkv/src/main/java/org/apache/inlong/sort/formats/inlongmsgtlogkv/InLongMsgTlogKvUtils.java
new file mode 100644
index 0000000000..a039079304
--- /dev/null
+++
b/inlong-sort/sort-formats/format-row/format-inlongmsg-tlogkv/src/main/java/org/apache/inlong/sort/formats/inlongmsgtlogkv/InLongMsgTlogKvUtils.java
@@ -0,0 +1,157 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.inlong.sort.formats.inlongmsgtlogkv;
+
+import org.apache.inlong.sort.formats.common.FormatInfo;
+import org.apache.inlong.sort.formats.common.RowFormatInfo;
+import org.apache.inlong.sort.formats.inlongmsg.InLongMsgBody;
+import org.apache.inlong.sort.formats.inlongmsg.InLongMsgHead;
+
+import org.apache.flink.types.Row;
+
+import java.nio.charset.Charset;
+import java.sql.Timestamp;
+import java.util.Collections;
+import java.util.List;
+import java.util.Map;
+
+import static
org.apache.inlong.sort.formats.base.TableFormatUtils.deserializeBasicField;
+import static
org.apache.inlong.sort.formats.inlongmsg.InLongMsgUtils.INLONGMSG_ATTR_TIME_DT;
+import static
org.apache.inlong.sort.formats.inlongmsg.InLongMsgUtils.INLONGMSG_ATTR_TIME_T;
+import static
org.apache.inlong.sort.formats.inlongmsg.InLongMsgUtils.getPredefinedFields;
+import static
org.apache.inlong.sort.formats.inlongmsg.InLongMsgUtils.parseAttr;
+import static
org.apache.inlong.sort.formats.inlongmsg.InLongMsgUtils.parseDateTime;
+import static
org.apache.inlong.sort.formats.inlongmsg.InLongMsgUtils.parseEpochTime;
+import static org.apache.inlong.sort.formats.util.StringUtils.splitCsv;
+import static org.apache.inlong.sort.formats.util.StringUtils.splitKv;
+
+/**
+ * Utilities for {@link InLongMsgTlogKv}.
+ */
+public class InLongMsgTlogKvUtils {
+
+ public static final String DEFAULT_INLONGMSG_TLOGKV_CHARSET = "ISO_8859_1";
+
+ public static InLongMsgHead parseHead(String attr) {
+ Map<String, String> attributes = parseAttr(attr);
+
+ Timestamp time;
+ if (attributes.containsKey(INLONGMSG_ATTR_TIME_T)) {
+ String date = attributes.get(INLONGMSG_ATTR_TIME_T).trim();
+ time = parseDateTime(date);
+ } else if (attributes.containsKey(INLONGMSG_ATTR_TIME_DT)) {
+ String epoch = attributes.get(INLONGMSG_ATTR_TIME_DT).trim();
+ time = parseEpochTime(epoch);
+ } else {
+ throw new IllegalArgumentException(
+ "Could not find " + INLONGMSG_ATTR_TIME_T +
+ " or " + INLONGMSG_ATTR_TIME_DT + " in
attributes!");
+ }
+
+ List<String> predefinedFields = getPredefinedFields(attributes);
+
+ return new InLongMsgHead(attributes, null, time, predefinedFields);
+ }
+
+ public static InLongMsgBody parseBody(
+ byte[] bytes,
+ String charset,
+ char delimiter,
+ char entryDelimiter,
+ char kvDelimiter,
+ Character escapeChar,
+ Character quoteChar) {
+ String text;
+ if (bytes[0] == delimiter) {
+ text = new String(bytes, 1, bytes.length - 1,
Charset.forName(charset));
+ } else {
+ text = new String(bytes, Charset.forName(charset));
+ }
+
+ String[] segments = splitCsv(text, delimiter, escapeChar, quoteChar);
+
+ String tid = segments[0];
+
+ Map<String, String> entries;
+ if (segments.length > 1) {
+ entries = splitKv(segments[1], entryDelimiter, kvDelimiter,
escapeChar, quoteChar);
+ } else {
+ entries = Collections.emptyMap();
+ }
+
+ return new InLongMsgBody(bytes, tid, Collections.emptyList(), entries);
+ }
+
+ /**
+ * Deserializes the row from the given entries.
+ *
+ * @param rowFormatInfo The format information of the row.
+ * @param nullLiteral The literal for null values.
+ * @param predefinedFields The predefined fields.
+ * @param entries The entries.
+ * @return The row deserialized from the given entries.
+ */
+ public static Row deserializeRow(
+ RowFormatInfo rowFormatInfo,
+ String nullLiteral,
+ List<String> predefinedFields,
+ Map<String, String> entries) {
+ String[] fieldNames = rowFormatInfo.getFieldNames();
+ FormatInfo[] fieldFormatInfos = rowFormatInfo.getFieldFormatInfos();
+
+ Row row = new Row(fieldNames.length);
+
+ for (int i = 0; i < predefinedFields.size(); ++i) {
+
+ if (i >= fieldNames.length) {
+ break;
+ }
+
+ String fieldName = fieldNames[i];
+ FormatInfo fieldFormatInfo = fieldFormatInfos[i];
+
+ String fieldText = predefinedFields.get(i);
+
+ Object field =
+ deserializeBasicField(
+ fieldName,
+ fieldFormatInfo,
+ fieldText,
+ nullLiteral);
+ row.setField(i, field);
+ }
+
+ for (int i = predefinedFields.size(); i < fieldNames.length; ++i) {
+ String fieldName = fieldNames[i];
+ FormatInfo fieldFormatInfo = fieldFormatInfos[i];
+
+ String fieldText = entries.get(fieldName);
+
+ Object field =
+ deserializeBasicField(
+ fieldName,
+ fieldFormatInfo,
+ fieldText,
+ nullLiteral);
+ row.setField(i, field);
+ }
+
+ return row;
+ }
+
+}
diff --git
a/inlong-sort/sort-formats/format-row/format-inlongmsg-tlogkv/src/main/java/org/apache/inlong/sort/formats/inlongmsgtlogkv/InLongMsgTlogKvValidator.java
b/inlong-sort/sort-formats/format-row/format-inlongmsg-tlogkv/src/main/java/org/apache/inlong/sort/formats/inlongmsgtlogkv/InLongMsgTlogKvValidator.java
new file mode 100644
index 0000000000..8b163a4bb2
--- /dev/null
+++
b/inlong-sort/sort-formats/format-row/format-inlongmsg-tlogkv/src/main/java/org/apache/inlong/sort/formats/inlongmsgtlogkv/InLongMsgTlogKvValidator.java
@@ -0,0 +1,44 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.inlong.sort.formats.inlongmsgtlogkv;
+
+import org.apache.inlong.sort.formats.base.TextFormatDescriptorValidator;
+
+import org.apache.flink.table.descriptors.DescriptorProperties;
+
+import static
org.apache.inlong.sort.formats.base.TableFormatConstants.FORMAT_DELIMITER;
+import static
org.apache.inlong.sort.formats.base.TableFormatConstants.FORMAT_ENTRY_DELIMITER;
+import static
org.apache.inlong.sort.formats.base.TableFormatConstants.FORMAT_KV_DELIMITER;
+import static
org.apache.inlong.sort.formats.inlongmsg.InLongMsgUtils.validateInLongMsgSchema;
+
+/**
+ * The validator for {@link InLongMsgTlogKv}.
+ */
+public class InLongMsgTlogKvValidator extends TextFormatDescriptorValidator {
+
+ @Override
+ public void validate(DescriptorProperties properties) {
+ super.validate(properties);
+
+ properties.validateString(FORMAT_DELIMITER, true, 1, 1);
+ properties.validateString(FORMAT_ENTRY_DELIMITER, true, 1, 1);
+ properties.validateString(FORMAT_KV_DELIMITER, true, 1, 1);
+
+ validateInLongMsgSchema(properties);
+ }
+}
diff --git
a/inlong-sort/sort-formats/format-row/format-inlongmsg-tlogkv/src/main/resources/META-INF/services/org.apache.flink.table.factories.TableFactory
b/inlong-sort/sort-formats/format-row/format-inlongmsg-tlogkv/src/main/resources/META-INF/services/org.apache.flink.table.factories.TableFactory
new file mode 100644
index 0000000000..780d0af33b
--- /dev/null
+++
b/inlong-sort/sort-formats/format-row/format-inlongmsg-tlogkv/src/main/resources/META-INF/services/org.apache.flink.table.factories.TableFactory
@@ -0,0 +1,16 @@
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You under the Apache License, Version 2.0
+# (the "License"); you may not use this file except in compliance with
+# the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+org.apache.inlong.sort.formats.inlongmsgtlogkv.InLongMsgTlogKvFormatFactory
diff --git
a/inlong-sort/sort-formats/format-row/format-inlongmsg-tlogkv/src/test/java/org/apache/inlong/sort/formats/inlongmsgtlogkv/InLongMsgTlogKvFormatDeserializerTest.java
b/inlong-sort/sort-formats/format-row/format-inlongmsg-tlogkv/src/test/java/org/apache/inlong/sort/formats/inlongmsgtlogkv/InLongMsgTlogKvFormatDeserializerTest.java
new file mode 100644
index 0000000000..e722ae226a
--- /dev/null
+++
b/inlong-sort/sort-formats/format-row/format-inlongmsg-tlogkv/src/test/java/org/apache/inlong/sort/formats/inlongmsgtlogkv/InLongMsgTlogKvFormatDeserializerTest.java
@@ -0,0 +1,213 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.inlong.sort.formats.inlongmsgtlogkv;
+
+import org.apache.inlong.common.msg.InLongMsg;
+import org.apache.inlong.sort.formats.common.FormatInfo;
+import org.apache.inlong.sort.formats.common.IntFormatInfo;
+import org.apache.inlong.sort.formats.common.RowFormatInfo;
+import org.apache.inlong.sort.formats.common.StringFormatInfo;
+import org.apache.inlong.sort.formats.inlongmsg.FailureHandler;
+import org.apache.inlong.sort.formats.inlongmsg.InLongMsgBody;
+import org.apache.inlong.sort.formats.inlongmsg.InLongMsgHead;
+
+import org.apache.flink.api.common.functions.util.ListCollector;
+import org.apache.flink.types.Row;
+import org.apache.flink.util.Collector;
+import org.junit.Test;
+
+import java.sql.Timestamp;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import static
org.apache.inlong.sort.formats.base.TableFormatConstants.DEFAULT_DELIMITER;
+import static
org.apache.inlong.sort.formats.base.TableFormatConstants.DEFAULT_ENTRY_DELIMITER;
+import static
org.apache.inlong.sort.formats.base.TableFormatConstants.DEFAULT_KV_DELIMITER;
+import static
org.apache.inlong.sort.formats.inlongmsg.InLongMsgUtils.DEFAULT_ATTRIBUTES_FIELD_NAME;
+import static
org.apache.inlong.sort.formats.inlongmsg.InLongMsgUtils.DEFAULT_TIME_FIELD_NAME;
+import static
org.apache.inlong.sort.formats.inlongmsgtlogkv.InLongMsgTlogKvUtils.DEFAULT_INLONGMSG_TLOGKV_CHARSET;
+import static org.junit.Assert.assertEquals;
+
+/**
+ * Tests for {@link InLongMsgTlogKvFormatDeserializer}.
+ */
+public class InLongMsgTlogKvFormatDeserializerTest {
+
+ private static final RowFormatInfo TEST_ROW_INFO =
+ new RowFormatInfo(
+ new String[]{"pf1", "pf2", "f1", "f2", "f3"},
+ new FormatInfo[]{
+ IntFormatInfo.INSTANCE,
+ IntFormatInfo.INSTANCE,
+ StringFormatInfo.INSTANCE,
+ StringFormatInfo.INSTANCE,
+ StringFormatInfo.INSTANCE
+ });
+
+ @Test
+ public void testExceptionHandler() throws Exception {
+ TestFailureHandler errorHandler = new TestFailureHandler();
+ InLongMsgTlogKvFormatDeserializer deserializer =
+ new InLongMsgTlogKvFormatDeserializer(
+ TEST_ROW_INFO,
+ DEFAULT_TIME_FIELD_NAME,
+ DEFAULT_ATTRIBUTES_FIELD_NAME,
+ DEFAULT_INLONGMSG_TLOGKV_CHARSET,
+ DEFAULT_DELIMITER,
+ DEFAULT_ENTRY_DELIMITER,
+ DEFAULT_KV_DELIMITER,
+ null,
+ null,
+ null,
+ errorHandler);
+
+ InLongMsg inLongMsg1 = InLongMsg.newInLongMsg(true);
+ String attrs = "m=0&t=20200322&__addcol1_=1&__addcol2_=tes";
+ String body1 = "testInterfaceId1,f1=field1&f2=field2&f3=field3";
+ String body2 = "f1=field1&f2=field2&f3=field3";
+ inLongMsg1.addMsg(attrs, body1.getBytes());
+ inLongMsg1.addMsg(attrs, body2.getBytes());
+
+ List<Row> actualRows = new ArrayList<>();
+ Collector<Row> collector = new ListCollector<>(actualRows);
+ deserializer.flatMap(inLongMsg1.buildArray(), collector);
+ assertEquals(2, errorHandler.getRowCount());
+
+ InLongMsg inLongMsg1Head = InLongMsg.newInLongMsg();
+ String abNormalAttrs = "m=0&__addcol1_=1&__addcol2_=tes";
+ inLongMsg1Head.addMsg(abNormalAttrs, body1.getBytes());
+ inLongMsg1Head.addMsg(abNormalAttrs, body2.getBytes());
+ deserializer.flatMap(inLongMsg1Head.buildArray(), collector);
+ assertEquals(1, errorHandler.getHeadCount());
+ }
+
+ @Test
+ public void testDeserialize() throws Exception {
+ InLongMsg inLongMsg1 = InLongMsg.newInLongMsg(true);
+ String attrs = "m=0&t=20200322&__addcol1_=1&__addcol2_=2";
+ String body1 = "testInterfaceId1,f1=field1&f2=field2&f3=field3";
+ String body2 = "f1=field1&f2=field2&f3=field3";
+ String body3 = "f1=field1&f2=field2,f1=field1&f2=field2&f3=field3";
+ String body4 = ",testInterfaceId1,f1=field1&f2=field2&f3=field3";
+
+ inLongMsg1.addMsg(attrs, body1.getBytes());
+ inLongMsg1.addMsg(attrs, body2.getBytes());
+ inLongMsg1.addMsg(attrs, body3.getBytes());
+ inLongMsg1.addMsg(attrs, body4.getBytes());
+
+ Map<String, String> expectedAttributes = new HashMap<>();
+ expectedAttributes.put("m", "0");
+ expectedAttributes.put("t", "20200322");
+ expectedAttributes.put("__addcol1_", "1");
+ expectedAttributes.put("__addcol2_", "2");
+
+ Row expectedRow1 = Row.of(
+ Timestamp.valueOf("2020-03-22 00:00:00"),
+ expectedAttributes,
+ 1,
+ 2,
+ "field1",
+ "field2",
+ "field3");
+
+ Row expectedRow2 = Row.of(
+ Timestamp.valueOf("2020-03-22 00:00:00"),
+ expectedAttributes,
+ 1,
+ 2,
+ null,
+ null,
+ null);
+
+ Row expectedRow3 = Row.of(
+ Timestamp.valueOf("2020-03-22 00:00:00"),
+ expectedAttributes,
+ 1,
+ 2,
+ "field1",
+ "field2",
+ "field3");
+
+ Row expectedRow4 = Row.of(
+ Timestamp.valueOf("2020-03-22 00:00:00"),
+ expectedAttributes,
+ 1,
+ 2,
+ "field1",
+ "field2",
+ "field3");
+
+ testRowDeserialization(inLongMsg1.buildArray(),
+ Arrays.asList(expectedRow1, expectedRow2, expectedRow3,
expectedRow4));
+ }
+
+ private void testRowDeserialization(
+ byte[] bytes,
+ List<Row> expectedRows) throws Exception {
+ InLongMsgTlogKvFormatDeserializer deserializer =
+ new InLongMsgTlogKvFormatDeserializer.Builder(TEST_ROW_INFO)
+ .setTimeFieldName("inlongmsg_time")
+ .setAttributesFieldName("inlongmsg_attributes")
+ .build();
+
+ List<Row> actualRows = new ArrayList<>();
+ Collector<Row> collector = new ListCollector<>(actualRows);
+
+ deserializer.flatMap(bytes, collector);
+
+ assertEquals(expectedRows, actualRows);
+ }
+
+ private static class TestFailureHandler implements FailureHandler {
+
+ private int headCount = 0;
+ private int bodyCount = 0;
+ private int rowCount = 0;
+
+ public int getHeadCount() {
+ return headCount;
+ }
+
+ public int getBodyCount() {
+ return bodyCount;
+ }
+
+ public int getRowCount() {
+ return rowCount;
+ }
+
+ @Override
+ public void onParsingHeadFailure(String attribute, Exception
exception) throws Exception {
+ headCount++;
+ }
+
+ @Override
+ public void onParsingBodyFailure(byte[] body, Exception exception)
throws Exception {
+ bodyCount++;
+ }
+
+ @Override
+ public void onConvertingRowFailure(InLongMsgHead head,
+ InLongMsgBody body, Exception exception) throws Exception {
+ rowCount++;
+ }
+ }
+}
diff --git
a/inlong-sort/sort-formats/format-row/format-inlongmsg-tlogkv/src/test/java/org/apache/inlong/sort/formats/inlongmsgtlogkv/InLongMsgTlogKvFormatFactoryTest.java
b/inlong-sort/sort-formats/format-row/format-inlongmsg-tlogkv/src/test/java/org/apache/inlong/sort/formats/inlongmsgtlogkv/InLongMsgTlogKvFormatFactoryTest.java
new file mode 100644
index 0000000000..941a633a5a
--- /dev/null
+++
b/inlong-sort/sort-formats/format-row/format-inlongmsg-tlogkv/src/test/java/org/apache/inlong/sort/formats/inlongmsgtlogkv/InLongMsgTlogKvFormatFactoryTest.java
@@ -0,0 +1,125 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.inlong.sort.formats.inlongmsgtlogkv;
+
+import org.apache.inlong.sort.formats.base.TableFormatDeserializer;
+import org.apache.inlong.sort.formats.base.TableFormatForRowUtils;
+import org.apache.inlong.sort.formats.common.DateFormatInfo;
+import org.apache.inlong.sort.formats.common.FormatInfo;
+import org.apache.inlong.sort.formats.common.FormatUtils;
+import org.apache.inlong.sort.formats.common.IntFormatInfo;
+import org.apache.inlong.sort.formats.common.RowFormatInfo;
+import org.apache.inlong.sort.formats.common.StringFormatInfo;
+import org.apache.inlong.sort.formats.inlongmsg.InLongMsgUtils;
+
+import org.apache.flink.api.common.typeinfo.TypeInformation;
+import org.apache.flink.table.api.TableSchema;
+import org.apache.flink.table.api.Types;
+import org.apache.flink.table.descriptors.Schema;
+import org.apache.flink.types.Row;
+import org.junit.Test;
+
+import java.nio.charset.StandardCharsets;
+import java.util.HashMap;
+import java.util.Map;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+
+/**
+ * Tests for {@link InLongMsgTlogKvFormatFactory}.
+ */
+public class InLongMsgTlogKvFormatFactoryTest {
+
+ private static final TypeInformation<Row> SCHEMA =
+ Types.ROW(
+ new String[]{"time", "attributes", "student_name",
"score", "date"},
+ new TypeInformation[]{
+ Types.SQL_TIMESTAMP(),
+ Types.MAP(Types.STRING(), Types.STRING()),
+ Types.STRING(),
+ Types.INT(),
+ Types.SQL_DATE()
+ });
+
+ private static final RowFormatInfo TEST_FORMAT_SCHEMA =
+ new RowFormatInfo(
+ new String[]{"student_name", "score", "date"},
+ new FormatInfo[]{
+ StringFormatInfo.INSTANCE,
+ IntFormatInfo.INSTANCE,
+ new DateFormatInfo("yyyy-MM-dd")
+ });
+
+ @Test
+ public void testCreateTableFormatDeserializer() throws Exception {
+ final Map<String, String> properties =
+ new InLongMsgTlogKv()
+ .schema(FormatUtils.marshall(TEST_FORMAT_SCHEMA))
+ .charset(StandardCharsets.ISO_8859_1)
+ .delimiter(',')
+ .entryDelimiter('&')
+ .kvDelimiter('=')
+ .escapeCharacter('\\')
+ .quoteCharacter('\"')
+ .nullLiteral("null")
+ .toProperties();
+ assertNotNull(properties);
+
+ final InLongMsgTlogKvFormatDeserializer expectedDeser =
+ new InLongMsgTlogKvFormatDeserializer(
+ TEST_FORMAT_SCHEMA,
+ InLongMsgUtils.DEFAULT_TIME_FIELD_NAME,
+ InLongMsgUtils.DEFAULT_ATTRIBUTES_FIELD_NAME,
+ StandardCharsets.ISO_8859_1.name(),
+ ',',
+ '&',
+ '=',
+ '\\',
+ '\"',
+ "null",
+ false);
+
+ final TableFormatDeserializer actualDeser =
+ TableFormatForRowUtils.getTableFormatDeserializer(
+ properties,
+ getClass().getClassLoader());
+
+ assertEquals(expectedDeser, actualDeser);
+ }
+
+ @Test(expected = Exception.class)
+ public void testCreateCollectionDeserializationSchemaWithDerivation() {
+ final Map<String, String> properties = new HashMap<>();
+ properties.putAll(
+ new Schema()
+ .schema(TableSchema.fromTypeInfo(SCHEMA))
+ .toProperties());
+ properties.putAll(new InLongMsgTlogKv().deriveSchema().toProperties());
+
+ final InLongMsgTlogKvFormatDeserializer expectedDeser =
+ new
InLongMsgTlogKvFormatDeserializer.Builder(TEST_FORMAT_SCHEMA).build();
+
+ final TableFormatDeserializer actualDeser =
+ TableFormatForRowUtils.getTableFormatDeserializer(
+ properties,
+ getClass().getClassLoader());
+
+ assertEquals(expectedDeser, actualDeser);
+ }
+}
diff --git
a/inlong-sort/sort-formats/format-row/format-inlongmsg-tlogkv/src/test/java/org/apache/inlong/sort/formats/inlongmsgtlogkv/InLongMsgTlogKvTest.java
b/inlong-sort/sort-formats/format-row/format-inlongmsg-tlogkv/src/test/java/org/apache/inlong/sort/formats/inlongmsgtlogkv/InLongMsgTlogKvTest.java
new file mode 100644
index 0000000000..5a6568bb8b
--- /dev/null
+++
b/inlong-sort/sort-formats/format-row/format-inlongmsg-tlogkv/src/test/java/org/apache/inlong/sort/formats/inlongmsgtlogkv/InLongMsgTlogKvTest.java
@@ -0,0 +1,112 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.inlong.sort.formats.inlongmsgtlogkv;
+
+import org.apache.inlong.sort.formats.inlongmsg.InLongMsgValidator;
+
+import org.apache.flink.table.api.ValidationException;
+import org.apache.flink.table.descriptors.Descriptor;
+import org.apache.flink.table.descriptors.DescriptorTestBase;
+import org.apache.flink.table.descriptors.DescriptorValidator;
+import org.junit.Test;
+
+import java.nio.charset.StandardCharsets;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * Tests for the {@link InLongMsgTlogKv} descriptor.
+ */
+public class InLongMsgTlogKvTest extends DescriptorTestBase {
+
+ private static final String TEST_SCHEMA =
+ "{" +
+ "\"type\":\"row\"," +
+ "\"fieldFormats\":[{" +
+ "\"name\":\"student_name\"," +
+ "\"format\":{\"type\":\"string\"}" +
+ "},{" +
+ "\"name\":\"score\"," +
+ "\"format\":{\"type\":\"int\"}" +
+ "},{" +
+ "\"name\":\"date\"," +
+ "\"format\":{" +
+ "\"type\":\"date\"," +
+ "\"format\":\"yyyy-MM-dd\"" +
+ "}" +
+ "}]" +
+ "}";
+
+ private static final Descriptor CUSTOM_DESCRIPTOR_WITH_SCHEMA =
+ new InLongMsgTlogKv()
+ .schema(TEST_SCHEMA)
+ .timeFieldName("time")
+ .attributesFieldName("attributes")
+ .delimiter(';')
+ .entryDelimiter('&')
+ .kvDelimiter('=')
+ .charset(StandardCharsets.UTF_8)
+ .escapeCharacter('\\')
+ .quoteCharacter('\"')
+ .nullLiteral("n/a")
+ .ignoreErrors();
+
+ @Test(expected = ValidationException.class)
+ public void testInvalidIgnoreParseErrors() {
+ addPropertyAndVerify(CUSTOM_DESCRIPTOR_WITH_SCHEMA,
"format.escape-character", "DDD");
+ }
+
+ @Test(expected = ValidationException.class)
+ public void testMissingSchema() {
+ removePropertyAndVerify(CUSTOM_DESCRIPTOR_WITH_SCHEMA,
"format.schema");
+ }
+
+ //
--------------------------------------------------------------------------------------------
+
+ @Override
+ public List<Descriptor> descriptors() {
+ return Collections.singletonList(CUSTOM_DESCRIPTOR_WITH_SCHEMA);
+ }
+
+ @Override
+ public List<Map<String, String>> properties() {
+ final Map<String, String> props1 = new HashMap<>();
+ props1.put("format.type", "inlong-msg-tlogkv");
+ props1.put("format.property-version", "1");
+ props1.put("format.schema", TEST_SCHEMA);
+ props1.put("format.time-field-name", "time");
+ props1.put("format.attributes-field-name", "attributes");
+ props1.put("format.delimiter", ";");
+ props1.put("format.entry-delimiter", "&");
+ props1.put("format.kv-delimiter", "=");
+ props1.put("format.charset", "UTF-8");
+ props1.put("format.escape-character", "\\");
+ props1.put("format.quote-character", "\"");
+ props1.put("format.null-literal", "n/a");
+ props1.put("format.ignore-errors", "true");
+
+ return Collections.singletonList(props1);
+ }
+
+ @Override
+ public DescriptorValidator validator() {
+ return new InLongMsgValidator();
+ }
+}
diff --git
a/inlong-sort/sort-formats/format-row/format-inlongmsg-tlogkv/src/test/resources/log4j-test.properties
b/inlong-sort/sort-formats/format-row/format-inlongmsg-tlogkv/src/test/resources/log4j-test.properties
new file mode 100644
index 0000000000..881dc0609b
--- /dev/null
+++
b/inlong-sort/sort-formats/format-row/format-inlongmsg-tlogkv/src/test/resources/log4j-test.properties
@@ -0,0 +1,27 @@
+################################################################################
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+################################################################################
+
+# Set root logger level to DEBUG and its only appender to A1.
+log4j.rootLogger=OFF, A1
+
+# A1 is set to be a ConsoleAppender.
+log4j.appender.A1=org.apache.log4j.ConsoleAppender
+
+# A1 uses PatternLayout.
+log4j.appender.A1.layout=org.apache.log4j.PatternLayout
+log4j.appender.A1.layout.ConversionPattern=%-4r [%t] %-5p %c %x - %m%n
diff --git a/inlong-sort/sort-formats/format-row/pom.xml
b/inlong-sort/sort-formats/format-row/pom.xml
index 4b74124162..1fbff77f1f 100644
--- a/inlong-sort/sort-formats/format-row/pom.xml
+++ b/inlong-sort/sort-formats/format-row/pom.xml
@@ -40,6 +40,7 @@
<module>format-inlongmsg-csv</module>
<module>format-inlongmsg-kv</module>
<module>format-inlongmsg-pb</module>
+ <module>format-inlongmsg-tlogkv</module>
</modules>
<properties>