Skip to content

Commit df3e352

Browse files
committed
Pre-merge updates
Renamed from preamble/postamble to presql/postsql to be more specific and ensure translation across languages Updated index.js to make all pre/post sql transactional
1 parent acc6a14 commit df3e352

File tree

5 files changed

+24
-22
lines changed

5 files changed

+24
-22
lines changed

config.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
"table": "sensor_data_raw",
1010
"columnList": "",
1111
"truncateTable": "N",
12-
"preamble": "",
13-
"postamble": "",
12+
"presql": "",
13+
"postsql": "",
1414
"userName": "master",
1515
"userPwd": " ",
1616
"df": "CSV",

config.json.commented

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,10 @@
3737
"truncateTable": "",
3838
// Customized SQL that is placed just before the copy command.
3939
// This must end with a semicolon, and work with the other options that generate the copy command.
40-
"preamble": "",
40+
"presql": "",
4141
// Customized SQL that is placed just after the copy command.
4242
// This must end with a semicolon, and work with the other options that generate the copy command.
43-
"postamble": "",
43+
"postsql": "",
4444
// Enter the Database Username Y
4545
// The username which should be used to connect to perform the COPY.
4646
// Please note that only table owners can perform COPY, so this should
-26.9 KB
Binary file not shown.

index.js

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1034,14 +1034,16 @@ exports.handler = function (event, context) {
10341034
copyCommand = 'set statement_timeout to 60000;\n';
10351035
}
10361036

1037-
// if the preamble option is set, insert it into the copyCommand
1038-
if (clusterInfo.preamble && clusterInfo.preamble.S) {
1039-
copyCommand += clusterInfo.preamble.S + '\n'
1037+
// open a transaction so that all pre-sql, load, and post-sql commit at once
1038+
copyCommand += 'begin;\n';
1039+
1040+
// if the presql option is set, insert it into the copyCommand
1041+
if (clusterInfo.presql && clusterInfo.presql.S) {
1042+
copyCommand += clusterInfo.presql.S + (clusterInfo.presql.S.slice(-1) == ";" ? "" : ";") + '\n'
10401043
}
10411044

10421045
var copyOptions = "manifest ";
10431046

1044-
copyCommand += 'begin;\n';
10451047
// add the truncate option if requested
10461048
if (clusterInfo.truncateTarget && clusterInfo.truncateTarget.BOOL) {
10471049
copyCommand += 'truncate table ' + clusterInfo.targetTable.S + ';\n';
@@ -1169,9 +1171,9 @@ exports.handler = function (event, context) {
11691171
// build the final copy command
11701172
copyCommand = copyCommand + " with credentials as \'" + credentials + "\' " + copyOptions + ";\n";
11711173

1172-
// if the postamble option is set, insert it into the copyCommand
1173-
if (clusterInfo.postamble && clusterInfo.postamble.S) {
1174-
copyCommand += clusterInfo.postamble.S + '\n'
1174+
// if the post-sql option is set, insert it into the copyCommand
1175+
if (clusterInfo.postsql && clusterInfo.postsql.S) {
1176+
copyCommand += clusterInfo.postsql.S + (clusterInfo.postsql.S.slice(-1) == ";" ? "" : ";") + '\n'
11751177
}
11761178

11771179
copyCommand += 'commit;';

setup-file.js

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -201,23 +201,23 @@ q_truncateTable = function (callback) {
201201
callback(null);
202202
};
203203

204-
q_preamble = function (callback) {
205-
// the preamble sql lines
206-
if (setupConfig.preamble && common.blank(setupConfig.preamble) !== null) {
207-
dynamoConfig.Item.loadClusters.L[0].M.preamble = {
208-
S: setupConfig.preamble
204+
q_presql = function (callback) {
205+
// the pre-sql lines
206+
if (setupConfig.presql && common.blank(setupConfig.presql) !== null) {
207+
dynamoConfig.Item.loadClusters.L[0].M.presql = {
208+
S: setupConfig.presql
209209
};
210210
callback(null);
211211
} else {
212212
callback(null);
213213
}
214214
};
215215

216-
q_postamble = function (callback) {
216+
q_postsql = function (callback) {
217217
// the postamble sql lines
218-
if (setupConfig.postamble && common.blank(setupConfig.postamble) !== null) {
219-
dynamoConfig.Item.loadClusters.L[0].M.postamble = {
220-
S: setupConfig.postamble
218+
if (setupConfig.postsql && common.blank(setupConfig.postsql) !== null) {
219+
dynamoConfig.Item.loadClusters.L[0].M.postsql = {
220+
S: setupConfig.postsql
221221
};
222222
callback(null);
223223
} else {
@@ -439,8 +439,8 @@ qs.push(q_clusterDB);
439439
qs.push(q_table);
440440
qs.push(q_columnList);
441441
qs.push(q_truncateTable);
442-
qs.push(q_preamble);
443-
qs.push(q_postamble);
442+
qs.push(q_presql);
443+
qs.push(q_postsql);
444444
qs.push(q_userName);
445445
qs.push(q_userPwd);
446446
qs.push(q_df);

0 commit comments

Comments
 (0)