dengzhhu653 commented on a change in pull request #1205: URL: https://github.com/apache/hive/pull/1205#discussion_r489144324
########## File path: ql/src/java/org/apache/hadoop/hive/ql/hooks/HooksLoader.java ########## @@ -0,0 +1,162 @@ +/* + * 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.hooks; + +import com.cronutils.utils.VisibleForTesting; +import org.apache.hadoop.hive.conf.HiveConf; +import org.apache.hadoop.hive.ql.exec.Utilities; +import org.apache.hadoop.hive.ql.session.SessionState; +import org.apache.hive.common.util.HiveStringUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; + +/** + * Loads and stores different kinds of hooks, provides {@link HooksLoader#addHook(HookContext.HookType, Object)}} to + * add hook alone or {@link HooksLoader#getHooks(HookContext.HookType, Class)} to get all hooks + * corresponding to the specific hook type. + */ +public class HooksLoader { + private static final Logger LOG = LoggerFactory.getLogger(HooksLoader.class); + private final HiveConf conf; + private final Hooks[] hooks; + private SessionState.LogHelper console; + + public HooksLoader(HiveConf conf) { + this.conf = conf; + this.hooks = new Hooks[HookContext.HookType.values().length]; + for (int i = 0; i < hooks.length; i++) { + hooks[i] = new Hooks(); + } + } + + public HooksLoader(HiveConf conf, SessionState.LogHelper console) { + this(conf); + this.console = console; + } + + /** + * Loads the configured hooks corresponding to the specific hook type. + * @param type hook type + */ + @VisibleForTesting + void loadHooksFromConf(HookContext.HookType type) { + Hooks container = hooks[type.ordinal()]; + if (!container.loadedFromConf) { Review comment: When we use HooksLoader to load the session hooks, redactor hooks that running outside the HookRunner, maybe there is no need to initialize other types of hooks, so I make the hooks loading lazily on demand. ---------------------------------------------------------------- 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. For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: gitbox-unsubscr...@hive.apache.org For additional commands, e-mail: gitbox-h...@hive.apache.org