teradatasql
Version:
Teradata SQL Driver for Node.js
80 lines • 3.53 kB
JavaScript
;
// Copyright 2023 by Teradata Corporation. All rights reserved.
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
Object.defineProperty(exports, "__esModule", { value: true });
// This sample program measures the time to insert one million rows as 100 batches of 10000 rows per batch.
// @ts-ignore
const teradatasql = __importStar(require("teradatasql"));
const con = teradatasql.connect({ host: "whomooz", user: "guest", password: "please" });
try {
const cur = con.cursor();
try {
const sTableName = "batchinsperf";
const nRowsPerBatch = 10000;
const nBatchCount = 100;
try {
cur.execute("drop table " + sTableName);
}
catch (ex) {
if (ex instanceof teradatasql.OperationalError) {
console.log("Ignoring", ex.message.split("\n")[0]);
}
else {
throw ex;
}
}
cur.execute("create table " + sTableName + " (c1 integer, c2 varchar(100), c3 integer, c4 varchar(100))");
try {
let dStartTime1 = Date.now();
for (let iBatch = 0; iBatch < nBatchCount; iBatch++) {
const aaoBatch = [];
for (let nRow = 1; nRow < nRowsPerBatch + 1; nRow++) {
const nValue = iBatch * nRowsPerBatch + nRow;
aaoBatch.push([nValue, "a" + nValue.toString(), -nValue, "b" + nValue.toString()]);
}
const dStartTime2 = Date.now();
cur.execute("insert into " + sTableName + " values (?, ?, ?, ?)", aaoBatch);
console.log(`Batch insert #${iBatch + 1} of ${nRowsPerBatch} rows took ${Date.now() - dStartTime2} ms`);
} // end for iBatch
let dTotalTime = Date.now() - dStartTime1;
console.log(`Inserting ${nBatchCount} batches containing ${nBatchCount * nRowsPerBatch} total rows took ${dTotalTime} ms for ${((nBatchCount * nRowsPerBatch) / dTotalTime) * 1000} rows/sec throughput`);
cur.execute("select count(*) from " + sTableName + " order by 1");
const row = cur.fetchone();
if (row) {
console.log(`Table ${sTableName} contains ` + row[0] + " rows");
}
}
finally {
cur.execute("drop table " + sTableName);
}
}
finally {
cur.close();
}
}
finally {
con.close();
}
//# sourceMappingURL=BatchInsPerf.js.map