Repository navigation
Add howto docs for Cassandra Operators (issues#8189) #9877
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
mik-laj
merged 2 commits into
apache:master
from
rootcss:docs_howto/cassandra_operators
Jul 19, 2020
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
airflow/providers/apache/cassandra/example_dags/__init__.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| # 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. |
54 changes: 54 additions & 0 deletions
54
airflow/providers/apache/cassandra/example_dags/example_cassandra_dag.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| # | ||
| # 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. | ||
|
|
||
| """ | ||
| Example Airflow DAG to check if a Cassandra Table and a Records exists | ||
| or not using `CassandraTableSensor` and `CassandraRecordSensor`. | ||
| """ | ||
| from airflow.models import DAG | ||
| from airflow.providers.apache.cassandra.sensors.record import CassandraRecordSensor | ||
| from airflow.providers.apache.cassandra.sensors.table import CassandraTableSensor | ||
| from airflow.utils.dates import days_ago | ||
|
|
||
| args = { | ||
| 'owner': 'Airflow', | ||
| 'start_date': days_ago(2) | ||
| } | ||
|
|
||
| with DAG( | ||
| dag_id='example_cassandra_operator', | ||
| default_args=args, | ||
| schedule_interval=None, | ||
| tags=['example'] | ||
| ) as dag: | ||
| # [START howto_operator_cassandra_table_sensor] | ||
| table_sensor = CassandraTableSensor( | ||
| task_id="cassandra_table_sensor", | ||
| cassandra_conn_id="cassandra_default", | ||
| table="keyspace_name.table_name", | ||
| ) | ||
| # [END howto_operator_cassandra_table_sensor] | ||
|
|
||
| # [START howto_operator_cassandra_record_sensor] | ||
| record_sensor = CassandraRecordSensor( | ||
| task_id="cassandra_record_sensor", | ||
| cassandra_conn_id="cassandra_default", | ||
| table="keyspace_name.table_name", | ||
| keys={"p1": "v1", "p2": "v2"}, | ||
| ) | ||
| # [END howto_operator_cassandra_record_sensor] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,114 @@ | ||
| .. 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. | ||
|
|
||
|
|
||
|
|
||
| Apache Cassandra Connection | ||
| =========================== | ||
|
|
||
| The Apache Cassandra connection type enables connection to `Apache Cassandra <https://cassandra.apache.org/>`__. | ||
|
|
||
| Default Connection IDs | ||
| ---------------------- | ||
|
|
||
| Cassandra hook and Cassandra operators use ``cassandra_default`` by default. | ||
|
|
||
| Configuring the Connection | ||
| -------------------------- | ||
| Host (required) | ||
| The host to connect to. It is possible to specify multiple hosts as a comma-separated list. | ||
|
|
||
| Schema (required) | ||
| The schema (keyspace) name to be used in the database. | ||
|
|
||
| Login (required) | ||
| The user name to connect. | ||
|
|
||
| Password (required) | ||
| The password to connect. | ||
|
|
||
| Port (required) | ||
| The port to connect. | ||
|
|
||
| Extra (optional) | ||
| The extra parameters (as json dictionary) that can be used in cassandra | ||
| connection. The following parameters out of the standard python parameters | ||
| are supported: | ||
|
|
||
| * ``load_balancing_policy`` - This parameter specifies the load balancing policy to be used. There are four available policies: | ||
| ``RoundRobinPolicy``, ``DCAwareRoundRobinPolicy``, ``WhiteListRoundRobinPolicy`` and ``TokenAwarePolicy``. ``RoundRobinPolicy`` is the default load balancing policy. | ||
| * ``load_balancing_policy_args`` - This parameter specifies the arguments for the load balancing policy being used. | ||
| * ``cql_version`` - This parameter specifies the CQL version of cassandra. | ||
| * ``ssl_options`` - This parameter specifies the details related to SSL, if it's enabled in Cassandra. | ||
|
|
||
|
|
||
| Examples for the **Extra** field | ||
| -------------------------------- | ||
|
|
||
| 1. Specifying ``ssl_options`` | ||
|
|
||
| If SSL is enabled in Cassandra, pass in a dict in the extra field as kwargs for ``ssl.wrap_socket()``. For example: | ||
|
|
||
| .. code-block:: JSON | ||
|
|
||
| { | ||
| "ssl_options" : { | ||
| "ca_certs" : "PATH/TO/CA_CERTS" | ||
| } | ||
| } | ||
|
|
||
| 2. Specifying ``load_balancing_policy`` and ``load_balancing_policy_args`` | ||
|
|
||
| Default load balancing policy is ``RoundRobinPolicy``. Following are a few samples to specify a different LB policy: | ||
|
|
||
| DCAwareRoundRobinPolicy: | ||
|
|
||
| .. code-block:: JSON | ||
|
|
||
| { | ||
| "load_balancing_policy": "DCAwareRoundRobinPolicy", | ||
| "load_balancing_policy_args": { | ||
| "local_dc": "LOCAL_DC_NAME", | ||
| "used_hosts_per_remote_dc": "SOME_INT_VALUE" | ||
| } | ||
| } | ||
|
|
||
| WhiteListRoundRobinPolicy: | ||
|
|
||
| .. code-block:: JSON | ||
|
|
||
| { | ||
| "load_balancing_policy": "WhiteListRoundRobinPolicy", | ||
| "load_balancing_policy_args": { | ||
| "hosts": ["HOST1", "HOST2", "HOST3"] | ||
| } | ||
| } | ||
|
|
||
| TokenAwarePolicy: | ||
|
|
||
| .. code-block:: JSON | ||
|
|
||
| { | ||
| "load_balancing_policy": "TokenAwarePolicy", | ||
| "load_balancing_policy_args": { | ||
| "child_load_balancing_policy": "CHILD_POLICY_NAME", | ||
| "child_load_balancing_policy_args": {} | ||
| } | ||
| } | ||
|
|
||
| .. seealso:: | ||
| https://pypi.org/project/cassandra-driver/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,70 @@ | ||
| .. 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. | ||
|
|
||
|
|
||
|
|
||
| Apache Cassandra Operators | ||
| ========================== | ||
|
|
||
| `Apache Cassandra <https://cassandra.apache.org/>`__ is an open source distributed NoSQL database that can be used when you need scalability and high availability without compromising performance. It offers linear scalability and fault-tolerance on commodity hardware or cloud infrastructure which makes it the perfect platform for mission-critical data. It supports multi-datacenter replication with lower latencies. | ||
|
|
||
| .. contents:: | ||
| :depth: 1 | ||
| :local: | ||
|
|
||
| Prerequisite | ||
| ------------ | ||
|
|
||
| To use operators, you must configure a :doc:`Cassandra Connection <../../connection/cassandra>`. | ||
|
|
||
| .. _howto/operator:CassandraTableSensor: | ||
|
|
||
| Waiting for a Table to be created | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
|
||
| The :class:`~airflow.providers.apache.cassandra.sensors.table.CassandraTableSensor` operator is used to check for the existence of a table in a Cassandra cluster. | ||
|
|
||
| Use the ``table`` parameter to poke until the provided table is found. Use dot notation to target a specific keyspace. | ||
|
|
||
| .. exampleinclude:: /../airflow/providers/apache/cassandra/example_dags/example_cassandra_dag.py | ||
| :language: python | ||
| :dedent: 4 | ||
| :start-after: [START howto_operator_cassandra_table_sensor] | ||
| :end-before: [END howto_operator_cassandra_table_sensor] | ||
|
|
||
|
|
||
| .. _howto/operator:CassandraRecordSensor: | ||
|
|
||
| Waiting for a Record to be created | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | ||
|
|
||
| The :class:`~airflow.providers.apache.cassandra.sensors.record.CassandraRecordSensor` operator is used to check for the existence of a record of a table in the Cassandra cluster. | ||
|
|
||
| Use the ``table`` parameter to mention the keyspace and table for the record. Use dot notation to target a specific keyspace. | ||
|
|
||
| Use the ``keys`` parameter to poke until the provided record is found. The existence of record is identified using key value pairs. In the given example, we're are looking for value ``v1`` in column ``p1`` and ``v2`` in column ``p2``. | ||
|
|
||
| .. exampleinclude:: /../airflow/providers/apache/cassandra/example_dags/example_cassandra_dag.py | ||
| :language: python | ||
| :dedent: 4 | ||
| :start-after: [START howto_operator_cassandra_record_sensor] | ||
| :end-before: [END howto_operator_cassandra_record_sensor] | ||
|
|
||
| Reference | ||
| ^^^^^^^^^ | ||
|
|
||
| For further information, look at `Cassandra Query Language (CQL) SELECT statement <https://cassandra.apache.org/doc/latest/cql/dml.html#select>`_. | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.