AWS Amazon Redshift驱动程序错误,其中有子句IN中的列表

问题描述 投票:0回答:1

我在Redshift中使用spring NamedParameterJdbcDaoSupport类,并且当参数的类型为List / Set且没有元素或只有一个元素时,我遇到错误/崩溃(堰情况!)。>>

__这是我的神器

<dependency>
    <groupId>com.amazon.redshift</groupId>
    <artifactId>redshift-jdbc42</artifactId>
    <version>1.2.41.1065</version>
</dependency>

这是我的表脚本

CREATE TABLE IF NOT EXISTS test_table (
  id BIGINT NOT NULL,
  last_contact timestamp DEFAULT NULL,
  PRIMARY KEY (id)
);

这是我的验证码

public class TestDao extends NamedParameterJdbcDaoSupport {
private static final String QUERY_INTEGER_ID = "SELECT id FROM test_table WHERE id IN (:ids) GROUP BY id";

    public TestDao(DataSource dataSource) {
        setDataSource(dataSource);
    }

    public List<Map<String, Object>> queryId(List<Integer> list) {
        MapSqlParameterSource params = new MapSqlParameterSource();
        params.addValue("ids", list);
        return getNamedParameterJdbcTemplate().queryForList(QUERY_INTEGER_ID, params);
    }

}

这是我的考试课程

public class TheTestClass {

    // REDSHIFT > FAIL WITH ERROR "java.sql.SQLException: [Amazon](500310) Invalid operation: syntax error at or near ')'"
   // H2 Memory database > Pass OK
    @Test
    public void testQueryId_WithEmptyList() {
        List<Map<String, Object>> result = dao.queryId(Collections.emptyList());
        Assertions.assertNotNull(result);
    }

    // REDSHIFT > FAIL WITH ERROR "SQL state [XX000]; error code [500310]; [Amazon](500310) Invalid operation: Assert ... Query with multi-segment stream cannot be selective dispatched"
   // H2 Memory database > Pass OK
    @Test
    public void testQueryId_WithSingleElementList_Redshift() {
        List<Map<String, Object>> result = dao.queryId(Collections.singletonList(100));
        Assertions.assertNotNull(result);
    }

   // Redshift > Pass OK
   // H2 Memory database > Pass OK
    @Test
    public void testQueryId_WithMultipleElementsList_Redshift() {
        List<Map<String, Object>> result = dao.queryId(List.of(10,  20));
        Assertions.assertNotNull(result);
    }
}

最奇怪的错误是使用单个元素调用dao方法,这是堆栈跟踪的一部分:

org.springframework.jdbc.UncategorizedSQLException:PreparedStatementCallback; SQL的未分类SQLException [SELECTid from test_table,其中id为(?)GROUP BY id]; SQL状态[XX000];错误代码[500310]; Amazon无效操作:断言详细信息:--------------------------------------------------------------错误:断言代码:1000上下文:IsSDDisabled(m_dispatch_level)|| num_compute_segments == 1-多段流查询无法被选择性调度查询:7701161位置:query.cpp:1724进程:padbmaster [pid = 16104]----------------------------------------------- ;;嵌套异常为java.sql.SQLException:Amazon无效操作:断言详细信息:--------------------------------------------------------------错误:断言代码:1000上下文:IsSDDisabled(m_dispatch_level)|| num_compute_segments == 1-多段流查询无法被选择性调度查询:7701161位置:query.cpp:1724进程:padbmaster [pid = 16104]-----------------------------------------------;在org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:89)在org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:81)在org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:81)在org.springframework.jdbc.core.JdbcTemplate.translateException(JdbcTemplate.java:1443)在org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:633)在org.springframework.jdbc.core.JdbcTemplate.query(JdbcTemplate.java:669)引起原因:java.sql.SQLException:Amazon Invalid操作:断言详细信息:-----------------------------------------------错误:断言代码:1000上下文:IsSDDisabled(m_dispatch_level)||num_compute_segments == 1-不能使用多段流查询选择性调度查询:7701161位置:query.cpp:1724程序:padbmaster [pid = 16104]-----------------------------------------------;在com.amazon.redshift.client.messages.inbound.ErrorResponse.toErrorException(未知来源)com.amazon.redshift.client.PGMessagingContext.handleErrorResponse(未知来源)com.amazon.redshift.client.PGMessagingContext.handleMessage(未知来源)com.amazon.jdbc.communications.InboundMessagesPipeline.getNextMessageOfClass(未知来源)com.amazon.redshift.client.PGMessagingContext.doMoveToNextClass(未知来源)com.amazon.redshift.client.PGMessagingContext.getErrorResponse(未知来源)com.amazon.redshift.client.PGClient.handleErrorsScenario2ForPrepareExecution(未知来源)com.amazon.redshift.client.PGClient.handleErrorsPrepareExecute(未知来源)com.amazon.redshift.dataengine.CallablePreparedOrAtomicExecuteTask.call(未知来源)com.amazon.redshift.dataengine.CallablePreparedOrAtomicExecuteTask.call(未知来源)java.base / java.util.concurrent.FutureTask.run(FutureTask.java:264)在java.base / java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)在java.base / java.util.concurrent.ThreadPoolExecutor $ Worker.run(ThreadPoolExecutor.java:628)引起原因:com.amazon.support.exceptions.ErrorException:Amazon无效操作:断言详细信息:-----------------------------------------------错误:断言代码:1000上下文:IsSDDisabled(m_dispatch_level)||num_compute_segments == 1-不能使用多段流查询选择性调度查询:7701161位置:query.cpp:1724程序:padbmaster [pid = 16104]-----------------------------------------------;

我将非常感谢您的帮助。

我在Redshift中使用spring NamedParameterJdbcDaoSupport类,并且当参数的类型为List / Set且没有元素或只有一个元素时,会出现错误/崩溃(堰情况!)。 _这是...

java spring amazon-redshift driver
1个回答
0
投票

[恐怕在Redshift中,您不能在准备好的语句中将列表或数组传递给IN运算符。我也尝试过,但是没有用。我在文档中没有发现任何证据,在StackOverflow上只有this comment

© www.soinside.com 2019 - 2024. All rights reserved.