7
7
# to you under the Apache License, Version 2.0 (the
8
8
# "License"); you may not use this file except in compliance
9
9
# with the License. You may obtain a copy of the License at
10
- #
10
+ #
11
11
# http://www.apache.org/licenses/LICENSE-2.0
12
- #
12
+ #
13
13
# Unless required by applicable law or agreed to in writing,
14
14
# software distributed under the License is distributed on an
15
15
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
22
22
import datetime
23
23
import os
24
24
import unittest
25
- import mock
26
25
import nose
27
- import six
28
26
29
- from airflow import DAG , configuration , operators
27
+ from airflow import DAG , configuration
28
+ import airflow .operators .hive_operator
30
29
configuration .load_test_config ()
31
30
32
31
@@ -61,7 +60,7 @@ def setUp(self):
61
60
class HiveOperatorConfigTest (HiveEnvironmentTest ):
62
61
63
62
def test_hive_airflow_default_config_queue (self ):
64
- t = operators .hive_operator .HiveOperator (
63
+ t = airflow . operators .hive_operator .HiveOperator (
65
64
task_id = 'test_default_config_queue' ,
66
65
hql = self .hql ,
67
66
mapred_queue_priority = 'HIGH' ,
@@ -77,7 +76,7 @@ def test_hive_airflow_default_config_queue(self):
77
76
78
77
def test_hive_airflow_default_config_queue_override (self ):
79
78
specific_mapred_queue = 'default'
80
- t = operators .hive_operator .HiveOperator (
79
+ t = airflow . operators .hive_operator .HiveOperator (
81
80
task_id = 'test_default_config_queue' ,
82
81
hql = self .hql ,
83
82
mapred_queue = specific_mapred_queue ,
@@ -92,15 +91,15 @@ class HiveOperatorTest(HiveEnvironmentTest):
92
91
93
92
def test_hiveconf_jinja_translate (self ):
94
93
hql = "SELECT ${num_col} FROM ${hiveconf:table};"
95
- t = operators .hive_operator .HiveOperator (
94
+ t = airflow . operators .hive_operator .HiveOperator (
96
95
hiveconf_jinja_translate = True ,
97
96
task_id = 'dry_run_basic_hql' , hql = hql , dag = self .dag )
98
97
t .prepare_template ()
99
98
self .assertEqual (t .hql , "SELECT {{ num_col }} FROM {{ table }};" )
100
99
101
100
def test_hiveconf (self ):
102
101
hql = "SELECT * FROM ${hiveconf:table} PARTITION (${hiveconf:day});"
103
- t = operators .hive_operator .HiveOperator (
102
+ t = airflow . operators .hive_operator .HiveOperator (
104
103
hiveconfs = {'table' : 'static_babynames' , 'day' : '{{ ds }}' },
105
104
task_id = 'dry_run_basic_hql' , hql = hql , dag = self .dag )
106
105
t .prepare_template ()
@@ -117,13 +116,13 @@ def test_hiveconf(self):
117
116
class HivePrestoTest (HiveEnvironmentTest ):
118
117
119
118
def test_hive (self ):
120
- t = operators .hive_operator .HiveOperator (
119
+ t = airflow . operators .hive_operator .HiveOperator (
121
120
task_id = 'basic_hql' , hql = self .hql , dag = self .dag )
122
121
t .run (start_date = DEFAULT_DATE , end_date = DEFAULT_DATE ,
123
122
ignore_ti_state = True )
124
123
125
124
def test_hive_queues (self ):
126
- t = operators .hive_operator .HiveOperator (
125
+ t = airflow . operators .hive_operator .HiveOperator (
127
126
task_id = 'test_hive_queues' , hql = self .hql ,
128
127
mapred_queue = 'default' , mapred_queue_priority = 'HIGH' ,
129
128
mapred_job_name = 'airflow.test_hive_queues' ,
@@ -132,12 +131,12 @@ def test_hive_queues(self):
132
131
ignore_ti_state = True )
133
132
134
133
def test_hive_dryrun (self ):
135
- t = operators .hive_operator .HiveOperator (
134
+ t = airflow . operators .hive_operator .HiveOperator (
136
135
task_id = 'dry_run_basic_hql' , hql = self .hql , dag = self .dag )
137
136
t .dry_run ()
138
137
139
138
def test_beeline (self ):
140
- t = operators .hive_operator .HiveOperator (
139
+ t = airflow . operators .hive_operator .HiveOperator (
141
140
task_id = 'beeline_hql' , hive_cli_conn_id = 'beeline_default' ,
142
141
hql = self .hql , dag = self .dag )
143
142
t .run (start_date = DEFAULT_DATE , end_date = DEFAULT_DATE ,
@@ -147,13 +146,13 @@ def test_presto(self):
147
146
sql = """
148
147
SELECT count(1) FROM airflow.static_babynames_partitioned;
149
148
"""
150
- t = operators .presto_check_operator .PrestoCheckOperator (
149
+ t = airflow . operators .presto_check_operator .PrestoCheckOperator (
151
150
task_id = 'presto_check' , sql = sql , dag = self .dag )
152
151
t .run (start_date = DEFAULT_DATE , end_date = DEFAULT_DATE ,
153
152
ignore_ti_state = True )
154
153
155
154
def test_presto_to_mysql (self ):
156
- t = operators .presto_to_mysql .PrestoToMySqlTransfer (
155
+ t = airflow . operators .presto_to_mysql .PrestoToMySqlTransfer (
157
156
task_id = 'presto_to_mysql_check' ,
158
157
sql = """
159
158
SELECT name, count(*) as ccount
@@ -167,15 +166,15 @@ def test_presto_to_mysql(self):
167
166
ignore_ti_state = True )
168
167
169
168
def test_hdfs_sensor (self ):
170
- t = operators .sensors .HdfsSensor (
169
+ t = airflow . operators .sensors .HdfsSensor (
171
170
task_id = 'hdfs_sensor_check' ,
172
171
filepath = 'hdfs://user/hive/warehouse/airflow.db/static_babynames' ,
173
172
dag = self .dag )
174
173
t .run (start_date = DEFAULT_DATE , end_date = DEFAULT_DATE ,
175
174
ignore_ti_state = True )
176
175
177
176
def test_webhdfs_sensor (self ):
178
- t = operators .sensors .WebHdfsSensor (
177
+ t = airflow . operators .sensors .WebHdfsSensor (
179
178
task_id = 'webhdfs_sensor_check' ,
180
179
filepath = 'hdfs://user/hive/warehouse/airflow.db/static_babynames' ,
181
180
timeout = 120 ,
@@ -184,7 +183,7 @@ def test_webhdfs_sensor(self):
184
183
ignore_ti_state = True )
185
184
186
185
def test_sql_sensor (self ):
187
- t = operators .sensors .SqlSensor (
186
+ t = airflow . operators .sensors .SqlSensor (
188
187
task_id = 'hdfs_sensor_check' ,
189
188
conn_id = 'presto_default' ,
190
189
sql = "SELECT 'x' FROM airflow.static_babynames LIMIT 1;" ,
@@ -193,7 +192,7 @@ def test_sql_sensor(self):
193
192
ignore_ti_state = True )
194
193
195
194
def test_hive_stats (self ):
196
- t = operators .hive_stats_operator .HiveStatsCollectionOperator (
195
+ t = airflow . operators .hive_stats_operator .HiveStatsCollectionOperator (
197
196
task_id = 'hive_stats_check' ,
198
197
table = "airflow.static_babynames_partitioned" ,
199
198
partition = {'ds' : DEFAULT_DATE_DS },
@@ -202,7 +201,7 @@ def test_hive_stats(self):
202
201
ignore_ti_state = True )
203
202
204
203
def test_named_hive_partition_sensor (self ):
205
- t = operators .sensors .NamedHivePartitionSensor (
204
+ t = airflow . operators .sensors .NamedHivePartitionSensor (
206
205
task_id = 'hive_partition_check' ,
207
206
partition_names = [
208
207
"airflow.static_babynames_partitioned/ds={{ds}}"
@@ -212,7 +211,7 @@ def test_named_hive_partition_sensor(self):
212
211
ignore_ti_state = True )
213
212
214
213
def test_named_hive_partition_sensor_succeeds_on_multiple_partitions (self ):
215
- t = operators .sensors .NamedHivePartitionSensor (
214
+ t = airflow . operators .sensors .NamedHivePartitionSensor (
216
215
task_id = 'hive_partition_check' ,
217
216
partition_names = [
218
217
"airflow.static_babynames_partitioned/ds={{ds}}" ,
@@ -223,15 +222,15 @@ def test_named_hive_partition_sensor_succeeds_on_multiple_partitions(self):
223
222
ignore_ti_state = True )
224
223
225
224
def test_named_hive_partition_sensor_parses_partitions_with_periods (self ):
226
- t = operators .sensors .NamedHivePartitionSensor .parse_partition_name (
225
+ t = airflow . operators .sensors .NamedHivePartitionSensor .parse_partition_name (
227
226
partition = "schema.table/part1=this.can.be.an.issue/part2=ok" )
228
227
self .assertEqual (t [0 ], "schema" )
229
228
self .assertEqual (t [1 ], "table" )
230
229
self .assertEqual (t [2 ], "part1=this.can.be.an.issue/part2=this_should_be_ok" )
231
230
232
231
@nose .tools .raises (airflow .exceptions .AirflowSensorTimeout )
233
232
def test_named_hive_partition_sensor_times_out_on_nonexistent_partition (self ):
234
- t = operators .sensors .NamedHivePartitionSensor (
233
+ t = airflow . operators .sensors .NamedHivePartitionSensor (
235
234
task_id = 'hive_partition_check' ,
236
235
partition_names = [
237
236
"airflow.static_babynames_partitioned/ds={{ds}}" ,
@@ -244,15 +243,15 @@ def test_named_hive_partition_sensor_times_out_on_nonexistent_partition(self):
244
243
ignore_ti_state = True )
245
244
246
245
def test_hive_partition_sensor (self ):
247
- t = operators .sensors .HivePartitionSensor (
246
+ t = airflow . operators .sensors .HivePartitionSensor (
248
247
task_id = 'hive_partition_check' ,
249
248
table = 'airflow.static_babynames_partitioned' ,
250
249
dag = self .dag )
251
250
t .run (start_date = DEFAULT_DATE , end_date = DEFAULT_DATE ,
252
251
ignore_ti_state = True )
253
252
254
253
def test_hive_metastore_sql_sensor (self ):
255
- t = operators .sensors .MetastorePartitionSensor (
254
+ t = airflow . operators .sensors .MetastorePartitionSensor (
256
255
task_id = 'hive_partition_check' ,
257
256
table = 'airflow.static_babynames_partitioned' ,
258
257
partition_name = 'ds={}' .format (DEFAULT_DATE_DS ),
@@ -261,7 +260,7 @@ def test_hive_metastore_sql_sensor(self):
261
260
ignore_ti_state = True )
262
261
263
262
def test_hive2samba (self ):
264
- t = operators .hive_to_samba_operator .Hive2SambaOperator (
263
+ t = airflow . operators .hive_to_samba_operator .Hive2SambaOperator (
265
264
task_id = 'hive2samba_check' ,
266
265
samba_conn_id = 'tableau_samba' ,
267
266
hql = "SELECT * FROM airflow.static_babynames LIMIT 10000" ,
@@ -271,7 +270,7 @@ def test_hive2samba(self):
271
270
ignore_ti_state = True )
272
271
273
272
def test_hive_to_mysql (self ):
274
- t = operators .hive_to_mysql .HiveToMySqlTransfer (
273
+ t = airflow . operators .hive_to_mysql .HiveToMySqlTransfer (
275
274
mysql_conn_id = 'airflow_db' ,
276
275
task_id = 'hive_to_mysql_check' ,
277
276
create = True ,
0 commit comments