简体   繁体   中英

How to execute list of hive queries which is in gcp storage bucket (in my case gs:/hive/hive.sql") while submitting hive job to dataproc cluster

Here i am writing queries in queryList which is under hiveJob.

To submit Hive job to dataproc cluster

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 file which is in bucket

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

I found that we can keep .sql file in bucket and then specify queryFileUri like below

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM