mattmartin14 commented on code in PR #1534: URL: https://github.com/apache/iceberg-python/pull/1534#discussion_r1941287673
########## pyiceberg/table/merge_rows_util.py: ########## @@ -0,0 +1,143 @@ + +# 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 pyarrow import Table as pyarrow_table +import pyarrow as pa +from pyarrow import compute as pc +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_pa(df: pyarrow_table) -> list: Review Comment: I'm not sure if i understood your remark; i updated the function to return a SET instead of a LIST. ########## pyiceberg/table/merge_rows_util.py: ########## @@ -0,0 +1,143 @@ + +# 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 pyarrow import Table as pyarrow_table +import pyarrow as pa +from pyarrow import compute as pc +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_pa(df: pyarrow_table) -> list: + return set(col for col in df.column_names) + +def get_table_column_list_iceberg(table: pyiceberg_table) -> list: + return set(col for col in table.schema().column_names) Review Comment: I'm not sure if i understood your remark; i updated the function to return a SET instead of a LIST. -- 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