Giter Club home page Giter Club logo

dimension-generator's Introduction

Overview

Scripts to help generate LookML dimensions with metadata from dbt's artifacts.

This speeds up the process of creating new view files, which can be generated based on the columns in a dbt model, with the corresponding field descriptions from their dbt docs.

Usage

  1. Generate the catalog.json file from a dbt project using dbt docs generate
  2. Generate the manifest.json file from a dbt project using dbt compile
  3. Copy both files to the root directory of this repo
  4. In the main file, update the model_name variable to the name of the dbt model you want to generate LookML for, and run.

Example Output

I've included two sample artifact files, the manifest.json and catalog.json from an arbitrary public dbt project (fivetran's dbt_stripe repo)

# Add a filename here and run
model_name = 'stg_stripe__payment_intent'

lookml_data = convert_model_to_lookml(combined_dict, model_name)

for lookml_entry in lookml_data:
    print(lkml.dump(lookml_entry))

Generates the following:

dimension: payment_intent_id {
  description: "Unique identifier for the object."
  type: string
  sql: ${TABLE}."PAYMENT_INTENT_ID" ;;
}
dimension: amount {
  description: "Amount intended to be collected by this PaymentIntent. A positive integer representing how much to charge in the smallest currency unit (e.g., 100 cents to charge $1.00 or 100 to charge ¥100, a zero-decimal currency)"
  type: number
  sql: ${TABLE}."AMOUNT" ;;
}
dimension: amount_capturable {
  description: "Amount that can be captured from this PaymentIntent."
  type: number
  sql: ${TABLE}."AMOUNT_CAPTURABLE" ;;
}
dimension: amount_received {
  description: "Amount that was collected by this PaymentIntent."
  type: number
  sql: ${TABLE}."AMOUNT_RECEIVED" ;;
}
dimension: application {
  description: "ID of the Connect application that created the PaymentIntent."
  type: string
  sql: ${TABLE}."APPLICATION" ;;
}
dimension: application_fee_amount {
  description: "The amount of the application fee (if any) for the resulting payment."
  type: number
  sql: ${TABLE}."APPLICATION_FEE_AMOUNT" ;;
}
dimension_group: canceled_at {
  description: "Populated when status is canceled, this is the time at which the PaymentIntent was canceled."
  type: time
  sql: ${TABLE}."CANCELED_AT" ;;
}
dimension: cancellation_reason {
  description: "Reason for cancellation of this PaymentIntent, either user-provided (duplicate, fraudulent, requested_by_customer, or abandoned) or generated by Stripe internally (failed_invoice, void_invoice, or automatic)."
  type: number
  sql: ${TABLE}."CANCELLATION_REASON" ;;
}
dimension: capture_method {
  description: "Controls when the funds will be captured from the customer’s account."
  type: string
  sql: ${TABLE}."CAPTURE_METHOD" ;;
}
dimension: confirmation_method {
  description: "Whether confirmed automatically or manually"
  type: string
  sql: ${TABLE}."CONFIRMATION_METHOD" ;;
}
dimension_group: created_at {
  description: "Time at which the object was created."
  type: time
  sql: ${TABLE}."CREATED_AT" ;;
}
dimension: currency {
  description: "Three-letter ISO currency code, in lowercase."
  type: string
  sql: ${TABLE}."CURRENCY" ;;
}
dimension: customer_id {
  description: "ID of the Customer this PaymentIntent belongs to, if one exists."
  type: string
  sql: ${TABLE}."CUSTOMER_ID" ;;
}
dimension: description {
  description: "An arbitrary string attached to the object. Often useful for displaying to users."
  type: string
  sql: ${TABLE}."DESCRIPTION" ;;
}
dimension: metadata {
  description: "Custom metadata added to the record, in JSON string format"
  type: string
  sql: ${TABLE}."METADATA" ;;
}
dimension: payment_method_id {
  description: "ID of the payment method used in this PaymentIntent."
  type: string
  sql: ${TABLE}."PAYMENT_METHOD_ID" ;;
}
dimension: receipt_email {
  description: "Email address that the receipt for the resulting payment will be sent to."
  type: string
  sql: ${TABLE}."RECEIPT_EMAIL" ;;
}
dimension: statement_descriptor {
  description: "For non-card charges, you can use this value as the complete description that appears on your customers’ statements."
  type: number
  sql: ${TABLE}."STATEMENT_DESCRIPTOR" ;;
}
dimension: status {
  description: "Status of this PaymentIntent, one of requires_payment_method, requires_confirmation, requires_action, processing, requires_capture, canceled, or succeeded."
  type: string
  sql: ${TABLE}."STATUS" ;;
}
dimension: source_relation {
  description: "The source where this data was pulled from. If you are making use of the `union_schemas` variable, this will be the source schema. If you are making use of the `union_databases` variable, this will be the source database. If you are not unioning together multiple sources, this will be an empty string."
  type: string
  sql: ${TABLE}."SOURCE_RELATION" ;;
}

dimension-generator's People

Contributors

segoldma avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.