You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by GitBox <gi...@apache.org> on 2021/07/12 20:04:03 UTC

[GitHub] [airflow] ciancolo opened a new pull request #16937: New Tableau operator: TableauRefreshDatasourceOperator

ciancolo opened a new pull request #16937:
URL: https://github.com/apache/airflow/pull/16937


   Hello all,
   I propose you a new Airflow Operator for Tableau: `TableauRefreshDatasourceOperator`. This new operator uses the Tableau API to refresh an existing Datasource published in a Tableau Server. 
   
   The operator is very similar to `TableauRefreshWorkbookOperator`, but I thought it was more clear and clean to create a new one instead to modify the existing one.
   
   The operator is very useful to refresh data sources, not in time set way but in an asynchronous way, in my case, it is very useful to add the refresh after my ETL pipelines. I'm currently using this operator in my Airflow installation.
   
   ### Changes:
   
   1. Created TableauRefreshDatasourceOperator
   2. Created unit test for TableauRefreshDatasourceOperator
   3. Added the operator to the provider.yaml file
   
   
   Thank you.


-- 
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: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [airflow] potiuk commented on pull request #16937: New Tableau operator: TableauRefreshDatasourceOperator

Posted by GitBox <gi...@apache.org>.
potiuk commented on pull request #16937:
URL: https://github.com/apache/airflow/pull/16937#issuecomment-879102173


   Sure ! 


-- 
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: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [airflow] ciancolo commented on pull request #16937: New Tableau operator: TableauRefreshDatasourceOperator

Posted by GitBox <gi...@apache.org>.
ciancolo commented on pull request #16937:
URL: https://github.com/apache/airflow/pull/16937#issuecomment-879096648


   > This PR address several points:
   > 
   > 1. Add functionality to `TableauHook` to support waiting
   > 2. Refactor to `TableauRefreshWorkbookOperator` (removing the Sensor usage)
   > 3. Add new `TableauRefreshDatasourceOperator`
   > 
   > Item 1-2 are independent from 3. Item 3 may not be needed if #16915 is merged.
   > If that's OK with you and with @potiuk I suggest to split 1-2 to another PR that we can review quickly & separately and afterwards think about 3. WDYT?
   
   I agree with you, let's split 1-2 and then wait for #16915. If @potiuk agrees, I will split and create a new PR.


-- 
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: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [airflow] ciancolo commented on pull request #16937: New Tableau operator: TableauRefreshDatasourceOperator

Posted by GitBox <gi...@apache.org>.
ciancolo commented on pull request #16937:
URL: https://github.com/apache/airflow/pull/16937#issuecomment-898437188


   I think #16915 covers the functionality of this PR. 
   
   The current PR is not needed anymore.


-- 
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: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [airflow] potiuk commented on a change in pull request #16937: New Tableau operator: TableauRefreshDatasourceOperator

Posted by GitBox <gi...@apache.org>.
potiuk commented on a change in pull request #16937:
URL: https://github.com/apache/airflow/pull/16937#discussion_r667782720



##########
File path: airflow/providers/tableau/operators/tableau_refresh_datasource.py
##########
@@ -0,0 +1,95 @@
+# 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 Optional
+
+from tableauserverclient import DatasourceItem
+
+from airflow.exceptions import AirflowException
+from airflow.models import BaseOperator
+from airflow.providers.tableau.hooks.tableau import TableauHook
+
+
+class TableauRefreshDatasourceOperator(BaseOperator):
+    """
+    Refreshes a Tableau Datasource
+
+    .. seealso:: https://tableau.github.io/server-client-python/docs/api-ref#data-sources
+
+    :param datasource_name: The name of the datasource to refresh.
+    :type datasource_name: str
+    :param site_id: The id of the site where the datasource belongs to.
+    :type site_id: Optional[str]
+    :param blocking: By default the extract refresh will be blocking means it will wait until it has finished.
+    :type blocking: bool
+    :param tableau_conn_id: The Tableau Connection id containing the credentials
+        to authenticate to the Tableau Server.
+    :type tableau_conn_id: str
+    """
+
+    def __init__(
+        self,
+        *,
+        datasource_name: str,
+        site_id: Optional[str] = None,
+        blocking: bool = True,
+        tableau_conn_id: str = 'tableau_default',
+        **kwargs,
+    ) -> None:
+        super().__init__(**kwargs)
+        self.datasource_name = datasource_name
+        self.site_id = site_id
+        self.blocking = blocking
+        self.tableau_conn_id = tableau_conn_id
+
+    def execute(self, context: dict) -> str:
+        """
+        Executes the Tableau Extract Refresh and pushes the job id to xcom.
+
+        :param context: The task context during execution.
+        :type context: dict
+        :return: the id of the job that executes the extract refresh
+        :rtype: str
+        """
+        with TableauHook(self.site_id, self.tableau_conn_id) as tableau_hook:
+            datasource = self._get_datasource_by_name(tableau_hook)
+
+            job_id = self._refresh_datasource(tableau_hook, datasource.id)
+            if self.blocking:
+                from airflow.providers.tableau.sensors.tableau_job_status import TableauJobStatusSensor

Review comment:
       One small comment here though. It looks a bit strange to use sensor in operator. While I understand where it comes from, I would like to propose a small refactor. Why don't you extract the "poke()" internals as a separate Hook method `wait_until_succeeded` and use that method in both Sensor and refresh_datasource Operator?




-- 
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: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [airflow] eladkal commented on pull request #16937: New Tableau operator: TableauRefreshDatasourceOperator

Posted by GitBox <gi...@apache.org>.
eladkal commented on pull request #16937:
URL: https://github.com/apache/airflow/pull/16937#issuecomment-895031220


   hi @ciancolo https://github.com/apache/airflow/pull/16915 was just merged.
   Please check if this PR is still needed. If so please rebase/fix conflicts and explain what is the functionality added that isn't covered by `TableauOperator`


-- 
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: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [airflow] eladkal commented on a change in pull request #16937: New Tableau operator: TableauRefreshDatasourceOperator

Posted by GitBox <gi...@apache.org>.
eladkal commented on a change in pull request #16937:
URL: https://github.com/apache/airflow/pull/16937#discussion_r667850316



##########
File path: airflow/providers/tableau/operators/tableau_refresh_datasource.py
##########
@@ -0,0 +1,95 @@
+# 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 Optional
+
+from tableauserverclient import DatasourceItem
+
+from airflow.exceptions import AirflowException
+from airflow.models import BaseOperator
+from airflow.providers.tableau.hooks.tableau import TableauHook
+
+
+class TableauRefreshDatasourceOperator(BaseOperator):
+    """
+    Refreshes a Tableau Datasource
+
+    .. seealso:: https://tableau.github.io/server-client-python/docs/api-ref#data-sources
+
+    :param datasource_name: The name of the datasource to refresh.
+    :type datasource_name: str
+    :param site_id: The id of the site where the datasource belongs to.
+    :type site_id: Optional[str]
+    :param blocking: By default the extract refresh will be blocking means it will wait until it has finished.
+    :type blocking: bool
+    :param tableau_conn_id: The Tableau Connection id containing the credentials
+        to authenticate to the Tableau Server.
+    :type tableau_conn_id: str
+    """
+
+    def __init__(
+        self,
+        *,
+        datasource_name: str,
+        site_id: Optional[str] = None,
+        blocking: bool = True,
+        tableau_conn_id: str = 'tableau_default',
+        **kwargs,
+    ) -> None:
+        super().__init__(**kwargs)
+        self.datasource_name = datasource_name
+        self.site_id = site_id
+        self.blocking = blocking
+        self.tableau_conn_id = tableau_conn_id
+
+    def execute(self, context: dict) -> str:
+        """
+        Executes the Tableau Extract Refresh and pushes the job id to xcom.
+
+        :param context: The task context during execution.
+        :type context: dict
+        :return: the id of the job that executes the extract refresh
+        :rtype: str
+        """
+        with TableauHook(self.site_id, self.tableau_conn_id) as tableau_hook:
+            datasource = self._get_datasource_by_name(tableau_hook)
+
+            job_id = self._refresh_datasource(tableau_hook, datasource.id)
+            if self.blocking:
+                from airflow.providers.tableau.sensors.tableau_job_status import TableauJobStatusSensor

Review comment:
       Sorry commented with my work account rather than my personal one :)
   soe removed the previous comments
   
   > One small comment here though. It looks a bit strange to use sensor in operator
   
   This is how it's done now in `TableauRefreshWorkbookOperator` https://github.com/apache/airflow/blob/2fea4cdceaa12b3ac13f24eeb383af624aacb2e7/airflow/providers/tableau/operators/tableau_refresh_workbook.py#L74
   
   Also #16916 will replace the usage of the TableauJobStatusSensor

##########
File path: airflow/providers/tableau/operators/tableau_refresh_datasource.py
##########
@@ -0,0 +1,95 @@
+# 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 Optional
+
+from tableauserverclient import DatasourceItem
+
+from airflow.exceptions import AirflowException
+from airflow.models import BaseOperator
+from airflow.providers.tableau.hooks.tableau import TableauHook
+
+
+class TableauRefreshDatasourceOperator(BaseOperator):
+    """
+    Refreshes a Tableau Datasource
+
+    .. seealso:: https://tableau.github.io/server-client-python/docs/api-ref#data-sources
+
+    :param datasource_name: The name of the datasource to refresh.
+    :type datasource_name: str
+    :param site_id: The id of the site where the datasource belongs to.
+    :type site_id: Optional[str]
+    :param blocking: By default the extract refresh will be blocking means it will wait until it has finished.
+    :type blocking: bool
+    :param tableau_conn_id: The Tableau Connection id containing the credentials
+        to authenticate to the Tableau Server.
+    :type tableau_conn_id: str
+    """
+
+    def __init__(
+        self,
+        *,
+        datasource_name: str,
+        site_id: Optional[str] = None,
+        blocking: bool = True,
+        tableau_conn_id: str = 'tableau_default',
+        **kwargs,
+    ) -> None:
+        super().__init__(**kwargs)
+        self.datasource_name = datasource_name
+        self.site_id = site_id
+        self.blocking = blocking
+        self.tableau_conn_id = tableau_conn_id
+
+    def execute(self, context: dict) -> str:
+        """
+        Executes the Tableau Extract Refresh and pushes the job id to xcom.
+
+        :param context: The task context during execution.
+        :type context: dict
+        :return: the id of the job that executes the extract refresh
+        :rtype: str
+        """
+        with TableauHook(self.site_id, self.tableau_conn_id) as tableau_hook:
+            datasource = self._get_datasource_by_name(tableau_hook)
+
+            job_id = self._refresh_datasource(tableau_hook, datasource.id)
+            if self.blocking:
+                from airflow.providers.tableau.sensors.tableau_job_status import TableauJobStatusSensor

Review comment:
       Sorry commented with my work account rather than my personal one :)
   so removed the previous comments
   
   > One small comment here though. It looks a bit strange to use sensor in operator
   
   This is how it's done now in `TableauRefreshWorkbookOperator` https://github.com/apache/airflow/blob/2fea4cdceaa12b3ac13f24eeb383af624aacb2e7/airflow/providers/tableau/operators/tableau_refresh_workbook.py#L74
   
   Also #16916 will replace the usage of the TableauJobStatusSensor




-- 
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: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [airflow] pmalafosse commented on pull request #16937: New Tableau operator: TableauRefreshDatasourceOperator

Posted by GitBox <gi...@apache.org>.
pmalafosse commented on pull request #16937:
URL: https://github.com/apache/airflow/pull/16937#issuecomment-880255509


   Nice new operator! 
   
   There is this issue about TableauRefreshWorkbookOperator operator FYI https://github.com/apache/airflow/issues/16669 @ciancolo 


-- 
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: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [airflow] ciancolo commented on pull request #16937: New Tableau operator: TableauRefreshDatasourceOperator

Posted by GitBox <gi...@apache.org>.
ciancolo commented on pull request #16937:
URL: https://github.com/apache/airflow/pull/16937#issuecomment-880741600


   @pmalafosse I think that that issue is solved (or partially) with PR #16916 with the deprecation of the access token authentication.


-- 
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: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [airflow] ciancolo commented on a change in pull request #16937: New Tableau operator: TableauRefreshDatasourceOperator

Posted by GitBox <gi...@apache.org>.
ciancolo commented on a change in pull request #16937:
URL: https://github.com/apache/airflow/pull/16937#discussion_r667897125



##########
File path: airflow/providers/tableau/operators/tableau_refresh_datasource.py
##########
@@ -0,0 +1,95 @@
+# 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 Optional
+
+from tableauserverclient import DatasourceItem
+
+from airflow.exceptions import AirflowException
+from airflow.models import BaseOperator
+from airflow.providers.tableau.hooks.tableau import TableauHook
+
+
+class TableauRefreshDatasourceOperator(BaseOperator):
+    """
+    Refreshes a Tableau Datasource
+
+    .. seealso:: https://tableau.github.io/server-client-python/docs/api-ref#data-sources
+
+    :param datasource_name: The name of the datasource to refresh.
+    :type datasource_name: str
+    :param site_id: The id of the site where the datasource belongs to.
+    :type site_id: Optional[str]
+    :param blocking: By default the extract refresh will be blocking means it will wait until it has finished.
+    :type blocking: bool
+    :param tableau_conn_id: The Tableau Connection id containing the credentials
+        to authenticate to the Tableau Server.
+    :type tableau_conn_id: str
+    """
+
+    def __init__(
+        self,
+        *,
+        datasource_name: str,
+        site_id: Optional[str] = None,
+        blocking: bool = True,
+        tableau_conn_id: str = 'tableau_default',
+        **kwargs,
+    ) -> None:
+        super().__init__(**kwargs)
+        self.datasource_name = datasource_name
+        self.site_id = site_id
+        self.blocking = blocking
+        self.tableau_conn_id = tableau_conn_id
+
+    def execute(self, context: dict) -> str:
+        """
+        Executes the Tableau Extract Refresh and pushes the job id to xcom.
+
+        :param context: The task context during execution.
+        :type context: dict
+        :return: the id of the job that executes the extract refresh
+        :rtype: str
+        """
+        with TableauHook(self.site_id, self.tableau_conn_id) as tableau_hook:
+            datasource = self._get_datasource_by_name(tableau_hook)
+
+            job_id = self._refresh_datasource(tableau_hook, datasource.id)
+            if self.blocking:
+                from airflow.providers.tableau.sensors.tableau_job_status import TableauJobStatusSensor

Review comment:
       I didn't notice that! The most generic implementation of #16915 is cooler than mine. I will go with that! 
   
   Anyway, I had already implemented the requested changes, in a similar way of #16916 , but modified both the sensor and the hook. I pushed the implementation in case you want to use it to replace the `TableauJobStatusSensor` in the operators.




-- 
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: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [airflow] eladkal closed pull request #16937: New Tableau operator: TableauRefreshDatasourceOperator

Posted by GitBox <gi...@apache.org>.
eladkal closed pull request #16937:
URL: https://github.com/apache/airflow/pull/16937


   


-- 
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: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [airflow] eladkal commented on pull request #16937: New Tableau operator: TableauRefreshDatasourceOperator

Posted by GitBox <gi...@apache.org>.
eladkal commented on pull request #16937:
URL: https://github.com/apache/airflow/pull/16937#issuecomment-879018797


   This PR address several points:
   1. Add functionality to `TableauHook` to support waiting
   2. Refactor to `TableauRefreshWorkbookOperator` (removing the Sensor usage)
   3. Add new `TableauRefreshDatasourceOperator`
   
   Item 1-2 are independent from 3. Item 3 may not be needed if https://github.com/apache/airflow/pull/16915 is merged.
   If that's OK with you and with @potiuk  I suggest to split 1-2 to another PR that we can review quickly & separately and afterwards think about 3. WDYT?
   


-- 
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: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [airflow] github-actions[bot] commented on pull request #16937: New Tableau operator: TableauRefreshDatasourceOperator

Posted by GitBox <gi...@apache.org>.
github-actions[bot] commented on pull request #16937:
URL: https://github.com/apache/airflow/pull/16937#issuecomment-878128130


   The PR is likely OK to be merged with just subset of tests for default Python and Database versions without running the full matrix of tests, because it does not modify the core of Airflow. If the committers decide that the full tests matrix is needed, they will add the label 'full tests needed'. Then you should rebase to the latest main or amend the last commit of the PR, and push it with --force-with-lease.


-- 
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: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [airflow] elad-k commented on a change in pull request #16937: New Tableau operator: TableauRefreshDatasourceOperator

Posted by GitBox <gi...@apache.org>.
elad-k commented on a change in pull request #16937:
URL: https://github.com/apache/airflow/pull/16937#discussion_r667847281



##########
File path: airflow/providers/tableau/operators/tableau_refresh_datasource.py
##########
@@ -0,0 +1,95 @@
+# 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 Optional
+
+from tableauserverclient import DatasourceItem
+
+from airflow.exceptions import AirflowException
+from airflow.models import BaseOperator
+from airflow.providers.tableau.hooks.tableau import TableauHook
+
+
+class TableauRefreshDatasourceOperator(BaseOperator):
+    """
+    Refreshes a Tableau Datasource
+
+    .. seealso:: https://tableau.github.io/server-client-python/docs/api-ref#data-sources
+
+    :param datasource_name: The name of the datasource to refresh.
+    :type datasource_name: str
+    :param site_id: The id of the site where the datasource belongs to.
+    :type site_id: Optional[str]
+    :param blocking: By default the extract refresh will be blocking means it will wait until it has finished.
+    :type blocking: bool
+    :param tableau_conn_id: The Tableau Connection id containing the credentials
+        to authenticate to the Tableau Server.
+    :type tableau_conn_id: str
+    """
+
+    def __init__(
+        self,
+        *,
+        datasource_name: str,
+        site_id: Optional[str] = None,
+        blocking: bool = True,
+        tableau_conn_id: str = 'tableau_default',
+        **kwargs,
+    ) -> None:
+        super().__init__(**kwargs)
+        self.datasource_name = datasource_name
+        self.site_id = site_id
+        self.blocking = blocking
+        self.tableau_conn_id = tableau_conn_id
+
+    def execute(self, context: dict) -> str:
+        """
+        Executes the Tableau Extract Refresh and pushes the job id to xcom.
+
+        :param context: The task context during execution.
+        :type context: dict
+        :return: the id of the job that executes the extract refresh
+        :rtype: str
+        """
+        with TableauHook(self.site_id, self.tableau_conn_id) as tableau_hook:
+            datasource = self._get_datasource_by_name(tableau_hook)
+
+            job_id = self._refresh_datasource(tableau_hook, datasource.id)
+            if self.blocking:
+                from airflow.providers.tableau.sensors.tableau_job_status import TableauJobStatusSensor

Review comment:
       This is how it's done now in `TableauRefreshWorkbookOperator` https://github.com/apache/airflow/blob/2fea4cdceaa12b3ac13f24eeb383af624aacb2e7/airflow/providers/tableau/operators/tableau_refresh_workbook.py#L74

##########
File path: airflow/providers/tableau/operators/tableau_refresh_datasource.py
##########
@@ -0,0 +1,95 @@
+# 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 Optional
+
+from tableauserverclient import DatasourceItem
+
+from airflow.exceptions import AirflowException
+from airflow.models import BaseOperator
+from airflow.providers.tableau.hooks.tableau import TableauHook
+
+
+class TableauRefreshDatasourceOperator(BaseOperator):
+    """
+    Refreshes a Tableau Datasource
+
+    .. seealso:: https://tableau.github.io/server-client-python/docs/api-ref#data-sources
+
+    :param datasource_name: The name of the datasource to refresh.
+    :type datasource_name: str
+    :param site_id: The id of the site where the datasource belongs to.
+    :type site_id: Optional[str]
+    :param blocking: By default the extract refresh will be blocking means it will wait until it has finished.
+    :type blocking: bool
+    :param tableau_conn_id: The Tableau Connection id containing the credentials
+        to authenticate to the Tableau Server.
+    :type tableau_conn_id: str
+    """
+
+    def __init__(
+        self,
+        *,
+        datasource_name: str,
+        site_id: Optional[str] = None,
+        blocking: bool = True,
+        tableau_conn_id: str = 'tableau_default',
+        **kwargs,
+    ) -> None:
+        super().__init__(**kwargs)
+        self.datasource_name = datasource_name
+        self.site_id = site_id
+        self.blocking = blocking
+        self.tableau_conn_id = tableau_conn_id
+
+    def execute(self, context: dict) -> str:
+        """
+        Executes the Tableau Extract Refresh and pushes the job id to xcom.
+
+        :param context: The task context during execution.
+        :type context: dict
+        :return: the id of the job that executes the extract refresh
+        :rtype: str
+        """
+        with TableauHook(self.site_id, self.tableau_conn_id) as tableau_hook:
+            datasource = self._get_datasource_by_name(tableau_hook)
+
+            job_id = self._refresh_datasource(tableau_hook, datasource.id)
+            if self.blocking:
+                from airflow.providers.tableau.sensors.tableau_job_status import TableauJobStatusSensor

Review comment:
       > One small comment here though. It looks a bit strange to use sensor in operator
   
   This is how it's done now in `TableauRefreshWorkbookOperator` https://github.com/apache/airflow/blob/2fea4cdceaa12b3ac13f24eeb383af624aacb2e7/airflow/providers/tableau/operators/tableau_refresh_workbook.py#L74

##########
File path: airflow/providers/tableau/operators/tableau_refresh_datasource.py
##########
@@ -0,0 +1,95 @@
+# 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 Optional
+
+from tableauserverclient import DatasourceItem
+
+from airflow.exceptions import AirflowException
+from airflow.models import BaseOperator
+from airflow.providers.tableau.hooks.tableau import TableauHook
+
+
+class TableauRefreshDatasourceOperator(BaseOperator):
+    """
+    Refreshes a Tableau Datasource
+
+    .. seealso:: https://tableau.github.io/server-client-python/docs/api-ref#data-sources
+
+    :param datasource_name: The name of the datasource to refresh.
+    :type datasource_name: str
+    :param site_id: The id of the site where the datasource belongs to.
+    :type site_id: Optional[str]
+    :param blocking: By default the extract refresh will be blocking means it will wait until it has finished.
+    :type blocking: bool
+    :param tableau_conn_id: The Tableau Connection id containing the credentials
+        to authenticate to the Tableau Server.
+    :type tableau_conn_id: str
+    """
+
+    def __init__(
+        self,
+        *,
+        datasource_name: str,
+        site_id: Optional[str] = None,
+        blocking: bool = True,
+        tableau_conn_id: str = 'tableau_default',
+        **kwargs,
+    ) -> None:
+        super().__init__(**kwargs)
+        self.datasource_name = datasource_name
+        self.site_id = site_id
+        self.blocking = blocking
+        self.tableau_conn_id = tableau_conn_id
+
+    def execute(self, context: dict) -> str:
+        """
+        Executes the Tableau Extract Refresh and pushes the job id to xcom.
+
+        :param context: The task context during execution.
+        :type context: dict
+        :return: the id of the job that executes the extract refresh
+        :rtype: str
+        """
+        with TableauHook(self.site_id, self.tableau_conn_id) as tableau_hook:
+            datasource = self._get_datasource_by_name(tableau_hook)
+
+            job_id = self._refresh_datasource(tableau_hook, datasource.id)
+            if self.blocking:
+                from airflow.providers.tableau.sensors.tableau_job_status import TableauJobStatusSensor

Review comment:
       Also https://github.com/apache/airflow/pull/16916/ will replace the usage of the `TableauJobStatusSensor`




-- 
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: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org