auroflow commented on code in PR #28797:
URL: https://github.com/apache/flink/pull/28797#discussion_r3645031300


##########
flink-python/pyflink/dataframe/convert.py:
##########
@@ -0,0 +1,232 @@
+################################################################################
+#  Licensed to the Apache Software Foundation (ASF) under one
+#  or more contributor license agreements.  See the NOTICE file
+#  distributed with this work for additional information
+#  regarding copyright ownership.  The ASF licenses this file
+#  to you under the Apache License, Version 2.0 (the
+#  "License"); you may not use this file except in compliance
+#  with the License.  You may obtain a copy of the License at
+#
+#      http://www.apache.org/licenses/LICENSE-2.0
+#
+#  Unless required by applicable law or agreed to in writing, software
+#  distributed under the License is distributed on an "AS IS" BASIS,
+#  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+#  See the License for the specific language governing permissions and
+# limitations under the License.
+################################################################################
+
+from typing import Any, Iterable, Iterator, List, Mapping, Optional, Sequence, 
Tuple, Union, cast
+
+from pyflink.dataframe.context import get_or_create_table_environment
+from pyflink.dataframe.dataframe import DataFrame
+from pyflink.util.api_stability_decorators import PublicEvolving
+
+__all__ = ["from_dict", "from_records"]
+
+
+class _SequenceRowIterable:
+    """Produce tuple rows from row-oriented sequence records."""
+
+    def __init__(self, records: Sequence[Sequence[Any]]):
+        self._records = records
+
+    def __iter__(self) -> Iterator[Sequence[Any]]:
+        return (tuple(record) for record in self._records)
+
+
+class _ColumnRowIterable:
+    """Produce tuple rows from column-oriented sequences."""
+
+    def __init__(
+        self, data: Mapping[str, Sequence[Any]], columns: Sequence[str]
+    ):
+        self._data = data
+        self._columns = columns
+
+    def __iter__(self) -> Iterator[Sequence[Any]]:
+        return zip(*(self._data[name] for name in self._columns))
+
+
+def _validate_schema(schema: List[str]) -> None:
+    if not isinstance(schema, list) or any(not isinstance(name, str) for name 
in schema):
+        raise TypeError("schema must be a list of strings")
+    if not schema:
+        raise ValueError("schema must not be empty")
+    if any(not name for name in schema):
+        raise ValueError("schema field names must not be empty")
+    if len(set(schema)) != len(schema):
+        raise ValueError("schema field names must be unique")
+
+
+def _is_named_tuple_record(record: Any) -> bool:
+    return isinstance(record, tuple) and isinstance(
+        getattr(record, "_fields", None), tuple
+    )
+
+
+def _to_field_mapping(
+    record: Any, named_tuple_records: bool

Review Comment:
   Good idea! This is much neater. I've refactored this part.



-- 
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.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to