8000 Merge pull request #69 from diggymo/feature/treat-empty-string-as-is · classmethod/athena-query@0dc9251 · GitHub
[go: up one dir, main page]

Skip to content

Commit 0dc9251

Browse files
authored
Merge pull request #69 from diggymo/feature/treat-empty-string-as-is
2 parents 39d959b + b5065f6 commit 0dc9251

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
Original file line numberDiff line numberDiff line change
@@ -321,3 +321,42 @@ test("throw exception when query is respond as failed", async () => {
321321
"No QueryExecutionId was responded."
322322
);
323323
});
324+
325+
test("If empty string is returned from AthenaSDK, it will be returned as an empty string", async () => {
326+
athenaMock
327+
.on(StartQueryExecutionCommand)
328+
.resolves({ QueryExecutionId: "test-QueryExecutionId" })
329+
.on(GetQueryExecutionCommand)
330+
.resolves({ QueryExecution: { Status: { State: "SUCCEEDED" } } })
331+
.on(GetQueryResultsCommand)
332+
.resolves({
333+
ResultSet: {
334+
ResultSetMetadata: {
335+
ColumnInfo: [
336+
{ Name: "nullValue", Type: "unknown" },
337+
{ Name: "emptyValue", Type: "varchar" },
338+
],
339+
},
340+
Rows: [
341+
{
342+
// header row
343+
Data: [
344+
{ VarCharValue: "nullValue" },
345+
{ VarCharValue: "emptyValue" },
346+
],
347+
},
348+
{
349+
Data: [{}, { VarCharValue: "" }],
350+
},
351+
],
352+
},
353+
});
354+
355+
const athenaQuery = new AthenaQuery(athena);
356+
const resultGen = athenaQuery.query("");
357+
const res1 = await resultGen.next();
358+
expect(res1.value).toEqual({
359+
// nullValue is removed from the object
360+
emptyValue: "",
361+
});
362+
});

0 commit comments

Comments
 (0)
0