public static String translateTableName(String tableName, @Nullable String databaseName, boolean ignoreCase) {
    Preconditions.checkArgument(StringUtils.isNotEmpty(tableName), "'tableName' cannot be null or empty");
    String[] tableSplit = StringUtils.split(tableName, '.');
    switch (tableSplit.length) {
      case 1:
        // do not concat the database name prefix if it's a 'default' database
        if (StringUtils.isNotEmpty(databaseName) && !databaseName.equalsIgnoreCase(CommonConstants.DEFAULT_DATABASE)) {
          return databaseName + "." + tableName;
        }
        return tableName;
      case 2:
        Preconditions.checkArgument(!tableSplit[1].isEmpty(), "Invalid table name '%s'", tableName);
        String databasePrefix = tableSplit[0];
        if (!StringUtils.isEmpty(databaseName) && (ignoreCase || !databaseName.equals(databasePrefix))
            && (!ignoreCase || !databaseName.equalsIgnoreCase(databasePrefix))) {
          throw new DatabaseConflictException("Database name '" + databasePrefix
              + "' from table prefix does not match database name '" + databaseName + "' from header");
        }
        // skip database name prefix if it's a 'default' database
        return databasePrefix.equalsIgnoreCase(CommonConstants.DEFAULT_DATABASE) ? tableSplit[1] : tableName;
      default:
        throw new IllegalArgumentException(
            "Table name: '" + tableName + "' containing more than one '.' is not allowed");
    }
  }
@Test
  public void translateTableNameTest() {
    // valid cases with non-default database
    check(LOGICAL_TABLE_NAME, DATABASE_NAME, FULLY_QUALIFIED_TABLE_NAME);
    check(FULLY_QUALIFIED_TABLE_NAME, DATABASE_NAME, FULLY_QUALIFIED_TABLE_NAME);
    check(FULLY_QUALIFIED_TABLE_NAME, null, FULLY_QUALIFIED_TABLE_NAME);

    // error cases with non-default database
    error(null, DATABASE_NAME);
    error(FULLY_QUALIFIED_TABLE_NAME + "." + "foo", null);
    error(FULLY_QUALIFIED_TABLE_NAME + "." + "foo", DATABASE_NAME);
    error(FULLY_QUALIFIED_TABLE_NAME, DATABASE_NAME + "foo");

    // valid cases with default database
    check(LOGICAL_TABLE_NAME, null, LOGICAL_TABLE_NAME);
    check(LOGICAL_TABLE_NAME, DEFAULT_DATABASE_NAME, LOGICAL_TABLE_NAME);
    check(DEFAULT_DATABASE_NAME + "." + LOGICAL_TABLE_NAME, null, LOGICAL_TABLE_NAME);
    check(DEFAULT_DATABASE_NAME + "." + LOGICAL_TABLE_NAME, DEFAULT_DATABASE_NAME, LOGICAL_TABLE_NAME);

    // error cases with default database
    error(null, DEFAULT_DATABASE_NAME);
    error(FULLY_QUALIFIED_TABLE_NAME, DEFAULT_DATABASE_NAME);
    error(DEFAULT_DATABASE_NAME + "." + LOGICAL_TABLE_NAME, DATABASE_NAME);
    error(DEFAULT_DATABASE_NAME + "." + FULLY_QUALIFIED_TABLE_NAME, null);
    error(DEFAULT_DATABASE_NAME + "." + FULLY_QUALIFIED_TABLE_NAME, DATABASE_NAME);
    error(DEFAULT_DATABASE_NAME + "." + FULLY_QUALIFIED_TABLE_NAME, DEFAULT_DATABASE_NAME);
  }