forked from wgzhao/Addax
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[doriswriter] merge office doriswriter codes (wgzhao#448)
- Loading branch information
Showing
10 changed files
with
657 additions
and
108 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
77 changes: 77 additions & 0 deletions
77
...iter/doriswriter/src/main/java/com/wgzhao/addax/plugin/writer/doriswriter/DorisCodec.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
/* | ||
* 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 com.wgzhao.addax.plugin.writer.doriswriter; | ||
|
||
import com.wgzhao.addax.common.element.Column; | ||
import com.wgzhao.addax.common.element.DateColumn; | ||
import com.wgzhao.addax.common.element.Record; | ||
import org.apache.commons.lang3.time.DateFormatUtils; | ||
|
||
import java.util.List; | ||
import java.util.TimeZone; | ||
|
||
public abstract class DorisCodec | ||
{ | ||
protected static String timeZone = "GMT+8"; | ||
protected static TimeZone timeZoner = TimeZone.getTimeZone(timeZone); | ||
protected final List<String> fieldNames; | ||
|
||
public DorisCodec(final List<String> fieldNames) { | ||
this.fieldNames = fieldNames; | ||
} | ||
|
||
public abstract String serialize(Record row); | ||
|
||
/** | ||
* convert datax internal data to string | ||
* | ||
* @param col | ||
* @return | ||
*/ | ||
protected Object convertColumn(final Column col) { | ||
if (null == col.getRawData()) { | ||
return null; | ||
} | ||
Column.Type type = col.getType(); | ||
switch (type) { | ||
case BOOL: | ||
case INT: | ||
case LONG: | ||
return col.asLong(); | ||
case DOUBLE: | ||
return col.asDouble(); | ||
case STRING: | ||
return col.asString(); | ||
case DATE: { | ||
final DateColumn.DateType dateType = ((DateColumn) col).getSubType(); | ||
switch (dateType) { | ||
case DATE: | ||
return DateFormatUtils.format(col.asDate(), "yyyy-MM-dd", timeZoner); | ||
case DATETIME: | ||
return DateFormatUtils.format(col.asDate(), "yyyy-MM-dd HH:mm:ss", timeZoner); | ||
default: | ||
return col.asString(); | ||
} | ||
} | ||
default: | ||
// BAD, NULL, BYTES | ||
return null; | ||
} | ||
} | ||
} |
52 changes: 52 additions & 0 deletions
52
...r/doriswriter/src/main/java/com/wgzhao/addax/plugin/writer/doriswriter/DorisCsvCodec.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/* | ||
* 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 com.wgzhao.addax.plugin.writer.doriswriter; | ||
|
||
import com.wgzhao.addax.common.element.Record; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
public class DorisCsvCodec | ||
extends DorisCodec | ||
{ | ||
private final String columnSeparator; | ||
|
||
public DorisCsvCodec(final List<String> fieldNames, String columnSeparator) | ||
{ | ||
super(fieldNames); | ||
this.columnSeparator = columnSeparator; | ||
} | ||
|
||
@Override | ||
public String serialize(final Record row) | ||
{ | ||
if (null == this.fieldNames) { | ||
return ""; | ||
} | ||
List<String> list = new ArrayList<>(); | ||
|
||
for (int i = 0; i < this.fieldNames.size(); i++) { | ||
Object value = this.convertColumn(row.getColumn(i)); | ||
list.add(value != null ? value.toString() : "\\N"); | ||
} | ||
|
||
return String.join(columnSeparator, list); | ||
} | ||
} |
59 changes: 59 additions & 0 deletions
59
...doriswriter/src/main/java/com/wgzhao/addax/plugin/writer/doriswriter/DorisFlushBatch.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
/* | ||
* 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 com.wgzhao.addax.plugin.writer.doriswriter; | ||
|
||
public class DorisFlushBatch | ||
{ | ||
private final String lineDelimiter; | ||
private String label; | ||
private long rows = 0; | ||
private final StringBuilder data = new StringBuilder(); | ||
|
||
public DorisFlushBatch(String lineDelimiter) { | ||
this.lineDelimiter = lineDelimiter; | ||
} | ||
|
||
public void setLabel(String label) { | ||
this.label = label; | ||
} | ||
|
||
public String getLabel() { | ||
return label; | ||
} | ||
|
||
public long getRows() { | ||
return rows; | ||
} | ||
|
||
public void putData(String row) { | ||
if (data.length() > 0) { | ||
data.append(lineDelimiter); | ||
} | ||
data.append(row); | ||
rows++; | ||
} | ||
|
||
public StringBuilder getData() { | ||
return data; | ||
} | ||
|
||
public long getSize() { | ||
return data.length(); | ||
} | ||
} |
50 changes: 50 additions & 0 deletions
50
.../doriswriter/src/main/java/com/wgzhao/addax/plugin/writer/doriswriter/DorisJsonCodec.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
/* | ||
* 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 com.wgzhao.addax.plugin.writer.doriswriter; | ||
|
||
import com.alibaba.fastjson.JSON; | ||
import com.wgzhao.addax.common.element.Record; | ||
|
||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
public class DorisJsonCodec | ||
extends DorisCodec | ||
{ | ||
public DorisJsonCodec(final List<String> fieldNames) | ||
{ | ||
super(fieldNames); | ||
} | ||
|
||
@Override | ||
public String serialize(final Record row) | ||
{ | ||
if (null == this.fieldNames) { | ||
return ""; | ||
} | ||
final Map<String, Object> rowMap = new HashMap<>(this.fieldNames.size()); | ||
int idx = 0; | ||
for (final String fieldName : this.fieldNames) { | ||
rowMap.put(fieldName, this.convertColumn(row.getColumn(idx))); | ||
++idx; | ||
} | ||
return JSON.toJSONString(rowMap); | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
...writer/doriswriter/src/main/java/com/wgzhao/addax/plugin/writer/doriswriter/DorisKey.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/* | ||
* 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 com.wgzhao.addax.plugin.writer.doriswriter; | ||
|
||
import com.wgzhao.addax.common.base.Key; | ||
|
||
public class DorisKey extends Key | ||
{ | ||
public final static String LINE_DELIMITER = "lineDelimiter"; | ||
public static final String CONNECT_TIMEOUT = "connectTimeout"; | ||
public static final String LOAD_PROPS = "loadProps"; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.