Skip to content

Commit

Permalink
feat: Speedup PG external pre-aggregations (#201)
Browse files Browse the repository at this point in the history
* Speedup PG aggregations

* Clean up postgres driver

* Remove unnecessary cast

* Add fromGenericType conversion

Fixes #200
  • Loading branch information
landyrev authored and paveltiunov committed Sep 5, 2019
1 parent 646ec74 commit 7abf504
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions packages/cubejs-postgres-driver/driver/PostgresDriver.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,24 @@ class PostgresDriver extends BaseDriver {
}
}

async uploadTable(table, columns, tableData) {
if (!tableData.rows) {
throw new Error(`${this.constructor} driver supports only rows upload`);
}
await this.createTable(table, columns);
try {
await this.query(
`INSERT INTO ${table}
(${columns.map(c => this.quoteIdentifier(c.name)).join(', ')})
SELECT * FROM UNNEST (${columns.map((c, columnIndex) => `${this.param(columnIndex)}::${this.fromGenericType(c.type)}[]`).join(', ')})`,
columns.map(c => tableData.rows.map(r => r[c.name]))
);
} catch (e) {
await this.dropTable(table);
throw e;
}
}

release() {
return this.pool.end();
}
Expand Down

0 comments on commit 7abf504

Please sign in to comment.