feat(emr): give a cluster with HCatalog Hive's client and metastore (#7719)

A docker cluster ran Hive steps, made its steps' image with Hive and ran
Hive's metastore service on its primary node only when its Applications
named Hive. EMR installs Hive's client and its HCatalog server with
HCatalog too, and the Release Guide's HCatalog page says "HCatalog is a
tool that allows you to access Hive metastore tables within Pig, Spark
SQL, and/or custom MapReduce applications".

- EMR's hive-script, in the emr-scripts package every node has, checks
  only "which hive" ("Hive isn't installed." otherwise), and the hive
  it finds is hive-client's, which HCatalog installs, so a Hive step
  runs on a cluster with HCatalog alone.
- Its HCatalog server, hcatalog-server, is the metastore service:
  Hive's hcat_server.sh runs "hive --service metastore".

So a cluster whose Applications name HCatalog installs Hive as one
naming Hive does: its Hive steps run, in the release's image with Hive,
on the metastore service its primary node runs, which its Spark steps'
Hive client uses too.

An emr-spark-* release, the AWS runtime for Apache Spark, includes
neither ("This release includes the following applications:
AmazonCloudWatchAgent, Delta, Hudi, Iceberg, JupyterEnterpriseGateway,
Livy, and Spark."), and has no Hive image to make its steps' image with
Hive from, so a cluster of one installs neither, whatever its
Applications name; one naming Hive asked for that image since #7459.

emr.md now backs a cluster's Spark steps using its metastore with the
Release Guide's EMR pages, in place of the Glue page #7636 quoted:
Spark's default catalog "always connects to a Hive metastore", and
Using HCatalog has Spark SQL read a table the HCat CLI made.
This commit is contained in:
Priamo Germosen authored and GitHub committed 2026-11-07 00:34:27 -06:00
1 parent a102cd16d5
commit 6974d8c096
8 files changed
+150 -43

No files matched your search

@@ -44,9 +44,9 @@ import java.util.function.LongSupplier;
* emr-7.14.0 on, "When you select Trino as the only application at launch, Amazon EMR no longer starts YARN and
* HDFS", a cluster Floci does not run), is a NameNode and a DataNode in a container of their own, the cluster's
* primary node's, with their data in a third volume, so that the first container to mount the {@code /mnt} one is a
* step's, which fills it from the step's image. On a cluster with Hive the same container runs Hive's metastore
* service, as EMR's primary node does, with its database in that third volume, reaching S3 with a session for the
* cluster's instance profile's role, which goes with the container.
* step's, which fills it from the step's image. On a cluster with Hive or HCatalog the same container runs Hive's
* metastore service, as EMR's primary node does, with its database in that third volume, reaching S3 with a session
* for the cluster's instance profile's role, which goes with the container.
*/
@ApplicationScoped
public class EmrClusterStorage implements ClusterStorage, ContainerTeardown {
@@ -65,9 +65,11 @@ public class EmrClusterStorage implements ClusterStorage, ContainerTeardown {
// starting a JVM of hdfs's own each time it is asked; each look is given five seconds, so one the NameNode does not
// answer while it starts is asked again.
private static final String NAMENODE_JMX = "http://127.0.0.1:9870/jmx?qry=Hadoop:service=NameNode,name=";
// The metastore service's --hiveconf settings, Floci's S3 among them; set only on a cluster with Hive.
// The metastore service's --hiveconf settings, Floci's S3 among them; set only on a cluster with Hive or
// HCatalog.
private static final String HIVE_METASTORE_VARIABLE = "FLOCI_HIVE_METASTORE";
// The cluster's core-site and hive-site, as --hiveconf settings one to a line, which the service gets after its own.
// The cluster's core-site and hive-site, as --hiveconf settings one to a line, which the service gets after its
// own.
private static final String HIVE_METASTORE_SITE_VARIABLE = "FLOCI_HIVE_METASTORE_SITE";
private static final int HIVE_METASTORE_PORT = 9083;
// The folder a Hive session uploads Hive's exec jar to when it is not there, named after its SHA-256, under the
@@ -1456,8 +1456,8 @@ public class EmrService implements Resettable, StoredResourceArns, ContainerTear
executing.add(stepKey(accountId, step.getId()));
return;
}
EmrSparkSteps.HiveCommand hive = EmrSparkSteps.hive(step, cluster.getApplications(),
cluster.getConfigurations(), SNAPSHOT_MAPPER);
EmrSparkSteps.HiveCommand hive = EmrSparkSteps.hive(step, cluster.getReleaseLabel(),
cluster.getApplications(), cluster.getConfigurations(), SNAPSHOT_MAPPER);
List<String> application = hive == null ? EmrSparkSteps.application(step) : null;
List<String> command = hive == null && application == null ? EmrSparkSteps.command(step) : null;
SparkJobRunner.Storage storage = null;
@@ -1471,13 +1471,15 @@ public class EmrService implements Resettable, StoredResourceArns, ContainerTear
Supplier<String> releaseImage = cluster.getBootstrapImage() == null ? releaseImage(cluster) : null;
// Every EMR cluster runs HDFS on its primary node, which the step's thread starts when it is not running:
// a NameNode and a DataNode, in a container of the release's Hive image, the one with HDFS's daemons, and
// on a cluster with Hive its metastore service.
// on a cluster with Hive or HCatalog its metastore service.
String clusterId = cluster.getId();
String hdfsHost = masterPrivateDnsName(cluster);
String hdfsImage = hdfsImage(cluster.getReleaseLabel());
ClusterStorage.HiveMetastore hiveMetastore = EmrSparkSteps.installsHive(cluster.getApplications(),
SNAPSHOT_MAPPER) ? new ClusterStorage.HiveMetastore(instanceProfileRole(cluster, accountId),
EmrSparkSteps.hiveMetastoreSettings(cluster.getConfigurations(), SNAPSHOT_MAPPER)) : null;
ClusterStorage.HiveMetastore hiveMetastore = EmrSparkSteps.installsHive(cluster.getReleaseLabel(),
cluster.getApplications(), SNAPSHOT_MAPPER)
? new ClusterStorage.HiveMetastore(instanceProfileRole(cluster, accountId),
EmrSparkSteps.hiveMetastoreSettings(cluster.getConfigurations(), SNAPSHOT_MAPPER))
: null;
Function<BooleanSupplier, SparkJobRunner.Storage> hdfs = storage == null ? null
: stopped -> clusterStorage.hdfs(clusterId, accountId, region, hdfsHost, hdfsImage, dockerNetwork,
hiveMetastore, stopped);
@@ -1617,7 +1619,8 @@ public class EmrService implements Resettable, StoredResourceArns, ContainerTear
* without Hive, which starts from the release's EMR Serverless image.
*/
private Supplier<String> releaseImage(EmrCluster cluster) {
if (releaseImages == null || !EmrSparkSteps.installsHive(cluster.getApplications(), SNAPSHOT_MAPPER)) {
if (releaseImages == null
|| !EmrSparkSteps.installsHive(cluster.getReleaseLabel(), cluster.getApplications(), SNAPSHOT_MAPPER)) {
return null;
}
String release = cluster.getReleaseLabel();
@@ -71,6 +71,7 @@ final class EmrSparkSteps {
private static final String HIVE_SCRIPT = "hive-script";
private static final String HIVE_SCRIPT_ARGS = "--args";
private static final String HIVE = "hive";
private static final String HCATALOG = "hcatalog";
// The Hive classifications a Hive step's hive gets, each property a --hiveconf, in the order Hive reads their
// files, a later one winning: core-site, tez-site, which will "Change values in Tez's tez-site.xml file", and
// hive-site, which will "Change values in Hive's hive-site.xml"; and hive-env's exports, which will "Change
@@ -176,11 +177,12 @@ final class EmrSparkSteps {
* Floci's settings: the cluster's Hive classifications, then the step's own arguments, so that a
* {@code --hiveconf} of the step's replaces a classification's property, as it replaces a hive-site.xml one.
*/
static HiveCommand hive(EmrStep step, String applications, String configurations, ObjectMapper objectMapper) {
static HiveCommand hive(EmrStep step, String releaseLabel, String applications, String configurations,
ObjectMapper objectMapper) {
String jar = step.getJar();
List<String> args = step.getArgs() != null ? step.getArgs() : List.of();
if (jar == null || !named(jar, COMMAND_RUNNER) || args.isEmpty()
|| !installsHive(applications, objectMapper)) {
|| !installsHive(releaseLabel, applications, objectMapper)) {
return null;
}
List<String> runner;
@@ -218,12 +220,23 @@ final class EmrSparkSteps {
}
/**
* Whether a cluster's {@code Applications}, the JSON array RunJobFlow was given, name Hive ("A case-insensitive
* list of applications for Amazon EMR to install").
* Whether a cluster installs Hive: its {@code Applications}, the JSON array RunJobFlow was given ("A
* case-insensitive list of applications for Amazon EMR to install"), name Hive, or HCatalog, with which EMR
* installs Hive's client, {@code hive-client}, the {@code hive} that EMR's {@code hive-script} looks for, and its
* HCatalog server, {@code hcatalog-server}, whose {@code hcat_server.sh} runs {@code hive --service metastore}.
* HCatalog "allows you to access Hive metastore tables within Pig, Spark SQL, and/or custom MapReduce
* applications". Such a cluster's Hive steps run, its steps' image has Hive, and its primary node runs Hive's
* metastore service. A release of the AWS runtime for Apache Spark has neither: "This release includes the
* following applications: AmazonCloudWatchAgent, Delta, Hudi, Iceberg, JupyterEnterpriseGateway, Livy, and
* Spark."
*/
static boolean installsHive(String applications, ObjectMapper objectMapper) {
static boolean installsHive(String releaseLabel, String applications, ObjectMapper objectMapper) {
if (releaseLabel != null && EmrServerlessSparkRunner.sparkRuntime(releaseLabel)) {
return false;
}
for (JsonNode application : stored(applications, objectMapper)) {
if (HIVE.equalsIgnoreCase(application.path("Name").asText())) {
String name = application.path("Name").asText();
if (HIVE.equalsIgnoreCase(name) || HCATALOG.equalsIgnoreCase(name)) {
return true;
}
}
@@ -980,9 +980,9 @@ public class EmrServerlessSparkRunner implements SparkJobRunner, ContainerTeardo
// Floci's settings, then the job's spark-defaults, in the order a later one wins. Spark's own Hadoop configuration
// takes HDFS's client back from the core-site.xml's view, for Spark and its Hive client, which writes a Hive table
// in HDFS only through it. On a cluster with Hive, Spark's Hive client uses the cluster's metastore too, as the
// Glue Data Catalog is the one to pick "when you require a persistent Hive metastore or a Hive metastore shared by
// different clusters"; a spark-hive-site naming its client factory still wins.
// in HDFS only through it. On a cluster with Hive or HCatalog, Spark's Hive client uses the cluster's metastore
// too, as the Glue Data Catalog is the one to pick "when you require a persistent Hive metastore or a Hive
// metastore shared by different clusters"; a spark-hive-site naming its client factory still wins.
private static List<SparkSetting> sparkSettings(Job job, String flociEndpoint) {
List<SparkSetting> hadoop = new ArrayList<>(hadoopSettings(job, flociEndpoint));
List<SparkSetting> hdfs = hdfsSettings(job.storage());
@@ -111,8 +111,8 @@ public interface SparkJobRunner {
* {@code /home/hadoop} and {@code mnt} at {@code /mnt}; its HDFS, whose NameNode is on the cluster's primary
* node, named {@code hdfsHost}, which a step's container reaches at {@code hdfsAddress} on the Docker network
* {@code hdfsNetwork}, the cluster's own, which the container joins (all three null until it runs, the network
* also on the host's own network, which steps share with it); and, on a cluster with Hive, the URI of the Hive
* metastore service on that node, or null.
* also on the host's own network, which steps share with it); and, on a cluster with Hive or HCatalog, the URI of
* the Hive metastore service on that node, or null.
*/
record Storage(String home, String mnt, String hdfsHost, String hdfsAddress, String hdfsNetwork,
String hiveMetastore) {