首页 > 解决方案 > 如何在将 hive 作业提交到 dataproc 集群时执行 gcp 存储桶中的 hive 查询列表(在我的情况下为 gs:/hive/hive.sql")

问题描述

在这里,我在 hiveJob 下的 queryList 中编写查询。

将 Hive 作业提交到 dataproc 集群

def submit_hive_job(dataproc, project, region,
                       cluster_name):
    job_details = {
        'projectId': project,
        'job': {
            'placement': {
                'clusterName': cluster_name
            },
            "hiveJob": {
                "queryList": {
                    ###
                    how can i execute .sql file here which is in bucket
                    ####
                    "queries": [
                        "CREATE TABLE IF NOT EXISTS sai ( eid int, name String, salary String, destination String)",
                        "Insert into table sai values (26,'Shiv','1500','ac')"
                    ]
                }
            }
        }
    }
    result = dataproc.projects().regions().jobs().submit(
        projectId=project,
        region=region,
        body=job_details).execute()
    job_id = result['reference']['jobId']
    print('Submitted job Id {}'.format(job_id))
    return job_id

存储桶中的 hive.sql 文件

create table employee ( employeeid: int, employeename: string, salary: float) rows format delimited fields terminated by ‘,’ ;
describe employee;
select * from employee;

标签: hadoophivegoogle-cloud-platformgoogle-cloud-dataproc

解决方案


我发现我们可以将 .sql 文件保存在存储桶中,然后像下面一样指定 queryFileUri

"hiveJob": {
 "queryFileUri":"gs://queryfile/test.sql"             
}

推荐阅读