mattmartin14 commented on code in PR #1534: URL: https://github.com/apache/iceberg-python/pull/1534#discussion_r1940049404
########## pyiceberg/table/merge_rows_util.py: ########## @@ -0,0 +1,165 @@ + +# 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 datafusion import SessionContext +from pyarrow import Table as pyarrow_table +import pyarrow as pa +from pyiceberg import table as pyiceberg_table + +from pyiceberg.expressions import ( + BooleanExpression, + And, + EqualTo, + Or, + In, +) + +def get_filter_list(df: pyarrow_table, join_cols: list) -> BooleanExpression: + + unique_keys = df.select(join_cols).group_by(join_cols).aggregate([]) + + pred = None + + if len(join_cols) == 1: + pred = In(join_cols[0], unique_keys[0].to_pylist()) + else: + pred = Or(*[ + And(*[ + EqualTo(col, row[col]) + for col in join_cols + ]) + for row in unique_keys.to_pylist() + ]) + + return pred + + +def get_table_column_list(connection: SessionContext, table_name: str) -> list: + """ + This function retrieves the column names and their data types for the specified table. + It returns a list of tuples where each tuple contains the column name and its data type. + + Args: + connection: DataFusion SessionContext. + table_name: The name of the table for which to retrieve column information. + + Returns: + A list of tuples containing column names and their corresponding data types. + """ + # DataFusion logic + res = connection.sql(f""" + SELECT column_name, data_type + FROM information_schema.columns + WHERE table_name = '{table_name}' + """).collect() + + column_names = res[0][0].to_pylist() # Extract the first column (column names) + data_types = res[0][1].to_pylist() # Extract the second column (data types) + + return list(zip(column_names, data_types)) # Combine into list of tuples + +def dups_check_in_source(source_table: str, join_cols: list, connection: SessionContext) -> bool: Review Comment: Nice: added this and replaced the datafusion part it was leveraging. -- 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: issues-unsubscr...@iceberg.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: issues-unsubscr...@iceberg.apache.org For additional commands, e-mail: issues-h...@iceberg.apache.org