@Override
    public Catalog createCatalog(Context context) {
        final FactoryUtil.CatalogFactoryHelper helper =
                FactoryUtil.createCatalogFactoryHelper(this, context);
        helper.validate();

        return new HiveCatalog(
                context.getName(),
                helper.getOptions().get(DEFAULT_DATABASE),
                helper.getOptions().get(HIVE_CONF_DIR),
                helper.getOptions().get(HADOOP_CONF_DIR),
                helper.getOptions().get(HIVE_VERSION));
    }
@Test
    public void testLoadHadoopConfigFromEnv() throws IOException {
        Map<String, String> customProps = new HashMap<>();
        String k1 = "what is connector?";
        String v1 = "Hive";
        final String catalogName = "HiveCatalog";

        // set HADOOP_CONF_DIR env
        final File hadoopConfDir = tempFolder.newFolder();
        final File hdfsSiteFile = new File(hadoopConfDir, "hdfs-site.xml");
        writeProperty(hdfsSiteFile, k1, v1);
        customProps.put(k1, v1);

        // add mapred-site file
        final File mapredSiteFile = new File(hadoopConfDir, "mapred-site.xml");
        k1 = "mapred.site.config.key";
        v1 = "mapred.site.config.val";
        writeProperty(mapredSiteFile, k1, v1);
        customProps.put(k1, v1);

        final Map<String, String> originalEnv = System.getenv();
        final Map<String, String> newEnv = new HashMap<>(originalEnv);
        newEnv.put("HADOOP_CONF_DIR", hadoopConfDir.getAbsolutePath());
        newEnv.remove("HADOOP_HOME");
        CommonTestUtils.setEnv(newEnv);

        // create HiveCatalog use the Hadoop Configuration
        final HiveConf hiveConf;
        try {
            final Map<String, String> options = new HashMap<>();
            options.put(
                    CommonCatalogOptions.CATALOG_TYPE.key(), HiveCatalogFactoryOptions.IDENTIFIER);
            options.put(HiveCatalogFactoryOptions.HIVE_CONF_DIR.key(), CONF_DIR.getPath());

            final HiveCatalog hiveCatalog =
                    (HiveCatalog)
                            FactoryUtil.createCatalog(
                                    catalogName,
                                    options,
                                    null,
                                    Thread.currentThread().getContextClassLoader());

            hiveConf = hiveCatalog.getHiveConf();
        } finally {
            // set the Env back
            CommonTestUtils.setEnv(originalEnv);
        }
        // validate the result
        for (String key : customProps.keySet()) {
            assertThat(hiveConf.get(key, null)).isEqualTo(customProps.get(key));
        }
    }