sjyangkevin opened a new pull request, #50735:
URL: https://github.com/apache/airflow/pull/50735

   ### Motivation
   
   By adding the `delete_by_property` method, users can delete multiple objects 
in multiple collections based on various filtering criteria, making data 
management more targeted and efficient.
   
   Close #42565 
   
   ### Reference
   
   https://weaviate.io/developers/weaviate/search/filters
   
https://weaviate.io/developers/weaviate/manage-data/delete#delete-multiple-objects
   
   ### Testing
   1. Two unit tests are created to capture failure scenarios
   2. Various filtering criteria have been tested in Jupyter notebook 
environment to connect to Weaviate and delete objects in collection.
   3. Failure scenarios also tested in notebook environment.
   
   ### Testing Code Sample
   ```python
   import os
   os.environ["WEAVIATE_URL"] = "<REST_ENDPOINT>"
   os.environ["WEAVIATE_API_KEY"] = "<API Key>"
   
   import weaviate
   from weaviate.classes.init import Auth
   from weaviate.classes.query import Filter
   
   weaviate_url = os.environ["WEAVIATE_URL"]
   weaviate_api_key = os.environ["WEAVIATE_API_KEY"]
   
   # Connect to Weaviate Cloud
   client = weaviate.connect_to_weaviate_cloud(
       cluster_url=weaviate_url,
       auth_credentials=Auth.api_key(weaviate_api_key),
   )
   
   def delete_by_property(...): ...
   
   # create collection and add data.
   data_rows = [
       {"title": f"Object {i+1}"} for i in range(5)
   ]
   
   collection = client.collections.get("collection_a")
   
   with collection.batch.fixed_size(batch_size=200) as batch:
       for data_row in data_rows:
           batch.add_object(
               properties=data_row,
           )
           if batch.number_errors > 10:
               print("Batch import stopped due to excessive errors.")
               break
   
   failed_objects = collection.batch.failed_objects
   if failed_objects:
       print(f"Number of failed imports: {len(failed_objects)}")
       print(f"First failed object: {failed_objects[0]}")
   
   # Execute the deletion
   delete_by_property(
       collection_names="collection_a",
       filter_criteria=Filter.by_property("title").equal("Object 1"),
       if_error="continue"
   )
   ```
   
   <!--
    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.
    -->
   
   <!--
   Thank you for contributing! Please make sure that your code changes
   are covered with tests. And in case of new features or big changes
   remember to adjust the documentation.
   
   Feel free to ping committers for the review!
   
   In case of an existing issue, reference it using one of the following:
   
   closes: #ISSUE
   related: #ISSUE
   
   How to write a good git commit message:
   http://chris.beams.io/posts/git-commit/
   -->
   
   
   
   <!-- Please keep an empty line above the dashes. -->
   ---
   **^ Add meaningful description above**
   Read the **[Pull Request 
Guidelines](https://github.com/apache/airflow/blob/main/contributing-docs/05_pull_requests.rst#pull-request-guidelines)**
 for more information.
   In case of fundamental code changes, an Airflow Improvement Proposal 
([AIP](https://cwiki.apache.org/confluence/display/AIRFLOW/Airflow+Improvement+Proposals))
 is needed.
   In case of a new dependency, check compliance with the [ASF 3rd Party 
License Policy](https://www.apache.org/legal/resolved.html#category-x).
   In case of backwards incompatible changes please leave a note in a 
newsfragment file, named `{pr_number}.significant.rst` or 
`{issue_number}.significant.rst`, in 
[airflow-core/newsfragments](https://github.com/apache/airflow/tree/main/airflow-core/newsfragments).
   


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