Skip to content

Commit

Permalink
[Sort] Sort format supports InLongMsg-kv format apache#9521
Browse files Browse the repository at this point in the history
  • Loading branch information
baomingyu committed Dec 28, 2023
1 parent 118663d commit 1d51aa9
Show file tree
Hide file tree
Showing 14 changed files with 1,963 additions and 0 deletions.
5 changes: 5 additions & 0 deletions inlong-sort/sort-dist/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,11 @@
<artifactId>sort-format-inlongmsg-csv</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.apache.inlong</groupId>
<artifactId>sort-format-inlongmsg-kv</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.apache.inlong</groupId>
<artifactId>sort-format-kv</artifactId>
Expand Down
129 changes: 129 additions & 0 deletions inlong-sort/sort-formats/format-inlongmsg-kv/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
<?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>sort-formats</artifactId>
<version>1.11.0-SNAPSHOT</version>
</parent>

<artifactId>sort-format-inlongmsg-kv</artifactId>
<name>Apache InLong - Sort Format-inlongmsg-kv</name>

<properties>
<inlong.root.dir>${project.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>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>org.apache.inlong</groupId>
<artifactId>sort-format-base</artifactId>
<version>${project.version}</version>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>org.apache.inlong</groupId>
<artifactId>sort-format-inlongmsg-base</artifactId>
<version>${project.version}</version>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>org.xerial.snappy</groupId>
<artifactId>snappy-java</artifactId>
<version>${snappy.version}</version>
<scope>provided</scope>
</dependency>

<dependency>
<groupId>org.apache.flink</groupId>
<artifactId>flink-shaded-jackson</artifactId>
<version>${flink.jackson.version}</version>
<scope>provided</scope>
</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>
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
/*
* 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.inlongmsgkv;

import org.apache.inlong.sort.formats.base.TextFormatDescriptor;

import static org.apache.flink.util.Preconditions.checkNotNull;
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.base.TableFormatConstants.FORMAT_LINE_DELIMITER;
import static org.apache.inlong.sort.formats.inlongmsg.InLongMsgUtils.FORMAT_ATTRIBUTES_FIELD_NAME;
import static org.apache.inlong.sort.formats.inlongmsg.InLongMsgUtils.FORMAT_RETAIN_PREDEFINED_FIELD;
import static org.apache.inlong.sort.formats.inlongmsg.InLongMsgUtils.FORMAT_TIME_FIELD_NAME;

/**
* Format descriptor for KVs.
*/
public class InLongMsgKv extends TextFormatDescriptor<InLongMsgKv> {

public static final String FORMAT_TYPE_VALUE = "InLongMsg-KV";

public InLongMsgKv() {
super(FORMAT_TYPE_VALUE, 1);
}

/**
* Sets the entry delimiter character ('&amp;' by default).
*
* @param delimiter the entry delimiter character
* @return The instance which has delimiter set.
*/
public InLongMsgKv 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 InLongMsgKv kvDelimiter(char delimiter) {
internalProperties.putCharacter(FORMAT_KV_DELIMITER, delimiter);
return this;
}

/**
* Sets the delimiter between lines.
*
* @param lineDelimiter The delimiter between lines (e.g. '\n').
* @return The instance which has lineDelimiter set.
*/
public InLongMsgKv lineDelimiter(char lineDelimiter) {
internalProperties.putCharacter(FORMAT_LINE_DELIMITER, lineDelimiter);
return this;
}

/**
* Sets the name of the time field.
*
* @param timeFieldName The name of the time field.
* @return The instance which has timeFieldName set.
*/
public InLongMsgKv timeFieldName(String timeFieldName) {
checkNotNull(timeFieldName);
internalProperties.putString(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 set.
*/
public InLongMsgKv attributesFieldName(String attributesFieldName) {
checkNotNull(attributesFieldName);
internalProperties.putString(FORMAT_ATTRIBUTES_FIELD_NAME, attributesFieldName);
return this;
}

/**
* Skips the predefined Field.
*/
public InLongMsgKv skipPredefinedField() {
internalProperties.putBoolean(FORMAT_RETAIN_PREDEFINED_FIELD, false);
return this;
}
}
Loading

0 comments on commit 1d51aa9

Please sign in to comment.