Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Athenaの実行結果に空文字が含まれている場合、変換されず空文字のまま取得できように修正 #69

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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]) {
Expand Down
39 changes: 39 additions & 0 deletions test/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -312,3 +312,42 @@ test("throw exception when query is respond as failed", async () => {
"No QueryExecutionId was responded."
);
});

test("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: "",
});
});