Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public HttpSink(Config pluginConfig, SeaTunnelRowType rowType) {

@Override
public String getPluginName() {
return "Http";
return HttpConfig.CONNECTOR_IDENTITY;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@

public class RedisConfig {

public static final String CONNECTOR_IDENTITY = "Redis";

public enum RedisMode {
SINGLE,
CLUSTER;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,9 @@

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

import org.apache.seatunnel.api.common.PrepareFailException;
import org.apache.seatunnel.api.common.SeaTunnelAPIErrorCode;
import org.apache.seatunnel.api.sink.SeaTunnelSink;
import org.apache.seatunnel.api.sink.SinkWriter;
import org.apache.seatunnel.api.table.catalog.CatalogTable;
import org.apache.seatunnel.api.table.type.SeaTunnelRow;
import org.apache.seatunnel.api.table.type.SeaTunnelRowType;
import org.apache.seatunnel.common.config.CheckConfigUtil;
Expand All @@ -34,24 +33,17 @@
import org.apache.seatunnel.connectors.seatunnel.redis.config.RedisParameters;
import org.apache.seatunnel.connectors.seatunnel.redis.exception.RedisConnectorException;

import com.google.auto.service.AutoService;

import java.io.IOException;

@AutoService(SeaTunnelSink.class)
public class RedisSink extends AbstractSimpleSink<SeaTunnelRow, Void> {
private final RedisParameters redisParameters = new RedisParameters();
private SeaTunnelRowType seaTunnelRowType;
private Config pluginConfig;
private CatalogTable catalogTable;

@Override
public String getPluginName() {
return "Redis";
}

@Override
public void prepare(Config pluginConfig) throws PrepareFailException {
this.pluginConfig = pluginConfig;
public RedisSink(Config config, CatalogTable table) {
this.pluginConfig = config;
this.catalogTable = table;
CheckResult result =
CheckConfigUtil.checkAllExists(
pluginConfig,
Expand All @@ -67,11 +59,12 @@ public void prepare(Config pluginConfig) throws PrepareFailException {
getPluginName(), PluginType.SINK, result.getMsg()));
}
this.redisParameters.buildWithConfig(pluginConfig);
this.seaTunnelRowType = catalogTable.getSeaTunnelRowType();
}

@Override
public void setTypeInfo(SeaTunnelRowType seaTunnelRowType) {
this.seaTunnelRowType = seaTunnelRowType;
public String getPluginName() {
return RedisConfig.CONNECTOR_IDENTITY;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,11 @@
package org.apache.seatunnel.connectors.seatunnel.redis.sink;

import org.apache.seatunnel.api.configuration.util.OptionRule;
import org.apache.seatunnel.api.table.catalog.CatalogTable;
import org.apache.seatunnel.api.table.connector.TableSink;
import org.apache.seatunnel.api.table.factory.Factory;
import org.apache.seatunnel.api.table.factory.TableSinkFactory;
import org.apache.seatunnel.api.table.factory.TableSinkFactoryContext;
import org.apache.seatunnel.connectors.seatunnel.redis.config.RedisConfig;

import com.google.auto.service.AutoService;
Expand All @@ -31,6 +34,12 @@ public String factoryIdentifier() {
return "Redis";
}

@Override
public TableSink createSink(TableSinkFactoryContext context) {
CatalogTable catalogTable = context.getCatalogTable();
return () -> new RedisSink(context.getOptions().toConfig(), catalogTable);
}

@Override
public OptionRule optionRule() {
return OptionRule.builder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,12 @@

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

import org.apache.seatunnel.api.common.PrepareFailException;
import org.apache.seatunnel.api.common.SeaTunnelAPIErrorCode;
import org.apache.seatunnel.api.serialization.DeserializationSchema;
import org.apache.seatunnel.api.source.Boundedness;
import org.apache.seatunnel.api.source.SeaTunnelSource;
import org.apache.seatunnel.api.table.catalog.CatalogTable;
import org.apache.seatunnel.api.table.catalog.CatalogTableUtil;
import org.apache.seatunnel.api.table.catalog.schema.TableSchemaOptions;
import org.apache.seatunnel.api.table.type.SeaTunnelDataType;
import org.apache.seatunnel.api.table.type.SeaTunnelRow;
import org.apache.seatunnel.api.table.type.SeaTunnelRowType;
import org.apache.seatunnel.common.config.CheckConfigUtil;
Expand All @@ -40,21 +38,23 @@
import org.apache.seatunnel.connectors.seatunnel.redis.exception.RedisConnectorException;
import org.apache.seatunnel.format.json.JsonDeserializationSchema;

import com.google.auto.service.AutoService;
import com.google.common.collect.Lists;

import java.util.List;

@AutoService(SeaTunnelSource.class)
public class RedisSource extends AbstractSingleSplitSource<SeaTunnelRow> {
private final RedisParameters redisParameters = new RedisParameters();
private SeaTunnelRowType seaTunnelRowType;
private DeserializationSchema<SeaTunnelRow> deserializationSchema;

private CatalogTable catalogTable;

@Override
public String getPluginName() {
return "Redis";
return RedisConfig.CONNECTOR_IDENTITY;
}

@Override
public void prepare(Config pluginConfig) throws PrepareFailException {
public RedisSource(Config pluginConfig) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use ReadOnlyConfig, do not convert ReadOnlyConfig to Config. This is a bad example, we want connectors to be able to use ReadOnlyConfig instead of Config

CheckResult result =
CheckConfigUtil.checkAllExists(
pluginConfig,
Expand Down Expand Up @@ -87,13 +87,14 @@ public void prepare(Config pluginConfig) throws PrepareFailException {
RedisConfig.Format.valueOf(
pluginConfig.getString(RedisConfig.FORMAT.key()).toUpperCase());
if (RedisConfig.Format.JSON.equals(format)) {
this.seaTunnelRowType =
CatalogTableUtil.buildWithConfig(pluginConfig).getSeaTunnelRowType();
this.catalogTable = CatalogTableUtil.buildWithConfig(pluginConfig);
this.seaTunnelRowType = catalogTable.getSeaTunnelRowType();
this.deserializationSchema =
new JsonDeserializationSchema(false, false, seaTunnelRowType);
}
} else {
this.seaTunnelRowType = CatalogTableUtil.buildSimpleTextSchema();
this.catalogTable = CatalogTableUtil.buildSimpleTextTable();
this.seaTunnelRowType = catalogTable.getSeaTunnelRowType();
this.deserializationSchema = null;
}
}
Expand All @@ -104,8 +105,8 @@ public Boundedness getBoundedness() {
}

@Override
public SeaTunnelDataType<SeaTunnelRow> getProducedType() {
return seaTunnelRowType;
public List<CatalogTable> getProducedCatalogTables() {
return Lists.newArrayList(catalogTable);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,31 +19,47 @@

import org.apache.seatunnel.api.configuration.util.OptionRule;
import org.apache.seatunnel.api.source.SeaTunnelSource;
import org.apache.seatunnel.api.source.SourceSplit;
import org.apache.seatunnel.api.table.catalog.schema.TableSchemaOptions;
import org.apache.seatunnel.api.table.connector.TableSource;
import org.apache.seatunnel.api.table.factory.Factory;
import org.apache.seatunnel.api.table.factory.TableSourceFactory;
import org.apache.seatunnel.api.table.factory.TableSourceFactoryContext;
import org.apache.seatunnel.connectors.seatunnel.redis.config.RedisConfig;

import com.google.auto.service.AutoService;

import java.io.Serializable;

@AutoService(Factory.class)
public class RedisSourceFactory implements TableSourceFactory {
@Override
public String factoryIdentifier() {
return "Redis";
}

@Override
public <T, SplitT extends SourceSplit, StateT extends Serializable>
TableSource<T, SplitT, StateT> createSource(TableSourceFactoryContext context) {
return () ->
(SeaTunnelSource<T, SplitT, StateT>)
new RedisSource(context.getOptions().toConfig());
}

@Override
public OptionRule optionRule() {
return OptionRule.builder()
.required(
RedisConfig.HOST, RedisConfig.PORT, RedisConfig.KEY, RedisConfig.DATA_TYPE)
RedisConfig.HOST,
RedisConfig.PORT,
RedisConfig.KEY_PATTERN,
RedisConfig.DATA_TYPE)
.optional(
RedisConfig.MODE,
RedisConfig.HASH_KEY_PARSE_MODE,
RedisConfig.AUTH,
RedisConfig.USER,
RedisConfig.KEY_PATTERN)
RedisConfig.KEY)
.conditional(RedisConfig.MODE, RedisConfig.RedisMode.CLUSTER, RedisConfig.NODES)
.bundled(RedisConfig.FORMAT, TableSchemaOptions.SCHEMA)
.build();
Expand Down