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.
- Generate the
catalog.json
file from a dbt project usingdbt docs generate
- Generate the
manifest.json
file from a dbt project usingdbt compile
- Copy both files to the root directory of this repo
- In the main file, update the
model_name
variable to the name of the dbt model you want to generate LookML for, and run.
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" ;;
}