Skip to content
This repository has been archived by the owner on Jan 6, 2022. It is now read-only.

Commit

Permalink
fixbug of replace_fields
Browse files Browse the repository at this point in the history
  • Loading branch information
RickyHuo committed Dec 7, 2017
1 parent 34f69db commit 9be7990
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/main/java/com/sina/bip/hangout/outputs/Clickhouse.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public class Clickhouse extends BaseOutput{
private String table;
private String jdbcLink;
private List<String> fields;
private List<String> replace_fields = new ArrayList<String>();
private List<String> replace_fields;
private int bulkSize;
private String preSql = initSql();
private List<Map> events;
Expand Down Expand Up @@ -67,6 +67,7 @@ protected void prepare() {
if(this.config.containsKey("replace_fields")) {
this.replace_fields = (List<String>) this.config.get("replace_fields");
}

this.jdbcLink = String.format("jdbc:clickhouse://%s/%s", this.host, this.database);

// ClickHouseDataSource 不支持逗号","分割的多个节点
Expand Down Expand Up @@ -109,14 +110,16 @@ protected void bulkInsert(Map event) throws Exception{
if (e.containsKey(field)) {
if (e.get(field) instanceof String) {
String fieldValue = e.get(field).toString();
if (replace_fields.contains(field)) {
if (this.replace_fields != null && this.replace_fields.contains(field)) {
if (!(fieldValue.indexOf("'") > 0)){
value += "'" + e.get(field) + "'";
} else {
if (fieldValue.indexOf("\\'") > 0)
if (fieldValue.indexOf("\\'") > 0) {
value += "'" + fieldValue.replace("'", "\\'").replace("\\\\'", "\\\\\\'") + "'";
else
}
else {
value += "'" + fieldValue.replace("'", "\\'") + "'";
}
}
} else {
value += "'" + fieldValue + "'";
Expand Down

0 comments on commit 9be7990

Please sign in to comment.