apache / apache/datafusion-python

Expose SessionContext.register_variable / deregister_variable for SQL @var support

未关闭
#1,571 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看
主要语言
Python
星标
604
派生
174
平均合并
1 天 7 小时
30 天内合并 PR
4

描述

## Background

DataFusion's `SessionContext` exposes `register_variable(var_type, provider)` and `deregister_variable(var_type)` for plugging in a `VarProvider` that resolves SQL ``@var`` / ``@@var`` references at execution time. These were surfaced during a v54 upstream coverage audit but are not exposed in the Python bindings.

## Upstream signature

```rust
pub fn register_variable(&self, var_type: VarType, provider: Arc)
pub fn deregister_variable(&self, var_type: VarType) -> Option>
```

`VarProvider` is a small trait with `get_value(&self, name: Vec) -> Result` and `get_type(&self, name: &[String]) -> Option`.

## User value

Enables SQL like ``SELECT * FROM sales WHERE region = @current_region AND user_id = @user_id`` where the provider supplies per-query values. Useful for multi-tenant SaaS embedders, BI / notebook tools that want session-scoped parameters without f-string interpolation (no SQL injection risk), and tools porting MySQL / Postgres SQL that uses session variables.

## Why deferred

Effort estimate is medium (~250-400 LOC): needs a `PyVarProvider` Rust wrapper that calls back into a user-supplied Python object across the GIL boundary, plus the register / deregister bindings on `PySessionContext`, plus a Python-facing ABC. No open user requests at the time of audit, so the work is currently speculative. Filed for tracking; revisit when a concrete user need surfaces or to complete the upstream surface area.

贡献指南

这个仓库没有索引到贡献指南

评估

这个 Issue 还没有评估数据。

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。