You are viewing documentation about an older version (1.2.0). View latest version

snowflake.snowpark.Session.generator¶

Session.generator(*columns: Column, rowcount: int = 0, timelimit: int = 0) → DataFrame[source]¶

Creates a new DataFrame using the Generator table function.

References: Snowflake Generator function.

Parameters:
  • columns – List of data generation function that work in tandem with generator table function.

  • rowcount – Resulting table with contain rowcount rows if only this argument is specified. Defaults to 0.

  • timelimit – The query runs for timelimit seconds, generating as many rows as possible within the time frame. The exact row count depends on the system speed. Defaults to 0.

Usage Notes:
  • When both rowcount and timelimit are specified, then:

    • if the rowcount is reached before the timelimit, the resulting table with contain rowcount rows.

    • if the timelimit is reached before the rowcount, the table will contain as many rows generated within this time.

  • If both rowcount and timelimit are not specified, 0 rows will be generated.

Example 1
>>> from snowflake.snowpark.functions import seq1, seq8, uniform
>>> df = session.generator(seq1(1).as_("sequence one"), uniform(1, 10, 2).as_("uniform"), rowcount=3)
>>> df.show()
------------------------------
|"sequence one"  |"UNIFORM"  |
------------------------------
|0               |3          |
|1               |3          |
|2               |3          |
------------------------------
Copy
Example 2
>>> df = session.generator(seq8(0), uniform(1, 10, 2), timelimit=1).order_by(seq8(0)).limit(3)
>>> df.show()
-----------------------------------
|"SEQ8(0)"  |"UNIFORM(1, 10, 2)"  |
-----------------------------------
|0          |3                    |
|1          |3                    |
|2          |3                    |
-----------------------------------
Copy
Returns:

A new DataFrame with data from calling the generator table function.