mirror of
https://github.com/alibaba/DataX.git
synced 2025-05-03 06:21:01 +08:00
Supports importing bitmap and other types
This commit is contained in:
parent
86b7935bb4
commit
ad7a0cce6b
@ -6,6 +6,11 @@ import java.util.StringJoiner;
|
||||
|
||||
public class CopySQLBuilder {
|
||||
private final static String COPY_SYNC = "copy.async";
|
||||
private final static String FIELD_DELIMITER_KEY = "file.column_separator";
|
||||
private final static String FIELD_DELIMITER_DEFAULT = "\t";
|
||||
private final static String LINE_DELIMITER_KEY = "file.line_delimiter";
|
||||
private final static String LINE_DELIMITER_DEFAULT = "\n";
|
||||
private final static String COLUMNS = "columns";
|
||||
private final String fileName;
|
||||
private final Keys options;
|
||||
private Map<String, Object> properties;
|
||||
@ -21,19 +26,39 @@ public class CopySQLBuilder {
|
||||
public String buildCopySQL(){
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("COPY INTO ")
|
||||
.append(options.getDatabase() + "." + options.getTable())
|
||||
.append(" FROM @~('").append(fileName).append("') ")
|
||||
.append(options.getDatabase() + "." + options.getTable());
|
||||
|
||||
if (properties.get(COLUMNS) != null && !properties.get(COLUMNS).equals("")) {
|
||||
sb.append(" FROM ( SELECT ").append(properties.get(COLUMNS))
|
||||
.append(" FROM @~('").append(fileName).append("') ) ")
|
||||
.append("PROPERTIES (");
|
||||
} else {
|
||||
sb.append(" FROM @~('").append(fileName).append("') ")
|
||||
.append("PROPERTIES (");
|
||||
}
|
||||
|
||||
//copy into must be sync
|
||||
properties.put(COPY_SYNC,false);
|
||||
StringJoiner props = new StringJoiner(",");
|
||||
for(Map.Entry<String,Object> entry : properties.entrySet()){
|
||||
String key = String.valueOf(entry.getKey());
|
||||
String value = String.valueOf(entry.getValue());
|
||||
String value = "";
|
||||
switch (key){
|
||||
case FIELD_DELIMITER_KEY:
|
||||
value = DelimiterParser.parse(String.valueOf(entry.getValue()),FIELD_DELIMITER_DEFAULT);
|
||||
break;
|
||||
case LINE_DELIMITER_KEY:
|
||||
value = DelimiterParser.parse(String.valueOf(entry.getValue()),LINE_DELIMITER_DEFAULT);
|
||||
break;
|
||||
default:
|
||||
value = String.valueOf(entry.getValue());
|
||||
break;
|
||||
}
|
||||
if(!key.equals(COLUMNS)){
|
||||
String prop = String.format("'%s'='%s'", key, value);
|
||||
props.add(prop);
|
||||
}
|
||||
}
|
||||
sb.append(props).append(" )");
|
||||
return sb.toString();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user