private boolean ensureHiveDbExistence ( String hiveDbName , IMetaStoreClient client ) throws IOException { try ( AutoCloseableLock lock = this . locks . getDbLock ( hiveDbName ) ) { Database db = new Database ( ) ; db . setName ( hiveDbName ) ; try { try ( Timer . Context context = this . metricContext . timer ( GET_HIVE_DATABASE ) . time ( ) ) { client . getDatabase ( db . getName ( ) ) ; } return false ; } catch ( NoSuchObjectException nsoe ) { // proceed with create } catch ( TException te ) { throw new IOException ( te ) ; } Preconditions . checkState ( this . hiveDbRootDir . isPresent ( ) , "Missing required property " + HiveRegProps . HIVE_DB_ROOT_DIR ) ; db . setLocationUri ( new Path ( this . hiveDbRootDir . get ( ) , hiveDbName + HIVE_DB_EXTENSION ) . toString ( ) ) ; try { try ( Timer . Context context = this . metricContext . timer ( CREATE_HIVE_DATABASE ) . time ( ) ) { client . createDatabase ( db ) ; } log . info ( "Created database " + hiveDbName ) ; HiveMetaStoreEventHelper . submitSuccessfulDBCreation ( this . eventSubmitter , hiveDbName ) ; return true ; } catch ( AlreadyExistsException e ) { return false ; } catch ( TException e ) { HiveMetaStoreEventHelper . submitFailedDBCreation ( this . eventSubmitter , hiveDbName , e ) ; throw new IOException ( "Unable to create Hive database " + hiveDbName , e ) ; } } }
If databse existed on Hive side will return false ; Or will create the table thru . RPC and return retVal from remote MetaStore .