Identifique e gere querys para normalização de JSONs via AWS Athena
Project description
Nice
Ferramenta para facilitar a normalização de JSON's via Amazon Athena
Getting Started
Nice é uma aplicação que tem como finalidade a identificação de possíveis tabelas em um JSON, gerando querys para sua normalização
via Amazon Athena.
Installation
Instalar o pacote via PyPI:
pip install nice_parser
Usage
Gerar Query
I. Importar Módulos
from nice import MappingJson
II. Criar Query a partir de JSON, passando como parâmetro a origem
de seu dado, o nome do database
e da tabela
parser = MappingJson('path/sample.json', databaseName='database', tableName='table')
database = parser.parse()
query = database.createQuery()
query.Save('output.sql', database)
Um JSON
com os seguintes valores:
{
"shipping_address":{
"province_code":"TX",
"latitude":-87.561414
},
"buyer_accepts_marketing":true,
"token":"a4b8c15d16e42",
"total_weight":0,
"line_items":[
{
"destination_location_id":4815162342,
"requires_shipping":true,
"variant_title":"rb_nice"
}
]
}
Será convertido e disponibilizado em um arquivo .sql
, como no exemplo abaixo:
/* ---------------------------------------------*
* Descrição: Tabela Principal - tableName *
* ---------------------------------------------*/
SELECT
CAST("json_extract"(table, '$.shipping_address.province_code') AS VARCHAR) "shipping_address_province_code",
CAST("json_extract"(table, '$.shipping_address.latitude') AS DECIMAL) "shipping_address_latitude",
CAST("json_extract"(table, '$.buyer_accepts_marketing') AS BOOLEAN) "buyer_accepts_marketing",
CAST("json_extract"(table, '$.token') AS VARCHAR) "token",
CAST("json_extract"(table, '$.total_weight') AS BIGINT) "total_weight"
FROM database.table
/* ---------------------------------------------*
* Descrição: Tabela Secundária - tableName *
* ---------------------------------------------*/
SELECT
CAST("json_extract"("line_items", '$.destination_location_id') AS BIGINT) "destination_location_id",
CAST("json_extract"("line_items", '$.requires_shipping') AS BOOLEAN) "requires_shipping",
CAST("json_extract"("line_items", '$.variant_title') AS VARCHAR) "variant_title",
FROM
(database.table
CROSS JOIN UNNEST(CAST("json_extract"(table, '$.line_items') AS array(json))) t (line_items))
...
Getting Help
Para bug report, perguntas ou solicitações, devem ser utilizadas as Issues do Bitbucket.
Contributing
Leia o documento CONTRIBUTING.md
antes de enviar qualquer Issue ou Pull Request, garantindo assim, que tenhamos todas as informações necessárias para responder efetivamente à sua contribuição.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for nice_parser-0.0.2-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3695f443ef268ed9706f7823cfaaeee1e7b3f7fcbba07dbfbb35437e49a4dfaa |
|
MD5 | 75f25074f9c901f83969934750184c2c |
|
BLAKE2b-256 | bb92922c5a30a8a71bd36cdec6b33a758de7cc7a38c1f2dcedfece37d2790924 |