How to find current executing line from a hql file

179 views Asked by At

I have a sample.hql file which contains below lines.

desc db.table1;
desc db.table2;
desc db.table3;

I am trying to run it from shell command I want to find out if a particular column is present in the table or not For eg-If col_1 is present in table1 the output should say col1_1 is found in db.table1

I am not sure how to find it. I am executing below command

hive -f sample.hql | grep -q "<column_name>"

But I am not sure how to get the db and table name from each executing line.

1

There are 1 answers

0
Matt Andruff On

You can make grep show you before -B and after -A. The below command would show you 10 lines before. This likely will get the job done quick and dirty.

 hive -f sample.hql | grep -B 10 -q "<column_name>"

If you wanted to be a little more careful you might try a for loop instead that feeds the lines to hive one at a time. If it finds the column it will echo the table it found the column in. ( the '&&' only executes code if the previous command was successful)

#!/bin/bash

for i in $(cat sample.hql); do
    
    hive -e "$i" | grep -q "<column_name>" && echo $i; 
done