From 59198e54d80ac4f2ca2e06a2e1c9bd95fc77933e Mon Sep 17 00:00:00 2001 From: manasibarate Date: Mon, 26 Oct 2020 17:31:01 +0530 Subject: [PATCH 1/5] Fix empty sql statement error --- lib/connections/snowflake.js | 18 ++++++++++++++---- package.json | 2 +- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/lib/connections/snowflake.js b/lib/connections/snowflake.js index de13b0e..811bfca 100644 --- a/lib/connections/snowflake.js +++ b/lib/connections/snowflake.js @@ -153,11 +153,15 @@ connection.prototype.query = function(query, data, callback, skipTransactions){ sqlText: query, binds: data, complete: function(err, stmt, rows) { - + isEmptySQLStatementError=false; if (err) { //In SQL Queries if there are empty lines between sql queries , snowflake throws a exception. This statement provides a workaround to not get that error. - if(String(err.message).includes('Empty SQL statement')) { - callback(null); + if(String(err.message).includes('Empty SQL statement')) { + self.book.logger.log('Error in : ' + String(query), 'error'); + self.book.logger.log('Error message : ' + err.message, 'error'); + self.book.logger.log('Stack Trace : ' + err.stack, 'error'); + // set the flag so that callback will be called only once + isEmptySQLStatementError=true; } else if(!(String(query).startsWith('SHOW COLUMNS') && String(query).endsWith('_TMP'))){ self.book.logger.log('Error in : ' + String(query), 'error'); self.book.logger.log('Error message : ' + err.message, 'error'); @@ -170,7 +174,13 @@ connection.prototype.query = function(query, data, callback, skipTransactions){ process.exit(1); } } - callback(err); + if(isEmptySQLStatementError){ + callback(null); + } + else{ + callback(err); + } + } else { if(String(query).includes('INSERT INTO EMPUJAR') ) { self.book.logger.log('Empujar insert , Query Id ' + stmt.getStatementId() + ' Payload Info : ' + String(data), 'debug'); diff --git a/package.json b/package.json index 8a794f7..4faf3d1 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "empujar", - "version": "0.2.23", + "version": "0.2.24", "description": "When you need to push data around, you push it. Push it real good. An ETL and Operations tool.", "main": "index.js", "engines": { From d2f646507604abcfb8037bb112f9977e7a7ff504 Mon Sep 17 00:00:00 2001 From: manasibarate Date: Tue, 27 Oct 2020 21:09:50 +0530 Subject: [PATCH 2/5] Checking in again so that the CI build can pass --- lib/connections/snowflake.js | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/connections/snowflake.js b/lib/connections/snowflake.js index 811bfca..6dd3f6b 100644 --- a/lib/connections/snowflake.js +++ b/lib/connections/snowflake.js @@ -160,7 +160,7 @@ connection.prototype.query = function(query, data, callback, skipTransactions){ self.book.logger.log('Error in : ' + String(query), 'error'); self.book.logger.log('Error message : ' + err.message, 'error'); self.book.logger.log('Stack Trace : ' + err.stack, 'error'); - // set the flag so that callback will be called only once + // set the flag so that callback will be called only once isEmptySQLStatementError=true; } else if(!(String(query).startsWith('SHOW COLUMNS') && String(query).endsWith('_TMP'))){ self.book.logger.log('Error in : ' + String(query), 'error'); diff --git a/package.json b/package.json index 4faf3d1..f6f4998 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "empujar", - "version": "0.2.24", + "version": "0.2.24" , "description": "When you need to push data around, you push it. Push it real good. An ETL and Operations tool.", "main": "index.js", "engines": { From 24646cbc56892cfcd792589d2805761dd7c23b14 Mon Sep 17 00:00:00 2001 From: manasibarate Date: Wed, 28 Oct 2020 15:08:29 +0530 Subject: [PATCH 3/5] Removing logging statements for empty sql and reset the flag --- lib/connections/snowflake.js | 9 ++++----- package.json | 2 +- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/lib/connections/snowflake.js b/lib/connections/snowflake.js index 6dd3f6b..63e00c8 100644 --- a/lib/connections/snowflake.js +++ b/lib/connections/snowflake.js @@ -156,10 +156,7 @@ connection.prototype.query = function(query, data, callback, skipTransactions){ isEmptySQLStatementError=false; if (err) { //In SQL Queries if there are empty lines between sql queries , snowflake throws a exception. This statement provides a workaround to not get that error. - if(String(err.message).includes('Empty SQL statement')) { - self.book.logger.log('Error in : ' + String(query), 'error'); - self.book.logger.log('Error message : ' + err.message, 'error'); - self.book.logger.log('Stack Trace : ' + err.stack, 'error'); + if(String(err.message).includes('Empty SQL statement')) { // set the flag so that callback will be called only once isEmptySQLStatementError=true; } else if(!(String(query).startsWith('SHOW COLUMNS') && String(query).endsWith('_TMP'))){ @@ -175,7 +172,9 @@ connection.prototype.query = function(query, data, callback, skipTransactions){ } } if(isEmptySQLStatementError){ - callback(null); + //reset the flag back to false so that next query can execute correctly + isEmptySQLStatementError=false; + callback(null); } else{ callback(err); diff --git a/package.json b/package.json index f6f4998..4faf3d1 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "empujar", - "version": "0.2.24" , + "version": "0.2.24", "description": "When you need to push data around, you push it. Push it real good. An ETL and Operations tool.", "main": "index.js", "engines": { From 6f0e2eafb98d378df0a2eebae0baa2b2cd8f8cfa Mon Sep 17 00:00:00 2001 From: manasibarate Date: Thu, 29 Oct 2020 15:38:43 +0530 Subject: [PATCH 4/5] Fix to return callback and not execute further lines of code Fix to return callback and not execute further lines of code --- lib/connections/snowflake.js | 21 +++++++-------------- 1 file changed, 7 insertions(+), 14 deletions(-) diff --git a/lib/connections/snowflake.js b/lib/connections/snowflake.js index 63e00c8..cac884b 100644 --- a/lib/connections/snowflake.js +++ b/lib/connections/snowflake.js @@ -152,13 +152,12 @@ connection.prototype.query = function(query, data, callback, skipTransactions){ var runner = self.connection.execute({ sqlText: query, binds: data, - complete: function(err, stmt, rows) { - isEmptySQLStatementError=false; + complete: function(err, stmt, rows) { if (err) { //In SQL Queries if there are empty lines between sql queries , snowflake throws a exception. This statement provides a workaround to not get that error. - if(String(err.message).includes('Empty SQL statement')) { - // set the flag so that callback will be called only once - isEmptySQLStatementError=true; + if(String(err.message).includes('Empty SQL statement')) { + //fix to avoid callback is already called error- We would want to continue the execution + return callback(null); } else if(!(String(query).startsWith('SHOW COLUMNS') && String(query).endsWith('_TMP'))){ self.book.logger.log('Error in : ' + String(query), 'error'); self.book.logger.log('Error message : ' + err.message, 'error'); @@ -170,15 +169,9 @@ connection.prototype.query = function(query, data, callback, skipTransactions){ self.book.logger.log('Exiting process due to Undefined Query Id ', 'error'); process.exit(1); } - } - if(isEmptySQLStatementError){ - //reset the flag back to false so that next query can execute correctly - isEmptySQLStatementError=false; - callback(null); - } - else{ - callback(err); - } + } + + return callback(err); } else { if(String(query).includes('INSERT INTO EMPUJAR') ) { From f09bf3ec930b8c4692aecd569e5a8f7a25234acc Mon Sep 17 00:00:00 2001 From: manasibarate Date: Thu, 29 Oct 2020 16:36:24 +0530 Subject: [PATCH 5/5] Changed the logic to return callback if error condition is met Changed the logic to return callback if error condition is met --- lib/connections/snowflake.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/connections/snowflake.js b/lib/connections/snowflake.js index cac884b..d113c84 100644 --- a/lib/connections/snowflake.js +++ b/lib/connections/snowflake.js @@ -157,7 +157,7 @@ connection.prototype.query = function(query, data, callback, skipTransactions){ //In SQL Queries if there are empty lines between sql queries , snowflake throws a exception. This statement provides a workaround to not get that error. if(String(err.message).includes('Empty SQL statement')) { //fix to avoid callback is already called error- We would want to continue the execution - return callback(null); + return callback(null); } else if(!(String(query).startsWith('SHOW COLUMNS') && String(query).endsWith('_TMP'))){ self.book.logger.log('Error in : ' + String(query), 'error'); self.book.logger.log('Error message : ' + err.message, 'error'); @@ -171,7 +171,7 @@ connection.prototype.query = function(query, data, callback, skipTransactions){ } } - return callback(err); + callback(err); } else { if(String(query).includes('INSERT INTO EMPUJAR') ) {