Skip to main content

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

Python Version

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

nice_parser-0.0.2.tar.gz (5.4 kB view hashes)

Uploaded Source

Built Distribution

nice_parser-0.0.2-py3-none-any.whl (7.2 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page