Apache DataFusion SQL Query Engine
python: update user doc to use new APIs (#1287)
QP Houb77380250d7f
diff --git a/.github/workflows/python_test.yaml b/.github/workflows/python_test.yamlindex 905b9c56d6..01a36af870 100644--- a/.github/workflows/python_test.yaml+++ b/.github/workflows/python_test.yaml@@ -50,7 +50,7 @@ jobs:run: |source venv/bin/activateflake8 python --ignore=E501- black --line-length 79 --check python+ black --line-length 79 --diff --check python- name: Run testsrun: |source venv/bin/activatediff --git a/docs/source/python/index.rst b/docs/source/python/index.rstindex 56f9097ffd..57ab8d16bf 100644--- a/docs/source/python/index.rst+++ b/docs/source/python/index.rst@@ -39,11 +39,10 @@ Simple usage:.. code-block:: pythonimport datafusion+ from datafusion import functions as f+ from datafusion import colimport pyarrow- # an alias- f = datafusion.functions-# create a contextctx = datafusion.ExecutionContext()@@ -56,8 +55,8 @@ Simple usage:# create a new statementdf = df.select(- f.col("a") + f.col("b"),- f.col("a") - f.col("b"),+ col("a") + col("b"),+ col("a") - col("b"),)# execute and collect the first (and only) batch@@ -77,7 +76,7 @@ UDFsudf = f.udf(is_null, [pyarrow.int64()], pyarrow.bool_())- df = df.select(udf(f.col("a")))+ df = df.select(udf(col("a")))UDAF@@ -117,7 +116,7 @@ UDAFdf = df.aggregate([],- [udaf(f.col("a"))]+ [udaf(col("a"))])diff --git a/python/datafusion/__init__.py b/python/datafusion/__init__.pyindex 4f9082e7e4..0a25592f80 100644--- a/python/datafusion/__init__.py+++ b/python/datafusion/__init__.py@@ -28,6 +28,7 @@ from ._internal import (ScalarUDF,)+__all__ = ["DataFrame","ExecutionContext",@@ -61,12 +62,18 @@ def column(value):return Expression.column(value)+col = column++def literal(value):if not isinstance(value, pa.Scalar):value = pa.scalar(value)return Expression.literal(value)+lit = literal++def udf(func, input_types, return_type, volatility, name=None):"""Create a new User Defined Functiondiff --git a/python/src/expression.rs b/python/src/expression.rsindex 21cecaa1cc..5e1cad246b 100644--- a/python/src/expression.rs+++ b/python/src/expression.rs@@ -90,6 +90,10 @@ impl PyObjectProtocol for PyExpr {};expr.into()}++ fn __str__(&self) -> PyResult<String> {+ Ok(format!("{}", self.expr))+ }}#[pymethods]