Run pig in java without embedding pig script

前端 未结 3 1877
忘掉有多难
忘掉有多难 2020-12-18 12:04

I am new to pig script, Hadoop, Hbase. Here\'s what i need to know. I wanted to run a pig script, I don\'t want to embed the pig script in my java program and wanted to run

3条回答
  •  孤城傲影
    2020-12-18 12:29

    Since others have well explained pig execution by embeding the same in java, let me just add on how to run parametrised pig without java.

    In this scenarion, all you need is your pig lines of code saved as a pig file, say myFirstPigScript.pig.

    The next thing that you need is parameters within. Well here is the way to run your myFirstPigScript.pig with three input parameters.

    pig -p in1=file1.txt -p in2=file2.txt -p outdirectory=outdirectory myFirstPigScript.pig 
    

    Your pig script will look like

    A = load '$in1' USING PigStorage(',') AS (id_one:chararray,file1field1:chararray); 
    B = load '$in2' USING PigStorage(',') AS (id_two:chararray,file2field1:chararray); 
    C = join A by id_one, B by id_two;
    store D into '$outdirectory' USING PigStorage(',') ;
    

    Sample input files will be a two column csv file

    Output 'part' files will be present in the outdirectory

提交回复
热议问题