Skip to content

Commit

Permalink
0001633: MySQL bulk loader error with Windows-based server
Browse files Browse the repository at this point in the history
  • Loading branch information
erilong committed Mar 5, 2014
1 parent 2768467 commit e1a0fff
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 12 deletions.
Expand Up @@ -73,12 +73,9 @@ public void write(CsvData data) {
statistics.get(batch).startTimer(DataWriterStatisticConstants.DATABASEMILLIS);
try {
String formattedData = CsvUtils.escapeCsvData(
data.getParsedData(CsvData.ROW_DATA), ' ', '"',
data.getParsedData(CsvData.ROW_DATA), '\n', '"',
CsvWriter.ESCAPE_MODE_DOUBLED);
byte[] dataToLoad = formattedData.getBytes();
this.stagedInputFile.getOutputStream().write(dataToLoad);
this.stagedInputFile.getOutputStream().write('\r');
this.stagedInputFile.getOutputStream().write('\n');
this.stagedInputFile.getOutputStream().write(formattedData.getBytes());
loadedRows++;
} catch (Exception ex) {
throw getPlatform().getSqlTemplate().translate(ex);
Expand Down Expand Up @@ -107,14 +104,14 @@ protected void flush() {
JdbcSqlTransaction jdbcTransaction = (JdbcSqlTransaction) transaction;
Connection c = jdbcTransaction.getConnection();
String sql = String.format("LOAD DATA " + (isLocal ? "LOCAL " : "") +
"INFILE '" + stagedInputFile.getFile().getAbsolutePath()) + "' " +
"INFILE '" + stagedInputFile.getFile().getAbsolutePath()).replace('\\', '/') + "' " +
(isReplace ? "REPLACE " : "IGNORE ") + "INTO TABLE " +
this.getTargetTable().getFullyQualifiedTableName() +
" FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '\"' ESCAPED BY '\\\\' LINES TERMINATED BY '\\n' STARTING BY ''";
Statement stmt = c.createStatement();

//TODO: clean this up, deal with errors, etc.?
log.error(sql);
log.debug(sql);
stmt.execute(sql);
stmt.close();

Expand Down
10 changes: 5 additions & 5 deletions symmetric-core/src/main/resources/symmetric-default.properties
Expand Up @@ -1181,36 +1181,36 @@ bsh.load.filter.handles.missing.tables=false

# Maximum number of rows to write to file before running with 'LOAD DATA INFILE' to MySQL
#
# DatabaseOverridable: true
# DatabaseOverridable: false
# Tags: other
# Type: boolean
mysql.bulk.load.max.rows.before.flush=100000

# Whether or not files are local to client only, so we must send the file to MySQL to load.
# If client is running on same server as MySQL, then this can be set to false to have MySQL read file directly.
#
# DatabaseOverridable: true
# DatabaseOverridable: false
# Tags: other
# Type: boolean
mysql.bulk.load.local=true

# Whether or not to replace rows that already exist, based on primary key or unique key.
# If set to false, duplicates will be skipped.
#
# DatabaseOverridable: true
# DatabaseOverridable: false
# Tags: other
# Type: boolean
mysql.bulk.load.replace=false

# Maximum number of rows to write to file before running with "BULK INSERT" to SQL-Server
#
# DatabaseOverridable: true
# DatabaseOverridable: false
# Tags: other
mssql.bulk.load.max.rows.before.flush=100000

# Whether or not triggers should be allowed to fire when bulk loading data.
#
# DatabaseOverridable: true
# DatabaseOverridable: false
# Tags: other
# Type: boolean
mssql.bulk.load.fire.triggers=false

0 comments on commit e1a0fff

Please sign in to comment.