本文属于机器翻译版本。若本译文内容与英语原文存在差异,则一律以英文原文为准。
将 Hive 用户定义的函数与 EMR Serverless 结合使用
Hive 用户定义函数 (UDFs) 允许您创建自定义函数来处理记录或记录组。在本教程中,您将使用示例 UDF 和预先存在的 Amazon EMR Serverless 应用程序来运行输出查询结果的作业。要了解如何设置应用程序,请参阅 开始使用 Amazon EMR Serverless。
将 UDF 与 EMR Serverless 结合使用
-
导航至查看GitHub
示例 UDF。克隆存储库并切换到要使用的 git 分支。更新存储库 pom.xml
文件中的maven-compiler-plugin
以获取源。同时将目标 Java 版本配置更新为1.8
。运行mvn package -DskipTests
以创建包含您的示例的 JAR 文件 UDFs。 -
创建 JAR 文件后,使用以下命令将其上传到 S3 存储桶。
aws s3 cp brickhouse-0.8.2-JS.jar s3://
amzn-s3-demo-bucket
/jars/ -
创建一个示例文件,使用其中一个 UDF 示例函数。将此查询另存为
udf_example.q
并上传到 S3 存储桶。add jar s3://
amzn-s3-demo-bucket
/jars/brickhouse-0.8.2-JS.jar; CREATE TEMPORARY FUNCTION from_json AS 'brickhouse.udf.json.FromJsonUDF'; select from_json('{"key1":[0,1,2], "key2":[3,4,5,6], "key3":[7,8,9]}', map("", array(cast(0 as int)))); select from_json('{"key1":[0,1,2], "key2":[3,4,5,6], "key3":[7,8,9]}', map("", array(cast(0 as int))))["key1"][2]; -
提交以下 Hive 作业。
aws emr-serverless start-job-run \ --application-id
application-id
\ --execution-role-arnjob-role-arn
\ --job-driver '{ "hive": { "query": "s3://amzn-s3-demo-bucket
/queries/udf_example.q", "parameters": "--hiveconf hive.exec.scratchdir=s3://amzn-s3-demo-bucket
/emr-serverless-hive/scratch --hiveconf hive.metastore.warehouse.dir=s3://'$BUCKET'/emr-serverless-hive/warehouse" } }' --configuration-overrides '{ "applicationConfiguration": [{ "classification": "hive-site", "properties": { "hive.driver.cores": "2", "hive.driver.memory": "6G" } }], "monitoringConfiguration": { "s3MonitoringConfiguration": { "logUri": "s3://amzn-s3-demo-bucket
/logs/" } } }' -
使用
get-job-run
命令检查作业的状态。等待状态变为SUCCESS
。aws emr-serverless get-job-run --application-id
application-id
--job-run-idjob-id
-
使用以下命令下载输出文件。
aws s3 cp --recursive s3://
amzn-s3-demo-bucket
/logs/applications/application-id
/jobs/job-id
/HIVE_DRIVER/ .stdout.gz
文件类似下列内容。{"key1":[0,1,2],"key2":[3,4,5,6],"key3":[7,8,9]} 2