Polars database reader/writer record file metadata, so SQL lineage is missing
メンテナーはふだん 2 日以内に返信
評価
この issue はまだ評価されていません。
説明
Related: #1720
PolarsDatabaseReader and PolarsDatabaseWriter (in both polars_post_1_0_0_extensions.py and polars_pre_1_0_0_extension.py) describe database I/O with get_file_and_dataframe_metadata. They pass the SQL query or table name in where a file path is expected:
# PolarsDatabaseReader.load_data
metadata = utils.get_file_and_dataframe_metadata(self.query, df)
# PolarsDatabaseWriter.save_data
return utils.get_file_and_dataframe_metadata(self.table_name, data)
This happens whatever connection is passed, including a SQLAlchemy Engine.
Effects
- The metadata has no
sql_metadatablock. So theOpenLineageAdaptercan't identify the tables, andsql_dataset_identity="datasource"(from #1720) resolves nothing:sql_datasets()returnsSQL datasource is unknown; no dataset emitted. - Lineage treats database I/O as filesystem I/O:
- a read becomes an input dataset named after the node (e.g.
orders_df), withstorageLayer="FileSystem"and the SQL text as itsdataSourceURI; - a write becomes an output dataset named after the table, also marked
FileSystem; - no
sqljob facet is emitted.
- a read becomes an input dataset named after the node (e.g.
file_metadatacarries meaningless values, e.g.path: "SELECT * FROM orders",scheme: "", and a note that the file does not exist.
Reproduction
import polars as pl
from sqlalchemy import create_engine
from hamilton.plugins.polars_post_1_0_0_extensions import PolarsDatabaseReader
engine = create_engine("sqlite:///a.db") # with a table `orders`
df, md = PolarsDatabaseReader(query="SELECT * FROM orders", connection=engine).load_data(pl.DataFrame)
print(sorted(md)) # ['dataframe_metadata', 'file_metadata']
print(md["file_metadata"]["path"]) # 'SELECT * FROM orders'
Proposed fix
- In both Polars database classes, record
get_sql_metadata(query_or_table, results, db_connection=self.connection, operation="read" | "write")plusget_dataframe_metadata, asPandasSqlReaderandPandasSqlWriterdo. SQLAlchemy URLs, Engines and Connections, andsqlite3connections, then get full datasource identity. - Extend
get_sql_sourceto recognise the other connections Polars accepts (ADBC connections, connectorx URI strings, cursors). Until then these are left out of lineage with a note, which is safe but gives no lineage. - Add Polars read and write tests against SQLite, mirroring the pandas SQL lineage tests.
Compatibility
Metadata for Polars database I/O changes from file_metadata to sql_metadata. Default-mode ("legacy") OpenLineage output changes with it: the fake filesystem datasets are replaced by the legacy SQL datasets. Anyone consuming file_metadata from these classes would be affected, so this probably deserves a changelog entry.
- 主要言語
- Jupyter Notebook
- スター
- 2.6k
- フォーク
- 221
- 平均マージ
- 2日 1分
- マージ済み PR(30日)
- 17
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートあり
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
apache/hamilton のほかの issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
メンテナーはふだん 2 日以内に返信
-
Engine crashes when client sends nan or inf float to UI再び着手できるかも @Exudev が 234 日前に担当しましたが、オープン中のプルリクエストはありません。 オープンbug SDK
難易度 2/5 1〜3時間 初心者へのやさしさ 65/100
apache/hamilton#1458 · コメント 5 件 ·
メンテナーはふだん 2 日以内に返信
-
More detailed type annotations in graph visualizations再び着手できるかも @Nishant-Manocha が 369 日前に担当しましたが、オープン中のプルリクエストはありません。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 70/100
apache/hamilton#1383 · コメント 4 件 ·
メンテナーはふだん 2 日以内に返信
-
Documentation: add explainer for FastAPI再び着手できるかも @Aditya-Deshwal23 が 188 日前に担当しましたが、オープン中のプルリクエストはありません。 オープンdocumentation
難易度 2/5 1〜2日 初心者へのやさしさ 65/100
apache/hamilton#1304 · コメント 5 件 ·
メンテナーはふだん 2 日以内に返信
-
Link back to github from reference API docs対応中かも @naikvaib が 26 日前に担当しました。 オープンdocumentation good first issue
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
apache/hamilton#572 · コメント 3 件 ·
メンテナーはふだん 2 日以内に返信