Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[INLONG-4659][Sort] Support field routing for Elasticsearch connector #4849

Merged
merged 16 commits into from
Jul 7, 2022
4 changes: 2 additions & 2 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion inlong-dashboard/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions inlong-sort/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@
<hbase.version>2.2.3</hbase.version>
<dlc.hive.version>2.3.7</dlc.hive.version>
<iceberg.hive.version>2.3.7</iceberg.hive.version>
<elasticsearch6.version>6.8.17</elasticsearch6.version>
<elasticsearch7.version>7.9.2</elasticsearch7.version>
</properties>
<dependencyManagement>
<dependencies>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,18 +97,22 @@ public ElasticsearchLoadNode(@JsonProperty("id") String id,
this.version = version;
}

/**
* if you want to set field routing, set the routing.field-name
*/
@Override
public Map<String, String> tableOptions() {
Map<String, String> options = super.tableOptions();
options.put("connector", "elasticsearch-7");
options.put("connector", "elasticsearch-7-inlong");
if (version == 6) {
options.put("connector", "elasticsearch-6");
options.put("connector", "elasticsearch-6-inlong");
options.put("document-type", documentType);
}
options.put("hosts", hosts);
options.put("index", index);
options.put("password", password);
options.put("username", username);
options.put("routing.field-name", primaryKey);
return options;
}

Expand Down
112 changes: 104 additions & 8 deletions inlong-sort/sort-connectors/elasticsearch-6/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,32 +31,128 @@
<name>Apache InLong - Sort-connector-elasticsearch6</name>
<packaging>jar</packaging>


<properties>
<elasticsearch.version>6.8.17</elasticsearch.version>
</properties>

<dependencies>
<dependency>
<groupId>org.apache.flink</groupId>
<artifactId>flink-connector-elasticsearch6_2.12</artifactId>
<version>${flink.version}</version>
</dependency>
<dependency>
<groupId>org.apache.inlong</groupId>
<artifactId>sort-connector-elasticsearch-base</artifactId>
<version>1.3.0-SNAPSHOT</version>
<exclusions>
<!-- Elasticsearch Java Client has been moved to a different module in 5.x -->
<exclusion>
<groupId>org.elasticsearch</groupId>
<artifactId>elasticsearch</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.elasticsearch.client</groupId>
<artifactId>elasticsearch-rest-high-level-client</artifactId>
<version>${elasticsearch.version}</version>
<version>${elasticsearch6.version}</version>
</dependency>
<dependency>
<groupId>org.elasticsearch.client</groupId>
<artifactId>elasticsearch-rest-client</artifactId>
<version>${elasticsearch.version}</version>
<version>${elasticsearch6.version}</version>
</dependency>
<dependency>
<groupId>org.elasticsearch</groupId>
<artifactId>elasticsearch</artifactId>
<version>${elasticsearch.version}</version>
<version>${elasticsearch6.version}</version>
</dependency>


<!-- test dependencies -->

<dependency>
<groupId>org.testcontainers</groupId>
<artifactId>elasticsearch</artifactId>
<version>1.15.1</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.apache.flink</groupId>
<artifactId>flink-test-utils_2.12</artifactId>
<version>${flink.version}</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.apache.flink</groupId>
<artifactId>flink-streaming-java_2.12</artifactId>
<version>${flink.version}</version>
<scope>test</scope>
<type>test-jar</type>
</dependency>

<dependency>
<groupId>org.apache.inlong</groupId>
<artifactId>sort-connector-elasticsearch-base</artifactId>
<version>1.3.0-SNAPSHOT</version>
<exclusions>
<exclusion>
<groupId>org.elasticsearch</groupId>
<artifactId>elasticsearch</artifactId>
</exclusion>
</exclusions>
<type>test-jar</type>
<scope>test</scope>
</dependency>

<!--
Including elasticsearch transport dependency for tests. Netty3 is not here anymore in 6.x
-->

<dependency>
<groupId>org.elasticsearch.client</groupId>
<artifactId>transport</artifactId>
<version>${elasticsearch6.version}</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.elasticsearch.plugin</groupId>
<artifactId>transport-netty4-client</artifactId>
<version>${elasticsearch6.version}</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<scope>provided</scope>
</dependency>

<!-- Elasticsearch table descriptor testing -->
<dependency>
<groupId>org.apache.flink</groupId>
<artifactId>flink-table-planner_2.12</artifactId>
<version>${flink.version}</version>
<type>test-jar</type>
<scope>test</scope>
</dependency>

<!-- Table API integration tests -->
<dependency>
<groupId>org.apache.flink</groupId>
<artifactId>flink-table-planner-blink_2.12</artifactId>
<version>${flink.version}</version>
<scope>test</scope>
</dependency>

<!-- Elasticsearch table sink factory testing -->
<dependency>
<groupId>org.apache.flink</groupId>
<artifactId>flink-json</artifactId>
<version>${flink.version}</version>
<scope>test</scope>
</dependency>

</dependencies>


Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
/*
* 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.elasticsearch6.table;

import org.apache.flink.annotation.Internal;
import org.apache.flink.configuration.ReadableConfig;
import org.apache.flink.table.api.ValidationException;
import org.apache.inlong.sort.elasticsearch.table.ElasticsearchConfiguration;

import org.apache.http.HttpHost;

import java.util.List;
import java.util.stream.Collectors;

import static org.apache.inlong.sort.elasticsearch.table.ElasticsearchOptions.HOSTS_OPTION;

/** Elasticsearch 6 specific configuration. */
@Internal
final class Elasticsearch6Configuration extends ElasticsearchConfiguration {
Elasticsearch6Configuration(ReadableConfig config, ClassLoader classLoader) {
super(config, classLoader);
}

public List<HttpHost> getHosts() {
return config.get(HOSTS_OPTION).stream()
.map(Elasticsearch6Configuration::validateAndParseHostsString)
.collect(Collectors.toList());
}

/**
* Parse Hosts String to list.
*
* <p>Hosts String format was given as following:
*
* <pre>
* connector.hosts = http://host_name:9092;http://host_name:9093
* </pre>
*/
private static HttpHost validateAndParseHostsString(String host) {
try {
HttpHost httpHost = HttpHost.create(host);
if (httpHost.getPort() < 0) {
throw new ValidationException(
String.format(
"Could not parse host '%s' in option '%s'. It should follow the format 'http://host_name:port'. Missing port.",
host, HOSTS_OPTION.key()));
}

if (httpHost.getSchemeName() == null) {
throw new ValidationException(
String.format(
"Could not parse host '%s' in option '%s'. It should follow the format 'http://host_name:port'. Missing scheme.",
host, HOSTS_OPTION.key()));
}
return httpHost;
} catch (Exception e) {
throw new ValidationException(
String.format(
"Could not parse host '%s' in option '%s'. It should follow the format 'http://host_name:port'.",
host, HOSTS_OPTION.key()),
e);
}
}
}
Loading