public Path getDefaultLocation(String dbName, String tableName) {
        Database database = getDb(dbName);

        if (database == null) {
            throw new StarRocksConnectorException("Database '%s' not found", dbName);
        }
        if (Strings.isNullOrEmpty(database.getLocation())) {
            throw new StarRocksConnectorException("Failed to find location in database '%s'. Please define the location" +
                    " when you create table or recreate another database with location." +
                    " You could execute the SQL command like 'CREATE TABLE <table_name> <columns> " +
                    "PROPERTIES('location' = '<location>')", dbName);
        }

        String dbLocation = database.getLocation();
        Path databasePath = new Path(dbLocation);

        if (!pathExists(databasePath, hadoopConf)) {
            throw new StarRocksConnectorException("Database '%s' location does not exist: %s", dbName, databasePath);
        }

        if (!isDirectory(databasePath, hadoopConf)) {
            throw new StarRocksConnectorException("Database '%s' location is not a directory: %s",
                    dbName, databasePath);
        }

        Path targetPath = new Path(databasePath, tableName);
        if (pathExists(targetPath, hadoopConf)) {
            throw new StarRocksConnectorException("Target directory for table '%s.%s' already exists: %s",
                    dbName, tableName, targetPath);
        }

        return targetPath;
    }
@Test
    public void testGetDefaultLocation() {
        class MockedTestMetaClient1 extends HiveMetastoreTest.MockedHiveMetaClient {
            public org.apache.hadoop.hive.metastore.api.Database getDb(String dbName) throws RuntimeException {
                org.apache.hadoop.hive.metastore.api.Database database = new org.apache.hadoop.hive.metastore.api.Database();
                database.setName("db");
                return database;
            }
        }
        HiveMetaClient client = new MockedTestMetaClient1();
        HiveMetastore metastore = new HiveMetastore(client, "hive_catalog", MetastoreType.HMS);
        ExecutorService executor = Executors.newFixedThreadPool(5);
        CachingHiveMetastore cachingHiveMetastore = new CachingHiveMetastore(
                metastore, executor, expireAfterWriteSec, refreshAfterWriteSec, 1000, false);
        HiveMetastoreOperations hmsOps = new HiveMetastoreOperations(cachingHiveMetastore, true,
                new Configuration(), MetastoreType.HMS, "hive_catalog");

        ExceptionChecker.expectThrowsWithMsg(StarRocksConnectorException.class,
                "Failed to find location in database 'db'",
                () -> hmsOps.getDefaultLocation("db", "table"));

        new MockUp<HiveWriteUtils>() {
            @Mock
            public boolean pathExists(Path path, Configuration conf) {
                return false;
            }
        };
        class MockedTestMetaClient2 extends HiveMetastoreTest.MockedHiveMetaClient {
            public org.apache.hadoop.hive.metastore.api.Database getDb(String dbName) throws RuntimeException {
                org.apache.hadoop.hive.metastore.api.Database database = new org.apache.hadoop.hive.metastore.api.Database();
                database.setName("db");
                database.setLocationUri("my_location");
                return database;
            }
        }
        HiveMetaClient client2 = new MockedTestMetaClient2();
        HiveMetastore metastore2 = new HiveMetastore(client2, "hive_catalog", MetastoreType.HMS);
        CachingHiveMetastore cachingHiveMetastore2 = new CachingHiveMetastore(
                metastore2, executor, expireAfterWriteSec, refreshAfterWriteSec, 1000, false);
        HiveMetastoreOperations hmsOps2 = new HiveMetastoreOperations(cachingHiveMetastore2, true,
                new Configuration(), MetastoreType.HMS, "hive_catalog");

        ExceptionChecker.expectThrowsWithMsg(StarRocksConnectorException.class,
                "Database 'db' location does not exist: my_location",
                () -> hmsOps2.getDefaultLocation("db", "table"));

        new MockUp<HiveWriteUtils>() {
            @Mock
            public boolean pathExists(Path path, Configuration conf) {
                return true;
            }

            @Mock
            public boolean isDirectory(Path path, Configuration conf) {
                return false;
            }
        };

        ExceptionChecker.expectThrowsWithMsg(StarRocksConnectorException.class,
                "Database 'db' location is not a directory: my_location",
                () -> hmsOps2.getDefaultLocation("db", "table"));

        new MockUp<HiveWriteUtils>() {
            @Mock
            public boolean pathExists(Path path, Configuration conf) {
                return true;
            }

            @Mock
            public boolean isDirectory(Path path, Configuration conf) {
                return true;
            }
        };

        ExceptionChecker.expectThrowsWithMsg(StarRocksConnectorException.class,
                "Target directory for table 'db.table' already exists: my_location/table",
                () -> hmsOps2.getDefaultLocation("db", "table"));
    }