Reply
New Contributor
Posts: 3
Registered: ‎08-06-2018

How to call hiveconf in perl programming.

Dear Team,

 

Like shell script, how can we call hql using hiveconf in perl programming.

 

I want to insert data into the table passing perl variable.

 

Like in shell script : 

SOURCE=$1

AUDIT_DATE=$2

hive --hiveconf SOURCE="${SOURCE}" --hiveconf AUDIT_DATE="${AUDIT_DATE}" -S -f /CODEBASE/AUDIT/Mod_Audit_lodging.sql

Mod_Audit_lodging.sql : 

INSERT INTO  test.WORKFLOW_DETAILED_AUDIT_FILE PARTITION (AUDIT_DATE='${hiveconf:AUDIT_DATE}') SELECT TRIM(FILE_RECORD_COUNT),TRIM(FILENAME),TRIM(JOBNAME),TRIM(PROGRAM),TRIM(SOURCE),TRIM(BATCH_ID) FROM test.WORKFLOW_DETAILED_AUDIT_FILE_STG where trim(SOURCE)='${hiveconf:SOURCE}';

 

how can we implement same in perl programming ?

 

 

Kindly guide.

 

Regards

Posts: 1,903
Kudos: 436
Solutions: 307
Registered: ‎07-31-2013

Re: How to call hiveconf in perl programming.

Like most other languages, Perl offers a function to execute a command on the host OS: https://perldoc.perl.org/functions/system.html

You can use Perl to prepare your Hive CLI command lines / query text, and then execute the "hive" command with args from within via the `system(…)` call.