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

[hotfix-710][redis] Fix writing to redis in sql mode reports illegal argument exception #715

Merged
merged 1 commit into from
Apr 15, 2022
Merged
Show file tree
Hide file tree
Changes from all 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
17 changes: 17 additions & 0 deletions docs/connectors-en/redis/redis-sink.md
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,23 @@ All major versions
- Default:(none)
<br />

- **type和mode**
- Description:Type indicates the data type and mode indicates the write mode
- Options:string/list/set/zset/hash

| Type | Mode |
| ---- | ---- |
| string | set |
| list | lpush |
| list | rpush |
| set | sadd |
| zset | zadd |
| hash | hset |
- Required:yes
- Default:(none)
<br />

Copy link

Choose a reason for hiding this comment

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

能否将这两个参数分开,拆成两个独立的参数说明呢?


## 五、Data Types
| support | BOOLEAN、TINYINT、SMALLINT、INT、BIGINT、FLOAT、DOUBLE、DECIMAL、STRING、VARCHAR、CHAR、TIMESTAMP、DATE、BINARY |
| ---------- | --- |
Expand Down
17 changes: 17 additions & 0 deletions docs/connectors/redis/redis-sink.md
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,23 @@ redis sink
- 默认值:无
<br />

- **type和mode**
- 描述:type 表示 value 的类型,mode 表示在选定的数据类型下的写入模式。
- 选项:string/list/set/zset/hash

| type | 描述 | mode | 说明 | 注意 |
| ---- | ---- | ---- | ---- | ---- |
| string | 字符串 | set | 存储这个数据,如果已经存在则覆盖 | |
| list | 字符串列表 | lpush | 在 list 最左边存储这个数据 | |
| list | 字符串列表 | rpush | 在 list 最右边存储这个数据 | |
| set | 字符串集合 | sadd | 向 set 集合中存储这个数据,如果已经存在则覆盖 | |
| zset | 有序字符串集合 | zadd | 向 zset 有序集合中存储这个数据,如果已经存在则覆盖 | 当 value 类型是 zset 时,数据源的每一行记录需要遵循相应的规范,即每一行记录除 key 以外,只能有一对 score 和 value,并且 score 必须在 value 前面,rediswriter 方能解析出哪一个 column 是 score,哪一个 column 是 value。 |
| hash | 哈希 | hset | 向 hash 有序集合中存储这个数据,如果已经存在则覆盖 | 当 value 类型是 hash 时,数据源的每一行记录需要遵循相应的规范,即每一行记录除 key 以外,只能有一对 attribute 和 value,并且 attribute 必须在 value 前面,Rediswriter 方能解析出哪一个 column 是 attribute,哪一个 column 是 value。 |
- 必选:是
- 默认值:无
<br />

Copy link

Choose a reason for hiding this comment

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

这两个参数能否拆开,分成两个独立的参数呢?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

之前json模式文档就是在一起的,type 和 mode 是配套使用的,拆开的话估计不利于用户理解使用


## 五、数据类型
| 支持 | BOOLEAN、TINYINT、SMALLINT、INT、BIGINT、FLOAT、DOUBLE、DECIMAL、STRING、VARCHAR、CHAR、TIMESTAMP、DATE、BINARY |
| --- | --- |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public class RedisOptions {
ConfigOptions.key("redis.default.port")
.stringType()
.defaultValue("6379")
.withDescription("edis.default.port");
.withDescription("redis.default.port");

public static final ConfigOption<String> URL =
ConfigOptions.key("url").stringType().noDefaultValue().withDescription("url");
Expand Down Expand Up @@ -93,4 +93,10 @@ public class RedisOptions {
.intType()
.defaultValue(0)
.withDescription("keyExpiredTime");

public static final ConfigOption<String> REDIS_DATA_TYPE =
ConfigOptions.key("type").stringType().noDefaultValue().withDescription("type");

public static final ConfigOption<String> REDIS_DATA_MODE =
ConfigOptions.key("mode").stringType().noDefaultValue().withDescription("mode");
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@

import com.dtstack.flinkx.connector.redis.conf.RedisConf;
import com.dtstack.flinkx.connector.redis.enums.RedisConnectType;
import com.dtstack.flinkx.connector.redis.enums.RedisDataMode;
import com.dtstack.flinkx.connector.redis.enums.RedisDataType;
import com.dtstack.flinkx.connector.redis.sink.RedisDynamicTableSink;
import com.dtstack.flinkx.connector.redis.source.RedisDynamicTableSource;
import com.dtstack.flinkx.lookup.conf.LookupConf;
Expand Down Expand Up @@ -50,6 +52,8 @@
import static com.dtstack.flinkx.connector.redis.options.RedisOptions.MINIDLE;
import static com.dtstack.flinkx.connector.redis.options.RedisOptions.PASSWORD;
import static com.dtstack.flinkx.connector.redis.options.RedisOptions.REDISTYPE;
import static com.dtstack.flinkx.connector.redis.options.RedisOptions.REDIS_DATA_MODE;
import static com.dtstack.flinkx.connector.redis.options.RedisOptions.REDIS_DATA_TYPE;
import static com.dtstack.flinkx.connector.redis.options.RedisOptions.TABLENAME;
import static com.dtstack.flinkx.connector.redis.options.RedisOptions.TIMEOUT;
import static com.dtstack.flinkx.connector.redis.options.RedisOptions.URL;
Expand Down Expand Up @@ -119,6 +123,8 @@ public Set<ConfigOption<?>> requiredOptions() {
Set<ConfigOption<?>> requiredOptions = new HashSet<>();
requiredOptions.add(URL);
requiredOptions.add(TABLENAME);
requiredOptions.add(REDIS_DATA_TYPE);
requiredOptions.add(REDIS_DATA_MODE);
return requiredOptions;
}

Expand Down Expand Up @@ -162,6 +168,8 @@ private RedisConf getRedisConf(ReadableConfig config, TableSchema schema) {
redisConf.setMaxIdle(config.get(MAXIDLE));
redisConf.setMinIdle(config.get(MINIDLE));
redisConf.setExpireTime(config.get(KEYEXPIREDTIME));
redisConf.setType(RedisDataType.getDataType(config.get(REDIS_DATA_TYPE)));
redisConf.setMode(RedisDataMode.getDataMode(config.get(REDIS_DATA_MODE)));

List<String> keyFields = schema.getPrimaryKey().map(pk -> pk.getColumns()).orElse(null);
redisConf.setUpdateKey(keyFields);
Expand Down
2 changes: 2 additions & 0 deletions flinkx-examples/sql/redis/stream_redis.sql
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ CREATE TABLE sink
,'min.idle' = '0' -- 最小空闲连接数 ,默认:0
-- ,'keyExpiredTime' = '1000' -- redis sink的key的过期时间。默认是0(永不过期),单位是s。默认:0
,'sink.parallelism' = '3' -- sink并行度
,'type' = 'hash'
,'mode' = 'hset'
);


Expand Down