Apache Airflow™
To operate under the Apache Airflow™YQExecuteQueryOperator
To run queries against Yandex Query, you need to initialize YQExecuteQueryOperator using the arguments listed below.
Required arguments:
name: Apache Airflow™ task name.sql: SQL query to run against Yandex Query.
Optional arguments:
folder_id: Target folder for the query. If not specified, it defaults to the Managed Service for Apache Airflow™ folder.yandex_conn_id: Connection ID of typeyandexcloud, containing the parameters for connecting to Yandex Cloud. If not specified, defaults to theyandexcloud_defaultconnection. Theyandexcloud_defaultconnection comes preconfigured with Managed Service for Apache Airflow™, so you do not need to create it manually.
Here is an example:
yq_operator = YQExecuteQueryOperator(task_id="yq_operator", sql="SELECT 'Hello, world!'")
This example creates an Apache Airflow™ task with ID yq_operator that runs SELECT 'Hello, world!'. For a complete example of running a query in Yandex Query from Managed Service for Apache Airflow™, refer to Automating Yandex Query tasks with Yandex Managed Service for Apache Airflow™.
Return values
A successful YQExecuteQueryOperator returns data as a dict that contains an array of column descriptions and an array of result rows.
Query:
yq_operator = YQExecuteQueryOperator(task_id="yq_operator", sql="SELECT 'Hello, World!'")
Result:
{
'rows': [['Hello, world!']],
'columns': [{'name': 'column0', 'type': 'String'}]
}
| Field | Description |
|---|---|
columns |
Result column array |
columns[].name |
Column name |
columns[].type |
Column data type |
rows |
Result row array Each row array’s element count matches the number of columns in the columns field |
YQL to Python type mapping
The following rules apply when converting YQL types to Python types.
Scalar types
| YQL type | Python type | Python example |
|---|---|---|
Int8, Int16, Int32, Uint8, Uint16, Uint32, Int64, Uint64 |
int |
647713 |
Bool |
bool |
True |
Float, Double |
doubleNaN and Inf become None |
7.88731023None |
Decimal |
Decimal |
45.23410083 |
Utf8 |
str |
String text |
String |
str bytes |
String text |
Complex types
| YQL type | Python type | Python example |
|---|---|---|
Json, JsonDocument |
str (whole node serialized to a string) |
{"a":[1,2,3]} |
Date, Datetime, Timestamp |
datetime |
2022-02-09 |
Optional types
| YQL type | Python type | Python example |
|---|---|---|
Optional |
Original type or None | 1 |
Containers
| YQL type | Python type | Python example |
|---|---|---|
List<Type> |
list |
[1,2,3,4] |
Dict<KeyType, ValueType> |
dict |
{key1: value1, key2: value2} |
Set<KeyType> |
set |
set(key_value1, key_value2) |
Tuple<Type1, Type2> |
tuple |
(element1, element2, ..) |
Struct<Name:Utf8,Age:Int32> |
dict |
{ "Name": "John", "Age": 128 } |
Variant<Type1, Type2> with a tuple |
list |
list[64563, 1] |
Variant<value:Int32,error:String> structured string |
dict |
{key1: value1, key2: value2} |
Special types
| YQL type | Python type |
|---|---|
Void, Null |
None |
EmptyList |
[] |
EmptyDict |
{} |