Skip to content

Commit

Permalink
Support seatunnel-translation-spark-3.3
Browse files Browse the repository at this point in the history
  • Loading branch information
zhaomin1423 committed Aug 30, 2022
1 parent 9d88b62 commit b71d350
Show file tree
Hide file tree
Showing 50 changed files with 1,643 additions and 86 deletions.
3 changes: 3 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,9 @@
<phoenix.version>5.2.5-HBase-2.x</phoenix.version>
<awaitility.version>4.2.0</awaitility.version>
<neo4j-java-driver.version>4.4.9</neo4j-java-driver.version>
<spark3.3.version>3.3.0</spark3.3.version>
<scala2.12.version>2.12.16</scala2.12.version>
<scala2.12.binary.version>2.12</scala2.12.binary.version>
</properties>

<dependencyManagement>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ public final class Constants {

public static final String NOW = "now";

public static final String SAVE_MODE = "saveMode";

private Constants() {
}
}
2 changes: 1 addition & 1 deletion seatunnel-core/seatunnel-spark-starter/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@

<dependency>
<groupId>org.apache.seatunnel</groupId>
<artifactId>seatunnel-translation-spark-2.4</artifactId>
<artifactId>seatunnel-translation-spark-common</artifactId>
<version>${project.version}</version>
</dependency>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,18 +20,20 @@
import org.apache.seatunnel.api.common.SeaTunnelContext;
import org.apache.seatunnel.api.sink.SeaTunnelSink;
import org.apache.seatunnel.api.table.type.SeaTunnelRowType;
import org.apache.seatunnel.common.Constants;
import org.apache.seatunnel.core.starter.exception.TaskExecuteException;
import org.apache.seatunnel.plugin.discovery.PluginIdentifier;
import org.apache.seatunnel.plugin.discovery.seatunnel.SeaTunnelSinkPluginDiscovery;
import org.apache.seatunnel.spark.SparkEnvironment;
import org.apache.seatunnel.translation.spark.common.sink.SparkSinkInjector;
import org.apache.seatunnel.translation.spark.common.utils.TypeConverterUtils;
import org.apache.seatunnel.translation.spark.sink.SparkSinkInjector;

import org.apache.seatunnel.shade.com.typesafe.config.Config;

import com.google.common.collect.Lists;
import org.apache.spark.sql.Dataset;
import org.apache.spark.sql.Row;
import org.apache.spark.sql.SaveMode;

import java.net.URL;
import java.util.ArrayList;
Expand Down Expand Up @@ -72,7 +74,16 @@ public List<Dataset<Row>> execute(List<Dataset<Row>> upstreamDataStreams) throws
Dataset<Row> dataset = fromSourceTable(sinkConfig, sparkEnvironment).orElse(input);
// TODO modify checkpoint location
seaTunnelSink.setTypeInfo((SeaTunnelRowType) TypeConverterUtils.convert(dataset.schema()));
SparkSinkInjector.inject(dataset.write(), seaTunnelSink).option("checkpointLocation", "/tmp").save();
String saveMode;
if (sinkConfig.hasPath(Constants.SAVE_MODE)) {
saveMode = sinkConfig.getString(Constants.SAVE_MODE);
} else {
saveMode = SaveMode.ErrorIfExists.name();
}
SparkSinkInjector.inject(dataset.write(), seaTunnelSink)
.option("checkpointLocation", "/tmp")
.mode(saveMode)
.save();
}
// the sink is the last stream
return null;
Expand Down
70 changes: 6 additions & 64 deletions seatunnel-examples/seatunnel-spark-connector-v2-example/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -28,69 +28,11 @@
<modelVersion>4.0.0</modelVersion>

<artifactId>seatunnel-spark-connector-v2-example</artifactId>
<packaging>pom</packaging>

<properties>
<spark.scope>compile</spark.scope>
</properties>
<dependencies>
<dependency>
<groupId>org.apache.seatunnel</groupId>
<artifactId>seatunnel-spark-starter</artifactId>
<version>${project.version}</version>
</dependency>

<!-- seatunnel connectors -->
<dependency>
<groupId>org.apache.seatunnel</groupId>
<artifactId>connector-fake</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.apache.seatunnel</groupId>
<artifactId>connector-console</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.apache.seatunnel</groupId>
<artifactId>connector-clickhouse</artifactId>
<version>${project.version}</version>
</dependency>
<!-- seatunnel connectors -->

<!--spark-->
<dependency>
<groupId>org.apache.spark</groupId>
<artifactId>spark-streaming_${scala.binary.version}</artifactId>
<version>${spark.version}</version>
<scope>${spark.scope}</scope>
</dependency>

<dependency>
<groupId>org.apache.spark</groupId>
<artifactId>spark-core_${scala.binary.version}</artifactId>
<version>${spark.version}</version>
<scope>${spark.scope}</scope>
</dependency>

<dependency>
<groupId>org.apache.spark</groupId>
<artifactId>spark-sql_${scala.binary.version}</artifactId>
<version>${spark.version}</version>
<scope>${spark.scope}</scope>
</dependency>

<dependency>
<groupId>org.apache.spark</groupId>
<artifactId>spark-hive_${scala.binary.version}</artifactId>
<version>${spark.version}</version>
<scope>${spark.scope}</scope>
</dependency>

<dependency>
<groupId>net.jpountz.lz4</groupId>
<artifactId>lz4</artifactId>
<version>1.3.0</version>
</dependency>
</dependencies>

<modules>
<module>seatunnel-spark-connector-v2-example-common</module>
<module>seatunnel-spark-connector-v2-example_2.4</module>
<module>seatunnel-spark-connector-v2-example_3.3</module>
</modules>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
<?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/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>seatunnel</artifactId>
<groupId>org.apache.seatunnel</groupId>
<version>${revision}</version>
<relativePath>../../../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>

<artifactId>seatunnel-spark-connector-v2-example-common</artifactId>

<properties>
<spark.scope>compile</spark.scope>
</properties>
<dependencies>
<dependency>
<groupId>org.apache.seatunnel</groupId>
<artifactId>seatunnel-spark-starter</artifactId>
<version>${project.version}</version>
</dependency>

<!-- seatunnel connectors -->
<dependency>
<groupId>org.apache.seatunnel</groupId>
<artifactId>connector-fake</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.apache.seatunnel</groupId>
<artifactId>connector-console</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.apache.seatunnel</groupId>
<artifactId>connector-clickhouse</artifactId>
<version>${project.version}</version>
</dependency>

<dependency>
<groupId>net.jpountz.lz4</groupId>
<artifactId>lz4</artifactId>
<version>1.3.0</version>
</dependency>
</dependencies>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* 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.seatunnel.spark.connector.example.v2;

import org.apache.seatunnel.core.starter.exception.CommandException;

import java.io.FileNotFoundException;
import java.net.URISyntaxException;

public class AbstractSeaTunnelApiExample {

protected static void run(String path) throws FileNotFoundException, URISyntaxException, CommandException {
ExampleUtils.builder(path);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* 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.seatunnel.spark.connector.example.v2;

import org.apache.seatunnel.core.starter.exception.CommandException;

import java.io.FileNotFoundException;
import java.net.URISyntaxException;

public class AbstractSeaTunnelApiToClickHouseExample {

protected static void run() throws FileNotFoundException, URISyntaxException, CommandException {
ExampleUtils.builder("/examples/spark.batch.clickhouse.conf");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* limitations under the License.
*/

package org.apache.seatunnel.example.spark.v2;
package org.apache.seatunnel.spark.connector.example.v2;

import org.apache.seatunnel.common.config.DeployMode;
import org.apache.seatunnel.core.starter.Seatunnel;
Expand Down Expand Up @@ -44,7 +44,7 @@ public static void builder(String configurePath) throws FileNotFoundException, U
}

private static String getTestConfigFile(String configFile) throws FileNotFoundException, URISyntaxException {
URL resource = SeaTunnelApiExample.class.getResource(configFile);
URL resource = AbstractSeaTunnelApiExample.class.getResource(configFile);
if (resource == null) {
throw new FileNotFoundException("Can't find config file: " + configFile);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
<?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/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>seatunnel</artifactId>
<groupId>org.apache.seatunnel</groupId>
<version>${revision}</version>
<relativePath>../../../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>

<artifactId>seatunnel-spark-connector-v2-example_2.4</artifactId>

<properties>
<spark.scope>compile</spark.scope>
</properties>
<dependencies>
<dependency>
<groupId>org.apache.seatunnel</groupId>
<artifactId>seatunnel-spark-connector-v2-example-common</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.apache.seatunnel</groupId>
<artifactId>seatunnel-translation-spark-2.4</artifactId>
<version>${project.version}</version>
</dependency>

<!--spark-->
<dependency>
<groupId>org.apache.spark</groupId>
<artifactId>spark-streaming_${scala.binary.version}</artifactId>
<version>${spark.version}</version>
<scope>${spark.scope}</scope>
</dependency>

<dependency>
<groupId>org.apache.spark</groupId>
<artifactId>spark-core_${scala.binary.version}</artifactId>
<version>${spark.version}</version>
<scope>${spark.scope}</scope>
</dependency>

<dependency>
<groupId>org.apache.spark</groupId>
<artifactId>spark-sql_${scala.binary.version}</artifactId>
<version>${spark.version}</version>
<scope>${spark.scope}</scope>
</dependency>

<dependency>
<groupId>org.apache.spark</groupId>
<artifactId>spark-hive_${scala.binary.version}</artifactId>
<version>${spark.version}</version>
<scope>${spark.scope}</scope>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,17 @@
* limitations under the License.
*/

package org.apache.seatunnel.example.spark.v2;
package org.apache.seatunnel.spark.connector.example.v2;

import org.apache.seatunnel.core.starter.exception.CommandException;

import java.io.FileNotFoundException;
import java.net.URISyntaxException;

public class SeaTunnelApiExample {
public class SeaTunnelApiExample extends AbstractSeaTunnelApiExample {

public static void main(String[] args) throws FileNotFoundException, URISyntaxException, CommandException {
String configurePath = args.length > 0 ? args[0] : "/examples/spark.batch.conf";
ExampleUtils.builder(configurePath);
run(configurePath);
}
}
Loading

0 comments on commit b71d350

Please sign in to comment.