https://github.com/jutaz/athena-struct-parser
Parse dict-like structs returned in responses of AWS Athena
https://github.com/jutaz/athena-struct-parser
athena npm-package parser
Last synced: 3 months ago
JSON representation
Parse dict-like structs returned in responses of AWS Athena
- Host: GitHub
- URL: https://github.com/jutaz/athena-struct-parser
- Owner: jutaz
- License: gpl-3.0
- Created: 2019-11-16T13:18:05.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2022-09-09T21:51:31.000Z (about 3 years ago)
- Last Synced: 2024-11-13T06:30:57.501Z (11 months ago)
- Topics: athena, npm-package, parser
- Language: JavaScript
- Size: 69.3 KB
- Stars: 4
- Watchers: 2
- Forks: 4
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# athena-struct-parser
A small utility to parse out structs returned by [AWS Athena](https://aws.amazon.com/athena/). Tools such as [`athena-express`](https://github.com/ghdna/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:
```js
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:
```sh
npm i athena-struct-parser
``````js
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
// }
// ]
// }
```