diff --git a/src/test/java/io/floci/aws/services/emr/EmrHiveStepsDockerIntegrationTest.java b/src/test/java/io/floci/aws/services/emr/EmrHiveStepsDockerIntegrationTest.java index 544ec9a80a..ea81abaa1a 100644 --- a/src/test/java/io/floci/aws/services/emr/EmrHiveStepsDockerIntegrationTest.java +++ b/src/test/java/io/floci/aws/services/emr/EmrHiveStepsDockerIntegrationTest.java @@ -81,7 +81,8 @@ class EmrHiveStepsDockerIntegrationTest { @Test void hiveAndSparkStepsShareTheClustersMetastoreServiceAndHdfs() { - startCluster(HIVE_AND_SPARK, "[]", null); + // The two steps that read what the first one made, and need nothing from each other, run at once. + startCluster(HIVE_AND_SPARK, "[]", null, 2); put("queries/load.q", """ create external table kv (k string, v int) row format delimited fields terminated by ',' location '${INPUT}'; @@ -93,24 +94,8 @@ class EmrHiveStepsDockerIntegrationTest { insert overwrite directory '${OUTPUT}' row format delimited fields terminated by ',' select k, v from scaled order by k; select k, v from scaled order by k; + select k from from_spark order by k; """); - - assertEquals("COMPLETED", hiveStep("-f", s3Uri("queries/load.q"), "-d", "INPUT=" + s3Uri("data/rows/"))); - // The table the first step made is in the cluster's metastore for the second. - String report = addStep("command-runner.jar", "hive-script", "--run-hive-script", "--args", - "-f", s3Uri("queries/report.q"), "-d", "OUTPUT=" + s3Uri("out/report/")); - assertEquals("COMPLETED", state(report)); - assertEquals("a,10\nb,20\nc,30\n", objects("out/report/")); - assertTrue(stepLog(report, "stdout.gz").contains("a\t10\nb\t20\nc\t30\n")); - // Its data is in the cluster's HDFS, which a step in the Spark image reads as hdfs://. - String cat = addStep("command-runner.jar", "hadoop", "fs", "-cat", "hdfs:///user/hive/warehouse/scaled/*"); - assertEquals("COMPLETED", state(cat)); - assertEquals("a\u000110\nb\u000120\nc\u000130\n", stepLog(cat, "stdout.gz")); - // An hdfs:// location is the cluster's HDFS too, whose NameNode answers Hive's encryption zone lookups. - String pinned = addStep("command-runner.jar", "hadoop", "fs", "-cat", "hdfs:///floci/pinned/*"); - assertEquals("COMPLETED", state(pinned)); - assertEquals("a\nb\nc\n", stepLog(pinned, "stdout.gz")); - // A Spark step uses the cluster's metastore too: it reads Hive's table, and makes one a Hive step reads. put("jobs/catalog.py", """ import sys from pyspark.sql import SparkSession @@ -119,13 +104,25 @@ class EmrHiveStepsDockerIntegrationTest { spark.createDataFrame([(" ".join(rows),)], ["value"]).coalesce(1).write.text(sys.argv[1]) spark.sql("create table from_spark stored as textfile as select upper(k) as k from scaled") """); - assertEquals("COMPLETED", state(addStep("command-runner.jar", "spark-submit", s3Uri("jobs/catalog.py"), - s3Uri("out/spark/")))); + + assertEquals("COMPLETED", hiveStep("-f", s3Uri("queries/load.q"), "-d", "INPUT=" + s3Uri("data/rows/"))); + // Its data is in the cluster's HDFS, which a step in the Spark image reads as hdfs://, and so is an hdfs:// + // location's, whose NameNode answers Hive's encryption zone lookups. + String cat = addStep("command-runner.jar", "hadoop", "fs", "-cat", "hdfs:///user/hive/warehouse/scaled/*", + "hdfs:///floci/pinned/*"); + // A Spark step uses the cluster's metastore too: it reads Hive's table, and makes one a Hive step reads. + String spark = addStep("command-runner.jar", "spark-submit", s3Uri("jobs/catalog.py"), s3Uri("out/spark/")); + assertEquals("COMPLETED", state(cat)); + assertEquals("a\u000110\nb\u000120\nc\u000130\na\nb\nc\n", stepLog(cat, "stdout.gz")); + assertEquals("COMPLETED", state(spark)); assertEquals("a10 b20 c30\n", objects("out/spark/")); - String fromSpark = addStep("command-runner.jar", "hive-script", "--run-hive-script", "--args", - "-e", "select k from from_spark order by k;"); - assertEquals("COMPLETED", state(fromSpark)); - assertTrue(stepLog(fromSpark, "stdout.gz").contains("A\nB\nC\n")); + // The tables the first step and the Spark step made are in the cluster's metastore for a later Hive step. + String report = addStep("command-runner.jar", "hive-script", "--run-hive-script", "--args", + "-f", s3Uri("queries/report.q"), "-d", "OUTPUT=" + s3Uri("out/report/")); + assertEquals("COMPLETED", state(report)); + assertEquals("a,10\nb,20\nc,30\n", objects("out/report/")); + String reported = stepLog(report, "stdout.gz"); + assertTrue(reported.contains("a\t10\nb\t20\nc\t30\n") && reported.contains("A\nB\nC\n"), reported); } @Test