Uh oh!
There was an error while loading. Please reload this page.
[AIRFLOW-2463] Make task instance context available for hive queries - #3405
[AIRFLOW-2463] Make task instance context available for hive queries#3405KevinYang21 wants to merge 2 commits into
Conversation
e830fb5 to
9815017CompareCodecov Report
@@ Coverage Diff @@## master #3405 +/- ##
==========================================
+ Coverage 77.45% 77.46% +0.01%
==========================================
Files 204 204 Lines 15299 15326 +27 ==========================================
+ Hits 11850 11873 +23 - Misses 3449 3453 +4
Continue to review full report at Codecov.
|
7ff263e to
fc7467fCompareFokko
commented
May 24, 2018
Could you rebase against master? I see a lot of changes, also some files that look unrelated, like the python operator. @gglanzani Hive master, can you take a peek? |
fc7467f to
266a27aCompareKevinYang21
commented
May 24, 2018
Thank you @Fokko for taking a look. I was working on making the PR pass the CI, will update the PR description later to provide more context on this change. |
266a27a to
b8237aaCompareKevinYang21
commented
May 25, 2018
There was a problem hiding this comment.
Needed to make beeline hook work.
There was a problem hiding this comment.
Since this is just a string, can you write it as
jdbc_url='"{}"'.format(jdbc_url)as to avoid escaping?
There was a problem hiding this comment.
Needed to make beeline hook work properly (otherwise last statement won't be executed).
b8237aa to
3b7ca79CompareThere was a problem hiding this comment.
Call me a moron, but I prefer dict comprehension here
8476d26 to
8d0f72fCompareFokko
commented
Jun 9, 2018
The most important thing is that we don't change current behaviour, we can extend it, but it should be backwards compatible. |
b9222c8 to
1eeba1bCompareKevinYang21
commented
Jun 10, 2018
94d1c56 to
be2ad65Compare
KevinYang21
left a comment
There was a problem hiding this comment.
Rebased to pyhive, also added unit test for hive server2 hook since the blocking dependency issue was lifted by switching to pyhive.
There was a problem hiding this comment.
@gglanzani adding the condition here for queries like set key
There was a problem hiding this comment.
@yrqls21 Pardon my ignorance – I couldn't get Google to help me either – what kind of queries do start with set key?
There was a problem hiding this comment.
I meant those query to get variable value like 'set airflow.ctx.task_id' would return the value set by set airflow.ctx.task_id=some_id.
There was a problem hiding this comment.
@gglanzani had to extract the actually result string from a result tuple after rebased to pyhive, while we use to get the result string directly when using impyla. Should we be concerned about this change or make it to UPDATING.md( or maybe u have done that and I missed)?
There was a problem hiding this comment.
@yrqls21 I understand what you mean. PyHive returns indeed always tuples, and I call list on them, i.e. we always get structures as
[(1,), (2,)]I did not know that Impyla returned a list of elements in the above case. I don't have a working impyla installation to test that.
The DB 2 API (that Impyla should have been following and PyHive is following) prescribes that the results should be a sequence of sequences. We are doing the proper thing here IMHO.
The fact remains that this behaviour might be unexpected when updating, so I guess we need to update UPDATING.md (I haven't done it).
Is it possible to do it here? I think this text would suffice:
HiveServer2Hook.get_results()always returns a list of tuples, even when a single column is queried, as per Python API 2.
@Fokko: Agree?
There was a problem hiding this comment.
I agree if that's what DB2 API specifies.
be2ad65 to
35345fdCompareKevinYang21
commented
Jul 3, 2018
ping |
1 similar comment
KevinYang21
commented
Jul 11, 2018
ping |
gglanzani
commented
Jul 11, 2018
@Fokko lgtm |
[AIRFLOW-2463] Make task instance context available for hive queries update UPDATING.md, please squash Closesapache#3405 from yrqls21/kevin_yang_add_context
[AIRFLOW-2463] Make task instance context available for hive queries update UPDATING.md, please squash Closesapache#3405 from yrqls21/kevin_yang_add_context
Make sure you have checked all steps below.
JIRA
Description
This PR is mainly to enable hive (e.g. through hive audit hook) to log task instance context( dag_id, task_id, dag_run_id and task instance execution_date) for hive queries. This would give users more audit and research power. For example:
This change will make task instance context available in the following cases:
The following cases are already covered without this change (with updated names):
The following cases are not cover even with this change:
NOTE:
If as environment variable, context would be available as
AIRFLOW_CTX_DAG_ID,AIRFLOW_CTX_TASK_ID,AIRFLOW_CTX_EXECUTION_DATE,AIRFLOW_CTX_DAG_RUN_ID.If as hvie_conf, as
airflow.ctx.dag_id,airflow.ctx.task_id,airflow.ctx.execution_date,airflow.ctx.dag_run_id. This is to follow the environment variable and hive conf naming convention.Tests
-- tests/operators/bash_operator.py
-- tests/operators/python_operator.py:PythonOperatorTest.test_echo_env_variables
-- tests/hooks/test_hive_hook.py: TestHiveCliHook.test_run_cli_with_hive_conf
-- tests/hooks/test_hive_hook.py: TestHiveServer2Hook. test_get_results_with_hive_conf
HiveServer2Hook uses impyla, which is compatible with at most thrift==0.9.3, but we are using thrift==0.11.0 in our CI. However we cannot just downgrade thrift because our new client package used in HiveCliHook, hmsclient, cannot work with thrift<=0.9.3. Thus the unit tests for HiveSever2Hook are removed and tested manually instead.
This logic has been running in Airbnb production for a week.
airflow testoutput:hive_cli task:
beeline task:
hive_in_python_op task:
echo_env_vars task:
Commits
Documentation
Code Quality
git diff upstream/master -u -- "*.py" | flake8 --diff