Calling two function

Hi,

I need to run start_load function for two tables.
Step 1: if HMAX_TBL_ID and GMAX_TBLI_D are same for tab_name1 then echo message "all table ids are processed"
Step 2: go back and call start_load for tab_name2 and check if table id are same for table 2 too.

Please let me know how to implement this logic.

get_table_id 
if [ ${HMAX_TBL_ID} = ${GMAX_TBLI_D} ]
 then   
   echo -e "All table ids are processed"
else
   echo "Do some processing"  
fi

##define start_load function##
start_load()
#some processing
get_table_id
#some more processing
############ Main section#################

if ${option} = 'ALL' then

start_load ${tab_name1} 
start_load ${tab_name2}

fi

thanks
sandy

I guess you need a loop and exit/return. Is start_Load() a function declaration? Define functions up top then comment the start of
############## MAIN ##############
like in PASCAL !

One good way to write loops is write what you want to do and when about to repeat, go back and wrap the repeating section so far in an unconditional loop: while : ; do ... done You can break, return or exit to get out! If you find yourself break-ing at the end or start, make it a loop condition in place of ':'. This applies to all languages !

One wonders who does error checking, and what to do about errors.

Is there supposed to be filtering if not 'ALL' ?

thanks for reply, yes start_load() is a function definition, I am calling "get_table_id" function inside the "start_load" function.
There are error checks and other conditions , but thoe pieces are owkring so I did not put them here.

Problem : there are several conditions for this script, I having problem in test case when
"All table ids are processed"
Step 1: when I call "start_load tab_name1" , it should go to "get_table_id" function and print "All table ids are processed"
Step 2 : come back and run "start_lod tab_name2", it should go to "get_table_id" function and print "All table ids are processed"
Step 3: exit

Lets step back from where for a moment and describe how it starts (first two loops unrolled) and how it ends (when can you tell it is done and is there anything else to do).

1 Like

Thanks for reply
I pass table names to migrate_table function and in case when table_ids are matching
I just want to print the message "All tableid are processed" and run migrate_table function for second table and if table_id are matchin then exit and print "All table ids are processed"

get_tbl_id_list()
{
        TABLE_NAME=$1
        LOADER_ID=$2

        LAST_PROCESSED_TABLEID=`nzsql -q -A -t -c "select max(last_processed_tableid) from tab_pqr where tbl_name='${TABLE_NAME}' and status_flag='S'"

        if [ $? -ne 0 ]
        then
                echo -e "Error While getting the last processed tableid"
                exit 1;
        fi

        HMAX_TBL_ID=`psql -U ${PG_USER} -h ${PG_HOST} -d ${PG_DB} -p ${PG_PASS} -A -t -c "select stp_ctr_tbl_id('ARIB', 'GET')"`

        if [ $? -ne 0 ]
        then
                echo -e " Error while getting the maximun table id processed in Hadoop "
        fi

        if [ ${HMAX_TBL_ID} = ${LAST_PROCESSED_TABLEID} ]
         then   
          echo -e "All table ids are processed"
        else
        psql -U ${PG_USER} -h ${PG_HOST} -d ${PG_DB} -p ${PG_PASS} -t -c "select distinct tbl_id from tbl_ctr_hdr where tbl_id between ${LAST_PROCESSED_TABLEID}+1 and ${HMAX_TBL_ID}" | sed '/^$/d' > ${TBL_ID_FILE}

           if [ $? -ne 0 ]
            then
                 echo -e " Error while getting the list of Table ids"
           fi
        fi
}

migrate_tables
{
TAB_NAME=$1
loader_id=BD

 echo -e " loader ids that are processing ... 
 
 get_tbl_id_list ${TAB_NAME} ${loader_id}
 
 ##some more processing##
 }
 
#########################Calling function to load data in table#####################
tab_name=$1 
#some checks and other processing
if [ ${tab_name} = 'ALL' ] 
	then
	   echo -e " Loading tab_abc table have started"
	     migrate_tables 'tab_abc'
       
	   if [ $? -ne 0 ]
		 then
			echo -e "Error While processing 'tab_abc' using ALL option"
			exit 1;
		fi
	   
	    echo -e "Loading tab_xyz has started"
	       migrate_tables 'tab_xyz'
 
		if [ $? -ne 0 ]
		 then
			echo -e "Error While processing tab_xyz using ALL option "
			exit 1;

		fi
fi		

OK, first routine get_tbl_id_list:

  1. you use table to get last table_id,
  2. then constants to get hmax table_id (does other processing change this result, not constant for the whole run and should be outside the loops?)
  3. if = then say all done and return
  4. else make a table id file.

Not sure why it needs to be a sub, since it looks like you call it once. Not sure who calls it when. $LOADER_ID never used, or hidden parameter to something?

Second, migrate_tables

  1. echos a message
  2. calls routine #1 with $1 and constant (which will be ignored?)
  3. other stuff

Hardly worth having a function.

Third, main code:

  1. $1 has to be ALL to do any of the referenced code.
  2. echo a message
  3. call #2 with constant tab_abc (low table?)
  4. call #2 with constant tab_xyz (high table?) which will overwrite product of step 3 unless all are done. Maybe that is always true, which would be somewhat contrived.

Not sure what it does or lacks. Normally, you want to loop through a process from a known starting point until a predictable end point. Nothing here loops. I am not sure what is modeled or processed. Who modifies tab_pqr? Who reads the file? Does stp_ctr_tbl_id('ARIB', 'GET') output change as tables are modified in this process? We only call it twice. Maybe we should take the table ids out of that file and migrate them?