Serverworks Sonic #006 ã«ãè¶ãé ããããã¨ããããã¾ããï¼
ããã«ã¡ã¯æè¡2課ã»å¤§éªã¡ã³ãã¼ã®æå°¾ã§ãã
å æ¥8/20ã«ãµãã½ãï¼Serverworks Sonic #006ï¼ãéå¬ããã¾ãããããããã®æ¹ã«ãåå ããã ã大çæ³ã®ãã¡ã«çµãããã¨ãã§ãã¾ããã
åãããã«ãã£ã¹ã«ãã·ã§ã³ã«åå ãã¾ããããå°ãã§ããµã¼ãã¼ã¯ã¼ã¯ã¹ã¨ããä¼ç¤¾ã®é åããä¼ãã§ãã¦ããã°å¹¸ãã§ãã ä»ååå åºæ¥ãªãã£ãæ¹ãã次åã®ãµãã½ãã«ã¯ã¼ããè¶ããã ããï¼
ãTalend Open Studioãã§Redshiftã¸ã®ãã¼ã¿ç»é²å¦çãéçºãã
ååã¨ã³ããªã®ç¶ãã«ãªãã¾ããã
ã»S3ãããã¼ã¿ãåå¾
ã»åå¾ãããã¼ã¿ããã£ã«ã¿ãªã³ã°
ã»Redshiftã«ç»é²
ã¨ããä¸é£ã®å¦çããTalend Open Studioãã使ã£ã¦å®è£ ãã¦ã¿ããã¨æãã¾ãã
â»ä»åã®å¦çãããã ã¨ãRedshiftã«ç´æ¥S3ã®ãã¼ã¿ãBulkã³ãã¼ãã¦ã´ãã§ã´ãã§ããã°ãããããããã¾ãããã説æã®ããã«ä¸è¨ã®ãããªããã¼ã§å¦çããããã¨æãã¾ãã
ãã¡ã¤ã«ãããã¼ã¿ãèªã¿è¾¼ããtFileInputDelimitedã
ååã®S3ããã®ãã¼ã¿åå¾ã¸ã§ãã«ãã¡ã¤ã«èªã¿è¾¼ã¿ã®ã¸ã§ãã追å ãã¦ããã¾ããS3ãããã¦ã³ãã¼ããããã¡ã¤ã«ãã1è¡ã¤ã¥ãã¼ã¿ãèªã¿åºãããã®å¦çã«ãªãã¾ãã
å³ã¡ãã¥ã¼ã®ãã¬ããã®æ¤ç´¢ããã¯ã¹ã«ãtFileInputDelimitedãã¨å ¥åãã¾ãã 表示ãããã³ã³ãã¼ãã³ãããã©ãã°ï¼ããããã§Designeré åã«é ç½®ãã¾ãã
ãt3Getãã³ã³ãã¼ãã³ããå³ã¯ãªãã¯ãããããªã¬ãâããµãã¸ã§ããOKã®å ´åããé¸æããã¨ãæ¥ç¶ç·ãåºç¾ãã¾ãã®ã§ããããtFileInputDelimitedãã³ã³ãã¼ãã³ãã«æ¥ç¶ãã¾ãã
â»ããµãã¸ã§ããã¨ããã®ã¯ããã¤ãã®ã³ã³ãã¼ãã³ãå¦çã®éã¾ããªã®ã§ãããä»åã¯ãt3Getãã³ã³ãã¼ãã³ãã ããªã®ã§ãã³ã³ãã¼ãã³ããOKã®å ´åããé¸æãã¦ãè¯ãã§ããå¹¾ã¤ãã®ã³ã³ãã¼ãã³ãã®å¦çãã¾ã¨ãã¦ãµãã¸ã§ãã¨ãã¦ããå ´åã§ããããä¸é£ã®å¦çãçµãã£ã¦ãã次ã®å¦çã«ç§»ãããå ´åã¯ãããµãã¸ã§ããOKã®å ´åãã¨ããå¿ è¦ãããã¾ãã
ãtFileInputDelimitedãã³ã³ãã¼ãã³ãã¯ã«ã³ããã¿ãåºåãã®ãã¼ã¿ãã¡ã¤ã«ã1è¡ã¥ã¤èªã¿è¾¼ãã§å¦çããããã®ã³ã³ãã¼ãã³ãã§ãããã®ã³ã³ãã¼ãã³ããé¸æãã¦ä¸é¨ã«è¡¨ç¤ºããããåºæ¬è¨å®ãã«è¨å®ãè¡ãã¾ãã
è¨å®å | è¨å®å¤ | è£è¶³ |
---|---|---|
ãã¡ã¤ã«å/ã¹ããªã¼ã | "/Users/kasshy/allusers_pipe.txt" | å¦ç対象ãã¡ã¤ã«ã®ãã¡ã¤ã«ãã¹ |
ãã£ã¼ã«ãåºåãè¨å· | "|" | åºåãè¨å·ï¼ä»åã®ãã¡ã¤ã«ã¯ãã¤ãåºåãï¼ |
ãã®ä»ã®è¨å®ã¯ããã©ã«ãã®ã¾ã¾ã§ããè¡åºåãã®è¨å·ããããã¼ããã¿ã¼ãããå ´åã¯ãã®è¡æ°ã®æå®ããåºæ¬è¨å®ãã§ããã¡ã¤ã«ã®æåã³ã¼ããæå®ãããå ´åã¯ã詳細è¨å®ãããè¡ããã¨ãã§ãã¾ãã
次ã«èªã¿è¾¼ããã¼ã¿ã®ã¹ãã¼ãè¨å®ãè¡ãã¾ããã¹ãã¼ãè¨å®ã¯ãªãã¸ããªã«ä½æãã¦ããã¦ããã使ãæ¹æ³ã¨ãã³ã³ãã¼ãã³ãã«ç´æ¥è¨å®ããæ¹æ³ãããã¾ããä»åã¯ç´æ¥ã³ã³ãã¼ãã³ãã«è¨å®ããæ¹æ³ã§è¨å®ãã¾ãã
ã¹ãã¼ãã®æ å ±ã¯AWSå ¥éã¬ã¤ãã§æä¾ããã¦ããS3ä¸ã®ãµã³ãã«ãã¼ã¿ã®ãusersããã¼ãã«ã®æ å ±ãå ã«è¨å®ãã¦ãã¾ãã
é ç®å | Javaãã¼ã¿å | NOT NULL |
---|---|---|
userid | int | ⯠|
username | String | |
firstname | String | |
lastname | String | |
city | String | |
state | String | |
String | ||
phone | String | |
likesports | Boolean | |
liketheatre | Boolean | |
likeconcerts | Boolean | |
likejazz | Boolean | |
likeclassical | Boolean | |
likeopera | Boolean | |
likerock | Boolean | |
likevegas | Boolean | |
likebroadway | Boolean | |
likemusicals | Boolean |
Rowãã¼ã¿ã®ãã£ã«ã¿ãªã³ã°ãè¡ããtFilterRowã
èªã¿è¾¼ãã ãã¼ã¿ããä¸è¦ãªãã¼ã¿ãåãé¤ããããªãã£ã«ã¿å¦çãä½æãããã¨æãã¾ãããtFilterRowãã³ã³ãã¼ãã³ãããã¬ããããæ¤ç´¢ãDesigneré åã«ãã©ãã°ã¢ã³ããããããã¾ãã
ãtFileInputDelimitedãã³ã³ãã¼ãã³ããå³ã¯ãªãã¯ãããRowãâãã¡ã¤ã³ããé¸æããã¨æ¥ç¶ç·ãåºç¾ãã¾ãã®ã§ãããããtFilterRowãã³ã³ãã¼ãã³ãã«æ¥ç¶ãã¾ãããã¡ã¤ã«ããèªã¿è¾¼ã¾ãã1è¡1è¡ã®ãã¼ã¿ããtFilterRowãã³ã³ãã¼ãã³ãã«æ¸¡ããããã¨ã«ãªãã¾ãã
ãtFilterRowãã³ã³ãã¼ãã³ãã®åºæ¬è¨å®ã«ã¯å ¥åããã¦ãã1è¡ãã¼ã¿ã®åã«ã©ã ãã¼ã¿ãè©ä¾¡ããããã®æ¡ä»¶ãè¤æ°è¨å®ãããã¨ãã§ãã¾ããä»åã¯ããlikesportsããtrueã®ã¬ã³ã¼ããã¤ããuseridãã100以ä¸ã®ãã¼ã¿ãã®ã¿ã次ã®å¦çã«éãããã«è¨å®ãããã¨æãã¾ãã
æ¡ä»¶1
è¨å®å | è¨å®å¤ | è£è¶³ |
---|---|---|
å ¥åã«ã©ã | likesports | |
ãªãã¬ã¼ã¿ | == | |
å¤ | true |
æ¡ä»¶2
è¨å®å | è¨å®å¤ | è£è¶³ |
---|---|---|
å ¥åã«ã©ã | userid | |
ãªãã¬ã¼ã¿ | <= | |
å¤ | 100 |
â»åºæ¬è¨å®ã®ä¸é¨ã«ããã詳細ã¢ã¼ãããã¤ããã°ãã¼ã¿ã®è©ä¾¡å¦çãJavaã³ã¼ããç´æ¥è¨è¿°ã§ããã®ã§ãããè¤éãªæ¡ä»¶ã®ãã£ã«ã¿å¦çãå¯è½ã§ãã
Rowãã¼ã¿ã®è¡¨ç¤ºãè¡ããtLogRowã
ããããã£ã«ã¿ããããã¼ã¿ãã³ã³ã½ã¼ã«ã«è¡¨ç¤ºãã¦ã¿ããã¨æãã¾ããå³ã¡ãã¥ã¼ã®ãã¬ããã§ãtLogRowãã§æ¤ç´¢ãã¾ãããtLogRowãã³ã³ãã¼ãã³ããDesigneré åã«ãã©ãã°ã¢ã³ããããããã¾ãã
ãtFilterRowãã³ã³ãã¼ãã³ããå³ã¯ãªãã¯ãããRowãâããã£ã«ã¿ã¼ããé¸æããã¨æ¥ç¶ç·ãåºç¾ãã¾ãã®ã§ãããããtLogRowãã³ã³ãã¼ãã³ãã«æ¥ç¶ãã¾ãããtFilterRowãã®ãã£ã«ã¿ã¼æ¡ä»¶ã«åè´ãã1è¡1è¡ã®ãã¼ã¿ããtLogRowãã³ã³ãã¼ãã³ãã«æ¸¡ããããã¨ã«ãªãã¾ãã
â»ãRowãâãRejectãã§ã¤ãªãã å ´åã¯ãæ¡ä»¶ã«ä¸è´ããªãã£ããã¼ã¿ãå¾ç¶ã®å¦çã«æµãããã¨ã«ãªãã¾ãããããå©ç¨ãããã¨ã§æ¡ä»¶ã«ä¸è´ãããã¼ã¿ãããªããã¼ã¿ãä»åãããã¨ãã£ããã¨ãã§ãã¾ãã
ãtLogRowãã³ã³ãã¼ãã³ãã®è¨å®ã§ã¯ãã©ãããå½¢å¼ã§ãã¼ã¿ãã³ã³ã½ã¼ã«ã«è¡¨ç¤ºããããæå®ãã¾ããä»åã¯ãæ¨æºãã§åºåãã¾ãã
ä¸æ¦ããã¸ã§ã¯ããä¿åããä½æããã¸ã§ããå®è¡ãã¦ã¿ããã¨æãã¾ãã
ããã¸ã§ã¯ãåãå³ã¯ãªãã¯ãã¦ãå®è¡ããããã¯ä¸é¨ã¡ãã¥ã¼ããã¸ã§ããå®è¡ãã¾ãã
ä¸é¨ã®ã³ã³ã½ã¼ã«ã«ãã£ã«ã¿ããããã¼ã¿ã表示ãããã°OKã§ãã
ãã¼ã¿ãRedshiftã«æå ¥ãããtRedshiftOutputã
æå¾ã«ãã£ã«ã¿ãªã³ã°ããããã¼ã¿ãRedshiftã«æå ¥ããå¦çãä½æãããã¨æãã¾ãã
usersãã¼ãã«ã®ä½æ
äºåã«ãAWSå ¥éã¬ã¤ãã§æä¾ããã¦ããS3ä¸ã®ãµã³ãã«ãã¼ã¿ã®ãusersããã¼ãã«ããSQL Workbench/Jããªã©ãå©ç¨ããRedshiftä¸ã«ä½æãã¦ããã¾ããSQL Workbench/Jã®å©ç¨æé ã¯SQL Workbench/J ã使ç¨ããã¯ã©ã¹ã¿ã¼ã«æ¥ç¶ãããåèã«ãã¦ãã ããã
tRedshiftã³ã³ãã¼ãã³ã
ãã¬ããã§ãtRedshiftãã¨æ¤ç´¢ããã¨Redshifté¢é£ã®ã³ã³ãã¼ãã³ããå¹¾ã¤ã表示ãããã¨æãã¾ãã
ãããã®ãã¡ããtRedshiftOutputãã³ã³ãã¼ãã³ããDesigneré åã«ãã©ãã°ï¼ãããããã¾ãããtRedshiftOutputãã³ã³ãã¼ãã³ãã¯ãã¼ã¿ãRedshiftã«åºåããããã®ã³ã³ãã¼ãã³ãã§ãã
ãtLogRowãã³ã³ãã¼ãã³ããå³ã¯ãªãã¯ããRowãâãã¡ã¤ã³ããé¸æããã¨æ¥ç¶ç·ãåºç¾ãã¾ãã®ã§ãããããtRedshiftOutputãã³ã³ãã¼ãã³ãã«æ¥ç¶ãã¾ãã
ãtRedshiftOutputãã³ã³ãã¼ãã³ãã®ãåºæ¬è¨å®ãã«ã¯Redshiftã¸ã®æ¥ç¶æ å ±ãã¹ãã¼ãæ å ±ãå ¥åãã¾ãã
è¨å®å | è¨å®å¤ | è£è¶³ |
---|---|---|
ãã¹ã | "xxxxx.xxxxxxxxxxxx.ap-northeast-1.redshift.amazonaws.com | Redshiftã®ãã¹ã |
ãã¼ã | "5439" | Redshiftã¸ã®æ¥ç¶ãã¼ãçªå· |
ãã¼ã¿ãã¼ã¹ | "xxxxx" | ãã¼ã¿ãã¼ã¹å |
ã¹ãã¼ã | "public" | ã¹ãã¼ãå |
ã¦ã¼ã¶ | "xxxxx" | æ¥ç¶ã¦ã¼ã¶å |
ãã¹ã¯ã¼ã | "xxxxxx" | ãã¹ã¯ã¼ã |
ãã¼ãã« | "users" | ãã¼ãã«å |
ãã¼ã¿ã«å¯¾ããã¢ã¯ã·ã§ã³ | æ¿å ¥ã¾ãã¯æ´æ° | ä¸è¨ï¼â»ï¼åç § |
â»Redshiftã®æ³¨æç¹ã¨ãã¦ãã©ã¤ããªã¼ãã¼å¶ç´ãå¹ããªããããããã°ã©ã ãªã©ã§åããã¼ã®ãã¼ã¿ãå ¥ããªãããã«å¶å¾¡ããå¿ è¦ãããã¾ãããtRedshiftOutputãã³ã³ãã¼ãã³ãã®ã¹ãã¼ãè¨å®ã§ãã©ã¤ããªãã¼ã¨ãªãé ç®ãè¨å®ãã¦ããããªããã¤ããã¼ã¿ã«å¯¾ããã¢ã¯ã·ã§ã³ãããæ¿å ¥ã¾ãã¯æ´æ°ãã«ãã¦ãããã¨ã§ãåããã©ã¤ããªã¼ãã¼ã®ãã¼ã¿ããã¼ãã«ã«åå¨ããå ´åã¯æ´æ°ãããã§ç¡ãå ´åã¯æ¿å ¥ã¨ããåãããã¦ãããããã«ãªã£ã¦ãã¾ãã
ã¸ã§ãã®å®è¡ã¨çµæã®ç¢ºèª
æå¾ã«talendä¸ã§ã¸ã§ããå®è¡ãã¦ãå®éã«ãã¼ã¿ãç»é²ããããã確èªãã¾ãã ã¸ã§ããå®è¡ããç°å¢ããRedshiftã«æ¥ç¶ããéã«ãã»ãã¥ãªãã£ã°ã«ã¼ãã§æ¥ç¶ã許å¯ããã¦ããå¿ è¦ãããã¾ãã®ã§äºåã«è¨±å¯ããã¦ããã¦ãã ããã
ãã£ã«ã¿ã¼æ¡ä»¶ã«åè´ãã21件ã®ã¬ã³ã¼ããæ¿å ¥ããã¦ãããã¨ã確èªã§ãã¾ããã
ãã¶ã¤ãä¸ã§ãä½ä»¶ãã¼ã¿ãå¦çããã¦ãããã確èªã§ããã®ã親åã§ããã
SQL Workbench/Jä¸ã§ããã¼ã¿ãæ¿å ¥ããã¦ãããã¨ã確èªã§ãã¾ããã
ã¾ã¨ã
ãããã§ããã§ããããï¼S3ãããã¼ã¿ããã¦ã³ãã¼ããããã®ãã¼ã¿ãå å·¥ããRedshiftã«ç»é²ããã¨ããä¸é£ã®å¦çãå®è£ ãã¦ã¿ã¾ããã
Talend Open Studioã使ããã¨ã§ã³ã¼ããæ¸ããªãã¦ããtalendã³ã³ãã¼ãã³ãã®çµã¿åããã§AWSã®ç°å¢ã«æ¥ç¶ããETLçãªå¦çãå®è£ ã§ãããã¨ããåããããã ãããã¨æãã¾ãã