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

@@ -342,6 +342,58 @@ class EmrServiceContainerStepsTest {
EmrServiceFixture.RecordingStorage.HDFS_NETWORK), runner.jobs.get(0).storage());
}
@Test
void aHiveStepOnAClusterWithHCatalogRunsHiveInTheReleasesImageWithHive() {
EmrCluster requested = cluster("hcatalog", true, hiveStep("report", "-e", "show tables;"));
requested.setApplications("[{\"Name\": \"HCatalog\"}]");
EmrCluster cluster = service.runJobFlow(requested, REGION);
fixture.runStepThread();
// EMR installs Hive's client with HCatalog, the hive EMR's hive-script looks for.
SparkJobRunner.Job job = runner.jobs.get(0);
assertEquals(SparkJobRunner.Engine.HIVE, job.engine());
assertEquals(List.of(List.of("emr-7.5.0", "public.ecr.aws/emr-serverless/spark/emr-7.5.0:latest",
"public.ecr.aws/emr-serverless/hive/emr-7.5.0:latest")), fixture.releaseImages.asked);
assertEquals(EmrServiceFixture.RecordingReleaseImages.IMAGE, job.imageTemplate());
assertEquals(hdfsStorage(cluster).withHiveMetastore("thrift://ip-10-0-0-1.ec2.internal:9083"), job.storage());
}
@Test
void aClusterWithHCatalogRunsHivesMetastoreServiceWhichItsSparkStepsUse() {
EmrCluster requested = cluster("hcatalog", true, sparkStep("report", "CONTINUE"));
requested.setApplications("[{\"Name\": \"HCatalog\"}, {\"Name\": \"Spark\"}]");
EmrCluster cluster = service.runJobFlow(requested, REGION);
fixture.runStepThread();
// EMR's HCatalog server is that service.
assertEquals("true", fixture.clusterStorage.hdfs.get(0).get(4));
assertEquals(hdfsStorage(cluster).withHiveMetastore("thrift://ip-10-0-0-1.ec2.internal:9083"),
runner.jobs.get(0).storage());
}
@Test
void aClusterOfTheAwsRuntimeForSparkNamingHiveOrHCatalogRunsAsOneWithout() {
// Its releases include neither, and there is no Hive image of them to make its steps' image from.
EmrCluster requested = cluster("spark-runtime-hive", true, hiveStep("report", "-e", "show tables;"));
requested.setReleaseLabel("emr-spark-8.1.0");
requested.setApplications("[{\"Name\": \"Hive\"}, {\"Name\": \"HCatalog\"}, {\"Name\": \"Spark\"}]");
EmrCluster cluster = service.runJobFlow(requested, REGION);
fixture.runStepThread();
assertEquals(List.of(), fixture.releaseImages.asked);
assertEquals("false", fixture.clusterStorage.hdfs.get(0).get(4));
// Its Hive step runs hive-script in the release's own image, which says "Hive isn't installed.".
SparkJobRunner.Job job = runner.jobs.get(0);
assertEquals(SparkJobRunner.Engine.SPARK, job.engine());
assertEquals(List.of("hive-script", "--run-hive-script", "--args", "-e", "show tables;"), job.command());
assertEquals("public.ecr.aws/emr-serverless/spark4/emr-spark-8.1.0:latest",
EmrServerlessSparkRunner.image(job.imageTemplate(), job.releaseLabel(), job.engine()));
assertEquals(hdfsStorage(cluster), job.storage());
}
@Test
void aClusterOfTheAwsRuntimeForSparkWhichHasNoHiveImageRunsItsHdfsInTheHiveImageOfEmr750() {
EmrCluster requested = cluster("spark-runtime", true, sparkStep("report", "CONTINUE"));
@@ -23,6 +23,7 @@ class EmrSparkStepsTest {
// A cluster's Applications, as RunJobFlow stores them, in a case of their own.
private static final String HIVE_AND_SPARK = "[{\"Name\": \"Spark\"}, {\"Name\": \"hive\"}]";
private static final String RELEASE = "emr-7.5.0";
private final ObjectMapper objectMapper = new ObjectMapper();
@@ -170,7 +171,7 @@ class EmrSparkStepsTest {
"com.amazonaws.glue.catalog.metastore.AWSGlueDataCatalogHiveClientFactory"}}]""";
EmrSparkSteps.HiveCommand hive = EmrSparkSteps.hive(step("command-runner.jar", null, "hive-script",
"--run-hive-script", "--args", "-f", "s3://bucket/queries/report.q", "-d", "INPUT=s3://bucket/in/",
"--hiveconf", "hive.exec.reducers.max=4"), HIVE_AND_SPARK, configurations, objectMapper);
"--hiveconf", "hive.exec.reducers.max=4"), RELEASE, HIVE_AND_SPARK, configurations, objectMapper);
assertEquals(List.of("hive-script", "--run-hive-script", "--args"), hive.runner());
// core-site, then tez-site, then hive-site, as Hive reads them, and the step's own --hiveconf last.
@@ -186,25 +187,25 @@ class EmrSparkStepsTest {
@Test
void aHiveScriptStepWithoutArgsGetsThemAtItsEndAndAStepCanRunHiveItself() {
EmrSparkSteps.HiveCommand script = EmrSparkSteps.hive(step("command-runner.jar", null, "hive-script",
"--run-hive-script"), HIVE_AND_SPARK, null, objectMapper);
"--run-hive-script"), RELEASE, HIVE_AND_SPARK, null, objectMapper);
EmrSparkSteps.HiveCommand hive = EmrSparkSteps.hive(step("command-runner.jar", null, "/usr/bin/hive",
"-e", "select 1"), HIVE_AND_SPARK, null, objectMapper);
"-e", "select 1"), RELEASE, HIVE_AND_SPARK, null, objectMapper);
assertEquals(List.of("hive-script", "--run-hive-script", "--args"), script.runner());
assertEquals(List.of(), script.arguments());
assertEquals(List.of("/usr/bin/hive-script", "--run-hive-script", "--args"), EmrSparkSteps.hive(step(
"command-runner.jar", null, "/usr/bin/hive-script", "--run-hive-script", "--args", "-e", "select 1"),
HIVE_AND_SPARK, null, objectMapper).runner());
RELEASE, HIVE_AND_SPARK, null, objectMapper).runner());
assertEquals(List.of("/usr/bin/hive"), hive.runner());
assertEquals(List.of("-e", "select 1"), hive.arguments());
}
@Test
void aStepRunsHiveOnlyWhenItsClustersApplicationsNameHive() {
void aStepRunsHiveOnlyWhenItsClusterInstallsHive() {
EmrStep query = step("command-runner.jar", null, "hive-script", "--run-hive-script", "--args", "-f",
"s3://bucket/queries/report.q");
for (String applications : new String[]{"[{\"Name\": \"Spark\"}]", "[]", null, "[{"}) {
assertNull(EmrSparkSteps.hive(query, applications, null, objectMapper));
assertNull(EmrSparkSteps.hive(query, RELEASE, applications, null, objectMapper));
}
// Where hive-script then runs, it says what EMR's says without Hive: "Hive isn't installed."
assertEquals(query.getArgs(), EmrSparkSteps.command(query));
@@ -212,7 +213,37 @@ class EmrSparkStepsTest {
step("command-runner.jar", null, "hive-scripts"),
step("script-runner.jar", null, "s3://bucket/hive.sh"),
step("s3://bucket/jars/hive.jar", null, "hive"))) {
assertNull(EmrSparkSteps.hive(other, HIVE_AND_SPARK, null, objectMapper));
assertNull(EmrSparkSteps.hive(other, RELEASE, HIVE_AND_SPARK, null, objectMapper));
}
}
@Test
void aClusterInstallsHiveWithHiveOrWithHCatalog() {
assertTrue(EmrSparkSteps.installsHive(RELEASE, HIVE_AND_SPARK, objectMapper));
// EMR installs Hive's client and metastore service with HCatalog too, in any case.
assertTrue(EmrSparkSteps.installsHive(RELEASE, "[{\"Name\": \"HCatalog\"}, {\"Name\": \"Spark\"}]",
objectMapper));
assertTrue(EmrSparkSteps.installsHive(RELEASE, "[{\"Name\": \"hcatalog\"}]", objectMapper));
for (String applications : new String[]{"[{\"Name\": \"Spark\"}]", "[]", null, "[{"}) {
assertFalse(EmrSparkSteps.installsHive(RELEASE, applications, objectMapper));
}
// So a Hive step runs there, EMR's hive-script finding the hive it looks for.
EmrStep query = step("command-runner.jar", null, "hive-script", "--run-hive-script", "--args", "-e",
"show tables;");
assertEquals(List.of("hive-script", "--run-hive-script", "--args"),
EmrSparkSteps.hive(query, RELEASE, "[{\"Name\": \"HCatalog\"}]", null, objectMapper).runner());
}
@Test
void aReleaseOfTheAwsRuntimeForSparkInstallsNeitherHiveNorHCatalog() {
// Each of its releases "includes the following applications: AmazonCloudWatchAgent, Delta, Hudi, Iceberg,
// JupyterEnterpriseGateway, Livy, and Spark."
EmrStep query = step("command-runner.jar", null, "hive-script", "--run-hive-script", "--args", "-e",
"show tables;");
for (String release : new String[]{"emr-spark-8.0.0", "emr-spark-8.1.0"}) {
assertFalse(EmrSparkSteps.installsHive(release, HIVE_AND_SPARK, objectMapper));
assertFalse(EmrSparkSteps.installsHive(release, "[{\"Name\": \"HCatalog\"}]", objectMapper));
assertNull(EmrSparkSteps.hive(query, release, HIVE_AND_SPARK, null, objectMapper));
}
}