Redashã®é·æéç¨ãè¦æ®ãã¦ã¯ã¨ãªã®ååä»ãã«ã¤ãã¦èãã
ãã®è¨äºã¯Redash Advent Calendar 2017 24æ¥ç®ã®è¨äºã§ãã
Redashã®ã¯ã¨ãªãååä»ãéè¦
Redashã¯ãã©ã¼ã¯æ©è½ã«ãã£ã¦ãããã¯ã¨ãªããã¨ã«ããæ´¾çã¯ã¨ãªãä½æãããã¨ãç°¡åã«ãªã£ã¦ãããæ°è¦ã¯ã¨ãªãUIããç°¡åã«ä½æã§ããããããææ¬ã®ã¯ã¨ãªãåèã«ãã¤ã¤ãå©ç¨è ã欲ãããã¼ã¿ãã¨ã³ã¸ãã¢ãä»ããã«æ½åºãããã¨ãã§ããããã«ãªãã¾ãã
ããããã¯ã¨ãªã®ä½æã»ãã©ã¼ã¯ãã«ã¸ã¥ã¢ã«ã«ã§ãããã¨ã«ãã£ã¦ããã¯ã¨ãªã®ååä»ããåé¡ãå°ããã¤å½±ãè½ã¨ãã¯ãããã®ãäºå®ã§ãã
ã¯ã¨ãªååä»ãã«é¢ããåé¡ã¨ãã¦ã¯ã以ä¸ã®ãããªåé¡ãèãããã¾ãã
- ä½ãããããã®ã¯ã¨ãªãªã®ãããããªã
- åããããªååã®ã¯ã¨ãªãããã¤ããã
- ãã©ã¼ã¯ãç¹°ãè¿ããçµæã"Copy of (#2) Copy of (#1).." ã®ãããªã¯ã¨ãªãä¹±ç«ãã
éå»ã«ã¯ã¨ã¦ã¬ã«ããã®ã¨ã³ã¸ãã¢ããã°ã§ãããå½åè¦åãã«ã¤ãã¦ãè¨åããã¦ãããRedashéç¨ã«ããã¦ãååä»ãåé¡ãé¿ãã¦éããªããã¨ã表ãã¦ããããã«ãæãã¾ãã
ã¯ã¨ãªã®å½åè¦åãèãã
ã©ã®ãããªæ å ±ãã¯ã¨ãªåã«åãè¾¼ãã¹ããã¯ãRedashã®å°å ¥ç®çãéç¨ã«ãã£ã¦ç°ãªããã®ã ã¨æãã¾ããããã®è¨äºã§ã¯ä¾ã¨ãã¦ã以ä¸ã®ããã«ã·ã³ãã«ãªå½åè¦åãå®ç¾©ãããã¨ã«ãã¾ãã
[ããã¸ã§ã¯ã]_[ãã¼ã¿ã½ã¼ã¹]_[説æ]
æ å ±éã®å¤ãã¯ã¨ãªåã§ã¯ããã¾ããããä½æè ãä½ææ¥æã¯ã¯ã¨ãªä¸è¦§ç»é¢ã§ç¢ºèªãããã¨ãã§ããä¸æ¹ãã©ã®ããã¸ã§ã¯ããæ¡ä»¶ã§ä½¿ããã¦ããã®ããã©ã®ãã¼ã¿ã½ã¼ã¹ã使ç¨ãã¦ããã®ãã¯ä¸è¦§ã§è¡¨ç¤ºãããªããã®ã«ãªãããããã®ãããªå½åè¦åã¨ãã¦ã¿ã¾ããã
kakakakakku/redash-hands-onã®è³æãä¾ã«åã£ã¦ã¿ã㨠å½ã®ä¸è¦§
ã¨ããã¯ã¨ãªå㯠ãã³ãºãªã³_MySQL_å½ã®ä¸è¦§
ã®ããã«æ¸ãæãããã¾ãã
å½åè¦åãéç¨ãããã¨ã®é£ãã
ã·ã³ãã«ãªå½åè¦åãå®ç¾©ã§ããã®ã§ããã°ããã¨ã¯éç¨ããã ãã§ããå©ç¨è ã«å¨ç¥ããå¿ è¦ã§ããã°ããã¥ã¢ã«åããå½åè¦åãå¾¹åºãã¦ãããã¾ãããã
ãã¦ãããã§æ¬å½ã«ãã¹ã¦ã®ã¯ã¨ãªãå½åè¦åã«å¾ã£ã¦éç¨ãããã§ããããï¼
æªæ°ããªãã¦ãã¯ã¨ãªã®å½åè¦åãééãã¦ãã¾ã£ããããã©ã¼ã¯ããã¨ãã®ååããã®ã¾ã¾ä½¿ã£ã¦ãã¾ããç·æ¥å¯¾å¿ã§å½åè¦åã«æ³¨æãåããªããªã©ã人éãä½æ¥ããã以ä¸ã100%å®è¡ãããã¨ã¯é£ããã¨èãã¦ãã¾ãã
ã¯ã¨ãªåãå®æçã«ãã§ãã¯ãã
人éã¯å¿ ãééãããã¨ããåæã«ç«ã¡ã¤ã¤ãå½åè¦åãå¥å ¨ã«éç¨ããã«ã¯ã©ãããã®ãè¯ãã§ããããã
ç§ã®ã¢ã¤ãã£ã¢ã¨ãã¦ã¯ãã¯ã¨ãªåãå®æçãã¤èªåçã«ãã§ãã¯ããå½åè¦åéåãéè¤ãªã©ãæ¤åºããã®ãããã¨èãã¦ãã¾ãã
Advent Calendarã§ãããã¤ãç´¹ä»ã®ãã£ããRedashã®ã¡ã¿ãã¼ã¿ã使ç¨ããæ¹æ³ãèãããã¾ããããã®è¨äºã§ã¯ã redashman ã¨Pythonã¹ã¯ãªããã使ã£ã¦ãã¯ã¨ãªåãå½åè¦åã«å¾ã£ã¦ãããããã§ãã¯ãã¦ã¿ã¾ãã
ãµã³ãã«ã¹ã¯ãªãã
redashman
ãã¤ã³ã¹ãã¼ã«ããã¦ããåæã§ã以ä¸ã®Pythonã¹ã¯ãªããã使ç¨ãã¾ãã
#!/usr/bin/python # -*- coding: utf-8 -*- from __future__ import print_function import json import os import subprocess import re REDASH_API_KEY = os.environ.get('REDASH_API_KEY') REDASH_URL = os.environ.get('REDASH_URL') PAGE_SIZE = 100 NAMING_CONVENTION_PATTERN = '\A[^_]+_[^_]+_[^_]+\Z' names = set() page = 1 while True: cmd = 'redashman query list %d %d --api-key=%s --url=%s --json' % ( PAGE_SIZE, page, REDASH_API_KEY, REDASH_URL) stdout, stderr = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True).communicate() if stderr: break queries = json.loads(stdout) for query in queries['results']: name = query['name'] warning = '' if re.match(NAMING_CONVENTION_PATTERN, name) is None: warning = u'%s (id: %d) must be follow the naming convention' % (name, query['id']) elif 'Copy of' in name.encode('utf-8'): warning = u'%s (id: %d) contains "Copy of" in its name' % (name, query['id']) elif name in names: warning = u'%s (id: %d) is duplicated' % (name, query['id']) if warning: print(warning) names.add(name) page += 1
ãã®ã¹ã¯ãªããã§ã¯ã redashman
ã§ã¯ã¨ãªã®ä¸è¦§ãåå¾ãã
[ããã¸ã§ã¯ã]_[ãã¼ã¿ã½ã¼ã¹]_[説æ]
ã®å½¢å¼ã«ãªã£ã¦ããªã- "Copy of" ãå«ãã§ãã(Forkããã¾ã¾ã®ã¯ã¨ãªåã«ãªã£ã¦ãã)
- ä»ã®ã¯ã¨ãªåã¨éè¤ãã¦ãã
ä¸è¨ã®ããããã®æ¡ä»¶ã«ä¸è´ããå ´åã¯è¦åã¡ãã»ã¼ã¸ã表示ããããã«ãªã£ã¦ãã¾ãã
åä½ç¢ºèª
以ä¸ã®ããã«ã¯ã¨ãªãç»é²ãã¦ãããã¨ãåæã¨ãã¦ãåä½ç¢ºèªãã¾ãã
å½åè¦ç´éåãã¯ã¨ãªåéè¤ãªã©ãéç¨ã§å°ããããªã¯ã¨ãªåãè¦åãããã¾ããã
$ export REDASH_URL="http://localhost" $ export REDASH_API_KEY="adminã¦ã¼ã¶ã¼ã®APIãã¼" $ python query_naming_convention.py ãã³ãºãªã³_MySQL_é½å¸ã®ä¸è¦§ (id: 6) is duplicated New Query (id: 5) must be follow the naming convention ç·æ¥èª¿æ»ç¨ (id: 4) must be follow the naming convention Copy of (#2) Copy of (#1) ãã³ãºãªã³_MySQL_å½ã®ä¸è¦§ (id: 3) contains "Copy of" in its name Copy of (#1) ãã³ãºãªã³_MySQL_å½ã®ä¸è¦§ (id: 2) contains "Copy of" in its name
å®è¡ãã¦ã¿ãã¨ãå ç¨å®ç¾©ããã«ã¼ã«ã«å¾ã£ã¦ã¯ã¨ãªåããã§ãã¯ããã¦ãããã¨ããããã¾ãã
ãã®ãµã³ãã«ã³ã¼ãã§ã¯ã·ã³ãã«ã«ã¡ãã»ã¼ã¸ã表示ããã ãã«ãªã£ã¦ãã¾ãããçµæãSlackã§éãããã«ãããªã©ãã¦ãéç¨è ãå½åè¦åéåã«æ°ã¥ããã¨ãã§ããã°ã対ççæ³çãªé¢ã¯ããã¤ã¤ããã«ã¼ã«ãç ´ç¶»ããªãããã«éç¨ãããã¨ãã§ããã¨æãã¾ãã
Pythonã§æ¸ãã¦ãããã¨ãæ´»ãããã¯ã¨ãªåã®é¡ä¼¼åº¦ãåã£ã¦ãç´ããããååä»ããçºè¦ãããªã©ã®å¿ç¨ãå¹ãããã§ãã
ã¾ã¨ã
Redashãé·æééç¨ããã¨ãä½ã«ä½¿ã£ã¦ããã®ãããããªããããªã¯ã¨ãªãæ··ä¹±ã®ãã¨ã«ãªããã¨ãããã¾ãã
ã¯ã¨ãªã®å©ç¨ç¶æ³ãã¡ã¿ãã¼ã¿ãªã©ã§ã¦ã©ãããããã¨ãæç¨ã§ã¯ããã¾ãããå©ç¨è ãè¦ã¤ãããããã¯ã¨ãªã®ä½æç®çãã²ã¨ç®ã§åãããããªã¯ã¨ãªã®ååä»ããæèãããããå®æçã«ãã§ãã¯ãããã¨ã§ãã«ã¼ã«ã®ç ´ç¶»ãé²ããã¨ãã§ããã¨èãã¾ãã
å®ã®ã¨ãããç¾ç¶ã¯ç§ãéç¨ãã¦ããRedashã§ããã¯ã¨ãªå½åã«ä¸è²«æ§ããªããã®ãå¤ããä¼¼ããããªååã®ã¯ã¨ãªã«ãã£ã¦èª¿æ»ã対å¿ã«æéåããããªãã¨ãèµ·ãå§ãã¦ãã¾ãã
ãã£ããAdvent Calendarã®è¨äºã«ããã®ã§ãæ¥å¹´ã¯ãã®è¨äºã§ç´¹ä»ããã¹ã¯ãªããã使ã£ã¦ãå°ããã¤éç¨ãæ¹åãã¦ããããã¨æãã¾ãã