This commit is contained in:
Pablo Moyano 2013-12-25 13:12:13 -03:00
parent f45ea488cd
commit a1cd605968

View File

@ -37,7 +37,7 @@ final class FusionTableSerializer implements TabularSerializer {
@Override @Override
public void endFile() { public void endFile() {
if (sbBatch != null) { if (sbBatch != null) {
sendBatch(); sendBatch(true);
} }
} }
@ -61,14 +61,14 @@ final class FusionTableSerializer implements TabularSerializer {
formatCsv(cells, sbBatch); formatCsv(cells, sbBatch);
rows++; rows++;
if (rows % BATCH_SIZE == 0) { if (rows % BATCH_SIZE == 0) {
if (!sendBatch()) { if (!sendBatch(false)) {
return; return;
} }
} }
} }
} }
private boolean sendBatch() { private boolean sendBatch(boolean isLastChunk) {
try { try {
// FIXME: text/csv doesn't work even though that's what the content is // FIXME: text/csv doesn't work even though that's what the content is
AbstractInputStreamContent content = ByteArrayContent.fromString("application/octet-stream", sbBatch.toString()); AbstractInputStreamContent content = ByteArrayContent.fromString("application/octet-stream", sbBatch.toString());
@ -77,8 +77,9 @@ final class FusionTableSerializer implements TabularSerializer {
// // TODO: we really want to do GZIP compression here // // TODO: we really want to do GZIP compression here
// new ByteArrayInputStream(sbBatch.toString().getBytes("UTF-8"))); // new ByteArrayInputStream(sbBatch.toString().getBytes("UTF-8")));
Long count = FusionTableHandler.insertRows(service, tableId, content); Long count = FusionTableHandler.insertRows(service, tableId, content);
if (count != BATCH_SIZE) { if (!isLastChunk && count != BATCH_SIZE) {
exceptions.add(new IOException("only imported %d of %d rows")); // FIXME: this message should say numbers instead of %d but we'd need to know the batch number for this
exceptions.add(new IOException("Only imported %d of %d rows"));
} }
} catch (IOException e) { } catch (IOException e) {
exceptions.add(e); exceptions.add(e);