Supports importing bitmap and other types

This commit is contained in:
caoliang 2024-01-11 12:01:57 +08:00
parent 86b7935bb4
commit ad7a0cce6b

View File

@ -6,6 +6,11 @@ import java.util.StringJoiner;
public class CopySQLBuilder { public class CopySQLBuilder {
private final static String COPY_SYNC = "copy.async"; 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 String fileName;
private final Keys options; private final Keys options;
private Map<String, Object> properties; private Map<String, Object> properties;
@ -21,18 +26,38 @@ public class CopySQLBuilder {
public String buildCopySQL(){ public String buildCopySQL(){
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
sb.append("COPY INTO ") sb.append("COPY INTO ")
.append(options.getDatabase() + "." + options.getTable()) .append(options.getDatabase() + "." + options.getTable());
.append(" FROM @~('").append(fileName).append("') ")
.append("PROPERTIES ("); 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 //copy into must be sync
properties.put(COPY_SYNC,false); properties.put(COPY_SYNC,false);
StringJoiner props = new StringJoiner(","); StringJoiner props = new StringJoiner(",");
for(Map.Entry<String,Object> entry : properties.entrySet()){ for(Map.Entry<String,Object> entry : properties.entrySet()){
String key = String.valueOf(entry.getKey()); String key = String.valueOf(entry.getKey());
String value = String.valueOf(entry.getValue()); String value = "";
String prop = String.format("'%s'='%s'",key,value); switch (key){
props.add(prop); 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(" )"); sb.append(props).append(" )");
return sb.toString(); return sb.toString();