Support Questions

Find answers, ask questions, and share your expertise
Announcements
Celebrating as our community reaches 100,000 members! Thank you!

Impala schedule with oozie -tutorial

avatar
Champion Alumni

Hello,

I'm searching for a good tutorial about how to schedule impala jobs into oozie.

 

The only threads that I found about this subject are:

 

o https://issues.apache.org/jira/browse/OOZIE-1591

o https://groups.google.com/a/cloudera.org/forum/#!topic/impala-user/8vM7fKR7F3A

 

 

Can you please help? (give at least one example)

GHERMAN Alina
1 ACCEPTED SOLUTION

avatar
Super Collaborator

Hey,

 

Currently there is not an Impala action, so you must use a shell action that calls impala-shell.  The shell script that calls impala-shell must also include an entry to set the PYTHON EGGS location.  Here is an example shell script:

 

#!/bin/bash

export PYTHON_EGG_CACHE=./myeggs
/usr/bin/kinit -kt cconner.keytab -V cconner
impala-shell -q "invalidate metadata"

 

NOTICE the PYTHON_EGG_CACHE, this is the location you must set or the job will fail.  This also does a kinit in the case of a kerberized cluster.  Here is the workflow that goes with that script:

 

<workflow-app name="shell-impala-invalidate-wf" xmlns="uri:oozie:workflow:0.4">

<start to="shell-impala-invalidate"/>

<action name="shell-impala-invalidate">
<shell xmlns="uri:oozie:shell-action:0.1">
<job-tracker>${jobTracker}</job-tracker>
<name-node>${nameNode}</name-node>
<configuration>
<property>
<name>mapred.job.queue.name</name>
<value>${queueName}</value>
</property>
</configuration>
<exec>shell-impala-invalidate.sh</exec>
<file>shell-impala-invalidate.sh#shell-impala-invalidate.sh</file>
<file>cconner.keytab#cconner.keytab</file>
</shell>
<ok to="end"/>
<error to="kill"/>
</action>
<kill name="kill">
<message>Action failed, error message[${wf:errorMessage(wf:lastErrorNode())}]</message>
</kill>
<end name="end"/>
</workflow-app>

 

You must include the <file> tag with the shell script, but not the keytab part unless you are using kerberos.

 

Hope this helps.

 

Thanks

Chris

View solution in original post

16 REPLIES 16

avatar
Super Collaborator

Hey,

 

Currently there is not an Impala action, so you must use a shell action that calls impala-shell.  The shell script that calls impala-shell must also include an entry to set the PYTHON EGGS location.  Here is an example shell script:

 

#!/bin/bash

export PYTHON_EGG_CACHE=./myeggs
/usr/bin/kinit -kt cconner.keytab -V cconner
impala-shell -q "invalidate metadata"

 

NOTICE the PYTHON_EGG_CACHE, this is the location you must set or the job will fail.  This also does a kinit in the case of a kerberized cluster.  Here is the workflow that goes with that script:

 

<workflow-app name="shell-impala-invalidate-wf" xmlns="uri:oozie:workflow:0.4">

<start to="shell-impala-invalidate"/>

<action name="shell-impala-invalidate">
<shell xmlns="uri:oozie:shell-action:0.1">
<job-tracker>${jobTracker}</job-tracker>
<name-node>${nameNode}</name-node>
<configuration>
<property>
<name>mapred.job.queue.name</name>
<value>${queueName}</value>
</property>
</configuration>
<exec>shell-impala-invalidate.sh</exec>
<file>shell-impala-invalidate.sh#shell-impala-invalidate.sh</file>
<file>cconner.keytab#cconner.keytab</file>
</shell>
<ok to="end"/>
<error to="kill"/>
</action>
<kill name="kill">
<message>Action failed, error message[${wf:errorMessage(wf:lastErrorNode())}]</message>
</kill>
<end name="end"/>
</workflow-app>

 

You must include the <file> tag with the shell script, but not the keytab part unless you are using kerberos.

 

Hope this helps.

 

Thanks

Chris

avatar
Explorer

Hi cconner

    It worked by your example, thanks!

    But if I want to execute impala-shell -f *.sql  , in Oozie ,there was error mentioned couldn't find the file.

    I had upload the sql file into Oozie workspace and add path for it .

    I try to pass shell argument, like ./impala-shell -f $2 ,but it didn't work.

    Could you please tell me how to do it in right way?

 

  This is my xml ( I replaced sensitive info by ***):

 

<workflow-app name="impala-shelltest" xmlns="uri:oozie:workflow:0.4">
  <credentials>
    <credential name="hcat" type="hcat">
      <property>
        <name>hcat.metastore.uri</name>
        <value>thrift://***:9083</value>
      </property>
      <property>
        <name>***</name>
        <value>***</value>
      </property>
    </credential>
    <credential name="hive2" type="hive2">
      <property>
        <name>hive2.jdbc.url</name>
        <value>jdbc:hive2://***:10000/default</value>
      </property>
      <property>
        <name>hive2.server.principal</name>
        <value>hive/***</value>
      </property>
    </credential>
  </credentials>
    <start to="impalashell"/>
    <action name="impalashell" cred="hcat,hive2">
        <shell xmlns="uri:oozie:shell-action:0.1">
            <job-tracker>${jobTracker}</job-tracker>
            <name-node>${nameNode}</name-node>
            <exec>runstats.sh</exec>
              <argument>***.keytab</argument>
              <argument>***.sql</argument>
            <file>runstats.sh#runstats.sh</file>
            <file>***.keytab#***.keytab</file>
            <file>***.sql#***.sql</file>
              <capture-output/>
        </shell>
        <ok to="end"/>
        <error to="kill"/>
    </action>
    <kill name="kill">
        <message>Action failed, error message[${wf:errorMessage(wf:lastErrorNode())}]</message>
    </kill>
    <end name="end"/>
</workflow-app>

avatar
Super Collaborator

The method you did was correct and should have worked.  Did you try a command like:

 

impala-shell -f ./file.sql

 

 

avatar
Explorer

Hi

     No, it didn't work....

     I assume impala -f only support <local>path , but the hard thing is we couldn't which node will run the script and we couldn't sync the file to every node for some security reason.

    Do you have more suggestion ?

    TK

    

 

avatar
Champion Alumni

Hello,

 

I also had this problem ( impala -f only support <local>path) . 

As for myself, I did a shell script that downloads the file from hdfs to /tmp/somedirectory.

Afterwards, I call the impala -f command. 

 

(I did something like)

FILE_TO_LAUNCH_LOCAL='/tmp'
FILE_TO_LAUNCH_LOCAL_WITH_TIMESTAMP=${FILE_TO_LAUNCH_LOCAL}/Oozie${TIMESTAMP}

export PYTHON_EGG_CACHE=./myeggs
mkdir ${FILE_TO_LAUNCH_LOCAL_WITH_TIMESTAMP}

mkdir ${FILE_TO_LAUNCH_LOCAL_WITH_TIMESTAMP}
hdfs dfs -copyToLocal ${FILE_TO_LAUNCH} ${FILE_TO_LAUNCH_LOCAL_WITH_TIMESTAMP}/

impala-shell -f ${FILE_TO_LAUNCH_LOCAL_WITH_TIMESTAMP}/myfile;

rm ${FILE_TO_LAUNCH_LOCAL_COMPLETE}

 

Alina

GHERMAN Alina

avatar
Super Collaborator

This right here works:

 

<workflow-app name="shell-impala-invalidate-wf" xmlns="uri:oozie:workflow:0.4">

<start to="shell-impala-invalidate"/>

<action name="shell-impala-invalidate">
<shell xmlns="uri:oozie:shell-action:0.1">
<job-tracker>${jobTracker}</job-tracker>
<name-node>${nameNode}</name-node>
<configuration>
<property>
<name>mapred.job.queue.name</name>
<value>${queueName}</value>
</property>
</configuration>
<exec>shell-impala-invalidate.sh</exec>
<file>shell-impala-invalidate.sh#shell-impala-invalidate.sh</file>
<file>shell-impala-invalidate.sql#shell-impala-invalidate.sql</file>
<file>cconner.keytab#cconner.keytab</file>
</shell>
<ok to="end"/>
<error to="kill"/>
</action>
<kill name="kill">
<message>Action failed, error message[${wf:errorMessage(wf:lastErrorNode())}]</message>
</kill>
<end name="end"/>
</workflow-app>

 

Script:

#!/bin/bash
LOG=/tmp/shell-impala-invalidate-$USER.log
ls -alrt > $LOG

export PYTHON_EGG_CACHE=./myeggs
/usr/bin/kinit -kt cconner.keytab -V cconner
/usr/bin/klist -e >> $LOG
impala-shell -f shell-impala-invalidate.sql

 

NOTE: the <file> tag puts that file on the local file system where the impala-shell is going to run, so the file is indeed local for the -f flag and it goes in "PWD/<whatever is after #>".  For example:

 

<file>test.sql#/test1/test.sql</file>

 

Then test.sql will be found in:

 

PWD/test1/test.sql

 

And:

 

<file>test.sql#test.sql</file>

 

Then test.sql will be found in:

 

PWD/test.sql

 

And the shell script and the keytab are also in "PWD" because of the file tags.  I would do the following in your shell script to get some more insight:

 

 

#!/bin/bash
LOG=/tmp/shell-impala-invalidate-$USER.log
ls -alrtR > $LOG  #This will show you all the files in the directory and their relative paths

export PYTHON_EGG_CACHE=./myeggs
/usr/bin/kinit -kt cconner.keytab -V cconner
/usr/bin/klist -e >> $LOG

hadoop fs -put $LOG /tmp  #put the log file in HDFS to find it easily

impala-shell -f shell-impala-invalidate.sql

 

 

NOTICE the "ls -lartR" and the "hadoop fs" command, this way you can easily grab the log file from HDFS and see what files are actually there.

 

 

avatar

In general 3 files are needed:

 

1) Linux shell-script to invoke

2) Sql file with impala queries/commands

3) Keytab

 

Those 3 files should be uploaded to the workflow deployment folder of the Oozie wf, and references as:

 

<workflow-app name="logdirs" xmlns="uri:oozie:workflow:0.4">
 <start to="invalidate_oozie"/>
 <action name="invalidate_oozie" cred="">
   <shell xmlns="uri:oozie:shell-action:0.1">
     <job-tracker>${jobTracker}</job-tracker>
     <name-node>${nameNode}</name-node>
     <exec>${SHELL_SCRIPT}</exec>
      <env-var>PYTHON_EGG_CACHE=./python-eggs</env-var>
     <file>${SHELL_SCRIPT}#${SHELL_SCRIPT}</file>
     <file>${KEYTAB_FILE}#${KEYTAB_FILE}</file>
     <file>${SQL_FILE}#${SQL_FILE}</file>
      <capture-output/>
    </shell>
    <ok to="end"/>
    <error to="kill"/>
 </action>
 <kill name="kill">
    <message>Action failed, error message[${wf:errorMessage(wf:lastErrorNode())}]</message>
 </kill>
 <end name="end"/>
</workflow-app>

 

Later replace the variables when invoking the workflow.

 

Then those 3 files will be avialble/reachable for the shell-script under the $PWD path.

So kinit -kt <keytab_file> -V <username> can be done from the linux shell-script as

 

kinit -kt $PWD/<keytab_file> -V <username>

 

and impala invoked as:

 

impala-shell -f $PWD/<sql_file>

 

 

In reallity, because the script is invoked from the PWD path, $PWD variable could be ommited. The important is to include the 3 files in the Shell action to make them available on runtime.

 

 

avatar
Explorer

I hope I didn't necro this one. I just want to ask if I need the python eggs if I just want to schedule a job for impala. and oh, since i am using  the oozie web rest api, i wanted to know if there is any XML sample I could relate to, especially when I needed the SQL line to be dynamic enough. e.g. first http request would be "select * from table1" while the next from it would be "select * from table2".

avatar
Champion Alumni

Hello,

 

 

For me it didn't work without the python eggs thing.

In order to by dynamic I replaced some well defined sequences in the shell script.

 

For example. I had my impala script something like this one:

select * from ${table1};
select * from ${table2};

Then in the shell script I did something like:

sed  "s/\${table1}/my_real_table_one/g;s/\${table2}/my_real_table_two/g;" $LOCAL_FILE_PATH > $LOCAL_FILE_WITH_VARIABLE_REPLACED

 

I hope this and my other post with the copyToLocal command for copying in local will help you.

 

Alina GHERMAN

GHERMAN Alina