Skip to content

Commit

Permalink
address comments
Browse files Browse the repository at this point in the history
  • Loading branch information
Xiaoji Chen committed Aug 6, 2019
1 parent cadef9f commit 9ca51e1
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 8 deletions.
2 changes: 1 addition & 1 deletion modules/csv/src/csv-loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ function parseCSVInBatches(asyncIterator, options) {

// Check if we need to save a header row
if (isFirstRow && !headerRow) {
const {header = isHeaderRow(row)} = options;
const header = options.header === undefined ? isHeaderRow(row) : options.header;
if (header) {
headerRow = row;
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ export default class ColumnarTableBatch {
this.pruneColumns();
const columns = Array.isArray(this.schema) ? this.columns : {};

// schema is an array if there're no headers
// object if there are headers
// columns should match schema format
if (!Array.isArray(this.schema)) {
for (const fieldName in this.schema) {
const field = this.schema[fieldName];
Expand Down
14 changes: 7 additions & 7 deletions modules/experimental/src/categories/table/row-table-batch.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ export default class RowTableBatch {
this.rows = null;
this.length = 0;

// schema is an array if there're no headers
// object if there are headers
if (!Array.isArray(schema)) {
this._headers = [];
for (const key in schema) {
Expand All @@ -18,7 +20,7 @@ export default class RowTableBatch {
this.rows = new Array(this.batchSize);
this.length = 0;
}
this.rows[this.length] = row;
this.rows[this.length] = convertRowToObject(row, this._headers);
this.length++;
}

Expand All @@ -28,12 +30,7 @@ export default class RowTableBatch {

getNormalizedBatch() {
if (this.rows) {
let rows = this.rows.slice(0, this.length);

if (this._headers) {
rows = rows.map(row => convertRowToObject(row, this._headers));
}

const rows = this.rows.slice(0, this.length);
this.rows = null;
return {data: rows, schema: this.schema, length: rows.length};
}
Expand All @@ -42,6 +39,9 @@ export default class RowTableBatch {
}

function convertRowToObject(row, headers) {
if (!headers) {
return row;
}
const result = {};
for (let i = 0; i < headers.length; i++) {
result[headers[i]] = row[i];
Expand Down

0 comments on commit 9ca51e1

Please sign in to comment.