"Mysql/hive/redis"의 두 판 사이의 차이
ph
잔글 (→HIVE) |
잔글 (→Mysql) |
||
11번째 줄: | 11번째 줄: | ||
DROP USER ‘demo’@‘localhost’; | DROP USER ‘demo’@‘localhost’; | ||
[https://www.digitalocean.com/community/tutorials/how-to-create-a-new-user-and-grant-permissions-in-mysql] | [https://www.digitalocean.com/community/tutorials/how-to-create-a-new-user-and-grant-permissions-in-mysql] | ||
+ | |||
+ | ===LEFT JOIN only first row=== | ||
+ | 뾰족한 방법이 없는듯. 아래와 같이 그냥 한다[https://stackoverflow.com/q/15626493/766330] | ||
+ | <pre> | ||
+ | SELECT * | ||
+ | FROM feeds f | ||
+ | LEFT JOIN artists a ON a.artist_id = ( | ||
+ | SELECT artist_id | ||
+ | FROM feeds_artists fa | ||
+ | WHERE fa.feed_id = f.id | ||
+ | LIMIT 1 | ||
+ | ) | ||
+ | WHERE f.id = ‘13815’ | ||
+ | </pre> | ||
==HIVE== | ==HIVE== |
2017년 9월 21일 (목) 11:34 판
목차
Rename table
ALTER TABLE table_name RENAME TO new_table_name;
Mysql
Create user
CREATE USER 'newuser'@'localhost' IDENTIFIED BY ‘password'; GRANT ALL PRIVILEGES ON * . * TO 'newuser'@‘localhost'; FLUSH PRIVILEGES;
DROP USER ‘demo’@‘localhost’;
LEFT JOIN only first row
뾰족한 방법이 없는듯. 아래와 같이 그냥 한다[3]
SELECT * FROM feeds f LEFT JOIN artists a ON a.artist_id = ( SELECT artist_id FROM feeds_artists fa WHERE fa.feed_id = f.id LIMIT 1 ) WHERE f.id = ‘13815’
HIVE
Hive Tutorial
view partitions
show partitions table;
http://stackoverflow.com/q/15616290/766330
특정 partition만을 대상으로 조회하는 특별한 쿼리는 없다. 파티션 정보를 where에 넣으면 hive가 자동으로 알아서 하는 것으로 보임. ref. how to select data from hive with specific partition?
median
select percentile(cast(age as BIGINT), 0.5) from table_name
show tables like
show tables in db_name like 'prefix_*'
Redis
pipe
- cluster모드에서는 pipe가 동작하지 않는다. 각 서버(slot)에 알맞게 알아서 날려주어야 함.
- 소스에서 key_to_slot함수 참고.
- slot 확인 : $ redis-cli cluster nodes
- 명령을 그대로 텍스트파일에 넣되 windows식 행바꿈이 필요하다. 참고
- 굳이 redis protocol 안써도 됨
- cluster모드에서 pattern으로 key찾아 지우기 코드: http://stackoverflow.com/a/43841705/766330 누가했는지 잘했구만