0
0
Apache Airflowdevops~10 mins

SqlOperator for database queries in Apache Airflow - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to import the SqlOperator from Airflow.

Apache Airflow
from airflow.operators.[1] import SqlOperator
Drag options to blanks, or click blank then click option'
Asql
Bpython
Cbash
Demail
Attempts:
3 left
💡 Hint
Common Mistakes
Importing SqlOperator from the wrong module like bash or python operators.
2fill in blank
medium

Complete the code to create a SqlOperator task with task_id 'run_query'.

Apache Airflow
run_query = SqlOperator(task_id=[1], sql='SELECT 1')
Drag options to blanks, or click blank then click option'
A'sql_task'
B'execute_sql'
C'run_query'
D'query_task'
Attempts:
3 left
💡 Hint
Common Mistakes
Using a different task_id string than 'run_query'.
3fill in blank
hard

Fix the error in the SqlOperator initialization by completing the missing parameter for the database connection id.

Apache Airflow
run_query = SqlOperator(task_id='run_query', sql='SELECT * FROM users', [1]='my_db')
Drag options to blanks, or click blank then click option'
Adatabase
Bconn_id
Cdb_id
Dconnection
Attempts:
3 left
💡 Hint
Common Mistakes
Using incorrect parameter names like 'connection' or 'database'.
4fill in blank
hard

Fill both blanks to create a SqlOperator that runs a query stored in a file and uses the correct connection id.

Apache Airflow
run_query = SqlOperator(task_id='run_query', sql=[1], [2]='my_conn')
Drag options to blanks, or click blank then click option'
A'/path/to/query.sql'
B'SELECT * FROM table'
Cconn_id
Dconnection_id
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'connection_id' instead of 'conn_id'.
Passing raw SQL string instead of file path when asked.
5fill in blank
hard

Fill all three blanks to create a SqlOperator that runs a parameterized query with parameters and uses the correct connection id.

Apache Airflow
run_query = SqlOperator(task_id='run_query', sql=[1], parameters=[2], [3]='my_conn')
Drag options to blanks, or click blank then click option'
A'SELECT * FROM users WHERE age > %s'
B{'age': 30}
Cconn_id
D'SELECT * FROM users'
Attempts:
3 left
💡 Hint
Common Mistakes
Not using parameter placeholders in the SQL string.
Using wrong parameter names or connection parameter.