ã¯ããã«
ããã«ã¡ã¯ãPEé¨ã®è°·ã§ãã
S3 Selectã使ã£ã¦SQLã¯ã¨ãªãå®è¡ãã¦ã¿ã¾ããã
åæç¥è
SQL
SQLã¯ãã¼ã¿ãã¼ã¹è¨èªã®ä¸ã¤ã§ããã¼ã¿ãã¼ã¹ã®å®ç¾©ãæä½ãè¡ããã¨ãã§ãã¾ãã ï¼ãã¼ã¿ãã¼ã¹ã¨ããåãããã¨ãã«ä½¿ãè¨èªï¼
Structured Query Languageã®ç¥ã¨ããè¨äºãããã°ãä½ãã®ç¥èªã§ã¯ãªãã¨ããè¨äºãããã¾ããã
SQLã®åºæ¬çãªå½ä»¤ã¯4ã¤ã§ãã
SELECTï¼ãã¼ã¿ã®æ¤ç´¢
INSERTï¼ãã¼ã¿ã®è¿½å
UPDATEï¼ãã¼ã¿ã®æ´æ°
DELETEï¼ãã¼ã¿ã®åé¤
SELECT ã«ã©ã å FROM ãã¼ãã«å WHERE hoge = 'fuga';
ä¸è¨ã¯ããã¼ãã«ããhogeã«ã©ã ã'fuga'ã¨ä¸è´ããã¬ã³ã¼ããæ¤ç´¢ãåå¾ããã¨ããå½ä»¤åã§ãã
S3 Select
S3 Select ã使ç¨ããã¨ããã¼ã¿ãç°¡åã« S3 ã«ä¿åããSQL ã¹ãã¼ãã¡ã³ãã使ç¨ã㦠S3 ãªãã¸ã§ã¯ãã®ã³ã³ãã³ãããã£ã«ã¿ãªã³ã°ããå¿ è¦ãªãã¼ã¿ã®ã¿ãåå¾ããã¯ã¨ãªãå®è¡ã§ãã¾ãã AWSå ¬å¼ããå¼ç¨
S3ã«ãã¡ã¤ã«ãã¢ãããã¼ãããã ãã§ãã®ãã¡ã¤ã«ã«å¯¾ãã¦SQLã¯ã¨ãªãå®è¡ãããã¨ãã§ãã¾ãã
対å¿ãã¦ãããã¡ã¤ã«å½¢å¼ã¯CSVãJSONãã¾ãã¯Parquetå½¢å¼ã§ã
ã¨ã³ã³ã¼ãã£ã³ã°ã¿ã¤ãã¯UTF-8ã®ã¿ã§ãã
ã¾ããSELECTã³ãã³ãã®ã¿ããµãã¼ããã¦ãã¾ãã
ãã£ã¦ã¿ãã
ä»å使ããã¼ã¿ã¯ãæè¿1å¹´éï¼2021/2/23~2022/2/23ï¼ã®åå¤å±ã®å¤©æ°æ å ±ï¼å¹³åæ°æ¸©ãå¹³å風éãæ¼ã¨å¤ã®å¤©æ°ï¼ã§ãã æ°è±¡åºã®å種ãã¼ã¿ã»è³æããCSVãã¡ã¤ã«ãä½æãã¾ããã
åå¤å±ã®å¤©æ°.csv
ãã®ãã¡ã¤ã«ãS3ã«ã¢ãããã¼ããã[ãªãã¸ã§ã¯ãã¢ã¯ã·ã§ã³]ãã[S3 Select ã使ç¨ããã¯ã¨ãª]ãã¯ãªãã¯ãã¾ãã
å ¥åè¨å®ãåºåè¨å®ãè¡ãSQLã¯ã¨ãªãå®è¡ãã¦ã¿ã¾ãã
ä¸ãã5件ã®ã¬ã³ã¼ããåå¾ãã
SELECT * FROM s3object s LIMIT 5
2021/2/23,9.4,5.9,æ´æã èæ,æ´æã èæ 2021/2/24,5.5,5.8,æ´,æ´ 2021/2/25,7.0,2.3,èææã æ´,æ 2021/2/26,8.7,3.8,é¨å¾æ,æ 2021/2/27,7.8,4.5,èæå¾ä¸ææ´,ææã æ´
SELECTã®å¾ã® * ã¯ãå ¨ã¦ã表ãã¾ãã
FROMã®å¾ã®s3object sã¯ãããã«ãã£ã¦ãã¼ãã«åãsã«ãªãã®ã§ãã«ã©ã ãæå®ããæã¯ãs.ã«ã©ã åãã¨æ¸ããã¨ãã§ãã¾ãã
LIMITã¯ãåå¾ãããã¼ã¿ã®è¡æ°ã®ä¸éãè¨å®ãããã¨ãã§ãã¾ãã
å¹³åæ°æ¸©ã10â以ä¸ã®æ¥ä»ã¨å¹³åæ°æ¸©ãåå¾ãã
SELECT s.NagoyaDate,s.AverageTemperature FROM s3object s WHERE s.AverageTemperature <= '10.0'
2021/3/14,10.0 2021/12/26,1.5 2021/12/27,0.9 2021/12/31,1.5 2022/1/1,1.4 2022/2/5,1.6 2022/2/6,0.9 2022/2/17,1.0 2022/2/21,1.7
該å½ããã¬ã³ã¼ãã®æ¥ä»ã¨å¹³åæ°æ¸©ã«ã©ã ã®ã¿åå¾ãããã®ã§ãSELECTã®å¾ãs.NagoyaDate,s.AverageTemperatureã«ãã¾ãã
å¹³åæ°æ¸©ã10â以ä¸ãªã©æ¤ç´¢æ¡ä»¶ã追å ãããæã«WHEREã使ãã¾ãã
天æ°ãä¸ç¬ã§ãæ´ã ã£ãæ¥ãåå¾ãã
SELECT * FROM s3object s WHERE s.DaytimeWeather LIKE '%æ´%' OR s.NightWeather LIKE '%æ´%'
2021/2/23,9.4,5.9,æ´æã èæ,æ´æã èæ 2021/2/24,5.5,5.8,æ´,æ´ 2021/2/25,7.0,2.3,èææã æ´,æ 2021/2/27,7.8,4.5,èæå¾ä¸ææ´,ææã æ´ 2021/2/28,8.8,1.8,æ´å¾æ,æä¸ææ´ 2021/3/1,12.9,2.7,ææã æ´,ææã é¨ 2021/3/2,10.8,6.2,é¨å¾æ,å¿«æ´ ã» ã» ã»
ãæ¼ã®å¤©æ°ã¨å¤ã®å¤©æ°ã®ã«ã©ã ã©ã¡ããã«'æ´'ã¨ããæååãå«ãã¬ã³ã¼ããåå¾ãã¾ãã LIKEã使ã£ã¦ç¹å®ã®æååãå«ãå«ã¾ãªãæ¤ç´¢ãè¡ãã¾ãã
å¹³åæ°æ¸©ãé«ãé ã«ã¬ã³ã¼ããåå¾ãã
SELECT * FROM s3object s ORDER BY s.AverageTemperature DESC
Unexpected token found KEYWORD
ã¨ã©ã¼ã«ãªã£ã¦ãã¾ãã¾ããã
調ã¹ã¦ã¿ãã¨ãã½ã¼ããã¦ä¸¦ã³æ¿ããORDER BYã¯S3 Selectã§ã¯ã§ããªãã¿ããã§ãã
ãã¼ã¿ãã°ã«ã¼ãåãããGROUP BYãã§ããªãã¿ããã§ãã
ã¾ã¨ã
S3 Selectã使ã£ã¦ã¿ãææ³ã¯ãç°¡åï¼ã§ãã
ãã¡ã¤ã«ã®ã¢ãããã¼ãããS3 Selectã®è¨å®ãã¯ã¨ãªã®å®è¡ã¾ã§ããã¨ã§ãã¦é©ãã¾ããã
S3 Selectã§ã¯ã§ãããã¨ãéããã¦ãããããããå°ãè¤éãªã¯ã¨ãªã®å®è¡ãAmazon Athenaã§ãã£ã¦ã¿ããã¨æãã¾ãã