use of net.snowflake.client.loader.LoaderProperty in project components by Talend.
the class SnowflakeWriter method open.
@Override
public void open(String uId) throws IOException {
this.uId = uId;
processingConnection = sink.createConnection(container);
uploadConnection = sink.createConnection(container);
if (null == mainSchema) {
mainSchema = sink.getRuntimeSchema(container);
}
SnowflakeConnectionProperties connectionProperties = sprops.getConnectionProperties();
Map<LoaderProperty, Object> prop = new HashMap<>();
boolean isUpperCase = sprops.convertColumnsAndTableToUppercase.getValue();
String tableName = isUpperCase ? sprops.getTableName().toUpperCase() : sprops.getTableName();
prop.put(LoaderProperty.tableName, tableName);
prop.put(LoaderProperty.schemaName, connectionProperties.schemaName.getStringValue());
prop.put(LoaderProperty.databaseName, connectionProperties.db.getStringValue());
switch(sprops.outputAction.getValue()) {
case INSERT:
prop.put(LoaderProperty.operation, Operation.INSERT);
break;
case UPDATE:
prop.put(LoaderProperty.operation, Operation.MODIFY);
break;
case UPSERT:
prop.put(LoaderProperty.operation, Operation.UPSERT);
break;
case DELETE:
prop.put(LoaderProperty.operation, Operation.DELETE);
break;
}
List<Field> columns = mainSchema.getFields();
List<String> keyStr = new ArrayList<>();
List<String> columnsStr = new ArrayList<>();
for (Field f : columns) {
String dbColumnName = f.getProp(SchemaConstants.TALEND_COLUMN_DB_COLUMN_NAME);
String fName = isUpperCase ? dbColumnName.toUpperCase() : dbColumnName;
columnsStr.add(fName);
if (null != f.getProp(SchemaConstants.TALEND_COLUMN_IS_KEY)) {
keyStr.add(fName);
}
}
row = new Object[columnsStr.size()];
prop.put(LoaderProperty.columns, columnsStr);
if (sprops.outputAction.getValue() == UPSERT) {
keyStr.clear();
keyStr.add(sprops.upsertKeyColumn.getValue());
}
if (keyStr.size() > 0) {
prop.put(LoaderProperty.keys, keyStr);
}
prop.put(LoaderProperty.remoteStage, "~");
loader = (StreamLoader) LoaderFactory.createLoader(prop, uploadConnection, processingConnection);
loader.setListener(listener);
loader.start();
}
Aggregations