Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[feat] 데이터 전처리 및 맛집(운영테이블) 데이터 저장 #16

Merged
merged 6 commits into from
Sep 2, 2024

Conversation

jeongeungyeong
Copy link
Contributor

Issue

PR 타입(하나 이상의 PR 타입을 선택해주세요)

  • 기능 추가
  • 기능 삭제
  • 버그 수정
  • 의존성, 환경 변수, 빌드 관련 코드 업데이트

반영 브랜치

ex) feat/data_pipeline -> dev

변경 사항

  • 데이터 전처리
    • openAPI로 응답을 받고 저장된 genrestrts 테이블의 raw data를 내부에서 사용될 형태로 변경
    • genrestrts에 데이터 배치 처리 여부를 나타내는 필드
      private Boolean processed = false; 추가
    • 조건: genrestrt(rawData 테이블)에서 현재 영업상태이고, processed가 false
    • 시군명, 사업장명, 위생업태명, 소재지도로명주소,WGS84위도,WGS84경도 필드의 정보만 선택 조회
    • 조회한 데이터는 rawData 리스트에 담기
  • 데이터 저장
    • rawDatastores 테이블(운영 테이블) 형식에 맞게 변환
    • 데이터를 stores(운영 테이블)에 저장
    • DB에 성공적으로 저장되면 rawData에 담긴 상호명과 도로명주소를 조건으로 genrestrts 테이블 조회
    • 조회된 데이터는 processed=true 로 변경해서 데이터 배치 처리됐음을 알 수 있도록 함
  • 배치처리를 위한 Spring Batch 의존성 추가
  • 최신 배치처리를 위한 Spring Batch Core 5.1 의존성 추가
  • 현재 spring �application 시작 시 자동 실행

테스트 결과

Job 성공시

Step: [dataPipeStep] executed 
Job: [SimpleJob: [name=dataPipeJob]] completed with the following parameters: [{}] and the following status: [COMPLETED]

Job 실패시

  • 데이터 처리 중 예외 발생 시 로그와 함께 "데이터 처리에 오류가 발생했습니다." 오류 메시지 출력
  • 서버 에러로 처리
Step: [dataPipeStep] failed with exception: [NullPointerException]
Job: [SimpleJob: [name=dataPipeJob]] failed with status: [FAILED]

Copy link
Contributor

@jw427 jw427 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

고생하셨습니다!

import java.sql.ResultSet;
import java.sql.SQLException;

public class RawDataRowMapper implements RowMapper<RawData> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

찾아봤는데 이해가 안돼서요! RowMapper를 쓴 이유는 JdbcTemplate를 사용해야 해서인가요?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

찾아봤는데 이해가 안돼서요! RowMapper를 쓴 이유는 JdbcTemplate를 사용해야 해서인가요?

네! JdbcTemplate의 활용해 SQL 쿼리 결과를 RawData의 객체로 변환해주기 위해 사용했습니다.

  • DataPipeTasklet의 처리 과정:
    1. JdbcTemplate이 직접 DB에서 SQL 쿼리를 실행하고 그 결과를 ResultSet로 받아옵니다.
    2. RowMapperResultSet에서 각 행의 데이터를 추출한 후, 추출된 데이터를 RawData 객체로 변환하여 리스트로 담아 반환합니다.
    3. 이후에는 RawData의 담긴 데이터를 바탕으로 Store 객체를 생성하고, stores테이블에 저장되게 됩니다.

Copy link
Contributor

@K-0joo K-0joo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

수고하셨습니다!

Copy link
Contributor

@rhaehf rhaehf left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

고생하셨습니다!

@rhaehf rhaehf linked an issue Sep 2, 2024 that may be closed by this pull request
4 tasks
@jeongeungyeong jeongeungyeong merged commit 6c8a6fc into dev Sep 2, 2024
@jeongeungyeong jeongeungyeong deleted the feat/data_pipeline branch September 2, 2024 08:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

데이터 전처리 및 운영테이블 데이터 저장
4 participants