SQL 5

Airflow query csv export, 쿼리로 csv export

공식문서를 기반으로 만들었다. https://airflow.apache.org/docs/apache-airflow/stable/_api/airflow/hooks/dbapi/index.html#airflow.hooks.dbapi.DbApiHook.get_pandas_df 아래 내용을 토대로 만들었다. https://pepega.tistory.com/49 전체 코드는 아래에 있다. https://github.com/GHGHGHKO/airflow/commit/7509b3c13816629c450afc8f8a325143c1da1d65 기존에는 get_records 메서드를 활용했다. def execute(self, context): hook = PostgresHook( postgres_conn_id = self...

Airflow 2022.03.20

Airflow XComs Email 전송

Airflow로 Email 전송하는 글을 포스팅했었다. https://pepega.tistory.com/47 블로그 코드는 https://github.com/GHGHGHKO/airflow/blob/master/dags/email_xcom_test.py 전 포스팅 내용을 기반으로 DAG을 만들었다. email_operator = EmailOperator( task_id='send_email', to='receiver@example.com', subject='[TEST] 테스트 메일입니다.', html_content=""" 테스트 메일입니다. ninja template {{ data_interval_start }} {{ ds }} {{ task_instance.xcom_pull(dag_id='postgres..

Airflow 2022.03.18

Airflow OracleOperator Custom 하기

공식 문서를 기반으로 작성하였다. PostgresHook https://airflow.apache.org/docs/apache-airflow-providers-oracle/stable/_modules/airflow/providers/oracle/hooks/oracle.html#OracleHook DbApi https://airflow.apache.org/docs/apache-airflow/stable/_modules/airflow/hooks/dbapi.html#DbApiHook.get_first 하단 코드는 아래에 있다. https://github.com/GHGHGHKO/airflow/commit/47de1fd55ff2be812702ba4539adf54e6d9bd292 OracleOperator 사용 할..

Airflow 2022.03.17

Airflow BranchSQLOperator 활용

apache/airflow github commit을 활용했다. https://github.com/apache/airflow/blob/39e395f9816c04ef2f033eb0b4f635fc3018d803/airflow/operators/sql.py#L470 활용한 전체 소스코드는 github에 올렸다. https://github.com/GHGHGHKO/airflow/blob/master/dags/postgres_test.py Airflow에서 제공하는 BranchSQLOperator를 활용한 예제이다. 쿼리의 결과(true or false)에 따라 TAG를 활용 할 수 있다. 추후 이 예시를 통해 테이블 스페이스가 가득 찰 경우 알람 메일이 전송되는 스케줄을 등록 할 것이다. true_branch_o..

Airflow 2022.03.14

SpringBoot redis 활용(.haskey, .set, .get)

토큰 제한시간은 30분 만료시간 10분 이내에 재발급 하면 토큰이 재생성 되는 방식이다. 만료시간 이전에 토큰을 발급하면 바뀌지 않은 기존의 토큰이 발급된다. 위 내용을 예시로 진행할 예정이다. OS : Windows 10 Redis : docker, P3X Redis UI Java 14 redis 위주의 코드를 적을 계획이다. @Configuration public class RedisConfig { @Value("${spring.redis.host}") private String redisHost; @Value("${spring.redis.port}") private int redisPort; @Bean public LettuceConnectionFactory lettuceConnectionFacto..

DB 2021.10.22