josh-fell commented on code in PR #24473:
URL: https://github.com/apache/airflow/pull/24473#discussion_r902739430


##########
airflow/providers/salesforce/operators/salesforce_bulk.py:
##########
@@ -0,0 +1,112 @@
+# 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 TYPE_CHECKING
+
+from airflow.exceptions import AirflowException
+from airflow.models import BaseOperator
+from airflow.providers.salesforce.hooks.salesforce import SalesforceHook
+
+if TYPE_CHECKING:
+    from airflow.utils.context import Context
+
+
+class SalesforceBulkOperator(BaseOperator):
+    """
+    Execute a Salesforce Bulk API and pushes results to xcom.
+
+    .. seealso::
+        For more information on how to use this operator, take a look at the 
guide:
+        :ref:`howto/operator:SalesforceBulkOperator`
+
+    :param operation: Bulk operation to be performed
+        Available operations are in ['insert', 'update', 'upsert', 'delete', 
'hard_delete']
+    :param object_name: The name of the Salesforce object
+    :param payload: list of dict to be passed as a batch
+    :param external_id_field: unique identifier field for upsert operations
+    :param batch_size: number of records to assign for each batch in the job
+    :param use_serial: Process batches in serial mode
+    :param salesforce_conn_id: The :ref:`Salesforce Connection id 
<howto/connection:SalesforceHook>`.
+    """
+
+    def __init__(
+        self,
+        *,
+        operation: str,
+        object_name: str,
+        payload: list,
+        external_id_field: str = 'Id',
+        batch_size: int = 10000,
+        use_serial: bool = False,
+        salesforce_conn_id: str = 'salesforce_default',
+        **kwargs,
+    ) -> None:
+        super().__init__(**kwargs)
+        self.operation = operation
+        self.object_name = object_name
+        self.payload = payload
+        self.external_id_field = external_id_field
+        self.batch_size = batch_size
+        self.use_serial = use_serial
+        self.salesforce_conn_id = salesforce_conn_id
+        self._validate_inputs()
+
+    def _validate_inputs(self) -> None:
+        if not self.object_name:
+            raise AirflowException("The required parameter 'object_name' is 
missing.")
+
+        available_operations = ['insert', 'update', 'upsert', 'delete', 
'hard_delete']
+        if self.operation not in available_operations:
+            raise AirflowException(f"Operation not found! Available operations 
are f{available_operations}.")

Review Comment:
   Same comment here too also looks like some leftovers from a previous 
f-string.
   ```suggestion
               raise ValueError(f"Operation not found! Available operations are 
{available_operations}.")
   ```



##########
docs/apache-airflow-providers-salesforce/operators/salesforce_bulk.rst:
##########
@@ -0,0 +1,55 @@
+ .. 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.
+
+.. _howto/operator:SalesforceBulkOperator:
+
+
+SalesforceBulkOperator
+======================
+
+Use the 
:class:`~airflow.providers.salesforce.operators.salesforce_bulk.SalesforceBulkOperator`
 to execute Bulk API.
+
+Using the Operator
+^^^^^^^^^^^^^^^^^^
+
+You can use this operator to access Bulk Insert API:
+
+.. exampleinclude:: 
/../../tests/system/providers/salesforce/example_salesforce_bulk.py
+    :language: python
+    :start-after: [START howto_salesforce_bulk_insert_operator]
+    :end-before: [END howto_salesforce_bulk_insert_operator]
+
+You can use this operator to access Bulk Update API:
+
+.. exampleinclude:: 
/../../tests/system/providers/salesforce/example_salesforce_bulk.py
+    :language: python
+    :start-after: [START howto_salesforce_bulk_update_operator]
+    :end-before: [END howto_salesforce_bulk_update_operator]
+
+You can use this operator to access Bulk Upsert API:
+
+.. exampleinclude:: 
/../../tests/system/providers/salesforce/example_salesforce_bulk.py
+    :language: python

Review Comment:
   ```suggestion
       :language: python
       :dedent: 4
   ```



##########
docs/apache-airflow-providers-salesforce/operators/salesforce_bulk.rst:
##########
@@ -0,0 +1,55 @@
+ .. 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.
+
+.. _howto/operator:SalesforceBulkOperator:
+
+
+SalesforceBulkOperator
+======================
+
+Use the 
:class:`~airflow.providers.salesforce.operators.salesforce_bulk.SalesforceBulkOperator`
 to execute Bulk API.
+
+Using the Operator
+^^^^^^^^^^^^^^^^^^
+
+You can use this operator to access Bulk Insert API:
+
+.. exampleinclude:: 
/../../tests/system/providers/salesforce/example_salesforce_bulk.py
+    :language: python
+    :start-after: [START howto_salesforce_bulk_insert_operator]
+    :end-before: [END howto_salesforce_bulk_insert_operator]
+
+You can use this operator to access Bulk Update API:
+
+.. exampleinclude:: 
/../../tests/system/providers/salesforce/example_salesforce_bulk.py
+    :language: python

Review Comment:
   ```suggestion
       :language: python
       :dedent: 4
   ```



##########
airflow/providers/salesforce/operators/salesforce_bulk.py:
##########
@@ -0,0 +1,110 @@
+# Licensed to the Apache Software Foundation (ASF) under one

Review Comment:
   I agree. Slightly unfortunate we already have `salesforce_apex_rest.py`. The 
naming is a little redundant and I don't think we need to continue to pattern.



##########
tests/providers/salesforce/operators/test_salesforce_bulk.py:
##########
@@ -0,0 +1,221 @@
+# 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.
+
+import unittest
+from unittest.mock import Mock, patch
+
+import pytest
+
+from airflow.exceptions import AirflowException
+from airflow.providers.salesforce.operators.salesforce_bulk import 
SalesforceBulkOperator
+
+
+class TestSalesforceBulkOperator(unittest.TestCase):

Review Comment:
   For net-new unit tests, `pytest` is preferable over `unittest`.



##########
docs/apache-airflow-providers-salesforce/operators/salesforce_bulk.rst:
##########
@@ -0,0 +1,55 @@
+ .. 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.
+
+.. _howto/operator:SalesforceBulkOperator:
+
+
+SalesforceBulkOperator
+======================
+
+Use the 
:class:`~airflow.providers.salesforce.operators.salesforce_bulk.SalesforceBulkOperator`
 to execute Bulk API.
+
+Using the Operator
+^^^^^^^^^^^^^^^^^^
+
+You can use this operator to access Bulk Insert API:
+
+.. exampleinclude:: 
/../../tests/system/providers/salesforce/example_salesforce_bulk.py
+    :language: python

Review Comment:
   ```suggestion
       :language: python
       :dedent: 4
   ```
   Since the `START` marker is indented we should use the `:dedent:` param for 
rendering the code snippet appropriately.



##########
airflow/providers/salesforce/operators/salesforce_bulk.py:
##########
@@ -0,0 +1,112 @@
+# 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 TYPE_CHECKING
+
+from airflow.exceptions import AirflowException
+from airflow.models import BaseOperator
+from airflow.providers.salesforce.hooks.salesforce import SalesforceHook
+
+if TYPE_CHECKING:
+    from airflow.utils.context import Context
+
+
+class SalesforceBulkOperator(BaseOperator):
+    """
+    Execute a Salesforce Bulk API and pushes results to xcom.
+
+    .. seealso::
+        For more information on how to use this operator, take a look at the 
guide:
+        :ref:`howto/operator:SalesforceBulkOperator`
+
+    :param operation: Bulk operation to be performed
+        Available operations are in ['insert', 'update', 'upsert', 'delete', 
'hard_delete']
+    :param object_name: The name of the Salesforce object
+    :param payload: list of dict to be passed as a batch
+    :param external_id_field: unique identifier field for upsert operations
+    :param batch_size: number of records to assign for each batch in the job
+    :param use_serial: Process batches in serial mode
+    :param salesforce_conn_id: The :ref:`Salesforce Connection id 
<howto/connection:SalesforceHook>`.
+    """
+
+    def __init__(
+        self,
+        *,
+        operation: str,
+        object_name: str,
+        payload: list,
+        external_id_field: str = 'Id',
+        batch_size: int = 10000,
+        use_serial: bool = False,
+        salesforce_conn_id: str = 'salesforce_default',
+        **kwargs,
+    ) -> None:
+        super().__init__(**kwargs)
+        self.operation = operation
+        self.object_name = object_name
+        self.payload = payload
+        self.external_id_field = external_id_field
+        self.batch_size = batch_size
+        self.use_serial = use_serial
+        self.salesforce_conn_id = salesforce_conn_id
+        self._validate_inputs()
+
+    def _validate_inputs(self) -> None:
+        if not self.object_name:
+            raise AirflowException("The required parameter 'object_name' is 
missing.")

Review Comment:
   ```suggestion
               raise ValueError("The required parameter 'object_name' is 
missing.")
   ```
   I think `AirflowException` is used _too_ broadly throughout the code base. 
`ValueError` seems like a better choice.



##########
airflow/providers/salesforce/operators/salesforce_bulk.py:
##########
@@ -0,0 +1,112 @@
+# 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 TYPE_CHECKING
+
+from airflow.exceptions import AirflowException
+from airflow.models import BaseOperator
+from airflow.providers.salesforce.hooks.salesforce import SalesforceHook
+
+if TYPE_CHECKING:
+    from airflow.utils.context import Context
+
+
+class SalesforceBulkOperator(BaseOperator):

Review Comment:
   WDYT about adding some `template_fields` for the operator? Not required, but 
just thinking about developer use cases for dynamic/templatized values, pulling 
values from Airflow Variables, etc.



##########
docs/apache-airflow-providers-salesforce/operators/salesforce_bulk.rst:
##########
@@ -0,0 +1,55 @@
+ .. 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.
+
+.. _howto/operator:SalesforceBulkOperator:
+
+
+SalesforceBulkOperator
+======================
+
+Use the 
:class:`~airflow.providers.salesforce.operators.salesforce_bulk.SalesforceBulkOperator`
 to execute Bulk API.
+
+Using the Operator
+^^^^^^^^^^^^^^^^^^
+
+You can use this operator to access Bulk Insert API:
+
+.. exampleinclude:: 
/../../tests/system/providers/salesforce/example_salesforce_bulk.py
+    :language: python
+    :start-after: [START howto_salesforce_bulk_insert_operator]
+    :end-before: [END howto_salesforce_bulk_insert_operator]
+
+You can use this operator to access Bulk Update API:
+
+.. exampleinclude:: 
/../../tests/system/providers/salesforce/example_salesforce_bulk.py
+    :language: python
+    :start-after: [START howto_salesforce_bulk_update_operator]
+    :end-before: [END howto_salesforce_bulk_update_operator]
+
+You can use this operator to access Bulk Upsert API:
+
+.. exampleinclude:: 
/../../tests/system/providers/salesforce/example_salesforce_bulk.py
+    :language: python
+    :start-after: [START howto_salesforce_bulk_upsert_operator]
+    :end-before: [END howto_salesforce_bulk_upsert_operator]
+
+You can use this operator to access Bulk Delete API:
+
+.. exampleinclude:: 
/../../tests/system/providers/salesforce/example_salesforce_bulk.py
+    :language: python

Review Comment:
   ```suggestion
       :language: python
       :dedent: 4
   ```



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