@Override
  public ObjectInspector initialize(ObjectInspector[] arguments) throws UDFArgumentException {
    if (arguments.length != 0) {
      throw new UDFArgumentLengthException(
          "The function RestrictInformationSchema does not take any arguments, but found " + arguments.length);
    }

    if (enabled == null) {
      HiveConf hiveConf = SessionState.getSessionConf();

      boolean enableHS2PolicyProvider = false;
      boolean enableMetastorePolicyProvider = false;

      HiveAuthorizer authorizer = SessionState.get().getAuthorizerV2();
      try {
        if (hiveConf.getBoolVar(HiveConf.ConfVars.HIVE_AUTHORIZATION_ENABLED)
            && authorizer.getHivePolicyProvider() != null) {
          enableHS2PolicyProvider = true;
        }
      } catch (HiveAuthzPluginException e) {
        LOG.warn("Error getting HivePolicyProvider", e);
      }

      if (!enableHS2PolicyProvider) {
        if (MetastoreConf.getVar(hiveConf, MetastoreConf.ConfVars.PRE_EVENT_LISTENERS) != null &&
            !MetastoreConf.getVar(hiveConf, MetastoreConf.ConfVars.PRE_EVENT_LISTENERS).isEmpty() &&
            HiveConf.getVar(hiveConf, HiveConf.ConfVars.HIVE_METASTORE_AUTHORIZATION_MANAGER) != null) {
          List<HiveMetastoreAuthorizationProvider> authorizerProviders;
          try {
            authorizerProviders = HiveUtils.getMetaStoreAuthorizeProviderManagers(
              hiveConf, HiveConf.ConfVars.HIVE_METASTORE_AUTHORIZATION_MANAGER,
              SessionState.get().getAuthenticator());
            for (HiveMetastoreAuthorizationProvider authProvider : authorizerProviders) {
              if (authProvider.getHivePolicyProvider() != null) {
                enableMetastorePolicyProvider = true;
                break;
              }
            }
          } catch (HiveAuthzPluginException e) {
            LOG.warn("Error getting HivePolicyProvider", e);
          } catch (HiveException e) {
            LOG.warn("Error instantiating hive.security.metastore.authorization.manager", e);
          }
        }
      }
      if (enableHS2PolicyProvider || enableMetastorePolicyProvider) {
        enabled = new BooleanWritable(true);
      } else {
        enabled = new BooleanWritable(false);
      }
    }

    return PrimitiveObjectInspectorFactory.writableBooleanObjectInspector;
  }
UDF to determine whether to enforce restriction of information schema.
This is intended for internal usage only. This function is not a deterministic function,
but a runtime constant. The return value is constant within a query but can be different between queries
ql/src/java/org/apache/hadoop/hive/ql/udf/generic/GenericUDFRestrictInformationSchema.java