From edd96a9acfcaeae47bf7a16aa6810031d1384cf6 Mon Sep 17 00:00:00 2001 From: diggymo Date: Thu, 9 Nov 2023 16:09:08 +0900 Subject: [PATCH 1/2] change so that empty strings are treated as is --- src/helper.ts | 4 ++-- test/index.test.ts | 39 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+), 2 deletions(-) diff --git a/src/helper.ts b/src/helper.ts index c5b5573..64bc6ff 100644 --- a/src/helper.ts +++ b/src/helper.ts @@ -88,7 +88,7 @@ function cleanUpPaginatedDML( if (!Data) return acc; const rowObject = Data?.reduce((acc, row, index) => { - if (row.VarCharValue) { + if (row.VarCharValue !== undefined && row.VarCharValue !== null) { // use mutable operation for performance acc[columnNames[index]] = row.VarCharValue; } @@ -113,7 +113,7 @@ function addDataType( > = {}; for (const key in input) { - if (!input[key]) { + if (input[key] === null || input[key] === undefined) { updatedObjectWithDataType[key] = null; } else { switch (dataTypes[key]) { diff --git a/test/index.test.ts b/test/index.test.ts index 5064dff..e3d4679 100644 --- a/test/index.test.ts +++ b/test/index.test.ts @@ -312,3 +312,42 @@ test("throw exception when query is respond as failed", async () => { "No QueryExecutionId was responded." ); }); + +test.only("If empty string is returned from AthenaSDK, it will be returned as an empty string", async () => { + athenaMock + .on(StartQueryExecutionCommand) + .resolves({ QueryExecutionId: "test-QueryExecutionId" }) + .on(GetQueryExecutionCommand) + .resolves({ QueryExecution: { Status: { State: "SUCCEEDED" } } }) + .on(GetQueryResultsCommand) + .resolves({ + ResultSet: { + ResultSetMetadata: { + ColumnInfo: [ + { Name: "nullValue", Type: "unknown" }, + { Name: "emptyValue", Type: "varchar" }, + ], + }, + Rows: [ + { + // header row + Data: [ + { VarCharValue: "nullValue" }, + { VarCharValue: "emptyValue" }, + ], + }, + { + Data: [{}, { VarCharValue: "" }], + }, + ], + }, + }); + + const athenaQuery = new AthenaQuery(athena); + const resultGen = athenaQuery.query(""); + const res1 = await resultGen.next(); + expect(res1.value).toEqual({ + // nullValue is removed from the object + emptyValue: "", + }); +}); From b5065f68684850d5d6a9417c5c95766e80a0a1c3 Mon Sep 17 00:00:00 2001 From: diggymo Date: Thu, 9 Nov 2023 18:27:46 +0900 Subject: [PATCH 2/2] remove test.only --- test/index.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/index.test.ts b/test/index.test.ts index e3d4679..8d1b7f2 100644 --- a/test/index.test.ts +++ b/test/index.test.ts @@ -313,7 +313,7 @@ test("throw exception when query is respond as failed", async () => { ); }); -test.only("If empty string is returned from AthenaSDK, it will be returned as an empty string", async () => { +test("If empty string is returned from AthenaSDK, it will be returned as an empty string", async () => { athenaMock .on(StartQueryExecutionCommand) .resolves({ QueryExecutionId: "test-QueryExecutionId" })