-
Notifications
You must be signed in to change notification settings - Fork 4.7k
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
HIVE-28409: Column lineage when creating view is missing if atlas HiveHook is set #5370
Changes from all commits
1d14221
75787b6
e30d4e5
76a0e26
5a91e20
01cbcd0
9ac7895
346f7ab
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||
---|---|---|---|---|---|---|---|---|
|
@@ -79,7 +79,7 @@ public void initialize(HiveConf hiveConf) { | |||||||
|| postExecHooks.contains("org.apache.hadoop.hive.ql.hooks.PostExecutePrinter") | ||||||||
|| postExecHooks.contains("org.apache.hadoop.hive.ql.hooks.LineageLogger") | ||||||||
|| postExecHooks.contains("org.apache.atlas.hive.hook.HiveHook")) { | ||||||||
transformations.add(new Generator(postExecHooks)); | ||||||||
transformations.add(Generator.fromConf(hiveConf)); | ||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I assume that before that change, we read the transformations from the postExecHooks that is as far I remember, calculated once. And from now, we read those again at every single query execution. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
hive/ql/src/java/org/apache/hadoop/hive/ql/optimizer/Optimizer.java Lines 75 to 77 in 09553fc
I think this should be addressed in a follow-up only if this is bottleneck. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. thx |
||||||||
} | ||||||||
|
||||||||
// Try to transform OR predicates in Filter into simpler IN clauses first | ||||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,10 +19,15 @@ | |
package org.apache.hadoop.hive.ql.optimizer.lineage; | ||
|
||
import java.util.ArrayList; | ||
import java.util.HashSet; | ||
import java.util.LinkedHashMap; | ||
import java.util.Map; | ||
import java.util.Set; | ||
import java.util.function.Predicate; | ||
|
||
import org.apache.commons.lang3.EnumUtils; | ||
import org.apache.hadoop.conf.Configuration; | ||
import org.apache.hadoop.hive.conf.HiveConf; | ||
import org.apache.hadoop.hive.ql.exec.CommonJoinOperator; | ||
import org.apache.hadoop.hive.ql.exec.FilterOperator; | ||
import org.apache.hadoop.hive.ql.exec.GroupByOperator; | ||
|
@@ -59,11 +64,62 @@ public class Generator extends Transform { | |
|
||
private static final Logger LOG = LoggerFactory.getLogger(Generator.class); | ||
|
||
private final Set<String> hooks; | ||
private static final String ATLAS_HOOK_CLASSNAME = "org.apache.atlas.hive.hook.HiveHook"; | ||
private final Predicate<ParseContext> statementFilter; | ||
|
||
public Generator(Set<String> hooks) { | ||
this.hooks = hooks; | ||
enum LineageInfoFilter { | ||
CREATE_TABLE(parseContext -> parseContext.getCreateTable() != null), | ||
CREATE_TABLE_AS_SELECT(parseContext -> parseContext.getQueryProperties().isCTAS()), | ||
CREATE_VIEW(parseContext -> parseContext.getQueryProperties().isView()), | ||
CREATE_MATERIALIZED_VIEW(parseContext -> parseContext.getQueryProperties().isMaterializedView()), | ||
LOAD(parseContext -> !(parseContext.getLoadTableWork() == null || parseContext.getLoadTableWork().isEmpty())), | ||
QUERY(parseContext -> parseContext.getQueryProperties().isQuery()), | ||
ALL(parseContext -> true), | ||
NONE(parseContext -> false); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i still think that NONE is redundant, but I am fine to keep it |
||
|
||
final Predicate<ParseContext> predicate; | ||
|
||
LineageInfoFilter(Predicate<ParseContext> predicate) { | ||
this.predicate = predicate; | ||
} | ||
} | ||
|
||
public static Generator fromConf(HiveConf conf) { | ||
return new Generator(createFilterPredicateFromConf(conf)); | ||
} | ||
|
||
static Predicate<ParseContext> createFilterPredicateFromConf(Configuration conf) { | ||
Set<LineageInfoFilter> operations = new HashSet<>(); | ||
boolean noneSpecified = false; | ||
for (String valueText : conf.getStringCollection(HiveConf.ConfVars.HIVE_LINEAGE_STATEMENT_FILTER.varname)) { | ||
LineageInfoFilter enumValue = EnumUtils.getEnumIgnoreCase(LineageInfoFilter.class, valueText); | ||
if (enumValue == null) { | ||
throw new EnumConstantNotPresentException(LineageInfoFilter.class, valueText); | ||
} | ||
|
||
if (LineageInfoFilter.NONE == enumValue) { | ||
noneSpecified = true; | ||
deniskuzZ marked this conversation as resolved.
Show resolved
Hide resolved
|
||
continue; | ||
} | ||
|
||
operations.add(enumValue); | ||
} | ||
|
||
if (noneSpecified) { | ||
if (!operations.isEmpty()) { | ||
throw new IllegalArgumentException( | ||
"No other value can be specified when " + LineageInfoFilter.NONE.name() + " is present!"); | ||
} | ||
else { | ||
return parseContext -> false; | ||
} | ||
} | ||
|
||
return parseContext -> | ||
operations.stream().anyMatch(lineageInfoFilter -> lineageInfoFilter.predicate.test(parseContext)); | ||
} | ||
|
||
public Generator(Predicate<ParseContext> statementFilter) { | ||
this.statementFilter = statementFilter; | ||
} | ||
|
||
/* (non-Javadoc) | ||
|
@@ -72,18 +128,11 @@ public Generator(Set<String> hooks) { | |
@Override | ||
public ParseContext transform(ParseContext pctx) throws SemanticException { | ||
|
||
if (hooks != null && hooks.contains(ATLAS_HOOK_CLASSNAME)) { | ||
// Atlas would be interested in lineage information for insert,load,create etc. | ||
if (!pctx.getQueryProperties().isCTAS() | ||
&& !pctx.getQueryProperties().isMaterializedView() | ||
&& pctx.getQueryProperties().isQuery() | ||
&& pctx.getCreateTable() == null | ||
&& pctx.getCreateViewDesc() == null | ||
&& (pctx.getLoadTableWork() == null || pctx.getLoadTableWork().isEmpty())) { | ||
LOG.debug("Not evaluating lineage"); | ||
return pctx; | ||
} | ||
if (!statementFilter.test(pctx)) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have a fear that this change will break existing configs: Previously, we said that if the Atlas HiveHook is set, we will run that transformation. Now we are saying that if There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yes, it breaks existing configs but previously Atlas HiveHook-related filters were hardcoded and impossible to test. Now |
||
LOG.debug("Not evaluating lineage"); | ||
return pctx; | ||
deniskuzZ marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
Index index = pctx.getQueryState().getLineageState().getIndex(); | ||
if (index == null) { | ||
index = new Index(); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
/* | ||
* 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. | ||
*/ | ||
|
||
package org.apache.hadoop.hive.ql.optimizer.lineage; | ||
|
||
import org.apache.hadoop.hive.conf.HiveConf; | ||
import org.apache.hadoop.hive.ql.QueryProperties; | ||
import org.apache.hadoop.hive.ql.parse.ParseContext; | ||
import org.apache.hadoop.hive.ql.plan.HiveOperation; | ||
import org.junit.Test; | ||
|
||
import java.util.function.Predicate; | ||
|
||
import static org.hamcrest.CoreMatchers.is; | ||
import static org.hamcrest.MatcherAssert.assertThat; | ||
import static org.junit.Assert.*; | ||
|
||
public class TestGenerator { | ||
@Test | ||
public void testCreateFilterPredicateFromConf() { | ||
HiveConf conf = new HiveConf(); | ||
conf.set(HiveConf.ConfVars.HIVE_LINEAGE_STATEMENT_FILTER.varname, | ||
"CREATE_tABLE_AS_sELECT," + HiveOperation.QUERY.name()); | ||
|
||
Predicate<ParseContext> predicate = Generator.createFilterPredicateFromConf(conf); | ||
|
||
ParseContext parseContext = new ParseContext(); | ||
QueryProperties queryProperties = new QueryProperties(); | ||
queryProperties.setCTAS(true); | ||
parseContext.setQueryProperties(queryProperties); | ||
assertThat(predicate.test(parseContext), is(true)); | ||
|
||
parseContext = new ParseContext(); | ||
queryProperties = new QueryProperties(); | ||
queryProperties.setQuery(true); | ||
parseContext.setQueryProperties(queryProperties); | ||
assertThat(predicate.test(parseContext), is(true)); | ||
|
||
parseContext = new ParseContext(); | ||
queryProperties = new QueryProperties(); | ||
queryProperties.setView(true); | ||
parseContext.setQueryProperties(queryProperties); | ||
assertThat(predicate.test(parseContext), is(false)); | ||
} | ||
|
||
@Test | ||
public void testCreateFilterPredicateFromConfReturnsAlwaysTrueWhenSettingIsNotPresent() { | ||
HiveConf conf = new HiveConf(); | ||
|
||
Predicate<ParseContext> predicate = Generator.createFilterPredicateFromConf(conf); | ||
|
||
assertThat(predicate.test(new ParseContext()), is(true)); | ||
} | ||
|
||
@Test | ||
public void testCreateFilterPredicateFromConfReturnsAlwaysFalseWhenSettingValueIsEmptyString() { | ||
HiveConf conf = new HiveConf(); | ||
conf.set(HiveConf.ConfVars.HIVE_LINEAGE_STATEMENT_FILTER.varname, ""); | ||
|
||
Predicate<ParseContext> predicate = Generator.createFilterPredicateFromConf(conf); | ||
|
||
assertThat(predicate.test(new ParseContext()), is(false)); | ||
} | ||
|
||
@Test | ||
public void testCreateFilterPredicateFromConfThrowsExceptionWhenInputStringIsInvalid() { | ||
HiveConf conf = new HiveConf(); | ||
conf.set(HiveConf.ConfVars.HIVE_LINEAGE_STATEMENT_FILTER.varname, "Invalid"); | ||
|
||
EnumConstantNotPresentException exception = assertThrows( | ||
EnumConstantNotPresentException.class, | ||
() -> Generator.createFilterPredicateFromConf(conf) | ||
); | ||
|
||
assertThat(exception.getMessage(), is( | ||
"org.apache.hadoop.hive.ql.optimizer.lineage.Generator$LineageInfoFilter.Invalid")); | ||
} | ||
|
||
@Test | ||
public void testCreateFilterPredicateFromConfThrowsExceptionWhenNoneAndAnyOtherConstantPresent() { | ||
HiveConf conf = new HiveConf(); | ||
conf.set(HiveConf.ConfVars.HIVE_LINEAGE_STATEMENT_FILTER.varname, "None," + HiveOperation.QUERY.name()); | ||
|
||
IllegalArgumentException exception = assertThrows( | ||
IllegalArgumentException.class, | ||
() -> Generator.createFilterPredicateFromConf(conf) | ||
); | ||
|
||
assertThat(exception.getMessage(), is("No other value can be specified when NONE is present!")); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
set hive.exec.post.hooks=org.apache.hadoop.hive.ql.hooks.LineageLogger; | ||
set hive.lineage.statement.filter=Query; | ||
|
||
create table table_1_qegkz (id int, first_name string); | ||
create table table_2_gkvuw (id int, last_name string); | ||
|
||
select table_1_qegkz.id, concat_ws(' ' , table_1_qegkz.first_name, table_2_gkvuw.last_name) full_name from table_1_qegkz, table_2_gkvuw where table_1_qegkz.id = table_2_gkvuw.id; | ||
|
||
create view view_fcuyp as (select table_1_qegkz.id, concat_ws(' ' , table_1_qegkz.first_name, table_2_gkvuw.last_name) full_name from table_1_qegkz, table_2_gkvuw where table_1_qegkz.id = table_2_gkvuw.id); | ||
|
||
set hive.lineage.statement.filter=Query,CREATE_VIEW; | ||
|
||
create view view_fcuyp2 as (select table_1_qegkz.id, concat_ws(' ' , table_1_qegkz.first_name, table_2_gkvuw.last_name) full_name from table_1_qegkz, table_2_gkvuw where table_1_qegkz.id = table_2_gkvuw.id); |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
PREHOOK: query: create table table_1_qegkz (id int, first_name string) | ||
PREHOOK: type: CREATETABLE | ||
PREHOOK: Output: database:default | ||
PREHOOK: Output: default@table_1_qegkz | ||
PREHOOK: query: create table table_2_gkvuw (id int, last_name string) | ||
PREHOOK: type: CREATETABLE | ||
PREHOOK: Output: database:default | ||
PREHOOK: Output: default@table_2_gkvuw | ||
PREHOOK: query: select table_1_qegkz.id, concat_ws(' ' , table_1_qegkz.first_name, table_2_gkvuw.last_name) full_name from table_1_qegkz, table_2_gkvuw where table_1_qegkz.id = table_2_gkvuw.id | ||
PREHOOK: type: QUERY | ||
PREHOOK: Input: default@table_1_qegkz | ||
PREHOOK: Input: default@table_2_gkvuw | ||
#### A masked pattern was here #### | ||
{"version":"1.0","engine":"tez","database":"default","hash":"35144a690834a6399b85caf27dbf8a3c","queryText":"select table_1_qegkz.id, concat_ws(' ' , table_1_qegkz.first_name, table_2_gkvuw.last_name) full_name from table_1_qegkz, table_2_gkvuw where table_1_qegkz.id = table_2_gkvuw.id","edges":[{"sources":[2],"targets":[0],"edgeType":"PROJECTION"},{"sources":[3,4],"targets":[1],"expression":"concat_ws(' ', table_1_qegkz.first_name, table_2_gkvuw.last_name)","edgeType":"PROJECTION"},{"sources":[2],"targets":[0,1],"expression":"table_1_qegkz.id is not null","edgeType":"PREDICATE"},{"sources":[2,5],"targets":[0,1],"expression":"(table_1_qegkz.id = table_2_gkvuw.id)","edgeType":"PREDICATE"},{"sources":[5],"targets":[0,1],"expression":"table_2_gkvuw.id is not null","edgeType":"PREDICATE"}],"vertices":[{"id":0,"vertexType":"COLUMN","vertexId":"table_1_qegkz.id"},{"id":1,"vertexType":"COLUMN","vertexId":"full_name"},{"id":2,"vertexType":"COLUMN","vertexId":"default.table_1_qegkz.id"},{"id":3,"vertexType":"COLUMN","vertexId":"default.table_1_qegkz.first_name"},{"id":4,"vertexType":"COLUMN","vertexId":"default.table_2_gkvuw.last_name"},{"id":5,"vertexType":"COLUMN","vertexId":"default.table_2_gkvuw.id"}]} | ||
PREHOOK: query: create view view_fcuyp as (select table_1_qegkz.id, concat_ws(' ' , table_1_qegkz.first_name, table_2_gkvuw.last_name) full_name from table_1_qegkz, table_2_gkvuw where table_1_qegkz.id = table_2_gkvuw.id) | ||
PREHOOK: type: CREATEVIEW | ||
PREHOOK: Input: default@table_1_qegkz | ||
PREHOOK: Input: default@table_2_gkvuw | ||
PREHOOK: Output: database:default | ||
PREHOOK: Output: default@view_fcuyp | ||
{"version":"1.0","engine":"tez","database":"default","hash":"26e597ea7b3ca43b008466502b235b52","queryText":"create view view_fcuyp as (select table_1_qegkz.id, concat_ws(' ' , table_1_qegkz.first_name, table_2_gkvuw.last_name) full_name from table_1_qegkz, table_2_gkvuw where table_1_qegkz.id = table_2_gkvuw.id)","edges":[],"vertices":[]} | ||
PREHOOK: query: create view view_fcuyp2 as (select table_1_qegkz.id, concat_ws(' ' , table_1_qegkz.first_name, table_2_gkvuw.last_name) full_name from table_1_qegkz, table_2_gkvuw where table_1_qegkz.id = table_2_gkvuw.id) | ||
PREHOOK: type: CREATEVIEW | ||
PREHOOK: Input: default@table_1_qegkz | ||
PREHOOK: Input: default@table_2_gkvuw | ||
PREHOOK: Output: database:default | ||
PREHOOK: Output: default@view_fcuyp2 | ||
{"version":"1.0","engine":"tez","database":"default","hash":"3c6019537df2f6001cce07de1aa0e352","queryText":"create view view_fcuyp2 as (select table_1_qegkz.id, concat_ws(' ' , table_1_qegkz.first_name, table_2_gkvuw.last_name) full_name from table_1_qegkz, table_2_gkvuw where table_1_qegkz.id = table_2_gkvuw.id)","edges":[{"sources":[2],"targets":[0],"edgeType":"PROJECTION"},{"sources":[3,4],"targets":[1],"expression":"concat_ws(' ', table_1_qegkz.first_name, table_2_gkvuw.last_name)","edgeType":"PROJECTION"},{"sources":[2],"targets":[0,1],"expression":"table_1_qegkz.id is not null","edgeType":"PREDICATE"},{"sources":[2,5],"targets":[0,1],"expression":"(table_1_qegkz.id = table_2_gkvuw.id)","edgeType":"PREDICATE"},{"sources":[5],"targets":[0,1],"expression":"table_2_gkvuw.id is not null","edgeType":"PREDICATE"}],"vertices":[{"id":0,"vertexType":"COLUMN","vertexId":"default.view_fcuyp2.id"},{"id":1,"vertexType":"COLUMN","vertexId":"default.view_fcuyp2.full_name"},{"id":2,"vertexType":"COLUMN","vertexId":"default.table_1_qegkz.id"},{"id":3,"vertexType":"COLUMN","vertexId":"default.table_1_qegkz.first_name"},{"id":4,"vertexType":"COLUMN","vertexId":"default.table_2_gkvuw.last_name"},{"id":5,"vertexType":"COLUMN","vertexId":"default.table_2_gkvuw.id"}]} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would suggest using NONE as default.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
NONE means that this functionality is never triggered. IMHO all functionality should be tested otherwise follow-up changes in the project may make it impossible to turn it on in the future. We have experienced this in the past a few times.