Skip to main content
Ctrl+K
PyFlink 1.20+vvr.11.7.dev0 documentation - Home PyFlink 1.20+vvr.11.7.dev0 documentation - Home
  • API Reference
  • Examples
  • API Reference
  • Examples

Section Navigation

  • PyFlink Table
    • TableEnvironment
    • Table
    • Data Types
    • Window
    • Expressions
    • User Defined Functions
    • Descriptors
    • StatementSet
    • Catalog
  • PyFlink DataStream
  • PyFlink DataFrame
  • PyFlink Common
  • API Reference
  • PyFlink Table
  • TableEnvironment
  • pyflink.table.table_environment.TableEnvironment.from_elements

pyflink.table.table_environment.TableEnvironment.from_elements#

TableEnvironment.from_elements(elements: Iterable, schema: DataType | List[str] | None = None, verify_schema: bool = True) → Table[source]#

Creates a table from a collection of elements. The elements types must be acceptable atomic types or acceptable composite types. All elements must be of the same type. If the elements types are composite types, the composite types must be strictly equal, and its subtypes must also be acceptable types. e.g. if the elements are tuples, the length of the tuples must be equal, the element types of the tuples must be equal in order.

The built-in acceptable atomic element types contains:

int, long, str, unicode, bool, float, bytearray, datetime.date, datetime.time, datetime.datetime, datetime.timedelta, decimal.Decimal

The built-in acceptable composite element types contains:

list, tuple, dict, array, Row

If the element type is a composite type, it will be unboxed. e.g. table_env.from_elements([(1, ‘Hi’), (2, ‘Hello’)]) will return a table like:

_1

_2

1

Hi

2

Hello

“_1” and “_2” are generated field names.

Example:

# use the second parameter to specify custom field names
>>> table_env.from_elements([(1, 'Hi'), (2, 'Hello')], ['a', 'b'])
# use the second parameter to specify custom table schema
>>> table_env.from_elements([(1, 'Hi'), (2, 'Hello')],
...                         DataTypes.ROW([DataTypes.FIELD("a", DataTypes.INT()),
...                                        DataTypes.FIELD("b", DataTypes.STRING())]))
# use the third parameter to switch whether to verify the elements against the schema
>>> table_env.from_elements([(1, 'Hi'), (2, 'Hello')],
...                         DataTypes.ROW([DataTypes.FIELD("a", DataTypes.INT()),
...                                        DataTypes.FIELD("b", DataTypes.STRING())]),
...                         False)
# create Table from expressions
>>> table_env.from_elements([row(1, 'abc', 2.0), row(2, 'def', 3.0)],
...                         DataTypes.ROW([DataTypes.FIELD("a", DataTypes.INT()),
...                                        DataTypes.FIELD("b", DataTypes.STRING()),
...                                        DataTypes.FIELD("c", DataTypes.FLOAT())]))
Parameters:
  • elements – The elements to create a table from.

  • schema – The schema of the table.

  • verify_schema – Whether to verify the elements against the schema.

Returns:

The result table.

previous

pyflink.table.table_environment.TableEnvironment.from_descriptor

next

pyflink.table.table_environment.TableEnvironment.from_pandas

On this page
  • TableEnvironment.from_elements()

This Page

  • Show Source

Created using Sphinx 7.4.7.

Built with the PyData Sphinx Theme 0.16.1.