diff --git a/docs/services/emr.md b/docs/services/emr.md index 288a29f597..29427cd3fb 100644 --- a/docs/services/emr.md +++ b/docs/services/emr.md @@ -127,10 +127,13 @@ but for its bootstrap actions and its storage. `s3://.elasticmapreduce/libs/script-runner/script-runner.jar` URI) its script, as the Release Guide's "Run commands and scripts on an Amazon EMR cluster" describes them. An `s3-dist-cp` step runs Floci's own S3DistCp (see **S3DistCp**), and `hadoop-streaming` and `hadoop-lzo` steps the image's - Hadoop (see **Hadoop streaming and MapReduce**). On a cluster whose `Applications` name Hive, a Hive step - runs Hive (see **Hive steps**); on one without, `hive-script` runs in the release's image, and says - what EMR's does without Hive, "Hive isn't installed.", and the step fails. `pig-script`, which the image - does not have, is `FAILED` without running. + Hadoop (see **Hadoop streaming and MapReduce**). On a cluster whose `Applications` name Hive, or HCatalog, with + which EMR installs Hive's client too, a Hive step runs Hive (see **Hive steps**); on one with neither, `hive-script` + runs in the release's image, and says what EMR's does without Hive, "Hive isn't installed.", and the step fails. An + `emr-spark-*` release includes neither ("This release includes the following applications: AmazonCloudWatchAgent, + Delta, Hudi, Iceberg, JupyterEnterpriseGateway, Livy, and Spark."), so a cluster of one has neither, whatever its + `Applications` name: no image with Hive, no metastore service. `pig-script`, which the image does not have, is + `FAILED` without running. * **Commands and scripts**: they run as the image's `hadoop` user in `/home/hadoop`, with `bash`, Python 3, Java, `curl` and the AWS CLI v2, which reaches Floci through `AWS_ENDPOINT_URL`. A `script-runner.jar` step's script is fetched from S3 with the AWS CLI and the step's credentials, then @@ -150,10 +153,11 @@ but for its bootstrap actions and its storage. container of their own, `emr--hdfs`, from the release's EMR Serverless Hive image, which has HDFS where the release's image has only its client (`hive-image-template` names another), or, for an `emr-spark-*` release, which has no Hive image, from `emr-7.5.0`'s, with their data in a third volume, one copy of each block, - and permissions off. On a cluster whose `Applications` name Hive, the same container runs Hive's metastore - service, on port 9083, its Derby database in that volume and its warehouse in the HDFS; it reaches the S3 - locations of tables through Floci's S3 as the role of the cluster's EC2 instance profile, as the bootstrap actions - do, with a session that goes with the container. It gets the cluster's `core-site` and `hive-site` after its own + and permissions off. On a cluster with Hive or HCatalog (see **Which steps run**), the same container runs Hive's + metastore service, which EMR's HCatalog server is, on port 9083, its Derby database in that volume and its warehouse + in the HDFS; it reaches the S3 locations of tables through Floci's S3 as the role of the cluster's EC2 instance + profile, as the bootstrap actions do, with a session that goes with the container. It gets the cluster's `core-site` + and `hive-site` after its own settings, as EMR's primary node does, so a `hive-site` setting of `hive.metastore.warehouse.dir`, say, holds for the service as for the Hive steps. A primary node with the service that an earlier Floci left running starts again, on the data its volume keeps, as its session went with that Floci. The container is on a Docker network of the cluster's own, also @@ -225,7 +229,8 @@ but for its bootstrap actions and its storage. Hadoop's `log4j.properties`, so those two do not reach it: a `hadoop-env` `HADOOP_CLASSPATH`, say, is not on its class path, and it logs as Spark does. * **Hive steps**: an EMR cluster's nodes hold every application it installs, so a cluster whose `Applications` name - Hive runs its bootstrap actions and all its steps in an image of the release's with Hive added: the release's EMR + Hive, or HCatalog, which installs Hive's client and metastore service, runs its bootstrap actions and all its steps + in an image of the release's with Hive added: the release's EMR Serverless image with the Hive, Tez, HDFS, MapReduce and YARN of its EMR Serverless Hive image (`public.ecr.aws/emr-serverless/hive/`, 2.7 GB unpacked, pulled to make it; `hive-image-template` names another). Floci makes it the first time one of the release's clusters needs it: a container of the release's @@ -251,10 +256,11 @@ but for its bootstrap actions and its storage. with the cluster's account as its `hive.metastore.glue.catalogid`, which a `hive-site` one replaces. A table without a `LOCATION` is in the cluster's HDFS, under `/user/hive/warehouse` ("By default, this is a location in HDFS"), which other steps read as `hdfs:///user/hive/warehouse/`, and an `hdfs://` `LOCATION` is there too. - The cluster's Spark steps use that metastore too, so a Spark step with Hive support reads a Hive step's tables and - makes tables Hive steps read, 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 - uses Floci's Glue. Where that service does not run, with `docker-network` set to `host` or `container:`, or to + The cluster's Spark steps use that metastore too, as Spark's default catalog "always connects to a Hive metastore" + (the Release Guide's "Use an Iceberg cluster with Spark") and its "Using HCatalog" has Spark SQL read a table the + HCat CLI made, so a Spark step with Hive support reads a Hive step's tables and makes tables Hive steps read; a + `spark-hive-site` naming the Glue Data Catalog's client factory still uses Floci's Glue. Where that service does not + run, with `docker-network` set to `host` or `container:`, or to `none`, the metastore is an embedded Derby database in the cluster's `/mnt` instead, which only one Hive step at a time can use: with `StepConcurrencyLevel` above 1, a Hive step that starts while another runs fails ("Another instance of Derby may have already booted the database"), and Spark steps see a Hive step's tables only through diff --git a/src/main/java/io/floci/aws/services/emr/EmrClusterStorage.java b/src/main/java/io/floci/aws/services/emr/EmrClusterStorage.java index 71ba72e4d2..fa6eb64777 100644 --- a/src/main/java/io/floci/aws/services/emr/EmrClusterStorage.java +++ b/src/main/java/io/floci/aws/services/emr/EmrClusterStorage.java @@ -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 diff --git a/src/main/java/io/floci/aws/services/emr/EmrService.java b/src/main/java/io/floci/aws/services/emr/EmrService.java index 5f62c1c778..6ed6727feb 100644 --- a/src/main/java/io/floci/aws/services/emr/EmrService.java +++ b/src/main/java/io/floci/aws/services/emr/EmrService.java @@ -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 application = hive == null ? EmrSparkSteps.application(step) : null; List 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 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 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 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(); diff --git a/src/main/java/io/floci/aws/services/emr/EmrSparkSteps.java b/src/main/java/io/floci/aws/services/emr/EmrSparkSteps.java index 4332a3e658..4569568078 100644 --- a/src/main/java/io/floci/aws/services/emr/EmrSparkSteps.java +++ b/src/main/java/io/floci/aws/services/emr/EmrSparkSteps.java @@ -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 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 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; } } diff --git a/src/main/java/io/floci/aws/services/emrserverless/EmrServerlessSparkRunner.java b/src/main/java/io/floci/aws/services/emrserverless/EmrServerlessSparkRunner.java index 5221ee5985..9ba197c4b4 100644 --- a/src/main/java/io/floci/aws/services/emrserverless/EmrServerlessSparkRunner.java +++ b/src/main/java/io/floci/aws/services/emrserverless/EmrServerlessSparkRunner.java @@ -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 sparkSettings(Job job, String flociEndpoint) { List hadoop = new ArrayList<>(hadoopSettings(job, flociEndpoint)); List hdfs = hdfsSettings(job.storage()); diff --git a/src/main/java/io/floci/aws/services/emrserverless/SparkJobRunner.java b/src/main/java/io/floci/aws/services/emrserverless/SparkJobRunner.java index abce5349b2..637f96b068 100644 --- a/src/main/java/io/floci/aws/services/emrserverless/SparkJobRunner.java +++ b/src/main/java/io/floci/aws/services/emrserverless/SparkJobRunner.java @@ -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) { diff --git a/src/test/java/io/floci/aws/services/emr/EmrServiceContainerStepsTest.java b/src/test/java/io/floci/aws/services/emr/EmrServiceContainerStepsTest.java index d2a75382ee..03d2915dc8 100644 --- a/src/test/java/io/floci/aws/services/emr/EmrServiceContainerStepsTest.java +++ b/src/test/java/io/floci/aws/services/emr/EmrServiceContainerStepsTest.java @@ -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")); diff --git a/src/test/java/io/floci/aws/services/emr/EmrSparkStepsTest.java b/src/test/java/io/floci/aws/services/emr/EmrSparkStepsTest.java index 34b4697ab6..3f501c742f 100644 --- a/src/test/java/io/floci/aws/services/emr/EmrSparkStepsTest.java +++ b/src/test/java/io/floci/aws/services/emr/EmrSparkStepsTest.java @@ -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)); } }