Redashã§ç¬èªã®Query Runnerãä½ã
ãã®è¨äºã¯Redash Advent Calendar 2017 8æ¥ç®ã®è¨äºã§ãã
ç¬èªã®Query Runnerãä½ã
ãããªãå ãã¿ãåºãã¾ãããRedashã®éçºè Arikããã«ããã以ä¸ã®æ稿ãè¦ãã¨ã ãããä½ãæ¹ã®é°å²æ°ãããã£ã¦ãã¾ãã
ä¸è¨ã®è¨äºãåèã«ãã¯ã¨ãªã®ä»£ããã«æååãè²¼ãä»ããã¨ããã®æååãCSVã®ããã«ãã¼ã¹ãã¦çµæãè¿ããããªãã¡ãã£ã¨å¤ãã£ãQuery Runnerãä½æãã¾ãã
éçºç°å¢
ç´°ããéçºç°å¢æ§ç¯æ¹æ³ã®èª¬æã¯å²æãã¾ãã®ã§ããäºæ¿ãã ããã
以ä¸ã®å ¬å¼ããã¥ã¡ã³ãã«éçºç°å¢ã®æ§ç¯æé ãè¨è¼ããã¦ããããããã®æé ã«æ²¿ã£ã¦ãDockerä¸ã®éçºç°å¢ãæ´ã£ã¦ãããã¨ãåæã«é²ãã¾ãã
Docker Based Developer Installation Guide · Redash Help Center
ãªãã使ç¨ãã¦ããRedashã®ãã¼ã¸ã§ã³ã¯ master
ãã©ã³ãã®ä»¥ä¸ã®ã³ãããæç¹ã®ãã®ã§ãv4.xç³»ã«è©²å½ãããã®ã ã¨æãã¾ãã
ãµã³ãã«ã³ã¼ã
以ä¸ã®ã¹ã¯ãªããã redash/query_runner/csv_parser.py
ã¨ãã¦ä¿åãã¾ãã
import csv as csv import json from redash.query_runner import BaseQueryRunner, register class CsvParser(BaseQueryRunner): @classmethod def configuration_schema(cls): return { 'type': 'object', 'properties': { 'delimiter': { 'type': 'string', 'title': 'Delimiter' } } } @classmethod def annotate_query(cls): return False def __init__(self, configuration): super(CsvParser, self).__init__(configuration) def test_connection(self): pass def run_query(self, query, user): data = { 'columns': [], 'rows': [], } delimiter = str(self.configuration.get('delimiter')) for row in csv.DictReader(query.strip().splitlines(), delimiter=delimiter): if len(data['columns']) == 0: for key in row.keys(): data['columns'].append({'name': key, 'friendly_name': key}) data['rows'].append(row) return json.dumps(data), None register(CsvParser)
ã³ã¼ãã®è©³ç´°ã¯å²æãã¾ãããã¯ã¨ãªæååãCSVã¨ãã¦ãã¼ã¹ããRedashã®ã¯ã¨ãªçµæã®å½¢å¼ã«æºæ ããå½¢ã«æ´å½¢ãã¾ãã
CSVã®1è¡ç®ã¯ãããã¼ã¨ãã¦æ±ãããã«ãã¦ãã¾ãã
åºåãæåã¯ãã¼ã¿ã½ã¼ã¹ã®è¨å®ã¨ãã¦å®ç¾©ã§ããããã«ãªã£ã¦ãããããã©ã«ãã¯,
(åè§ã«ã³ã)ã¨ãã¦ãã¾ãã
æ¬æ¥ã¯ã«ã©ã ã«ã¯ string
ãªã©ã®åãæ示ãããã¨ãå¯è½ã§ããããã®ã¹ã¯ãªããã§ã¯çç¥ãã¦ãã¾ãã
docker-compose.ymlã®å¤æ´
ç¬èªã®Query Runnerã使ç¨ããããã docker-compose.yml
ãç·¨éãã¾ãã
以ä¸ã¯ docker-compose.yml
ã®å·®åã«ãªãã¾ãã
diff --git a/docker-compose.yml b/docker-compose.yml index 536dd446..2f948d90 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -17,6 +17,7 @@ services: REDASH_LOG_LEVEL: "INFO" REDASH_REDIS_URL: "redis://redis:6379/0" REDASH_DATABASE_URL: "postgresql://postgres@postgres/postgres" + REDASH_ADDITIONAL_QUERY_RUNNERS: "redash.query_runner.csv_parser" worker: build: . command: scheduler @@ -31,6 +32,7 @@ services: REDASH_DATABASE_URL: "postgresql://postgres@postgres/postgres" QUEUES: "queries,scheduled_queries,celery" WORKERS_COUNT: 2 + REDASH_ADDITIONAL_QUERY_RUNNERS: "redash.query_runner.csv_parser" redis: image: redis:3.0-alpine restart: always
ç°å¢å¤æ° REDASH_ADDITIONAL_QUERY_RUNNERS
ã§è¿½å ã®Query Runnerãæå®ã§ãã¾ããç°å¢å¤æ°ã«ã¤ãã¦ã¯Advent Calendar 2æ¥ç®ã®è¨äºãã¨ã¦ãåèã«ãªãã®ã§ããããã§ãã
ããã¾ã§ã§ç¬èªQuery Runnerã使ãããã®æºåã¯å®äºã§ãã
åä½ç¢ºèª
æ©éã docker-compose up
ãã¦åä½ç¢ºèªãã¾ãã
ãã¼ã¿ãã¼ã¹ã®ä½æã管çã¦ã¼ã¶ã®ä½æã«ã¤ãã¦ã¯æ¸ãã§ãããã®ã¨ãã¦é²ãã¾ãã
ãã¼ã¿ã½ã¼ã¹ã®ä½æ
ãã¼ã¿ã½ã¼ã¹ã®ä½æç»é¢ã§Typeã®ãã«ãã¦ã³ãã¯ãªãã¯ããã¨ã以ä¸ã®ããã« CsvParser
ã追å ããã¦ãã¾ãã
CsvParser
ãé¸æããã¨ã以ä¸ã®ãããªãã©ã¼ã ã表示ããã¾ãã
ãã¼ã¿ã½ã¼ã¹å㯠CSV
ã¨ãã¦ãåºåãæåã¯ããã©ã«ã㧠,
ã¨ãªã£ã¦ããã®ã§ããã㦠:
(åè§ã³ãã³)ã«ãã¦ãã¼ã¿ã½ã¼ã¹ãä¿åãã¾ãã
ã¯ã¨ãªã®å®è¡
ã¯ã¨ãªã®ä½æç»é¢ã«ç§»åãããã¼ã¿ã½ã¼ã¹ã¨ã㦠CSV
ãé¸æã¾ãã
ã¯ã¨ãªã«ã¯ä»¥ä¸ã®ãããªåè§ã³ãã³åºåãã®æååãå ¥åãã¾ãã
name:ring_name:finishing_move:born_on Kanji Inoki:Antonio Inoki:Enzuigiri:1943-02-20 Baba Shohei:Giant Baba:Big boot:1938-01-23
ãã¹ããã¼ã¿ã®å 容ã«ã¤ãã¦ã¯ç¹ã«è§¦ãããå®è¡ãã¦ã¿ã¾ãã
ããã¾ã§ã®æé ã«åé¡ããªããã°ãä¸ã®ããã«æååããã¼ã¹ãã¦ã¯ã¨ãªçµæã¨ãã¦è¡¨ç¤ºãããã¨ãã§ãã¾ãã
ã«ã©ã ã®ä¸¦ã³é ãå ¥åãããã®ã¨éã£ã¦ããã®ã¯ãPythonã®Dictãæ¿å ¥é ãä¿æããªãããã§ãããããRedashã¯ç¾æç¹ã§Python2.7ã使ç¨ãã¦ãã¾ãããPython3.6ãããã§é åºãä¿æãããããã«ãªãã®ã§ãPython3対å¿ããããå°ãçµæãå¤ããã¨æãã¾ãã
1æ¥ç®ã®è¨äºã§ç§ãç´¹ä»ãã Query Results ãã¼ã¿ã½ã¼ã¹ã§å¥ã®çµæã¨çµåãããã¨ãã§ããããã¦é¢ç½ãããããã¾ãããã
ã¾ã¨ã
ãã®è¨äºã§ã¯ãã¾ãå®ç¨æ§ãèããã«ç¬èªã®Query Runnerãä½æãã¾ããããRedashããã¼ã ãäºæ¥ã«ãã£ããããããã«ã«ã¹ã¿ãã¤ãºãããã¨èããããå ´åãQuery Runnerãä½ãã¨ããã®ã¯é¸æè¢ã«ããã¦ã¿ã¦ã¯ãããã§ããããã
ææ¥ã¯ take4_k ããã®ãazure table storageã®query runnerä½ã£ã¦ã¿ãã®ã§æ¸ãã¾ããã§ãããã®è¨äºãããåæ¯ãã«ãªããã¨ãé¡ã£ã¦ãã¾ãã