Большое количество значений в запросе с ItemReader

Следующий ItemReader получает список из тысяч учетных записей (согласно).

База данных, к которой ItemReader будет подключаться для извлечения данных, - это HIVE. У меня нет разрешения на создание таблиц, только чтение.

 @Bean
 @StepScope
public ItemReader<OmsDto> omsItemReader(@Value("#{stepExecutionContext[acc]}") List<String> accountList) {

    String inParams = String.join(",", accountList.stream().map(id -> 
"'"+id+"'").collect(Collectors.toList()));

    String query = String.format("SELECT ..... account IN (%s)", inParams); 
    
    BeanPropertyRowMapper<OmsDto> rowMapper = new BeanPropertyRowMapper<>(OmsDto.class);
    rowMapper.setPrimitivesDefaultedForNullValue(true);
    JdbcCursorItemReader<OmsDto> reader = new JdbcCursorItemReader<OmsDto>();

    reader.setVerifyCursorPosition(false);
    reader.setDataSource(hiveDataSource());
    reader.setRowMapper(rowMapper);
    reader.setSql(query);
    reader.open(new ExecutionContext());
    return reader;
}

Это сообщение об ошибке, которое я получаю при использовании ItemReader:

Caused by: org.springframework.batch.item.ItemStreamException: Failed to initialize the reader
at org.springframework.batch.item.support.AbstractItemCountingItemStreamItemReader.open(AbstractItemCountingItemStreamItemReader.java:153) ~[spring-batch-infrastructure-4.2.4.RELEASE.jar:4.2.4.RELEASE]

 Caused by: java.sql.SQLException: Error executing query
at com.facebook.presto.jdbc.PrestoStatement.internalExecute(PrestoStatement.java:279) ~[presto-jdbc-0.243.2.jar:0.243.2-128118e]
at com.facebook.presto.jdbc.PrestoStatement.execute(PrestoStatement.java:228) ~[presto-jdbc-0.243.2.jar:0.243.2-128118e]
at com.facebook.presto.jdbc.PrestoPreparedStatement.<init>(PrestoPreparedStatement.java:84) ~[presto-jdbc-0.243.2.jar:0.243.2-128118e]
at com.facebook.presto.jdbc.PrestoConnection.prepareStatement(PrestoConnection.java:130) ~[presto-jdbc-0.243.2.jar:0.243.2-128118e]
at com.facebook.presto.jdbc.PrestoConnection.prepareStatement(PrestoConnection.java:300) ~[presto-jdbc-0.243.2.jar:0.243.2-128118e]
at org.springframework.batch.item.database.JdbcCursorItemReader.openCursor(JdbcCursorItemReader.java:121) ~[spring-batch-infrastructure-4.2.4.RELEASE.jar:4.2.4.RELEASE]
... 63 common frames omitted
Caused by: java.lang.RuntimeException: Error fetching next at https://prestoanalytics-ch2-p.sys.comcast.net:6443/v1/statement/executing/20201118_131314_11079_v3w47/yf55745951e0beccc234c98f36005723457073854/0 returned an invalid response: JsonResponse{statusCode=502, statusMessage=Bad Gateway, headers={cache-control=[no-cache], content-length=[107], content-type=[text/html]}, hasValue=false} [Error: <html><body><h1>502 Bad Gateway</h1>
The server returned an invalid or incomplete response.
</body></html>
]

Я был уверен, что основная причина заключается в драйвере, но на этот раз я протестировал драйвер с тем же SQL, используя DriverManager, и он отлично работает.

 @Component
 public class OmsItemReader implements ItemReader<OmsDto>, StepExecutionListener {

private ItemReader<OmsDto> delegate;
public SikOmsItemReader() {
    
    Properties properties = new Properties();
    properties.setProperty("user", "....");
    properties.setProperty("password", "...");
    properties.setProperty("SSL", "true");
    
    Connection connection = null;
    
    try {
        connection = DriverManager.getConnection("jdbc:presto://.....", properties);
        Statement statement = connection.createStatement();
        
        ResultSet resultSet = statement.executeQuery(

Я не уверен, в чем разница? Драйвер или запасная партия?

Я ищу обходной путь. Как я могу получить тысячи учетных записей с помощью предложений IN с помощью Spring Batch?

Спасибо

0 ответов

Другие вопросы по тегам