pyflink.table.table_environment.StreamTableEnvironment.from_elements#
- StreamTableEnvironment.from_elements(elements: Iterable, schema: Optional[Union[pyflink.table.types.DataType, List[str]]] = None, verify_schema: bool = True) pyflink.table.table.Table #
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.