dianfu commented on a change in pull request #8474: [FLINK-12409][python] Adds from_elements in TableEnvironment URL: https://github.com/apache/flink/pull/8474#discussion_r288399465
########## File path: flink-python/pyflink/table/table_environment.py ########## @@ -379,13 +383,97 @@ def create(cls, table_config): return t_env + def from_elements(self, elements, schema=None, verify_schema=True): + """ + Creates a table from a collection of elements. + + :param elements: The elements to create table from. + :param schema: The schema of the table. + :param verify_schema: Whether to verify the elements against the schema. + :return: A Table. + """ + + # verifies the elements against the specified schema + if isinstance(schema, RowType): + verify_func = _create_type_verifier(schema) if verify_schema else lambda _: True + + def verify_obj(obj): + verify_func(obj) + return obj + elif isinstance(schema, DataType): + data_type = schema + schema = RowType().add("value", schema) + + verify_func = _create_type_verifier( + data_type, name="field value") if verify_schema else lambda _: True + + def verify_obj(obj): + verify_func(obj) + return obj + else: + def verify_obj(obj): + return obj + + # makes sure we distribute data evenly if it's smaller than self.batchSize Review comment: Good catch. Will remove this comment. Originally there is code corresponding to this comment, just forgot to remove this comment when removing that part of code. ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: us...@infra.apache.org With regards, Apache Git Services