Java Code Examples for org.apache.hadoop.hive.conf.HiveConf#setHiveSiteLocation()

The following examples show how to use org.apache.hadoop.hive.conf.HiveConf#setHiveSiteLocation() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: HiveCatalog.java    From flink with Apache License 2.0 6 votes vote down vote up
private static HiveConf createHiveConf(@Nullable String hiveConfDir) {
	LOG.info("Setting hive conf dir as {}", hiveConfDir);

	try {
		HiveConf.setHiveSiteLocation(
			hiveConfDir == null ?
				null : Paths.get(hiveConfDir, "hive-site.xml").toUri().toURL());
	} catch (MalformedURLException e) {
		throw new CatalogException(
			String.format("Failed to get hive-site.xml from %s", hiveConfDir), e);
	}

	// create HiveConf from hadoop configuration
	return new HiveConf(HadoopUtils.getHadoopConfiguration(new org.apache.flink.configuration.Configuration()),
		HiveConf.class);
}
 
Example 2
Source File: HiveTestUtils.java    From flink with Apache License 2.0 6 votes vote down vote up
public static HiveConf createHiveConf() {
	ClassLoader classLoader = new HiveTestUtils().getClass().getClassLoader();
	HiveConf.setHiveSiteLocation(classLoader.getResource(HIVE_SITE_XML));

	try {
		TEMPORARY_FOLDER.create();
		String warehouseDir = TEMPORARY_FOLDER.newFolder().getAbsolutePath() + "/metastore_db";
		String warehouseUri = String.format(HIVE_WAREHOUSE_URI_FORMAT, warehouseDir);

		HiveConf hiveConf = new HiveConf();
		hiveConf.setVar(HiveConf.ConfVars.METASTOREWAREHOUSE, TEMPORARY_FOLDER.newFolder("hive_warehouse").getAbsolutePath());
		hiveConf.setVar(HiveConf.ConfVars.METASTORECONNECTURLKEY, warehouseUri);
		return hiveConf;
	} catch (IOException e) {
		throw new CatalogException(
			"Failed to create test HiveConf to HiveCatalog.", e);
	}
}
 
Example 3
Source File: HiveCatalog.java    From flink with Apache License 2.0 6 votes vote down vote up
private static HiveConf createHiveConf(@Nullable String hiveConfDir) {
	LOG.info("Setting hive conf dir as {}", hiveConfDir);

	try {
		HiveConf.setHiveSiteLocation(
			hiveConfDir == null ?
				null : Paths.get(hiveConfDir, "hive-site.xml").toUri().toURL());
	} catch (MalformedURLException e) {
		throw new CatalogException(
			String.format("Failed to get hive-site.xml from %s", hiveConfDir), e);
	}

	// create HiveConf from hadoop configuration
	Configuration hadoopConf = HadoopUtils.getHadoopConfiguration(new org.apache.flink.configuration.Configuration());

	// Add mapred-site.xml. We need to read configurations like compression codec.
	for (String possibleHadoopConfPath : HadoopUtils.possibleHadoopConfPaths(new org.apache.flink.configuration.Configuration())) {
		File mapredSite = new File(new File(possibleHadoopConfPath), "mapred-site.xml");
		if (mapredSite.exists()) {
			hadoopConf.addResource(new Path(mapredSite.getAbsolutePath()));
			break;
		}
	}
	return new HiveConf(hadoopConf, HiveConf.class);
}
 
Example 4
Source File: HiveTestUtils.java    From flink with Apache License 2.0 6 votes vote down vote up
public static HiveConf createHiveConf() {
	ClassLoader classLoader = new HiveTestUtils().getClass().getClassLoader();
	HiveConf.setHiveSiteLocation(classLoader.getResource(HIVE_SITE_XML));

	try {
		TEMPORARY_FOLDER.create();
		String warehouseDir = TEMPORARY_FOLDER.newFolder().getAbsolutePath() + "/metastore_db";
		String warehouseUri = String.format(HIVE_WAREHOUSE_URI_FORMAT, warehouseDir);

		HiveConf hiveConf = new HiveConf();
		hiveConf.setVar(HiveConf.ConfVars.METASTOREWAREHOUSE, TEMPORARY_FOLDER.newFolder("hive_warehouse").getAbsolutePath());
		hiveConf.setVar(HiveConf.ConfVars.METASTORECONNECTURLKEY, warehouseUri);
		return hiveConf;
	} catch (IOException e) {
		throw new CatalogException(
			"Failed to create test HiveConf to HiveCatalog.", e);
	}
}
 
Example 5
Source File: HiveConfFactory.java    From data-highway with Apache License 2.0 5 votes vote down vote up
public HiveConf newInstance(String hiveMetaStoreUris) {
  synchronized (HiveConf.class) {
    // The following prevents HiveConf from loading the default hadoop
    // *-site.xml and hive-site.xml if they're on the classpath.
    URL hiveSiteLocation = HiveConf.getHiveSiteLocation();
    HiveConf.setHiveSiteLocation(null);
    HiveConf conf = new HiveConf(new Configuration(false), getClass());
    HiveConf.setHiveSiteLocation(hiveSiteLocation);
    conf.setVar(ConfVars.METASTOREURIS, hiveMetaStoreUris);
    return conf;
  }
}
 
Example 6
Source File: FlinkStandaloneHiveServerContext.java    From flink with Apache License 2.0 5 votes vote down vote up
private void setHiveSitePath() {
	File hiveSite = new File(newFolder(basedir, "hive-conf"), "hive-site.xml");
	try (FileOutputStream outputStream = new FileOutputStream(hiveSite)) {
		hiveConf.writeXml(outputStream);
		HiveConf.setHiveSiteLocation(hiveSite.toURI().toURL());
	} catch (IOException e) {
		throw new RuntimeException("Failed to write hive-site.xml", e);
	}
}