{"id":342176,"date":"2022-12-06T04:29:55","date_gmt":"2022-12-06T04:29:55","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=342176"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=342176","title":{"rendered":"<span>\u041a\u0430\u043a \u043d\u0430\u0439\u0442\u0438 \u00ab\u0441\u043b\u043e\u043d\u0430\u00bb \u0432 \u043f\u0435\u0441\u043e\u0447\u043d\u0438\u0446\u0435 \u043d\u0430 Hadoop: \u0440\u0435\u0448\u0430\u0435\u043c \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0443 \u0441 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u0435\u043c \u043e\u0431\u044a\u0451\u043c\u0430 \u0432\u044b\u0434\u0435\u043b\u0435\u043d\u043d\u043e\u0439 \u043f\u0430\u043c\u044f\u0442\u0438<\/span>"},"content":{"rendered":"<div><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p>\u0418 \u0441\u043d\u043e\u0432\u0430 \u0437\u0434\u0440\u0430\u0432\u0441\u0442\u0432\u0443\u0439, \u0425\u0430\u0431\u0440! \u0421\u0435\u0433\u043e\u0434\u043d\u044f \u043f\u043e\u0433\u043e\u0432\u043e\u0440\u0438\u043c \u043e\u0431 \u0430\u043a\u0442\u0443\u0430\u043b\u044c\u043d\u043e\u0439 \u0434\u043b\u044f \u043c\u043d\u043e\u0433\u0438\u0445 \u0438\u0437 \u043d\u0430\u0441 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0435 \u043f\u0440\u0438 \u0440\u0430\u0431\u043e\u0442\u0435 \u0441 \u0431\u0430\u0437\u0430\u043c\u0438 \u0434\u0430\u043d\u043d\u044b\u0445. \u0412 \u0445\u043e\u0434\u0435 \u0440\u0430\u0431\u043e\u0442\u044b \u043d\u0430\u0434 \u0440\u0430\u0437\u043d\u044b\u043c\u0438 \u043f\u0440\u043e\u0435\u043a\u0442\u0430\u043c\u0438 \u0447\u0430\u0441\u0442\u043e \u043f\u0440\u0438\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u0431\u0430\u0437\u0443 \u0434\u0430\u043d\u043d\u044b\u0445\u00a0 (\u043a\u043e\u043c\u0430\u043d\u0434\u043d\u043e\u0435 \u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0441\u0442\u0432\u043e, \u043f\u0435\u0441\u043e\u0447\u043d\u0438\u0446\u0430 \u0438 \u0442.\u043f.), \u043a\u043e\u0442\u043e\u0440\u0443\u044e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 \u043a\u0430\u043a \u0441\u0430\u043c \u0430\u0432\u0442\u043e\u0440, \u0442\u0430\u043a \u0438\/\u0438\u043b\u0438 \u043a\u043e\u043b\u043b\u0435\u0433\u0438 \u0434\u043b\u044f \u0432\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0433\u043e \u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044f \u0434\u0430\u043d\u043d\u044b\u0445. \u041a\u0430\u043a \u0443 \u043b\u044e\u0431\u043e\u0433\u043e \u00ab\u043f\u043e\u043c\u0435\u0449\u0435\u043d\u0438\u044f\u00bb, \u0432 \u043d\u0430\u0448\u0435\u0439 \u00ab\u043f\u0435\u0441\u043e\u0447\u043d\u0438\u0446\u0435\u00bb \u0435\u0441\u0442\u044c \u0441\u0432\u043e\u0451 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u0435 \u043f\u043e \u043e\u0431\u044a\u0451\u043c\u0443 \u0432\u044b\u0434\u0435\u043b\u0435\u043d\u043d\u043e\u0433\u043e \u043c\u0435\u0441\u0442\u0430 \u0434\u043b\u044f \u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044f \u0434\u0430\u043d\u043d\u044b\u0445.\u00a0 \u041f\u0435\u0440\u0438\u043e\u0434\u0438\u0447\u0435\u0441\u043a\u0438 \u0431\u044b\u0432\u0430\u0435\u0442 \u0442\u0430\u043a, \u0447\u0442\u043e \u0432\u044b \u0438\u043b\u0438 \u0432\u0430\u0448\u0438 \u043a\u043e\u043b\u043b\u0435\u0433\u0438 \u0437\u0430\u0431\u044b\u0432\u0430\u0435\u0442\u0435 \u043e\u0431 \u044d\u0442\u043e\u043c \u043c\u0430\u043b\u0435\u043d\u044c\u043a\u043e\u043c \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u0438, \u0438\u0437-\u0437\u0430 \u0447\u0435\u0433\u043e, \u043a \u0441\u043e\u0436\u0430\u043b\u0435\u043d\u0438\u044e, \u0437\u0430\u043a\u0430\u043d\u0447\u0438\u0432\u0430\u0435\u0442\u0441\u044f \u043e\u0431\u044a\u0451\u043c \u0432\u044b\u0434\u0435\u043b\u0435\u043d\u043d\u043e\u0439 \u043f\u0430\u043c\u044f\u0442\u0438.<\/p>\n<p>\u0412 \u044d\u0442\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043c\u043e\u0436\u043d\u043e \u043f\u0440\u0438\u043c\u0435\u043d\u0438\u0442\u044c \u043c\u0430\u043b\u0435\u043d\u044c\u043a\u0438\u0439 \u043b\u0430\u0439\u0444\u0445\u0430\u043a, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u043e\u0437\u0432\u043e\u043b\u0438\u0442 \u043e\u043f\u0435\u0440\u0430\u0442\u0438\u0432\u043d\u043e \u043f\u0440\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c, \u043a\u0430\u043a\u0430\u044f \u0442\u0430\u0431\u043b\u0438\u0446\u0430 \u0431\u043e\u043b\u044c\u0448\u0435 \u0432\u0441\u0435\u0433\u043e \u0437\u0430\u043d\u0438\u043c\u0430\u0435\u0442 \u043c\u0435\u0441\u0442\u043e, \u043a\u0442\u043e \u0435\u0451 \u0432\u043b\u0430\u0434\u0435\u043b\u0435\u0446, \u043a\u0430\u043a \u0434\u043e\u043b\u0433\u043e \u043e\u043d\u0430 \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u0432 \u043e\u0431\u0449\u0435\u0439 \u043f\u0435\u0441\u043e\u0447\u043d\u0438\u0446\u0435 \u0438 \u0442.\u0434. \u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u0435\u0433\u043e, \u0432\u044b \u043e\u043f\u0435\u0440\u0430\u0442\u0438\u0432\u043d\u043e \u0441\u043c\u043e\u0436\u0435\u0442\u0435 \u043f\u043e\u0447\u0438\u0441\u0442\u0438\u0442\u044c \u043c\u0435\u0441\u0442\u043e \u0432 \u043f\u0435\u0441\u043e\u0447\u043d\u0438\u0446\u0435, \u043f\u0440\u0435\u0434\u0432\u0430\u0440\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0441\u043e\u0433\u043b\u0430\u0441\u043e\u0432\u0430\u0432 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f \u0441 \u0432\u043b\u0430\u0434\u0435\u043b\u044c\u0446\u0435\u043c \u0434\u0430\u043d\u043d\u044b\u0445 \u0431\u0435\u0437 \u043d\u0430\u043d\u0435\u0441\u0435\u043d\u0438\u044f \u0432\u0440\u0435\u0434\u0430 \u0434\u0430\u043d\u043d\u044b\u043c \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u044b\u0445 \u043a\u043e\u043b\u043b\u0435\u0433. \u041a\u0440\u043e\u043c\u0435 \u0442\u043e\u0433\u043e, \u044d\u0442\u043e\u0442 \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442 \u043f\u043e\u0437\u0432\u043e\u043b\u0438\u0442 \u043f\u0435\u0440\u0438\u043e\u0434\u0438\u0447\u0435\u0441\u043a\u0438 \u043f\u0440\u043e\u0432\u043e\u0434\u0438\u0442\u044c \u043c\u043e\u043d\u0438\u0442\u043e\u0440\u0438\u043d\u0433 \u043d\u0430\u043f\u043e\u043b\u043d\u044f\u0435\u043c\u043e\u0441\u0442\u0438 \u0432\u0430\u0448\u0435\u0439 \u043e\u0431\u0449\u0435\u0439 \u043f\u0435\u0441\u043e\u0447\u043d\u0438\u0446\u044b.<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/7b7\/2f4\/3ef\/7b72f43ef741188eaa86e30da4a5b78e.png\" width=\"1459\" height=\"765\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/7b7\/2f4\/3ef\/7b72f43ef741188eaa86e30da4a5b78e.png\"\/><figcaption><\/figcaption><\/figure>\n<h2>\u042d\u0442\u0430\u043f 1<\/h2>\n<p>\u0414\u043b\u044f \u043d\u0430\u0447\u0430\u043b\u0430 \u0438\u043c\u043f\u043e\u0440\u0442\u0438\u0440\u0443\u0435\u043c \u043d\u0443\u0436\u043d\u044b\u0435 \u043d\u0430\u043c \u043c\u043e\u0434\u0443\u043b\u0438 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a \u0434\u043b\u044f Python \u0438 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u043c \u043f\u0443\u0442\u044c \u043a \u043d\u0430\u0448\u0435\u0439 \u043f\u0435\u0441\u043e\u0447\u043d\u0438\u0446\u0435.<\/p>\n<pre><code>import subprocess import sys, getopt import re import pandas as pd %matplotlib inline pd.set_option('display.max_colwidth', -1) path = 'hdfs:\/\/arnsdpsbx\/user\/team\/team_sandbox\/hive'<\/code><\/pre>\n<p>\u041c\u043e\u0434\u0443\u043b\u044c subprocess \u0432 Python \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u043f\u0440\u043e\u0441\u0442\u044b\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u044e\u0442 \u043d\u0430\u043c \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0442\u044c \u043d\u043e\u0432\u044b\u0439 \u043f\u0440\u043e\u0446\u0435\u0441\u0441 \u0438 \u043f\u043e\u043b\u0443\u0447\u0430\u0442\u044c \u0438\u0445 \u043a\u043e\u0434\u044b \u0432\u043e\u0437\u0432\u0440\u0430\u0442\u0430. <\/p>\n<p>\u041c\u043e\u0434\u0443\u043b\u044c getopt \u2014 \u043e\u0434\u0438\u043d \u0438\u0437 \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u043e\u0432 \u0430\u043d\u0430\u043b\u0438\u0437\u0430 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u043e\u0432 \u043a\u043e\u043c\u0430\u043d\u0434\u043d\u043e\u0439 \u0441\u0442\u0440\u043e\u043a\u0438. \u0412 \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0434\u043b\u044f \u0430\u043d\u0430\u043b\u0438\u0437\u0430 \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u043e\u0432.<\/p>\n<p>\u041c\u043e\u0434\u0443\u043b\u044c re \u0432 Python \u2014 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0432 \u044d\u0442\u043e\u043c \u043c\u043e\u0434\u0443\u043b\u0435 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u044e\u0442 \u043f\u0440\u043e\u0432\u0435\u0440\u0438\u0442\u044c, \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u0435\u0442 \u043b\u0438 \u0441\u0442\u0440\u043e\u043a\u0430 \u0437\u0430\u0434\u0430\u043d\u043d\u043e\u043c\u0443 \u0440\u0435\u0433\u0443\u043b\u044f\u0440\u043d\u043e\u043c\u0443 \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u044e (\u0438\u043b\u0438 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u0435\u0442 \u043b\u0438 \u0434\u0430\u043d\u043d\u043e\u0435 \u0440\u0435\u0433\u0443\u043b\u044f\u0440\u043d\u043e\u0435 \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u0435 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0451\u043d\u043d\u043e\u0439 \u0441\u0442\u0440\u043e\u043a\u0435, \u0447\u0442\u043e \u0441\u0432\u043e\u0434\u0438\u0442\u0441\u044f \u043a \u0442\u043e\u043c\u0443 \u0436\u0435 \u0441\u0430\u043c\u043e\u043c\u0443). <\/p>\n<p>\u041c\u043e\u0434\u0443\u043b\u044c pandas\u00a0 \u2014 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u043d\u0430\u044f \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430 \u0434\u043b\u044f \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u0438 \u0430\u043d\u0430\u043b\u0438\u0437\u0430 \u0434\u0430\u043d\u043d\u044b\u0445. \u041a\u043e\u043c\u0430\u043d\u0434\u0430 %matplotlib inline \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043f\u043e\u0441\u0442\u0440\u043e\u0438\u0442\u044c \u0438 \u0432\u044b\u0432\u0435\u0441\u0442\u0438 \u043d\u0443\u0436\u043d\u044b\u0439 \u0432\u0430\u043c \u0433\u0440\u0430\u0444\u0438\u043a \u043f\u0440\u044f\u043c\u043e \u0432 Jupiter notebook (\u0434\u0430\u043b\u0435\u0435 \u0432 \u0441\u0442\u0430\u0442\u044c\u0435). <\/p>\n<h2>\u042d\u0442\u0430\u043f 2<\/h2>\n<p>\u0414\u0430\u043b\u0435\u0435 \u043c\u044b \u043f\u0440\u043e\u043f\u0438\u0448\u0435\u043c \u0444\u0443\u043d\u043a\u0446\u0438\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0442 \u043d\u0430\u043c \u0441\u0444\u043e\u0440\u043c\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0441\u0442\u0430\u0442\u0438\u0441\u0442\u0438\u043a\u0443 \u043f\u043e \u0437\u0430\u043f\u043e\u043b\u043d\u044f\u0435\u043c\u043e\u0441\u0442\u0438 \u043d\u0430\u0448\u0435\u0439 \u043f\u0435\u0441\u043e\u0447\u043d\u0438\u0446\u044b:\u00a0 <\/p>\n<p><em>&#8212; \u0434\u043b\u044f \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u0440\u0430\u0437\u043c\u0435\u0440\u0430 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u043e\u0439 \u043f\u0430\u043c\u044f\u0442\u0438 (human_readable_size)<\/em><\/p>\n<pre><code>def human_readable_size(size, decimal_places=2):     for unit in ['B', 'KiB', 'MiB', 'GiB', 'TiB', 'PiB']:         if size &lt; 1024.0 or unit == 'PiB':             break         size \/= 1024.0     return f'{size:.{decimal_places}f} {unit}'<\/code><\/pre>\n<p><em>&#8212; \u0434\u043b\u044f \u043f\u043e\u0438\u0441\u043a\u0430 \u0438 \u0444\u043e\u0440\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0441\u043f\u0438\u0441\u043a\u0430 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439 \u0432 \u043f\u0435\u0441\u043e\u0447\u043d\u0438\u0446\u0435 (get_ipa_login)<\/em><\/p>\n<pre><code>def get_ipa_login(domain, login):     if domain == '\u0412\u0430\u0448_\u0434\u043e\u043c\u0435\u043d_IPA':         return f'{login}_\u0412\u0430\u0448_\u0434\u043e\u043c\u0435\u043d_IPA'     return ''<\/code><\/pre>\n<p><em>&#8212; \u0434\u043b\u044f \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u0442\u0435\u0440\u0440\u0438\u0442\u043e\u0440\u0438\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u043f\u043e\u0434\u0440\u0430\u0437\u0434\u0435\u043b\u0435\u043d\u0438\u044f (get_tb)<\/em><\/p>\n<pre><code>def get_tb(dept):     try:         return dept.split('\/')[2]     except:         return '-'<\/code><\/pre>\n<p><em>&#8212; \u0434\u043b\u044f \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u043d\u0430\u0438\u043c\u0435\u043d\u043e\u0432\u0430\u043d\u0438\u044f \u0442\u0430\u0431\u043b\u0438\u0446\u044b \u0432 \u043f\u0435\u0441\u043e\u0447\u043d\u0438\u0446\u0435 (get_table_name)<\/em><\/p>\n<pre><code>def get_table_name(path):     try:         return path.split('\/')[-1]     except:         return '-'<\/code><\/pre>\n<p><em>&#8212; \u0434\u043b\u044f \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u0432\u043b\u0430\u0434\u0435\u043b\u044c\u0446\u0430 \u0442\u0430\u0431\u043b\u0438\u0446\u044b (get_owner_name)<\/em><\/p>\n<pre><code>def get_owner_name(owner, name):     return f'{owner} ({name})'<\/code><\/pre>\n<p><em>&#8212; \u0434\u043b\u044f \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u0442\u0430\u0431\u043b\u0438\u0446 \u00ab\u0444\u0430\u043d\u0442\u043e\u043c\u043e\u0432\u00bb \u0431\u0435\u0437 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u0432\u043b\u0430\u0434\u0435\u043b\u044c\u0446\u0430<\/em><\/p>\n<pre><code>def get_fix_cmd(merge, path, table_name):     if merge == 'right_only':         return f'DROP TABLE {table_name}'     elif merge == 'left_only':         return f'hdfs dfs -rm -f -R -skipTrash {path}'    return ''<\/code><\/pre>\n<h2>\u042d\u0442\u0430\u043f 3<\/h2>\n<p>\u0414\u0430\u043b\u0435\u0435 \u043c\u044b \u0441\u043e\u0437\u0434\u0430\u0435\u043c Dataframe, \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0449\u0438\u0439 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e \u043e \u0434\u0430\u043d\u043d\u044b\u0445, \u0440\u0430\u0437\u043c\u0435\u0449\u0451\u043d\u043d\u044b\u0445 \u0432 \u043f\u0435\u0441\u043e\u0447\u043d\u0438\u0446\u0435 (\u0434\u0430\u043d\u043d\u044b\u0435 \u043e \u0432\u043b\u0430\u0434\u0435\u043b\u044c\u0446\u0435, \u0433\u0440\u0443\u043f\u043f\u0435, \u0434\u0430\u0442\u0435, \u0432\u0440\u0435\u043c\u0435\u043d\u0438, \u043f\u0443\u0442\u0438 \u0440\u0430\u0437\u043c\u0435\u0449\u0435\u043d\u0438\u044f \u0442\u0430\u0431\u043b\u0438\u0446\u044b).<\/p>\n<pre><code>out = subprocess.Popen(['hdfs', 'dfs', '-du', path], stdout=subprocess.PIPE, stderr=subprocess.STDOUT) stdout, stderr = out.communicate() if 'GSSException' in stdout.decode('utf-8'):     print('GSSException! Run kinit')     exit(1) lines = stdout.decode('utf-8').split('\\n') list_du = [] for line in lines:     m = re.match(r'^(\\d+)\\s+(\\d+)\\s+(.*)$', line)     if m:         list_du.append([             int(m.group(1)),             int(m.group(2)),             m.group(3)         ]) df_du = pd.DataFrame(list_du, columns=['fsize', 'disk_space_consumed', 'path'])      out = subprocess.Popen(['hdfs', 'dfs', '-ls', path], stdout=subprocess.PIPE, stderr=subprocess.STDOUT) stdout, stderr = out.communicate() lines = stdout.decode('utf-8').split('\\n') del lines[0] list_ls = [] for line in lines:     list_ls.append(line.split())  df_ls = pd.DataFrame(list_ls, columns=['permission', 'links', 'owner', 'group', 'size', 'date', 'time', 'path']) df_ls.dropna(how='all', inplace=True) df_ls.drop(['permission', 'links', 'size'], axis=1, inplace=True) <\/code><\/pre>\n<p>\u041f\u043e \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u043d\u043e\u043c\u0443 \u043a\u043e\u0434\u0443 \u043c\u044b \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0434\u0430\u043d\u043d\u044b\u0435 \u043e \u0432\u043b\u0430\u0434\u0435\u043b\u044c\u0446\u0435, \u0433\u0440\u0443\u043f\u043f\u0435, \u0434\u0430\u0442\u0435, \u0432\u0440\u0435\u043c\u0435\u043d\u0438, \u043f\u0443\u0442\u0438 \u0440\u0430\u0437\u043c\u0435\u0449\u0435\u043d\u0438\u044f \u0442\u0430\u0431\u043b\u0438\u0446\u044b.<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/bc8\/85c\/3b0\/bc885c3b0c3787dd30a23c8663e6cfaf.png\" width=\"1058\" height=\"445\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/bc8\/85c\/3b0\/bc885c3b0c3787dd30a23c8663e6cfaf.png\"\/><figcaption><\/figcaption><\/figure>\n<h2>\u042d\u0442\u0430\u043f 4<\/h2>\n<p>\u041d\u0435 \u0437\u0430\u0431\u044b\u0432\u0430\u044f \u043e \u043a\u043e\u043b\u043b\u0435\u0433\u0430\u0445, \u043c\u044b \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u0432 \u043d\u0430\u0448 Dataframe \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u0443\u044e \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e \u043e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f\u0445, \u043a\u043e\u0442\u043e\u0440\u044b\u043c \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u044b \u043f\u0440\u0430\u0432\u0430 \u0438 \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442 \u043d\u0430\u0448\u0443 \u00ab\u043f\u0435\u0441\u043e\u0447\u043d\u0438\u0446\u0443\u00bb. \u0412 \u043d\u0430\u0448\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 \u043e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f\u0445 \u0438 \u0438\u0445 \u043f\u0440\u0438\u043d\u0430\u0434\u043b\u0435\u0436\u043d\u043e\u0441\u0442\u0438 \u043a \u0442\u0435\u0440\u0440\u0438\u0442\u043e\u0440\u0438\u0430\u043b\u044c\u043d\u043e\u043c\u0443 \u043f\u043e\u0434\u0440\u0430\u0437\u0434\u0435\u043b\u0435\u043d\u0438\u044e \u043c\u044b \u0432\u0437\u044f\u043b\u0438 \u0438\u0437 \u0441sv \u0444\u0430\u0439\u043b\u0430. \u0412 \u0446\u0435\u043b\u043e\u043c \u0441\u043a\u0440\u0438\u043f\u0442 \u043c\u043e\u0436\u043d\u043e \u0443\u043b\u0443\u0447\u0448\u0438\u0442\u044c, \u043d\u0430\u0441\u0442\u0440\u043e\u0438\u0432 \u0432\u044b\u0433\u0440\u0443\u0437\u043a\u0443 \u043d\u0430 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u0435 \u0434\u0430\u043d\u043d\u044b\u0445 \u0438\u0437 \u0441\u0438\u0441\u0442\u0435\u043c\u044b \u0443\u0447\u0451\u0442\u0430 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439 IPA (\u0432 \u043d\u0430\u0448\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u044d\u0442\u043e Red HAT Identity Management).<\/p>\n<pre><code>df_users = pd.read_csv('ad_users.csv', encoding='windows-1251', sep='|', header=None, names=['domain', 'login', 'tn', 'full_name', 'position', 'dept'], index_col=False) df_users['ipa_login'] = df_users.apply(lambda row: get_ipa_login(row.domain, row.login), axis=1)<\/code><\/pre>\n<h2>\u042d\u0442\u0430\u043f 5<\/h2>\n<p>\u041f\u043e\u0441\u043b\u0435 \u0444\u043e\u0440\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0431\u0430\u0437 \u0441 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0439 \u0434\u043b\u044f \u043d\u0430\u0441 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0435\u0439 \u043e \u0442\u0430\u0431\u043b\u0438\u0446\u0430\u0445 \u0438 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f\u0445 \u043c\u044b \u043e\u0431\u044a\u0435\u0434\u0438\u043d\u044f\u0435\u043c \u044d\u0442\u0438 \u0434\u0430\u043d\u043d\u044b\u0435 \u0432 \u0435\u0434\u0438\u043d\u0443\u044e \u0431\u0430\u0437\u0443 \u0434\u0430\u043d\u043d\u044b\u0445.<\/p>\n<pre><code>df_hdfs = pd.merge(df_du, df_ls, on='path') df_hdfs['fsize_h'] = df_hdfs['fsize'].apply(lambda x: human_readable_size(x)) df_hdfs['disk_space_consumed_h'] = df_hdfs['disk_space_consumed'].apply(lambda x: human_readable_size(x)) df_hdfs = df_hdfs.reindex(columns=['path', 'owner', 'group', 'fsize', 'fsize_h', 'disk_space_consumed', 'disk_space_consumed_h', 'date']) df_hdfs = pd.merge(df_hdfs, df_users, how='left', left_on='owner', right_on='ipa_login') df_hdfs['owner_name'] = df_hdfs.apply(lambda row: get_owner_name(row.owner, row.full_name), axis=1) df_hdfs['tb'] = df_hdfs['dept'].apply(lambda x: get_tb(x)) df_hdfs['table_name'] = df_hdfs['path'].apply(lambda x: get_table_name(x))<\/code><\/pre>\n<h2>\u042d\u0442\u0430\u043f 6<\/h2>\n<p>\u0414\u0435\u043b\u0430\u0435\u043c \u0435\u0449\u0451 \u043f\u0430\u0440\u0443 \u0448\u0430\u0433\u043e\u0432 \u0434\u043b\u044f \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u0431\u043e\u043b\u0435\u0435 \u0442\u043e\u0447\u043d\u043e\u0433\u043e \u043d\u0430\u0438\u043c\u0435\u043d\u043e\u0432\u0430\u043d\u0438\u044f \u0442\u0430\u0431\u043b\u0438\u0446, \u0440\u0430\u0437\u043c\u0435\u0449\u0451\u043d\u043d\u044b\u0445 \u0432 \u043d\u0430\u0448\u0435\u0439 \u00ab\u043f\u0435\u0441\u043e\u0447\u043d\u0438\u0446\u0435\u00bb, \u0441\u043e\u0431\u0438\u0440\u0430\u044f \u0432\u043e\u0435\u0434\u0438\u043d\u043e \u0438 \u00ab\u043e\u0442\u0441\u0435\u043a\u0430\u044f\u00bb \u043d\u0435\u043d\u0443\u0436\u043d\u0443\u044e \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e.<\/p>\n<pre><code>out = subprocess.Popen([     'beeline',     '--outputformat=csv2',     '--silent=true',     '--showHeader=false',     '--verbose=false',     '--showWarnings=false',     '-u',     '\"jdbc:hive2:\/\/&lt;URL JUPITER HUB \u0431\u0435\u0437 https:\/\/ >:10000\/default;principal=hive\/_HOST@\u0412\u0410\u0428 \u0434\u043e\u043c\u0435\u043d\"',     '-e',     '\"show tables in \u041d\u0430\u0438\u043c\u0435\u043d\u043e\u0432\u0430\u043d\u0438\u0435 \u041f\u0435\u0441\u043e\u0447\u043d\u0438\u0446\u044b (\u0431\u0430\u0448\u0435\u0439 \u0431\u0430\u0437\u044b);\"'     ],     stdout=subprocess.PIPE,     stderr=subprocess.STDOUT) stdout,stderr = out.communicate()  lines = stdout.decode('utf-8').split('\\n') list_tables = [] for line in lines:     if 'warning:' not in line:         list_tables.append(line) df_tables = pd.DataFrame(list_tables, columns=['table_name']) df_tables.dropna(how='all', inplace=True)<\/code><\/pre>\n<p>\u0412 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0435 \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u043d\u044b\u0439 \u043a\u043e\u0434 \u0444\u043e\u0440\u043c\u0438\u0440\u0443\u0435\u0442 \u043d\u0430\u0438\u043c\u0435\u043d\u043e\u0432\u0430\u043d\u0438\u0435 \u0442\u0430\u0431\u043b\u0438\u0446\u044b, \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043b\u0435\u043d\u043d\u043e\u0435 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u043c \u043f\u0440\u0438 \u0435\u0451 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0438. <\/p>\n<figure class=\"\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/470\/d66\/a73\/470d66a733e30a614c86c6db6d4a24d1.png\" width=\"230\" height=\"321\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/470\/d66\/a73\/470d66a733e30a614c86c6db6d4a24d1.png\"\/><figcaption><\/figcaption><\/figure>\n<p>\u041f\u043e\u0441\u043b\u0435 \u043f\u0440\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u044f \u043f\u043e\u0434\u0433\u043e\u0442\u043e\u0432\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0445 \u043c\u0435\u0440\u043e\u043f\u0440\u0438\u044f\u0442\u0438\u0439 \u043f\u043e \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u044e \u043a\u043e\u0434\u0430 \u0438 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u043d\u0443\u0436\u043d\u044b\u0445 \u043d\u0430\u043c \u0434\u0430\u043d\u043d\u044b\u0445 \u0432 DataFrame \u043f\u0435\u0440\u0435\u0439\u0434\u0451\u043c \u043a \u0441\u0430\u043c\u043e\u043c\u0443 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u043e\u043c\u0443 \u2014 \u043a \u043f\u0440\u043e\u0441\u043c\u043e\u0442\u0440\u0443 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u043e\u0432 \u0438 \u0430\u043d\u0430\u043b\u0438\u0437\u0443 \u0437\u0430\u043f\u043e\u043b\u043d\u044f\u0435\u043c\u043e\u0441\u0442\u0438 \u043d\u0430\u0448\u0435\u0439 \u00ab\u043f\u0435\u0441\u043e\u0447\u043d\u0438\u0446\u044b\u00bb.<\/p>\n<p>\u041d\u0430\u0447\u043d\u0451\u043c \u0441 \u0441\u0430\u043c\u043e\u0433\u043e \u043f\u0440\u043e\u0441\u0442\u043e\u0433\u043e \u0438 \u0432\u044b\u0432\u0435\u0434\u0435\u043c \u0442\u043e\u043f-10 \u0442\u0430\u0431\u043b\u0438\u0446 \u043f\u043e \u0440\u0430\u0437\u043c\u0435\u0440\u0430\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u043f\u0430\u043c\u044f\u0442\u0438 \u0432 \u00ab\u043f\u0435\u0441\u043e\u0447\u043d\u0438\u0446\u0435\u00bb \u0441 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0435\u0439 \u043e \u043a\u043e\u043b\u043b\u0435\u0433\u0430\u0445, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0438\u0445 \u0441\u043e\u0437\u0434\u0430\u043b\u0438.<\/p>\n<pre><code>df_hdfs_top = df_hdfs.sort_values(by=['fsize'], ascending=False).head(10)[['path', 'fsize_h', 'owner_name']] df_hdfs_top<\/code><\/pre>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/615\/ca4\/30d\/615ca430dbb8772e096185224e10be24.png\" width=\"1220\" height=\"168\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/615\/ca4\/30d\/615ca430dbb8772e096185224e10be24.png\"\/><figcaption><\/figcaption><\/figure>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043d\u0430 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0431\u043e\u043b\u044c\u0448\u0435 \u0432\u0441\u0435\u0433\u043e \u0437\u0430\u043d\u0438\u043c\u0430\u044e\u0442 \u043c\u0435\u0441\u0442\u043e \u0432 \u00ab\u043f\u0435\u0441\u043e\u0447\u043d\u0438\u0446\u0435\u00bb, \u0438 \u0432\u044b\u0432\u0435\u0434\u0435\u043c \u0442\u043e\u043f-10 \u0438\u0437 \u043d\u0438\u0445.<\/p>\n<pre><code>df_hdfs_size_by_owner = df_hdfs.groupby('owner_name')['fsize'].sum().reset_index().sort_values(by=['fsize']).tail(10) df_hdfs_size_by_owner.plot(x='owner_name', y='fsize', kind='barh')<\/code><\/pre>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/a19\/05c\/34d\/a1905c34db7126043fb3860663c5a450.png\" width=\"580\" height=\"267\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/a19\/05c\/34d\/a1905c34db7126043fb3860663c5a450.png\"\/><figcaption><\/figcaption><\/figure>\n<p>\u041e\u0434\u043d\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u043e \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043d\u0430 \u0437\u0430\u043f\u043e\u043b\u043d\u044f\u0435\u043c\u043e\u0441\u0442\u044c \u00ab\u043f\u0435\u0441\u043e\u0447\u043d\u0438\u0446\u044b\u00bb \u0432 \u0440\u0430\u0437\u0440\u0435\u0437\u0435 \u0442\u0435\u0440\u0440\u0438\u0442\u043e\u0440\u0438\u0430\u043b\u044c\u043d\u044b\u0445 \u043f\u043e\u0434\u0440\u0430\u0437\u0434\u0435\u043b\u0435\u043d\u0438\u0439. <\/p>\n<pre><code>df_hdfs_size_by_tb = df_hdfs.groupby('tb')['fsize'].sum().reset_index().sort_values(by=['fsize']) df_hdfs_size_by_tb.plot(x='tb', y='fsize', kind='barh')<\/code><\/pre>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/4dd\/837\/62f\/4dd83762fc97376dd51a78dbeffbde31.png\" width=\"728\" height=\"324\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/4dd\/837\/62f\/4dd83762fc97376dd51a78dbeffbde31.png\"\/><figcaption><\/figcaption><\/figure>\n<p>\u041f\u0440\u0438 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u0438 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043d\u0430 \u043d\u0430\u0448\u0438 \u0442\u0430\u0431\u043b\u0438\u0446\u044b \u043f\u043e \u0434\u0430\u0442\u0435 \u0438\u0445 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f, \u0434\u043b\u044f \u0443\u0442\u043e\u0447\u043d\u0435\u043d\u0438\u044f \u0443 \u043a\u043e\u043b\u043b\u0435\u0433 \u0438\u0445 \u0430\u043a\u0442\u0443\u0430\u043b\u044c\u043d\u043e\u0441\u0442\u0438 \u0438 \u043f\u043b\u0430\u043d\u043e\u0432 \u043f\u043e \u0434\u0430\u043b\u044c\u043d\u0435\u0439\u0448\u0435\u043c\u0443 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044e.<\/p>\n<pre><code>df_hdfs_oldest = df_hdfs[df_hdfs.fsize > 10000].sort_values(by=['date'], ascending=False).tail(50) df_hdfs_oldest<\/code><\/pre>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/5c8\/f41\/04c\/5c8f4104c7c750c1a8d64997fec011d4.png\" width=\"1260\" height=\"210\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/5c8\/f41\/04c\/5c8f4104c7c750c1a8d64997fec011d4.png\"\/><figcaption><\/figcaption><\/figure>\n<p>\u0414\u043b\u044f \u0431\u043e\u043b\u0435\u0435 \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u043e\u0433\u043e \u043f\u0440\u043e\u0441\u043c\u043e\u0442\u0440\u0430 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u043e\u0432 \u0432\u044b\u0433\u0440\u0443\u0437\u0438\u043c \u0434\u0430\u043d\u043d\u044b\u0435 \u0432 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u0439 \u0444\u0430\u0439\u043b, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0431\u043e\u043b\u0435\u0435 \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u043e \u043d\u0430\u043c \u043f\u043e\u043a\u0430\u0436\u0435\u0442 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e \u043e \u0442\u0430\u0431\u043b\u0438\u0446\u0430\u0445, \u0438\u0445 \u043e\u0431\u044a\u0451\u043c\u0435 \u0438 \u0432\u043b\u0430\u0434\u0435\u043b\u044c\u0446\u0430\u0445.<\/p>\n<pre><code>df_hdfs_top = df_hdfs[df_hdfs.fsize > 10000].sort_values(by=['fsize'], ascending=False) df_hdfs_top.to_csv('team_sandbox.csv', index=False)<\/code><\/pre>\n<h2>\u0427\u0442\u043e \u0435\u0449\u0451? <\/h2>\n<p>\u0422\u0430\u043a\u0436\u0435 \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u0441\u0442\u043e\u043b\u043a\u043d\u0443\u0442\u044c\u0441\u044f \u0441 \u0441\u0438\u0442\u0443\u0430\u0446\u0438\u0435\u0439, \u043a\u043e\u0433\u0434\u0430 \u0432 \u0432\u0430\u0448\u0435\u0439 \u00ab\u043f\u0435\u0441\u043e\u0447\u043d\u0438\u0446\u0435\u00bb \u043d\u0430\u0445\u043e\u0434\u044f\u0442\u0441\u044f HDFS \u0444\u0430\u0439\u043b\u044b \u00ab\u0444\u0430\u043d\u0442\u043e\u043c\u044b\u00bb \u2014 \u0442\u0430\u0431\u043b\u0438\u0446\u044b \u0431\u0435\u0437 \u043a\u0430\u0442\u0430\u043b\u043e\u0433\u0430 \u0438\/\u0438\u043b\u0438 \u043a\u0430\u0442\u0430\u043b\u043e\u0433 \u0431\u0435\u0437 \u0442\u0430\u0431\u043b\u0438\u0446\u044b, \u0430 \u0442\u0430\u043a\u0436\u0435 \u0444\u0430\u0439\u043b\u044b \u0431\u0435\u0437 \u043f\u0440\u0438\u043d\u0430\u0434\u043b\u0435\u0436\u043d\u043e\u0441\u0442\u0438 \u043a \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0451\u043d\u043d\u043e\u043c\u0443 \u0432\u043b\u0430\u0434\u0435\u043b\u044c\u0446\u0443. \u0414\u043b\u044f \u0438\u0445 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u0432\u043e\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u0441\u044f \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043a\u043e\u0434\u043e\u043c:<\/p>\n<pre><code>df_fantoms = pd.merge(df_hdfs, df_tables, how='outer', on='table_name', indicator=True).sort_values(by=['fsize'], ascending=False) df_fantoms['fix_cmd'] = df_fantoms.apply(lambda row: get_fix_cmd(row._merge, row.path, row.table_name), axis=1) df_fantoms = df_fantoms.reindex(columns=['path', 'table_name', 'owner_name', 'fsize', 'fsize_h', 'fix_cmd', '_merge'])<\/code><\/pre>\n<p><em>&#8212; \u0434\u043b\u044f \u043f\u0440\u043e\u0441\u043c\u043e\u0442\u0440\u0430 \u0442\u0430\u0431\u043b\u0438\u0446 \u0431\u0435\u0437 \u043a\u0430\u0442\u0430\u043b\u043e\u0433\u0430 \u0441\u0444\u043e\u0440\u043c\u0438\u0440\u0443\u0435\u043c \u0437\u0430\u043f\u0440\u043e\u0441<\/em><\/p>\n<pre><code>df_fantoms[df_fantoms._merge=='right_only']<\/code><\/pre>\n<p><em>&#8212; \u0434\u043b\u044f \u043f\u0440\u043e\u0441\u043c\u043e\u0442\u0440\u0430 \u043a\u0430\u0442\u0430\u043b\u043e\u0433\u043e\u0432 \u0431\u0435\u0437 \u0442\u0430\u0431\u043b\u0438\u0446 \u0441\u0444\u043e\u0440\u043c\u0438\u0440\u0443\u0435\u043c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u0437\u0430\u043f\u0440\u043e\u0441<\/em><\/p>\n<pre><code>print(human_readable_size(df_fantoms[df_fantoms._merge=='left_only']['fsize'].sum())) df_fantoms[(df_fantoms._merge=='left_only') &amp; (df_fantoms.fsize > 1000000000)]<\/code><\/pre>\n<p><em>&#8212; \u0434\u043b\u044f \u0431\u043e\u043b\u0435\u0435 \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u043e\u0433\u043e \u043f\u0440\u043e\u0441\u043c\u043e\u0442\u0440\u0430 \u0438 \u0430\u043d\u0430\u043b\u0438\u0437\u0430 \u00ab\u0444\u0430\u043d\u0442\u043e\u043c\u043e\u0432\u00bb \u0432\u044b\u0433\u0440\u0443\u0437\u0438\u043c \u0434\u0430\u043d\u043d\u044b\u0435 \u0432 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u0439 \u0444\u0430\u0439\u043b<\/em><\/p>\n<pre><code>df_fantoms[(df_fantoms._merge=='left_only') &amp; (df_fantoms.fsize > 1000000000)].to_csv('team_sandbox_fantoms.csv', index=False)      <\/code><\/pre>\n<p>\u0414\u0430\u043d\u043d\u044b\u0439 \u043f\u043e\u0434\u0445\u043e\u0434 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043d\u0435 \u0435\u0434\u0438\u043d\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u043c \u0441\u043f\u043e\u0441\u043e\u0431\u043e\u043c \u043d\u0430\u0439\u0442\u0438 \u0421\u041b\u041e\u041d\u0410 \u0432 \u00ab\u043f\u0435\u0441\u043e\u0447\u043d\u0438\u0446\u0435\u00bb: \u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0443\u0435\u0442 \u043c\u043d\u043e\u0436\u0435\u0441\u0442\u0432\u043e \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u043e\u0432 \u0435\u0433\u043e \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438, \u043e\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u043a\u043e\u043c\u0430\u043d\u0434 HDFS c \u0435\u0451 \u0440\u0430\u0437\u043b\u0438\u0447\u043d\u044b\u043c\u0438 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u0430\u043c\u0438 \u0434\u043e \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u044f Python \u043a\u043e\u0434\u0430 \u043f\u043e\u0434 \u0434\u0440\u0443\u0433\u0438\u043c \u00ab\u0443\u0433\u043b\u043e\u043c\u00bb \u0432 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u043e\u0442 \u043e\u0441\u043e\u0431\u0435\u043d\u043d\u043e\u0441\u0442\u0435\u0439 \u0432\u0435\u0434\u0435\u043d\u0438\u044f \u0432\u0430\u0448\u0435\u0439 \u0431\u0430\u0437\u044b.<\/p>\n<\/p>\n<\/div>\n<\/div>\n<\/div>\n<p> <!----> <!----><\/div>\n<p> <!----> <!----><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/company\/sberbank\/blog\/703608\/\"> https:\/\/habr.com\/ru\/company\/sberbank\/blog\/703608\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p>\u0418 \u0441\u043d\u043e\u0432\u0430 \u0437\u0434\u0440\u0430\u0432\u0441\u0442\u0432\u0443\u0439, \u0425\u0430\u0431\u0440! \u0421\u0435\u0433\u043e\u0434\u043d\u044f \u043f\u043e\u0433\u043e\u0432\u043e\u0440\u0438\u043c \u043e\u0431 \u0430\u043a\u0442\u0443\u0430\u043b\u044c\u043d\u043e\u0439 \u0434\u043b\u044f \u043c\u043d\u043e\u0433\u0438\u0445 \u0438\u0437 \u043d\u0430\u0441 \u043f\u0440\u043e\u0431\u043b\u0435\u043c\u0435 \u043f\u0440\u0438 \u0440\u0430\u0431\u043e\u0442\u0435 \u0441 \u0431\u0430\u0437\u0430\u043c\u0438 \u0434\u0430\u043d\u043d\u044b\u0445. \u0412 \u0445\u043e\u0434\u0435 \u0440\u0430\u0431\u043e\u0442\u044b \u043d\u0430\u0434 \u0440\u0430\u0437\u043d\u044b\u043c\u0438 \u043f\u0440\u043e\u0435\u043a\u0442\u0430\u043c\u0438 \u0447\u0430\u0441\u0442\u043e \u043f\u0440\u0438\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u0441\u043e\u0437\u0434\u0430\u0432\u0430\u0442\u044c \u0431\u0430\u0437\u0443 \u0434\u0430\u043d\u043d\u044b\u0445\u00a0 (\u043a\u043e\u043c\u0430\u043d\u0434\u043d\u043e\u0435 \u043f\u0440\u043e\u0441\u0442\u0440\u0430\u043d\u0441\u0442\u0432\u043e, \u043f\u0435\u0441\u043e\u0447\u043d\u0438\u0446\u0430 \u0438 \u0442.\u043f.), \u043a\u043e\u0442\u043e\u0440\u0443\u044e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442 \u043a\u0430\u043a \u0441\u0430\u043c \u0430\u0432\u0442\u043e\u0440, \u0442\u0430\u043a \u0438\/\u0438\u043b\u0438 \u043a\u043e\u043b\u043b\u0435\u0433\u0438 \u0434\u043b\u044f \u0432\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0433\u043e \u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044f \u0434\u0430\u043d\u043d\u044b\u0445. \u041a\u0430\u043a \u0443 \u043b\u044e\u0431\u043e\u0433\u043e \u00ab\u043f\u043e\u043c\u0435\u0449\u0435\u043d\u0438\u044f\u00bb, \u0432 \u043d\u0430\u0448\u0435\u0439 \u00ab\u043f\u0435\u0441\u043e\u0447\u043d\u0438\u0446\u0435\u00bb \u0435\u0441\u0442\u044c \u0441\u0432\u043e\u0451 \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u0435 \u043f\u043e \u043e\u0431\u044a\u0451\u043c\u0443 \u0432\u044b\u0434\u0435\u043b\u0435\u043d\u043d\u043e\u0433\u043e \u043c\u0435\u0441\u0442\u0430 \u0434\u043b\u044f \u0445\u0440\u0430\u043d\u0435\u043d\u0438\u044f \u0434\u0430\u043d\u043d\u044b\u0445.\u00a0 \u041f\u0435\u0440\u0438\u043e\u0434\u0438\u0447\u0435\u0441\u043a\u0438 \u0431\u044b\u0432\u0430\u0435\u0442 \u0442\u0430\u043a, \u0447\u0442\u043e \u0432\u044b \u0438\u043b\u0438 \u0432\u0430\u0448\u0438 \u043a\u043e\u043b\u043b\u0435\u0433\u0438 \u0437\u0430\u0431\u044b\u0432\u0430\u0435\u0442\u0435 \u043e\u0431 \u044d\u0442\u043e\u043c \u043c\u0430\u043b\u0435\u043d\u044c\u043a\u043e\u043c \u043e\u0433\u0440\u0430\u043d\u0438\u0447\u0435\u043d\u0438\u0438, \u0438\u0437-\u0437\u0430 \u0447\u0435\u0433\u043e, \u043a \u0441\u043e\u0436\u0430\u043b\u0435\u043d\u0438\u044e, \u0437\u0430\u043a\u0430\u043d\u0447\u0438\u0432\u0430\u0435\u0442\u0441\u044f \u043e\u0431\u044a\u0451\u043c \u0432\u044b\u0434\u0435\u043b\u0435\u043d\u043d\u043e\u0439 \u043f\u0430\u043c\u044f\u0442\u0438.<\/p>\n<p>\u0412 \u044d\u0442\u043e\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u043c\u043e\u0436\u043d\u043e \u043f\u0440\u0438\u043c\u0435\u043d\u0438\u0442\u044c \u043c\u0430\u043b\u0435\u043d\u044c\u043a\u0438\u0439 \u043b\u0430\u0439\u0444\u0445\u0430\u043a, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u043e\u0437\u0432\u043e\u043b\u0438\u0442 \u043e\u043f\u0435\u0440\u0430\u0442\u0438\u0432\u043d\u043e \u043f\u0440\u043e\u0441\u043c\u043e\u0442\u0440\u0435\u0442\u044c, \u043a\u0430\u043a\u0430\u044f \u0442\u0430\u0431\u043b\u0438\u0446\u0430 \u0431\u043e\u043b\u044c\u0448\u0435 \u0432\u0441\u0435\u0433\u043e \u0437\u0430\u043d\u0438\u043c\u0430\u0435\u0442 \u043c\u0435\u0441\u0442\u043e, \u043a\u0442\u043e \u0435\u0451 \u0432\u043b\u0430\u0434\u0435\u043b\u0435\u0446, \u043a\u0430\u043a \u0434\u043e\u043b\u0433\u043e \u043e\u043d\u0430 \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u0432 \u043e\u0431\u0449\u0435\u0439 \u043f\u0435\u0441\u043e\u0447\u043d\u0438\u0446\u0435 \u0438 \u0442.\u0434. \u0418\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u0435\u0433\u043e, \u0432\u044b \u043e\u043f\u0435\u0440\u0430\u0442\u0438\u0432\u043d\u043e \u0441\u043c\u043e\u0436\u0435\u0442\u0435 \u043f\u043e\u0447\u0438\u0441\u0442\u0438\u0442\u044c \u043c\u0435\u0441\u0442\u043e \u0432 \u043f\u0435\u0441\u043e\u0447\u043d\u0438\u0446\u0435, \u043f\u0440\u0435\u0434\u0432\u0430\u0440\u0438\u0442\u0435\u043b\u044c\u043d\u043e \u0441\u043e\u0433\u043b\u0430\u0441\u043e\u0432\u0430\u0432 \u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f \u0441 \u0432\u043b\u0430\u0434\u0435\u043b\u044c\u0446\u0435\u043c \u0434\u0430\u043d\u043d\u044b\u0445 \u0431\u0435\u0437 \u043d\u0430\u043d\u0435\u0441\u0435\u043d\u0438\u044f \u0432\u0440\u0435\u0434\u0430 \u0434\u0430\u043d\u043d\u044b\u043c \u043e\u0441\u0442\u0430\u043b\u044c\u043d\u044b\u0445 \u043a\u043e\u043b\u043b\u0435\u0433. \u041a\u0440\u043e\u043c\u0435 \u0442\u043e\u0433\u043e, \u044d\u0442\u043e\u0442 \u0438\u043d\u0441\u0442\u0440\u0443\u043c\u0435\u043d\u0442 \u043f\u043e\u0437\u0432\u043e\u043b\u0438\u0442 \u043f\u0435\u0440\u0438\u043e\u0434\u0438\u0447\u0435\u0441\u043a\u0438 \u043f\u0440\u043e\u0432\u043e\u0434\u0438\u0442\u044c \u043c\u043e\u043d\u0438\u0442\u043e\u0440\u0438\u043d\u0433 \u043d\u0430\u043f\u043e\u043b\u043d\u044f\u0435\u043c\u043e\u0441\u0442\u0438 \u0432\u0430\u0448\u0435\u0439 \u043e\u0431\u0449\u0435\u0439 \u043f\u0435\u0441\u043e\u0447\u043d\u0438\u0446\u044b.<\/p>\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<h2>\u042d\u0442\u0430\u043f 1<\/h2>\n<p>\u0414\u043b\u044f \u043d\u0430\u0447\u0430\u043b\u0430 \u0438\u043c\u043f\u043e\u0440\u0442\u0438\u0440\u0443\u0435\u043c \u043d\u0443\u0436\u043d\u044b\u0435 \u043d\u0430\u043c \u043c\u043e\u0434\u0443\u043b\u0438 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a \u0434\u043b\u044f Python \u0438 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0438\u043c \u043f\u0443\u0442\u044c \u043a \u043d\u0430\u0448\u0435\u0439 \u043f\u0435\u0441\u043e\u0447\u043d\u0438\u0446\u0435.<\/p>\n<pre><code>import subprocess import sys, getopt import re import pandas as pd %matplotlib inline pd.set_option('display.max_colwidth', -1) path = 'hdfs:\/\/arnsdpsbx\/user\/team\/team_sandbox\/hive'<\/code><\/pre>\n<p>\u041c\u043e\u0434\u0443\u043b\u044c subprocess \u0432 Python \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u043f\u0440\u043e\u0441\u0442\u044b\u0435 \u0444\u0443\u043d\u043a\u0446\u0438\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u044e\u0442 \u043d\u0430\u043c \u0437\u0430\u043f\u0443\u0441\u043a\u0430\u0442\u044c \u043d\u043e\u0432\u044b\u0439 \u043f\u0440\u043e\u0446\u0435\u0441\u0441 \u0438 \u043f\u043e\u043b\u0443\u0447\u0430\u0442\u044c \u0438\u0445 \u043a\u043e\u0434\u044b \u0432\u043e\u0437\u0432\u0440\u0430\u0442\u0430. <\/p>\n<p>\u041c\u043e\u0434\u0443\u043b\u044c getopt \u2014 \u043e\u0434\u0438\u043d \u0438\u0437 \u0432\u0430\u0440\u0438\u0430\u043d\u0442\u043e\u0432 \u0430\u043d\u0430\u043b\u0438\u0437\u0430 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u043e\u0432 \u043a\u043e\u043c\u0430\u043d\u0434\u043d\u043e\u0439 \u0441\u0442\u0440\u043e\u043a\u0438. \u0412 \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u0442\u0441\u044f \u0434\u043b\u044f \u0430\u043d\u0430\u043b\u0438\u0437\u0430 \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u0438 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u043e\u0432.<\/p>\n<p>\u041c\u043e\u0434\u0443\u043b\u044c re \u0432 Python \u2014 \u0444\u0443\u043d\u043a\u0446\u0438\u0438 \u0432 \u044d\u0442\u043e\u043c \u043c\u043e\u0434\u0443\u043b\u0435 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u044e\u0442 \u043f\u0440\u043e\u0432\u0435\u0440\u0438\u0442\u044c, \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u0435\u0442 \u043b\u0438 \u0441\u0442\u0440\u043e\u043a\u0430 \u0437\u0430\u0434\u0430\u043d\u043d\u043e\u043c\u0443 \u0440\u0435\u0433\u0443\u043b\u044f\u0440\u043d\u043e\u043c\u0443 \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u044e (\u0438\u043b\u0438 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u0435\u0442 \u043b\u0438 \u0434\u0430\u043d\u043d\u043e\u0435 \u0440\u0435\u0433\u0443\u043b\u044f\u0440\u043d\u043e\u0435 \u0432\u044b\u0440\u0430\u0436\u0435\u043d\u0438\u0435 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0451\u043d\u043d\u043e\u0439 \u0441\u0442\u0440\u043e\u043a\u0435, \u0447\u0442\u043e \u0441\u0432\u043e\u0434\u0438\u0442\u0441\u044f \u043a \u0442\u043e\u043c\u0443 \u0436\u0435 \u0441\u0430\u043c\u043e\u043c\u0443). <\/p>\n<p>\u041c\u043e\u0434\u0443\u043b\u044c pandas\u00a0 \u2014 \u043f\u0440\u043e\u0433\u0440\u0430\u043c\u043c\u043d\u0430\u044f \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430 \u0434\u043b\u044f \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u043a\u0438 \u0438 \u0430\u043d\u0430\u043b\u0438\u0437\u0430 \u0434\u0430\u043d\u043d\u044b\u0445. \u041a\u043e\u043c\u0430\u043d\u0434\u0430 %matplotlib inline \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0435\u0442 \u043f\u043e\u0441\u0442\u0440\u043e\u0438\u0442\u044c \u0438 \u0432\u044b\u0432\u0435\u0441\u0442\u0438 \u043d\u0443\u0436\u043d\u044b\u0439 \u0432\u0430\u043c \u0433\u0440\u0430\u0444\u0438\u043a \u043f\u0440\u044f\u043c\u043e \u0432 Jupiter notebook (\u0434\u0430\u043b\u0435\u0435 \u0432 \u0441\u0442\u0430\u0442\u044c\u0435). <\/p>\n<h2>\u042d\u0442\u0430\u043f 2<\/h2>\n<p>\u0414\u0430\u043b\u0435\u0435 \u043c\u044b \u043f\u0440\u043e\u043f\u0438\u0448\u0435\u043c \u0444\u0443\u043d\u043a\u0446\u0438\u0438, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043f\u043e\u0437\u0432\u043e\u043b\u044f\u0442 \u043d\u0430\u043c \u0441\u0444\u043e\u0440\u043c\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0441\u0442\u0430\u0442\u0438\u0441\u0442\u0438\u043a\u0443 \u043f\u043e \u0437\u0430\u043f\u043e\u043b\u043d\u044f\u0435\u043c\u043e\u0441\u0442\u0438 \u043d\u0430\u0448\u0435\u0439 \u043f\u0435\u0441\u043e\u0447\u043d\u0438\u0446\u044b:\u00a0 <\/p>\n<p><em>&#8212; \u0434\u043b\u044f \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u0440\u0430\u0437\u043c\u0435\u0440\u0430 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u043e\u0439 \u043f\u0430\u043c\u044f\u0442\u0438 (human_readable_size)<\/em><\/p>\n<pre><code>def human_readable_size(size, decimal_places=2):     for unit in ['B', 'KiB', 'MiB', 'GiB', 'TiB', 'PiB']:         if size &lt; 1024.0 or unit == 'PiB':             break         size \/= 1024.0     return f'{size:.{decimal_places}f} {unit}'<\/code><\/pre>\n<p><em>&#8212; \u0434\u043b\u044f \u043f\u043e\u0438\u0441\u043a\u0430 \u0438 \u0444\u043e\u0440\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0441\u043f\u0438\u0441\u043a\u0430 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439 \u0432 \u043f\u0435\u0441\u043e\u0447\u043d\u0438\u0446\u0435 (get_ipa_login)<\/em><\/p>\n<pre><code>def get_ipa_login(domain, login):     if domain == '\u0412\u0430\u0448_\u0434\u043e\u043c\u0435\u043d_IPA':         return f'{login}_\u0412\u0430\u0448_\u0434\u043e\u043c\u0435\u043d_IPA'     return ''<\/code><\/pre>\n<p><em>&#8212; \u0434\u043b\u044f \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u0442\u0435\u0440\u0440\u0438\u0442\u043e\u0440\u0438\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u043f\u043e\u0434\u0440\u0430\u0437\u0434\u0435\u043b\u0435\u043d\u0438\u044f (get_tb)<\/em><\/p>\n<pre><code>def get_tb(dept):     try:         return dept.split('\/')[2]     except:         return '-'<\/code><\/pre>\n<p><em>&#8212; \u0434\u043b\u044f \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u043d\u0430\u0438\u043c\u0435\u043d\u043e\u0432\u0430\u043d\u0438\u044f \u0442\u0430\u0431\u043b\u0438\u0446\u044b \u0432 \u043f\u0435\u0441\u043e\u0447\u043d\u0438\u0446\u0435 (get_table_name)<\/em><\/p>\n<pre><code>def get_table_name(path):     try:         return path.split('\/')[-1]     except:         return '-'<\/code><\/pre>\n<p><em>&#8212; \u0434\u043b\u044f \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u0432\u043b\u0430\u0434\u0435\u043b\u044c\u0446\u0430 \u0442\u0430\u0431\u043b\u0438\u0446\u044b (get_owner_name)<\/em><\/p>\n<pre><code>def get_owner_name(owner, name):     return f'{owner} ({name})'<\/code><\/pre>\n<p><em>&#8212; \u0434\u043b\u044f \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u0442\u0430\u0431\u043b\u0438\u0446 \u00ab\u0444\u0430\u043d\u0442\u043e\u043c\u043e\u0432\u00bb \u0431\u0435\u0437 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u0432\u043b\u0430\u0434\u0435\u043b\u044c\u0446\u0430<\/em><\/p>\n<pre><code>def get_fix_cmd(merge, path, table_name):     if merge == 'right_only':         return f'DROP TABLE {table_name}'     elif merge == 'left_only':         return f'hdfs dfs -rm -f -R -skipTrash {path}'    return ''<\/code><\/pre>\n<h2>\u042d\u0442\u0430\u043f 3<\/h2>\n<p>\u0414\u0430\u043b\u0435\u0435 \u043c\u044b \u0441\u043e\u0437\u0434\u0430\u0435\u043c Dataframe, \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0449\u0438\u0439 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e \u043e \u0434\u0430\u043d\u043d\u044b\u0445, \u0440\u0430\u0437\u043c\u0435\u0449\u0451\u043d\u043d\u044b\u0445 \u0432 \u043f\u0435\u0441\u043e\u0447\u043d\u0438\u0446\u0435 (\u0434\u0430\u043d\u043d\u044b\u0435 \u043e \u0432\u043b\u0430\u0434\u0435\u043b\u044c\u0446\u0435, \u0433\u0440\u0443\u043f\u043f\u0435, \u0434\u0430\u0442\u0435, \u0432\u0440\u0435\u043c\u0435\u043d\u0438, \u043f\u0443\u0442\u0438 \u0440\u0430\u0437\u043c\u0435\u0449\u0435\u043d\u0438\u044f \u0442\u0430\u0431\u043b\u0438\u0446\u044b).<\/p>\n<pre><code>out = subprocess.Popen(['hdfs', 'dfs', '-du', path], stdout=subprocess.PIPE, stderr=subprocess.STDOUT) stdout, stderr = out.communicate() if 'GSSException' in stdout.decode('utf-8'):     print('GSSException! Run kinit')     exit(1) lines = stdout.decode('utf-8').split('\\n') list_du = [] for line in lines:     m = re.match(r'^(\\d+)\\s+(\\d+)\\s+(.*)$', line)     if m:         list_du.append([             int(m.group(1)),             int(m.group(2)),             m.group(3)         ]) df_du = pd.DataFrame(list_du, columns=['fsize', 'disk_space_consumed', 'path'])      out = subprocess.Popen(['hdfs', 'dfs', '-ls', path], stdout=subprocess.PIPE, stderr=subprocess.STDOUT) stdout, stderr = out.communicate() lines = stdout.decode('utf-8').split('\\n') del lines[0] list_ls = [] for line in lines:     list_ls.append(line.split())  df_ls = pd.DataFrame(list_ls, columns=['permission', 'links', 'owner', 'group', 'size', 'date', 'time', 'path']) df_ls.dropna(how='all', inplace=True) df_ls.drop(['permission', 'links', 'size'], axis=1, inplace=True) <\/code><\/pre>\n<p>\u041f\u043e \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u043d\u043e\u043c\u0443 \u043a\u043e\u0434\u0443 \u043c\u044b \u043f\u043e\u043b\u0443\u0447\u0430\u0435\u043c \u0434\u0430\u043d\u043d\u044b\u0435 \u043e \u0432\u043b\u0430\u0434\u0435\u043b\u044c\u0446\u0435, \u0433\u0440\u0443\u043f\u043f\u0435, \u0434\u0430\u0442\u0435, \u0432\u0440\u0435\u043c\u0435\u043d\u0438, \u043f\u0443\u0442\u0438 \u0440\u0430\u0437\u043c\u0435\u0449\u0435\u043d\u0438\u044f \u0442\u0430\u0431\u043b\u0438\u0446\u044b.<\/p>\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<h2>\u042d\u0442\u0430\u043f 4<\/h2>\n<p>\u041d\u0435 \u0437\u0430\u0431\u044b\u0432\u0430\u044f \u043e \u043a\u043e\u043b\u043b\u0435\u0433\u0430\u0445, \u043c\u044b \u0434\u043e\u0431\u0430\u0432\u043b\u044f\u0435\u043c \u0432 \u043d\u0430\u0448 Dataframe \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u0443\u044e \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e \u043e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f\u0445, \u043a\u043e\u0442\u043e\u0440\u044b\u043c \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u044b \u043f\u0440\u0430\u0432\u0430 \u0438 \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044e\u0442 \u043d\u0430\u0448\u0443 \u00ab\u043f\u0435\u0441\u043e\u0447\u043d\u0438\u0446\u0443\u00bb. \u0412 \u043d\u0430\u0448\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u0434\u0430\u043d\u043d\u044b\u0435 \u043e \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f\u0445 \u0438 \u0438\u0445 \u043f\u0440\u0438\u043d\u0430\u0434\u043b\u0435\u0436\u043d\u043e\u0441\u0442\u0438 \u043a \u0442\u0435\u0440\u0440\u0438\u0442\u043e\u0440\u0438\u0430\u043b\u044c\u043d\u043e\u043c\u0443 \u043f\u043e\u0434\u0440\u0430\u0437\u0434\u0435\u043b\u0435\u043d\u0438\u044e \u043c\u044b \u0432\u0437\u044f\u043b\u0438 \u0438\u0437 \u0441sv \u0444\u0430\u0439\u043b\u0430. \u0412 \u0446\u0435\u043b\u043e\u043c \u0441\u043a\u0440\u0438\u043f\u0442 \u043c\u043e\u0436\u043d\u043e \u0443\u043b\u0443\u0447\u0448\u0438\u0442\u044c, \u043d\u0430\u0441\u0442\u0440\u043e\u0438\u0432 \u0432\u044b\u0433\u0440\u0443\u0437\u043a\u0443 \u043d\u0430 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u0435 \u0434\u0430\u043d\u043d\u044b\u0445 \u0438\u0437 \u0441\u0438\u0441\u0442\u0435\u043c\u044b \u0443\u0447\u0451\u0442\u0430 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439 IPA (\u0432 \u043d\u0430\u0448\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u044d\u0442\u043e Red HAT Identity Management).<\/p>\n<pre><code>df_users = pd.read_csv('ad_users.csv', encoding='windows-1251', sep='|', header=None, names=['domain', 'login', 'tn', 'full_name', 'position', 'dept'], index_col=False) df_users['ipa_login'] = df_users.apply(lambda row: get_ipa_login(row.domain, row.login), axis=1)<\/code><\/pre>\n<h2>\u042d\u0442\u0430\u043f 5<\/h2>\n<p>\u041f\u043e\u0441\u043b\u0435 \u0444\u043e\u0440\u043c\u0438\u0440\u043e\u0432\u0430\u043d\u0438\u044f \u0431\u0430\u0437 \u0441 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0439 \u0434\u043b\u044f \u043d\u0430\u0441 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0435\u0439 \u043e \u0442\u0430\u0431\u043b\u0438\u0446\u0430\u0445 \u0438 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u044f\u0445 \u043c\u044b \u043e\u0431\u044a\u0435\u0434\u0438\u043d\u044f\u0435\u043c \u044d\u0442\u0438 \u0434\u0430\u043d\u043d\u044b\u0435 \u0432 \u0435\u0434\u0438\u043d\u0443\u044e \u0431\u0430\u0437\u0443 \u0434\u0430\u043d\u043d\u044b\u0445.<\/p>\n<pre><code>df_hdfs = pd.merge(df_du, df_ls, on='path') df_hdfs['fsize_h'] = df_hdfs['fsize'].apply(lambda x: human_readable_size(x)) df_hdfs['disk_space_consumed_h'] = df_hdfs['disk_space_consumed'].apply(lambda x: human_readable_size(x)) df_hdfs = df_hdfs.reindex(columns=['path', 'owner', 'group', 'fsize', 'fsize_h', 'disk_space_consumed', 'disk_space_consumed_h', 'date']) df_hdfs = pd.merge(df_hdfs, df_users, how='left', left_on='owner', right_on='ipa_login') df_hdfs['owner_name'] = df_hdfs.apply(lambda row: get_owner_name(row.owner, row.full_name), axis=1) df_hdfs['tb'] = df_hdfs['dept'].apply(lambda x: get_tb(x)) df_hdfs['table_name'] = df_hdfs['path'].apply(lambda x: get_table_name(x))<\/code><\/pre>\n<h2>\u042d\u0442\u0430\u043f 6<\/h2>\n<p>\u0414\u0435\u043b\u0430\u0435\u043c \u0435\u0449\u0451 \u043f\u0430\u0440\u0443 \u0448\u0430\u0433\u043e\u0432 \u0434\u043b\u044f \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u0431\u043e\u043b\u0435\u0435 \u0442\u043e\u0447\u043d\u043e\u0433\u043e \u043d\u0430\u0438\u043c\u0435\u043d\u043e\u0432\u0430\u043d\u0438\u044f \u0442\u0430\u0431\u043b\u0438\u0446, \u0440\u0430\u0437\u043c\u0435\u0449\u0451\u043d\u043d\u044b\u0445 \u0432 \u043d\u0430\u0448\u0435\u0439 \u00ab\u043f\u0435\u0441\u043e\u0447\u043d\u0438\u0446\u0435\u00bb, \u0441\u043e\u0431\u0438\u0440\u0430\u044f \u0432\u043e\u0435\u0434\u0438\u043d\u043e \u0438 \u00ab\u043e\u0442\u0441\u0435\u043a\u0430\u044f\u00bb \u043d\u0435\u043d\u0443\u0436\u043d\u0443\u044e \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e.<\/p>\n<pre><code>out = subprocess.Popen([     'beeline',     '--outputformat=csv2',     '--silent=true',     '--showHeader=false',     '--verbose=false',     '--showWarnings=false',     '-u',     '\"jdbc:hive2:\/\/&lt;URL JUPITER HUB \u0431\u0435\u0437 https:\/\/ >:10000\/default;principal=hive\/_HOST@\u0412\u0410\u0428 \u0434\u043e\u043c\u0435\u043d\"',     '-e',     '\"show tables in \u041d\u0430\u0438\u043c\u0435\u043d\u043e\u0432\u0430\u043d\u0438\u0435 \u041f\u0435\u0441\u043e\u0447\u043d\u0438\u0446\u044b (\u0431\u0430\u0448\u0435\u0439 \u0431\u0430\u0437\u044b);\"'     ],     stdout=subprocess.PIPE,     stderr=subprocess.STDOUT) stdout,stderr = out.communicate()  lines = stdout.decode('utf-8').split('\\n') list_tables = [] for line in lines:     if 'warning:' not in line:         list_tables.append(line) df_tables = pd.DataFrame(list_tables, columns=['table_name']) df_tables.dropna(how='all', inplace=True)<\/code><\/pre>\n<p>\u0412 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0435 \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u043d\u044b\u0439 \u043a\u043e\u0434 \u0444\u043e\u0440\u043c\u0438\u0440\u0443\u0435\u0442 \u043d\u0430\u0438\u043c\u0435\u043d\u043e\u0432\u0430\u043d\u0438\u0435 \u0442\u0430\u0431\u043b\u0438\u0446\u044b, \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043b\u0435\u043d\u043d\u043e\u0435 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u043c \u043f\u0440\u0438 \u0435\u0451 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u0438. <\/p>\n<figure class=\"\"><figcaption><\/figcaption><\/figure>\n<p>\u041f\u043e\u0441\u043b\u0435 \u043f\u0440\u043e\u0432\u0435\u0434\u0435\u043d\u0438\u044f \u043f\u043e\u0434\u0433\u043e\u0442\u043e\u0432\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0445 \u043c\u0435\u0440\u043e\u043f\u0440\u0438\u044f\u0442\u0438\u0439 \u043f\u043e \u043d\u0430\u043f\u0438\u0441\u0430\u043d\u0438\u044e \u043a\u043e\u0434\u0430 \u0438 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u043d\u0443\u0436\u043d\u044b\u0445 \u043d\u0430\u043c \u0434\u0430\u043d\u043d\u044b\u0445 \u0432 DataFrame \u043f\u0435\u0440\u0435\u0439\u0434\u0451\u043c \u043a \u0441\u0430\u043c\u043e\u043c\u0443 \u0438\u043d\u0442\u0435\u0440\u0435\u0441\u043d\u043e\u043c\u0443 \u2014 \u043a \u043f\u0440\u043e\u0441\u043c\u043e\u0442\u0440\u0443 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u043e\u0432 \u0438 \u0430\u043d\u0430\u043b\u0438\u0437\u0443 \u0437\u0430\u043f\u043e\u043b\u043d\u044f\u0435\u043c\u043e\u0441\u0442\u0438 \u043d\u0430\u0448\u0435\u0439 \u00ab\u043f\u0435\u0441\u043e\u0447\u043d\u0438\u0446\u044b\u00bb.<\/p>\n<p>\u041d\u0430\u0447\u043d\u0451\u043c \u0441 \u0441\u0430\u043c\u043e\u0433\u043e \u043f\u0440\u043e\u0441\u0442\u043e\u0433\u043e \u0438 \u0432\u044b\u0432\u0435\u0434\u0435\u043c \u0442\u043e\u043f-10 \u0442\u0430\u0431\u043b\u0438\u0446 \u043f\u043e \u0440\u0430\u0437\u043c\u0435\u0440\u0430\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044f \u043f\u0430\u043c\u044f\u0442\u0438 \u0432 \u00ab\u043f\u0435\u0441\u043e\u0447\u043d\u0438\u0446\u0435\u00bb \u0441 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0435\u0439 \u043e \u043a\u043e\u043b\u043b\u0435\u0433\u0430\u0445, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0438\u0445 \u0441\u043e\u0437\u0434\u0430\u043b\u0438.<\/p>\n<pre><code>df_hdfs_top = df_hdfs.sort_values(by=['fsize'], ascending=False).head(10)[['path', 'fsize_h', 'owner_name']] df_hdfs_top<\/code><\/pre>\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u0434\u0430\u0432\u0430\u0439\u0442\u0435 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043d\u0430 \u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u0435\u043b\u0435\u0439, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0431\u043e\u043b\u044c\u0448\u0435 \u0432\u0441\u0435\u0433\u043e \u0437\u0430\u043d\u0438\u043c\u0430\u044e\u0442 \u043c\u0435\u0441\u0442\u043e \u0432 \u00ab\u043f\u0435\u0441\u043e\u0447\u043d\u0438\u0446\u0435\u00bb, \u0438 \u0432\u044b\u0432\u0435\u0434\u0435\u043c \u0442\u043e\u043f-10 \u0438\u0437 \u043d\u0438\u0445.<\/p>\n<pre><code>df_hdfs_size_by_owner = df_hdfs.groupby('owner_name')['fsize'].sum().reset_index().sort_values(by=['fsize']).tail(10) df_hdfs_size_by_owner.plot(x='owner_name', y='fsize', kind='barh')<\/code><\/pre>\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<p>\u041e\u0434\u043d\u043e\u0432\u0440\u0435\u043c\u0435\u043d\u043d\u043e \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043d\u0430 \u0437\u0430\u043f\u043e\u043b\u043d\u044f\u0435\u043c\u043e\u0441\u0442\u044c \u00ab\u043f\u0435\u0441\u043e\u0447\u043d\u0438\u0446\u044b\u00bb \u0432 \u0440\u0430\u0437\u0440\u0435\u0437\u0435 \u0442\u0435\u0440\u0440\u0438\u0442\u043e\u0440\u0438\u0430\u043b\u044c\u043d\u044b\u0445 \u043f\u043e\u0434\u0440\u0430\u0437\u0434\u0435\u043b\u0435\u043d\u0438\u0439. <\/p>\n<pre><code>df_hdfs_size_by_tb = df_hdfs.groupby('tb')['fsize'].sum().reset_index().sort_values(by=['fsize']) df_hdfs_size_by_tb.plot(x='tb', y='fsize', kind='barh')<\/code><\/pre>\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<p>\u041f\u0440\u0438 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e\u0441\u0442\u0438 \u043f\u043e\u0441\u043c\u043e\u0442\u0440\u0438\u043c \u043d\u0430 \u043d\u0430\u0448\u0438 \u0442\u0430\u0431\u043b\u0438\u0446\u044b \u043f\u043e \u0434\u0430\u0442\u0435 \u0438\u0445 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f, \u0434\u043b\u044f \u0443\u0442\u043e\u0447\u043d\u0435\u043d\u0438\u044f \u0443 \u043a\u043e\u043b\u043b\u0435\u0433 \u0438\u0445 \u0430\u043a\u0442\u0443\u0430\u043b\u044c\u043d\u043e\u0441\u0442\u0438 \u0438 \u043f\u043b\u0430\u043d\u043e\u0432 \u043f\u043e \u0434\u0430\u043b\u044c\u043d\u0435\u0439\u0448\u0435\u043c\u0443 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u044e.<\/p>\n<pre><code>df_hdfs_oldest = df_hdfs[df_hdfs.fsize > 10000].sort_values(by=['date'], ascending=False).tail(50) df_hdfs_oldest<\/code><\/pre>\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<p>\u0414\u043b\u044f \u0431\u043e\u043b\u0435\u0435 \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u043e\u0433\u043e \u043f\u0440\u043e\u0441\u043c\u043e\u0442\u0440\u0430 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u043e\u0432 \u0432\u044b\u0433\u0440\u0443\u0437\u0438\u043c \u0434\u0430\u043d\u043d\u044b\u0435 \u0432 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u0439 \u0444\u0430\u0439\u043b, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0431\u043e\u043b\u0435\u0435 \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u043e \u043d\u0430\u043c \u043f\u043e\u043a\u0430\u0436\u0435\u0442 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u044e \u043e \u0442\u0430\u0431\u043b\u0438\u0446\u0430\u0445, \u0438\u0445 \u043e\u0431\u044a\u0451\u043c\u0435 \u0438 \u0432\u043b\u0430\u0434\u0435\u043b\u044c\u0446\u0430\u0445.<\/p>\n<pre><code>df_hdfs_top = df_hdfs[df_hdfs.fsize > 10000].sort_values(by=['fsize'], ascending=False) df_hdfs_top.to_csv('team_sandbox.csv', index=False)<\/code><\/pre>\n<h2>\u0427\u0442\u043e \u0435\u0449\u0451? <\/h2>\n<p>\u0422\u0430\u043a\u0436\u0435 \u0432\u044b \u043c\u043e\u0436\u0435\u0442\u0435 \u0441\u0442\u043e\u043b\u043a\u043d\u0443\u0442\u044c\u0441\u044f \u0441 \u0441\u0438\u0442\u0443\u0430\u0446\u0438\u0435\u0439, \u043a\u043e\u0433\u0434\u0430 \u0432 \u0432\u0430\u0448\u0435\u0439 \u00ab\u043f\u0435\u0441\u043e\u0447\u043d\u0438\u0446\u0435\u00bb \u043d\u0430\u0445\u043e\u0434\u044f\u0442\u0441\u044f HDFS \u0444\u0430\u0439\u043b\u044b \u00ab\u0444\u0430\u043d\u0442\u043e\u043c\u044b\u00bb \u2014 \u0442\u0430\u0431\u043b\u0438\u0446\u044b \u0431\u0435\u0437 \u043a\u0430\u0442\u0430\u043b\u043e\u0433\u0430 \u0438\/\u0438\u043b\u0438 \u043a\u0430\u0442\u0430\u043b\u043e\u0433 \u0431\u0435\u0437 \u0442\u0430\u0431\u043b\u0438\u0446\u044b, \u0430 \u0442\u0430\u043a\u0436\u0435 \u0444\u0430\u0439\u043b\u044b \u0431\u0435\u0437 \u043f\u0440\u0438\u043d\u0430\u0434\u043b\u0435\u0436\u043d\u043e\u0441\u0442\u0438 \u043a \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0451\u043d\u043d\u043e\u043c\u0443 \u0432\u043b\u0430\u0434\u0435\u043b\u044c\u0446\u0443. \u0414\u043b\u044f \u0438\u0445 \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u0432\u043e\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u0441\u044f \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u043c \u043a\u043e\u0434\u043e\u043c:<\/p>\n<pre><code>df_fantoms = pd.merge(df_hdfs, df_tables, how='outer', on='table_name', indicator=True).sort_values(by=['fsize'], ascending=False) df_fantoms['fix_cmd'] = df_fantoms.apply(lambda row: get_fix_cmd(row._merge, row.path, row.table_name), axis=1) df_fantoms = df_fantoms.reindex(columns=['path', 'table_name', 'owner_name', 'fsize', 'fsize_h', 'fix_cmd', '_merge'])<\/code><\/pre>\n<p><em>&#8212; \u0434\u043b\u044f \u043f\u0440\u043e\u0441\u043c\u043e\u0442\u0440\u0430 \u0442\u0430\u0431\u043b\u0438\u0446 \u0431\u0435\u0437 \u043a\u0430\u0442\u0430\u043b\u043e\u0433\u0430 \u0441\u0444\u043e\u0440\u043c\u0438\u0440\u0443\u0435\u043c \u0437\u0430\u043f\u0440\u043e\u0441<\/em><\/p>\n<pre><code>df_fantoms[df_fantoms._merge=='right_only']<\/code><\/pre>\n<p><em>&#8212; \u0434\u043b\u044f \u043f\u0440\u043e\u0441\u043c\u043e\u0442\u0440\u0430 \u043a\u0430\u0442\u0430\u043b\u043e\u0433\u043e\u0432 \u0431\u0435\u0437 \u0442\u0430\u0431\u043b\u0438\u0446 \u0441\u0444\u043e\u0440\u043c\u0438\u0440\u0443\u0435\u043c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0439 \u0437\u0430\u043f\u0440\u043e\u0441<\/em><\/p>\n<pre><code>print(human_readable_size(df_fantoms[df_fantoms._merge=='left_only']['fsize'].sum())) df_fantoms[(df_fantoms._merge=='left_only') &amp; (df_fantoms.fsize > 1000000000)]<\/code><\/pre>\n<p><em>&#8212; \u0434\u043b\u044f \u0431\u043e\u043b\u0435\u0435 \u043f\u043e\u0434\u0440\u043e\u0431\u043d\u043e\u0433\u043e \u043f\u0440\u043e\u0441\u043c\u043e\u0442\u0440\u0430 \u0438 \u0430\u043d\u0430\u043b\u0438\u0437\u0430 \u00ab\u0444\u0430\u043d\u0442\u043e\u043c\u043e\u0432\u00bb \u0432\u044b\u0433\u0440\u0443\u0437\u0438\u043c \u0434\u0430\u043d\u043d\u044b\u0435 \u0432 \u043e\u0442\u0434\u0435\u043b\u044c\u043d\u044b\u0439 \u0444\u0430\u0439\u043b<\/em><\/p>\n<pre><code>df_fantoms[(df_fantoms._merge=='left_only') &amp; (df_fantoms.fsize > 1000000000)].to_csv('team_sandbox_fantoms.csv', index=False)      <\/code><\/pre>\n<p>\u0414\u0430\u043d\u043d\u044b\u0439 \u043f\u043e\u0434\u0445\u043e\u0434 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043d\u0435 \u0435\u0434\u0438\u043d\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u043c \u0441\u043f\u043e\u0441\u043e\u0431\u043e\u043c \u043d\u0430\u0439\u0442\u0438 \u0421\u041b\u041e\u041d\u0410 \u0432 \u00ab\u043f\u0435\u0441\u043e\u0447\u043d\u0438\u0446\u0435\u00bb:<\/p>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-342176","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/342176","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=342176"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/342176\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=342176"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=342176"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=342176"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}