sourcecode

JPA Spring Boot를 통해 AWS Athena 액세스

copyscript 2023. 7. 28. 22:33
반응형

JPA Spring Boot를 통해 AWS Athena 액세스

저는 스프링 부트 jpa 데이터 소스를 사용하여 AWS athena를 사용하려고 합니다.지정된 속성으로 데이터 소스를 설정하려고 했습니다.

    spring.datasource.driver-class-name=com.amazonaws.athena.jdbc.AthenaDriver
    spring.datasource.url=jdbc:awsathena://athena.us-east-1.amazonaws.com:443/default
    spring.datasource.username=*****
    spring.datasource.password=***
    spring.datasource.tomcat.connectionProperties=s3_staging_dir=*****

나는 예외를 인정받고 있습니다.

    Caused by:org.springframework.beans.BeanInstantiationException:    Failed to instantiate [org.springframework.orm.jpa.JpaVendorAdapter]: Factory method 'jpaVendorAdapter' threw exception; nested exception is java.lang.IllegalArgumentException: URL must start with 'jdbc'
at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:189) ~[spring-beans-4.3.7.RELEASE.jar:4.3.7.RELEASE]
at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(Constructo`enter code here`rResolver.java:588) ~[spring-beans-4.3.7.RELEASE.jar:4.3.7.RELEASE]
... 51 common frames omitted
    Caused by: java.lang.IllegalArgumentException: URL must start with 'jdbc'
at org.springframework.util.Assert.isTrue(Assert.java:92) ~[spring-core-4.3.7.RELEASE.jar:4.3.7.RELEASE]
at org.springframework.boot.jdbc.DatabaseDriver.fromJdbcUrl(DatabaseDriver.java:268) ~[spring-boot-1.5.2.RELEASE.jar:1.5.2.RELEASE]
at org.springframework.boot.autoconfigure.orm.jpa.DatabaseLookup.getDatabase(DatabaseLookup.java:73) ~[spring-boot-autoconfigure-1.5.2.RELEASE.jar:1.5.2.RELEASE]
at org.springframework.boot.autoconfigure.orm.jpa.JpaProperties.determineDatabase(JpaProperties.java:139) ~[spring-boot-autoconfigure-1.5.2.RELEASE.jar:1.5.2.RELEASE]
at org.springframework.boot.autoconfigure.orm.jpa.JpaBaseConfiguration.jpaVendorAdapter(JpaBaseConfiguration.java:105) ~[spring-boot-autoconfigure-1.5.2.RELEASE.jar:1.5.2.RELEASE]
at org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration$$EnhancerBySpringCGLIB$$720f8624.CGLIB$jpaVendorAdapter$4(<generated>) ~[spring-boot-autoconfigure-1.5.2.RELEASE.jar:1.5.2.RELEASE]
at org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration$$EnhancerBySpringCGLIB$$720f8624$$FastClassBySpringCGLIB$$9766cf.invoke(<generated>) ~[spring-boot-autoconfigure-1.5.2.RELEASE.jar:1.5.2.RELEASE]
at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:228) ~[spring-core-4.3.7.RELEASE.jar:4.3.7.RELEASE] 

여기에 제공된 답변(평판 때문에 코멘트할 수 없음)과 온라인에 작동 사례가 없기 때문에 Athena JDBC 드라이버를 사용하도록 스프링 부트(2.2.5) 데이터 JPA를 구성하는 방법을 제공할 것입니다.

Athena jdbc 연결 URL에 형식이 있습니다.
jdbc:awsathena://athena.[Region].amazonaws.com:443;User= [AccessKey];Password=[SecretKey];S3OutputLocation=[Output];

내 applications.properties 파일
spring.datasource.url=specifiedformat
spring.datasource.driver-class-name=com.simba.athena.jdbc42.Driver
spring.datasource.hikari.connection-test-query=SELECT 1
spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.MySQLDialect
spring.jpa.hibernate.ddl-auto=validate

Athena용 JDBC 드라이버는 여기에서 찾을 수 있습니다.
https://docs.aws.amazon.com/athena/latest/ug/connect-with-jdbc.html
또는 메이븐 리포지토리를 사용하려는 경우
https://mvnrepository.com/artifact/com.syncron.amazonaws/simba-athena-jdbc-driver/2.0.2

MySQLDialect는 ANSI SQL과 비슷하기 때문에 사용했습니다(현재 아테나에 대한 방언은 없습니다).물론 MySQL 방언과 Athena가 준비된 진술을 지원하지 않는다는 사실 때문에. (이를 가진 사람들만)?자리 표시자는 실제로 사용할 수 있습니다.String.format()이를 무시하려면, 참조: AWS Athena JDBC Prepared Statement)를 참조하십시오. 모든 스프링 부트 데이터 jpa 기본 구현 작업을 수행할 수는 없지만 를 사용하여 이를 무시할 수 있습니다.@Query저장소 클래스 내의 주석 및String.format()지원되지 않는 준비된 문을 무시합니다.

Spring boot + JPA + Hibernate + Athena JDBC 드라이버는 저에게 잘 작동합니다(현재는 데이터만 읽고 있습니다). 문제는 이 구성에서 지원되는 각 쿼리를 테스트해야 한다는 것입니다(지원되지 않는 작업에 대한 예외를 발생시킬 수 있음).

기본적으로 Spring 부팅은 JDBC 드라이버에서 검색된 데이터 소스의 메타데이터를 기반으로 사용할 최대 절전 모드 방언을 자동으로 감지합니다.

이 오류는 Athena JDBC 드라이버가 관련 메타데이터를 가져오지 못하기 때문에 발생합니다.실패하는 이유는 확실하지 않지만 이 탐지를 무시하고 다음을 선언하여 스스로 사용할 최대 절전 모드 방언을 명시적으로 선언할 수 있습니다.JpaVendorAdapter콩:

@Bean
public JpaVendorAdapter jpaVendorAdapter(JpaProperties properties) {
    AbstractJpaVendorAdapter adapter = new HibernateJpaVendorAdapter();
    adapter.setShowSql(properties.isShowSql());
    adapter.setGenerateDdl(properties.isGenerateDdl());
    return adapter;
}

기본 동작은 모두 유지하지만 자동 감지 사투리는 사용하지 않습니다.

그리고 다음에서 방언 정의합니다.application.properties:

spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.XXXXXX

하지만 요점은 아테나에 대한 기존 방언이 없기 때문에 아테나를 하이버네이트와 함께 사용할 수 있을지 의심스럽다는 것입니다.그래서 제가 제안하는 것은:

  1. SQL 구문이 Athena와 유사한 다른 데이터베이스에서 사투리를 사용해 보십시오.어떤 경우에는 효과가 없을 것이라는 것은 놀라운 일이 아닙니다.

  2. 아테나를 위한 방언을 직접 구현하십시오.

AWS Athena 설명서에는 포트 444가 아웃바운드 트래픽에 대해 열려 있는지 확인하는 내용이 나와 있습니다.여기 https://docs.aws.amazon.com/athena/latest/ug/connect-with-jdbc.html 의 연결 설명서를 참조하십시오.

이게 맞는 해결책인지 잘 모르겠어요, 그래서 이 질문이 너무 오래돼서 조금 파고들었어요.

언급URL : https://stackoverflow.com/questions/43089385/access-aws-athena-through-jpa-spring-boot

반응형