private boolean ensureHiveTableExistenceBeforeAlternation ( String tableName , String dbName , IMetaStoreClient client , Table table , HiveSpec spec ) throws TException { try ( AutoCloseableLock lock = this . locks . getTableLock ( dbName , tableName ) ) { try { try ( Timer . Context context = this . metricContext . timer ( CREATE_HIVE_TABLE ) . time ( ) ) { client . createTable ( getTableWithCreateTimeNow ( table ) ) ; log . info ( String . format ( "Created Hive table %s in db %s" , tableName , dbName ) ) ; return true ; } catch ( AlreadyExistsException e ) { } } catch ( TException e ) { log . error ( String . format ( "Unable to create Hive table %s in db %s: " + e . getMessage ( ) , tableName , dbName ) , e ) ; throw e ; } log . info ( "Table {} already exists in db {}." , tableName , dbName ) ; try { HiveTable existingTable ; try ( Timer . Context context = this . metricContext . timer ( GET_HIVE_TABLE ) . time ( ) ) { existingTable = HiveMetaStoreUtils . getHiveTable ( client . getTable ( dbName , tableName ) ) ; } if ( needToUpdateTable ( existingTable , spec . getTable ( ) ) ) { try ( Timer . Context context = this . metricContext . timer ( ALTER_TABLE ) . time ( ) ) { client . alter_table ( dbName , tableName , getNewTblByMergingExistingTblProps ( table , existingTable ) ) ; } log . info ( String . format ( "updated Hive table %s in db %s" , tableName , dbName ) ) ; } } catch ( TException e2 ) { log . error ( String . format ( "Unable to create or alter Hive table %s in db %s: " + e2 . getMessage ( ) , tableName , dbName ) , e2 ) ; throw e2 ; } // When the logic up to here it means table already existed in db and alteration happen. Return false. return false ; } }
If table existed on Hive side will return false ; Or will create the table thru . RPC and return retVal from remote MetaStore .