Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Generate Manifold Merge #25

Merged
merged 3 commits into from
Feb 11, 2025
Merged

Conversation

claytongentry
Copy link
Member

@claytongentry claytongentry commented Feb 9, 2025

This PR adds support for generating BigQuery merge routines for Manifold tables. The merge routines are responsible for aggregating metrics across different contexts and dimensions.

For now, we support COUNTIF and SUM(IF...) style aggregations.

Configuration Format

  • Added support for a simplified source configuration format in manifold.yml:
    source: my_project.my_dataset.my_table
    filter: timestamp >= TIMESTAMP_SUB(CURRENT_TIMESTAMP(), INTERVAL 90 DAY)
    timestamp:
      field: created_at
      interval: DAY

SQL Generation

  • Added MetricsBuilder class to handle complex metric aggregations:

    • Supports COUNTIF and SUMIF metrics
    • Handles nested context conditions with logical operators (AND, OR, NOT, etc.)
    • Generates properly structured metric fields in the output
  • Added SQLBuilder class to generate merge routine SQL:

    • Generates CTE for metrics calculation
    • Properly handles timestamp truncation and filtering
    • Joins with dimensions table for complete manifold records
    • Implements MERGE semantics for upserting records

Schema Validation

  • Added validation for required manifold configuration fields:
    • Source table
    • Timestamp field
    • Contexts
    • Metrics

Example

timestamp:
  field: created_at
  interval: DAY

contexts:
  paid: IS_PAID(context.location)

metrics:
  countif: tapCount

source: analytics.events

will generate a merge

  1. Aggregates tap counts for paid contexts
  2. Groups by day using the created_at field
  3. Merges with existing dimensions
  4. Updates or inserts records in the manifold table

@claytongentry claytongentry marked this pull request as ready for review February 9, 2025 18:09
@claytongentry claytongentry merged commit 2513c4a into master Feb 11, 2025
3 checks passed
@claytongentry claytongentry deleted the claytongentry/merge-metrics branch February 18, 2025 14:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant