feat: read metrics from a SQL query via from_sql (DuckDB) (#52)#74
Draft
msto wants to merge 7 commits into
Draft
feat: read metrics from a SQL query via from_sql (DuckDB) (#52)#74msto wants to merge 7 commits into
msto wants to merge 7 commits into
Conversation
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Address code-quality review: generalize the class docstring opening to "parsed source" and mention the from_sql construction path, and rewrite the alias test to the file's established equality idiom. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Contributor
|
Important Review skippedDraft detected. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #52
MetricReaderwas text-IO-only: reading metrics that already live in Parquet, Arrow, or a database meant routing through a TSV intermediary. This addsMetricReader.from_sql(metric_class, query, *, connection=None)(and an eagerMetric.from_sql(query)mirroringMetric.read), which validates the rows of a SQL query as metrics. The query names its own source, so any backend DuckDB can read works — Parquet/Arrow/JSON/CSV/SQLite/Postgres/S3 — and fgmetric reimplements no parsing.DuckDB is an optional dependency (
fgmetric[duckdb]) and an implementation detail: it's imported lazily inside the single helper that touches it (_duckdb.query_rows), so importingfgmetricand the text path never require it. A missing duckdb raises a friendlyImportError. Without aconnection, a transient in-memory connection is opened and closed internally; a supplied connection is borrowed and never closed (for Postgres/secrets/ATTACH).The existing text path is unchanged.
from_sqlis an additive sibling constructor —open/read/__init__keep their behavior; both paths funnel into the samemodel_validatecore via a shared_from_records. Unlikeopen,from_sqlis not a context manager (it owns no file handle).Test plan
tests/test_from_sql.pycovers native typing,NULL→None,AScolumn→field renaming, field-alias resolution, missing-columnValidationError, empty result, transient vs. borrowed-connection lifecycle (borrowed never closed), a Parquet round-trip, both reader- andMetric-level entry points, and the friendlyImportErrorwhen duckdb is absent.poe check-allgreen: ruff format + lint, mypy strict, 195 tests at 98% coverage; confirmedimport fgmetricdoes not load duckdb.🤖 Generated with Claude Code