Builtins Functions

This module contains a list of predefined dataframe functions in database.

greenplumpython.builtins.functions.count(arg=None)

Count the number of rows or non-NULL values against a specified column or an entire table.

Example

>>> import greenplumpython.builtins.functions as F
>>> rows = [(i,) for i in range(10)]
>>> df = db.create_dataframe(rows=rows, column_names=["a"])
>>> df.group_by().assign(count=lambda t: F.count())
-------
 count
-------
    10
-------
(1 row)
Parameters

arg (Optional[Any]) –

Return type

FunctionExpr

greenplumpython.builtins.functions.min(arg)

Return the minimum value in a set of values.

Example

>>> import greenplumpython.builtins.functions as F
>>> rows = [(i,) for i in range(10)]
>>> df = db.create_dataframe(rows=rows, column_names=["a"])
>>> df.group_by().assign(min=lambda t: F.min(t["a"]))
-----
 min
-----
   0
-----
(1 row)
Parameters

arg (Any) –

Return type

FunctionExpr

greenplumpython.builtins.functions.max(arg)

Return the maximum value in a set of values.

Example

>>> import greenplumpython.builtins.functions as F
>>> rows = [(i,) for i in range(10)]
>>> df = db.create_dataframe(rows=rows, column_names=["a"])
>>> df.group_by().assign(max=lambda t: F.max(t["a"]))
-----
 max
-----
   9
-----
(1 row)
Parameters

arg (Any) –

Return type

FunctionExpr

greenplumpython.builtins.functions.avg(arg)

Calculate the average value of a set.

Example

>>> import greenplumpython.builtins.functions as F
>>> rows = [(i,) for i in range(10)]
>>> df = db.create_dataframe(rows=rows, column_names=["a"])
>>> df.group_by().assign(avg=lambda t: F.avg(t["a"]))
-----
 avg
-----
 4.5
-----
(1 row)
Parameters

arg (Any) –

Return type

FunctionExpr

greenplumpython.builtins.functions.sum(arg)

Calculate the sum of a set of values.

Example

>>> import greenplumpython.builtins.functions as F
>>> rows = [(i,) for i in range(10)]
>>> df = db.create_dataframe(rows=rows, column_names=["a"])
>>> df.group_by().assign(sum=lambda t: F.sum(t["a"]))
-----
 sum
-----
  45
-----
(1 row)
Parameters

arg (Any) –

Return type

FunctionExpr

greenplumpython.builtins.functions.generate_series(start, stop, step=None)

Generate a series of values from start to stop, with a step size of step.

step defaults to 1.

Example

>>> import greenplumpython.builtins.functions as F
>>> db.assign(id=lambda: F.generate_series(0, 9))
----
 id
----
  0
  1
  2
  3
  4
  5
  6
  7
  8
  9
----
(10 rows)
Parameters
  • start (Any) –

  • stop (Any) –

  • step (Optional[Any]) –

Return type

FunctionExpr