Skip to content

Parse dict-like structs returned in responses of AWS Athena

License

Notifications You must be signed in to change notification settings

comicrelief/athena-struct-parser

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

athena-struct-parser

A small utility to parse out structs returned by AWS Athena. Tools such as athena-express do a great job at querying Athena, however there's no easy way to get freeform JSON out of it. This tool allows one to parse the Athena's structs & Arrays into JS objects.

Problem

Let's take the following code as an example:

const results = await athenaExpress.query('SELECT struct, foo, bar FROM my_table');

// `results` is:
// {
//   "Items": [
//     {
//       "struct": "{foo=bar, baz=[{foe=moe}]}",
//       "foo": "baz",
//       "bar": zab
//     }
//   ]
// }

It's not easy to get the data out of that struct column, even if that's pretty common way to store data (as JSON blobs). One could try to use a rudimentary parser, but it might trip up on un-escaped characters.

Usage

Install the library via:

npm i athena-struct-parser
import parseStruct from 'athena-struct-parser';

const results = await athenaExpress.query('SELECT struct, foo, bar FROM my_table');

results.Items.map(result => {
  result.struct = parseStruct(result.struct);
  return result;
});

// `results.struct` now contains JS object with data from the struct:
// {
//   "Items": [
//     {
//       "struct": {
//         "foo": "bar",
//         "baz": [
//           {
//             "foe": "moe"
//           }
//         ]
//       }",
//       "foo": "baz",
//       "bar": zab
//     }
//   ]
// }

About

Parse dict-like structs returned in responses of AWS Athena

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • JavaScript 100.0%