kasakrisz commented on code in PR #5370:
URL: https://github.com/apache/hive/pull/5370#discussion_r1694702041


##########
ql/src/java/org/apache/hadoop/hive/ql/optimizer/lineage/Generator.java:
##########
@@ -59,11 +68,63 @@ 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";
+  public static Generator fromConf(HiveConf conf) {
+    return new Generator(createFilterPredicateFromConf(conf));
+  }
+
+  private static final String ALL = "ALL";
+  private static final String NONE = "NONE";
+  private static final Map<HiveOperation, Function<ParseContext, Boolean>> 
filterMap;
 
-  public Generator(Set<String> hooks) {
-    this.hooks = hooks;
+  static {
+    Map<HiveOperation, Function<ParseContext, Boolean>> map = new HashMap<>();
+    map.put(HiveOperation.CREATETABLE, parseContext -> 
parseContext.getCreateTable() != null);
+    map.put(HiveOperation.CREATETABLE_AS_SELECT, parseContext -> 
parseContext.getQueryProperties().isCTAS());
+    map.put(HiveOperation.CREATEVIEW, parseContext -> 
parseContext.getQueryProperties().isView());
+    map.put(HiveOperation.CREATE_MATERIALIZED_VIEW,
+        parseContext -> 
parseContext.getQueryProperties().isMaterializedView());
+    map.put(HiveOperation.LOAD,
+        parseContext -> !(parseContext.getLoadTableWork() == null || 
parseContext.getLoadTableWork().isEmpty()));
+    map.put(HiveOperation.QUERY, parseContext -> 
parseContext.getQueryProperties().isQuery());
+    filterMap = Collections.unmodifiableMap(map);
+  }
+
+  static Predicate<ParseContext> createFilterPredicateFromConf(Configuration 
conf) {
+    Set<HiveOperation> operations = new HashSet<>();
+    boolean noneSpecified = false;
+    for (String valueText : 
conf.getStringCollection(HiveConf.ConfVars.HIVE_LINEAGE_STATEMENT_FILTER.varname))
 {
+      if (ALL.equalsIgnoreCase(valueText)) {
+        return parseContext -> true;
+      }
+      if (NONE.equalsIgnoreCase(valueText)) {
+        noneSpecified = true;
+        continue;
+      }
+
+      HiveOperation enumValue = 
EnumUtils.getEnumIgnoreCase(HiveOperation.class, valueText);
+      if (enumValue == null) {
+        throw new EnumConstantNotPresentException(HiveOperation.class, 
valueText);

Review Comment:
   Exception is thrown at compile time.
   Example:
   ```
   java.lang.EnumConstantNotPresentException: 
org.apache.hadoop.hive.ql.plan.HiveOperation.Hello
        at 
org.apache.hadoop.hive.ql.optimizer.lineage.Generator.createFilterPredicateFromConf(Generator.java:106)
        at 
org.apache.hadoop.hive.ql.optimizer.lineage.Generator.fromConf(Generator.java:72)
        at 
org.apache.hadoop.hive.ql.optimizer.Optimizer.initialize(Optimizer.java:82)
        at 
org.apache.hadoop.hive.ql.parse.SemanticAnalyzer.analyzeInternal(SemanticAnalyzer.java:13274)
   ...
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to