8000 change so that empty strings are treated as is · classmethod/athena-query@edd96a9 · GitHub
[go: up one dir, main page]

Skip to content

Commit edd96a9

Browse files
committed
change so that empty strings are treated as is
1 parent 85e8e46 commit edd96a9

File tree

2 files changed

+41
-2
lines changed

2 files changed

+41
-2
lines changed

src/helper.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ function cleanUpPaginatedDML(
8888
if (!Data) return acc;
8989

9090
const rowObject = Data?.reduce((acc, row, index) => {
91-
if (row.VarCharValue) {
91+
if (row.VarCharValue !== undefined && row.VarCharValue !== null) {
9292
// use mutable operation for performance
9393
acc[columnNames[index]] = row.VarCharValue;
9494
}
@@ -113,7 +113,7 @@ function addDataType(
113113
> = {};
114114

115115
for (const key in input) {
116-
if (!input[key]) {
116+
if (input[key] === null || input[key] === undefined) {
117117
updatedObjectWithDataType[key] = null;
118118
} else {
119119
switch (dataTypes[key]) {

test/index.test.ts

Lines changed: 39 additions & 0 deletions
< 7F0A tr class="diff-line-row">
Original file line numberDiff line numberDiff line change
@@ -312,3 +312,42 @@ test("throw exception when query is respond as failed", async () => {
312312
"No QueryExecutionId was responded."
313313
);
314314
});
315+
316+
test.only("If empty string is returned from AthenaSDK, it will be returned as an empty string", async () => {
317+
athenaMock
318+
.on(StartQueryExecutionCommand)
319+
.resolves({ QueryExecutionId: "test-QueryExecutionId" })
320+
.on(GetQueryExecutionCommand)
321+
.resolves({ QueryExecution: { Status: { State: "SUCCEEDED" } } })
322+
.on(GetQueryResultsCommand)
323+
.resolves({
324+
ResultSet: {
325+
ResultSetMetadata: {
326+
ColumnInfo: [
327+
{ Name: "nullValue", Type: "unknown" },
328+
{ Name: "emptyValue", Type: "varchar" },
329+
],
330+
},
331+
Rows: [
332+
{
333+
// header row
334+
Data: [
335+
{ VarCharValue: "nullValue" },
336+
{ VarCharValue: "emptyValue" },
337+
],
338+
},
339+
{
340+
Data: [{}, { VarCharValue: "" }],
341+
},
342+
],
343+
},
344+
});
345+
346+
const athenaQuery = new AthenaQuery(athena);
347+
const resultGen = athenaQuery.query("");
348+
const res1 = await resultGen.next();
349+
expect(res1.value).toEqual({
350+
// nullValue is removed from the object
351+
emptyValue: "",
352+
});
353+
});

0 commit comments

Comments
 (0)
0