array of promises containing cassandra queris not triggering well











up vote
1
down vote

favorite












I'm currently trying to fill a cassandra table with the content of an xlsx file, but i'm facing a problem.



I managed to do an array with all the queries necessary to fill my table ("insert into my_table (values name, ...) values (values, ...);" ).
So my array got like 7000 strings.



I'm then doing a promise and inside this promise I made a loop to fill and array of promises in order to trigger the first promise when all the promises are over.



this is the code I made



index.js =>



const ImportFileContent = require("./scripts/import_file_content")
const InsertDb = require("./scripts/insertDb")

const cassandra = require('cassandra-driver');
const databaseConfig = require('./config/database.json');

const authProvider = new cassandra.auth.PlainTextAuthProvider(databaseConfig.cassandra.username, databaseConfig.cassandra.password);

const db = new cassandra.Client({
contactPoints: databaseConfig.cassandra.contactPoints,
authProvider: authProvider
});


// ImportFileContent.importFileContent return an array of string, those strings contains all the 7000+ queries
ImportFileContent.importFileContent().then(queries => {
InsertDb.clients(db, queries).then(result => {
console.log(result);
db.shutdown(function (err, result) {
});
});
});


insertDb.js =>



let DB = null;

module.exports = {
ClientsLeasing: function (db, queries) {
DB = db;
return insertClientsLeasing(queries);
}
}

function insertClientsLeasing(queries) {
return new Promise((resolve, reject) => {
let nbError = 0;
let nbSuccess = 0;
let promisesArray = ;
//I made i <2000 here because my cassandra setup doesn't manage more than 2048 request in parallele
for (let i = 0; i < 2000; i++) {
promisesArray.push(new Promise(function (resolve, reject) {
DB.execute(queries[i], function (err, result) {
if (err) {
nbError++;
reject(err)
} else {
nbSuccess++;
resolve();
}
});
}));
}
Promise.all(promisesArray).then((result) => {
console.log("is over")
console.log("over ===================== success => ", nbSuccess, " errors => ", nbError);
resolve("success");
}).catch((error) => {
console.log(error);
console.log("is over error")
console.log("over ===================== success => ", nbSuccess, " errors => ", nbError);
resolve("error");
});

});
}


My table got two primary keys the creation date (wich is now()) and the client id that may be in multiple rows of the xlsx (that can be the source of the problem ?).



So now when i launch this code my output is enter image description here



then when i do a count in the table via cqls i only get 1962 rows with this output
enter image description here



I feel like i'm missing something in the way I use my promises. I don't really get it.



Thanks










share|improve this question




















  • 2




    please add the table schema, and queries that you execute - it could be that your primary key definition isn't correct, and you simply overwrite the data...
    – Alex Ott
    2 days ago










  • the table i'm trying to insert the value has two primary keys, the date of insert (now()) and a client id. that client id may be in multiple rows, is that the source of the problem ? I thought now was used to create uuid ? here it's just for the date but it's used in the primary key. I'm working with an existing table and i can't really change it
    – lanetrotro
    2 days ago












  • ok so you were right the problem was that i overwrited some data. thanks for the help :)
    – lanetrotro
    2 days ago















up vote
1
down vote

favorite












I'm currently trying to fill a cassandra table with the content of an xlsx file, but i'm facing a problem.



I managed to do an array with all the queries necessary to fill my table ("insert into my_table (values name, ...) values (values, ...);" ).
So my array got like 7000 strings.



I'm then doing a promise and inside this promise I made a loop to fill and array of promises in order to trigger the first promise when all the promises are over.



this is the code I made



index.js =>



const ImportFileContent = require("./scripts/import_file_content")
const InsertDb = require("./scripts/insertDb")

const cassandra = require('cassandra-driver');
const databaseConfig = require('./config/database.json');

const authProvider = new cassandra.auth.PlainTextAuthProvider(databaseConfig.cassandra.username, databaseConfig.cassandra.password);

const db = new cassandra.Client({
contactPoints: databaseConfig.cassandra.contactPoints,
authProvider: authProvider
});


// ImportFileContent.importFileContent return an array of string, those strings contains all the 7000+ queries
ImportFileContent.importFileContent().then(queries => {
InsertDb.clients(db, queries).then(result => {
console.log(result);
db.shutdown(function (err, result) {
});
});
});


insertDb.js =>



let DB = null;

module.exports = {
ClientsLeasing: function (db, queries) {
DB = db;
return insertClientsLeasing(queries);
}
}

function insertClientsLeasing(queries) {
return new Promise((resolve, reject) => {
let nbError = 0;
let nbSuccess = 0;
let promisesArray = ;
//I made i <2000 here because my cassandra setup doesn't manage more than 2048 request in parallele
for (let i = 0; i < 2000; i++) {
promisesArray.push(new Promise(function (resolve, reject) {
DB.execute(queries[i], function (err, result) {
if (err) {
nbError++;
reject(err)
} else {
nbSuccess++;
resolve();
}
});
}));
}
Promise.all(promisesArray).then((result) => {
console.log("is over")
console.log("over ===================== success => ", nbSuccess, " errors => ", nbError);
resolve("success");
}).catch((error) => {
console.log(error);
console.log("is over error")
console.log("over ===================== success => ", nbSuccess, " errors => ", nbError);
resolve("error");
});

});
}


My table got two primary keys the creation date (wich is now()) and the client id that may be in multiple rows of the xlsx (that can be the source of the problem ?).



So now when i launch this code my output is enter image description here



then when i do a count in the table via cqls i only get 1962 rows with this output
enter image description here



I feel like i'm missing something in the way I use my promises. I don't really get it.



Thanks










share|improve this question




















  • 2




    please add the table schema, and queries that you execute - it could be that your primary key definition isn't correct, and you simply overwrite the data...
    – Alex Ott
    2 days ago










  • the table i'm trying to insert the value has two primary keys, the date of insert (now()) and a client id. that client id may be in multiple rows, is that the source of the problem ? I thought now was used to create uuid ? here it's just for the date but it's used in the primary key. I'm working with an existing table and i can't really change it
    – lanetrotro
    2 days ago












  • ok so you were right the problem was that i overwrited some data. thanks for the help :)
    – lanetrotro
    2 days ago













up vote
1
down vote

favorite









up vote
1
down vote

favorite











I'm currently trying to fill a cassandra table with the content of an xlsx file, but i'm facing a problem.



I managed to do an array with all the queries necessary to fill my table ("insert into my_table (values name, ...) values (values, ...);" ).
So my array got like 7000 strings.



I'm then doing a promise and inside this promise I made a loop to fill and array of promises in order to trigger the first promise when all the promises are over.



this is the code I made



index.js =>



const ImportFileContent = require("./scripts/import_file_content")
const InsertDb = require("./scripts/insertDb")

const cassandra = require('cassandra-driver');
const databaseConfig = require('./config/database.json');

const authProvider = new cassandra.auth.PlainTextAuthProvider(databaseConfig.cassandra.username, databaseConfig.cassandra.password);

const db = new cassandra.Client({
contactPoints: databaseConfig.cassandra.contactPoints,
authProvider: authProvider
});


// ImportFileContent.importFileContent return an array of string, those strings contains all the 7000+ queries
ImportFileContent.importFileContent().then(queries => {
InsertDb.clients(db, queries).then(result => {
console.log(result);
db.shutdown(function (err, result) {
});
});
});


insertDb.js =>



let DB = null;

module.exports = {
ClientsLeasing: function (db, queries) {
DB = db;
return insertClientsLeasing(queries);
}
}

function insertClientsLeasing(queries) {
return new Promise((resolve, reject) => {
let nbError = 0;
let nbSuccess = 0;
let promisesArray = ;
//I made i <2000 here because my cassandra setup doesn't manage more than 2048 request in parallele
for (let i = 0; i < 2000; i++) {
promisesArray.push(new Promise(function (resolve, reject) {
DB.execute(queries[i], function (err, result) {
if (err) {
nbError++;
reject(err)
} else {
nbSuccess++;
resolve();
}
});
}));
}
Promise.all(promisesArray).then((result) => {
console.log("is over")
console.log("over ===================== success => ", nbSuccess, " errors => ", nbError);
resolve("success");
}).catch((error) => {
console.log(error);
console.log("is over error")
console.log("over ===================== success => ", nbSuccess, " errors => ", nbError);
resolve("error");
});

});
}


My table got two primary keys the creation date (wich is now()) and the client id that may be in multiple rows of the xlsx (that can be the source of the problem ?).



So now when i launch this code my output is enter image description here



then when i do a count in the table via cqls i only get 1962 rows with this output
enter image description here



I feel like i'm missing something in the way I use my promises. I don't really get it.



Thanks










share|improve this question















I'm currently trying to fill a cassandra table with the content of an xlsx file, but i'm facing a problem.



I managed to do an array with all the queries necessary to fill my table ("insert into my_table (values name, ...) values (values, ...);" ).
So my array got like 7000 strings.



I'm then doing a promise and inside this promise I made a loop to fill and array of promises in order to trigger the first promise when all the promises are over.



this is the code I made



index.js =>



const ImportFileContent = require("./scripts/import_file_content")
const InsertDb = require("./scripts/insertDb")

const cassandra = require('cassandra-driver');
const databaseConfig = require('./config/database.json');

const authProvider = new cassandra.auth.PlainTextAuthProvider(databaseConfig.cassandra.username, databaseConfig.cassandra.password);

const db = new cassandra.Client({
contactPoints: databaseConfig.cassandra.contactPoints,
authProvider: authProvider
});


// ImportFileContent.importFileContent return an array of string, those strings contains all the 7000+ queries
ImportFileContent.importFileContent().then(queries => {
InsertDb.clients(db, queries).then(result => {
console.log(result);
db.shutdown(function (err, result) {
});
});
});


insertDb.js =>



let DB = null;

module.exports = {
ClientsLeasing: function (db, queries) {
DB = db;
return insertClientsLeasing(queries);
}
}

function insertClientsLeasing(queries) {
return new Promise((resolve, reject) => {
let nbError = 0;
let nbSuccess = 0;
let promisesArray = ;
//I made i <2000 here because my cassandra setup doesn't manage more than 2048 request in parallele
for (let i = 0; i < 2000; i++) {
promisesArray.push(new Promise(function (resolve, reject) {
DB.execute(queries[i], function (err, result) {
if (err) {
nbError++;
reject(err)
} else {
nbSuccess++;
resolve();
}
});
}));
}
Promise.all(promisesArray).then((result) => {
console.log("is over")
console.log("over ===================== success => ", nbSuccess, " errors => ", nbError);
resolve("success");
}).catch((error) => {
console.log(error);
console.log("is over error")
console.log("over ===================== success => ", nbSuccess, " errors => ", nbError);
resolve("error");
});

});
}


My table got two primary keys the creation date (wich is now()) and the client id that may be in multiple rows of the xlsx (that can be the source of the problem ?).



So now when i launch this code my output is enter image description here



then when i do a count in the table via cqls i only get 1962 rows with this output
enter image description here



I feel like i'm missing something in the way I use my promises. I don't really get it.



Thanks







javascript node.js cassandra es6-promise






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited 2 days ago

























asked Nov 19 at 9:18









lanetrotro

669




669








  • 2




    please add the table schema, and queries that you execute - it could be that your primary key definition isn't correct, and you simply overwrite the data...
    – Alex Ott
    2 days ago










  • the table i'm trying to insert the value has two primary keys, the date of insert (now()) and a client id. that client id may be in multiple rows, is that the source of the problem ? I thought now was used to create uuid ? here it's just for the date but it's used in the primary key. I'm working with an existing table and i can't really change it
    – lanetrotro
    2 days ago












  • ok so you were right the problem was that i overwrited some data. thanks for the help :)
    – lanetrotro
    2 days ago














  • 2




    please add the table schema, and queries that you execute - it could be that your primary key definition isn't correct, and you simply overwrite the data...
    – Alex Ott
    2 days ago










  • the table i'm trying to insert the value has two primary keys, the date of insert (now()) and a client id. that client id may be in multiple rows, is that the source of the problem ? I thought now was used to create uuid ? here it's just for the date but it's used in the primary key. I'm working with an existing table and i can't really change it
    – lanetrotro
    2 days ago












  • ok so you were right the problem was that i overwrited some data. thanks for the help :)
    – lanetrotro
    2 days ago








2




2




please add the table schema, and queries that you execute - it could be that your primary key definition isn't correct, and you simply overwrite the data...
– Alex Ott
2 days ago




please add the table schema, and queries that you execute - it could be that your primary key definition isn't correct, and you simply overwrite the data...
– Alex Ott
2 days ago












the table i'm trying to insert the value has two primary keys, the date of insert (now()) and a client id. that client id may be in multiple rows, is that the source of the problem ? I thought now was used to create uuid ? here it's just for the date but it's used in the primary key. I'm working with an existing table and i can't really change it
– lanetrotro
2 days ago






the table i'm trying to insert the value has two primary keys, the date of insert (now()) and a client id. that client id may be in multiple rows, is that the source of the problem ? I thought now was used to create uuid ? here it's just for the date but it's used in the primary key. I'm working with an existing table and i can't really change it
– lanetrotro
2 days ago














ok so you were right the problem was that i overwrited some data. thanks for the help :)
– lanetrotro
2 days ago




ok so you were right the problem was that i overwrited some data. thanks for the help :)
– lanetrotro
2 days ago

















active

oldest

votes











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














 

draft saved


draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53371507%2farray-of-promises-containing-cassandra-queris-not-triggering-well%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown






























active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes
















 

draft saved


draft discarded



















































 


draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53371507%2farray-of-promises-containing-cassandra-queris-not-triggering-well%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

'app-layout' is not a known element: how to share Component with different Modules

android studio warns about leanback feature tag usage required on manifest while using Unity exported app?

WPF add header to Image with URL pettitions [duplicate]