apache / apache/datafusion-python

Create more user friendly aliases from `col`

未關閉
#754 5 則留言 3 個 reaction 已指派 0 人 在 GitHub 檢視
enhancement
主要語言
Python
星號
604
分支
174
平均合併
1 天 7 小時
30 天內合併 PR
4

描述

**Is your feature request related to a problem or challenge? Please describe what you are trying to do.**
This is a user enhancement request to make the python interface remove the default `?table?` on columns.

**Describe the solution you'd like**
I have not yet reviewed the applicable code to offer a best solution yet. I'm adding this feature request to track.

**Describe alternatives you've considered**
User adds an `.alias()` command as below, which may be tedious.

**Additional context**
See the below example from @datapythonista that includes the desired use case

```
import datafusion
from datafusion import col, lit, functions as f
import pyarrow

# something like this would be implemented internally, so users can call `datafusion.read_*`
def _read_parquet(*args, **kwargs):
ctx = datafusion.SessionContext()
return ctx.read_parquet(*args, **kwargs)
datafusion.read_parquet = _read_parquet # creating an alias of `read_*` functions so users don't need to know about `SessionContext` when the defaults are fine

df = (datafusion.read_parquet("buildings.parquet")
.filter( # `.filter()` accepting multiple conditions (which will be an AND) instead of having to use `&` with its operator precedence problems
col("is_offplan") == False,
col("rooms") >= 2, # `.lit(2)` not being required, and Python literals working with operators
)
.aggregate(
[col("area_name_en")],
[f.mean(col("has_parking").cast(float))], # `.cast()` accepting Python types, which would be internally converted to the PyArrow equivalent
)
.select(
col("area_name_en").alias("Area"),
col("AVG(has_parking)").alias("Percentage of buildings with parking"), # removing the default `?table?` in column names, the column name was "AVG(?table?.has_parking)"
)
)
```

貢獻指南

這個儲存庫沒有索引到貢獻指南

研究方向

此 issue 將 `col(...)` 和 `.alias()` 確定為相關的 Python 入口,範例顯示 `AVG(?table?.has_parking)` 是不需要的輸出。首先定位它們的實作和現有測試;當預設的 `?table?` 被移除,同時 `Area` 和 `Percentage of buildings with parking` 等明確別名仍可正常運作時,即視為完成。

由索引模型根據 Issue 內容生成。

評估

技術堆疊
python
領域
data
Issue 類型
功能
難度
5/5
預估耗時
一週以上
活躍度
停滯
描述清晰度
需要釐清
新手友好度
25/100

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。