S02056

错误代码

S02056

报错信息

For a distributed query, the TOP or LIMIT clause cannot specify an offset when used with GROUP BY/CONTEXT BY clause. RefId: S02056

错误原因

在分布式查询中,LIMIT/TOP 关键字和 group by/context by 一起使用时,不支持设置起始位置。如下 case 会报错:

dbName = "dfs://test"
if (existsDatabase(dbName)) {
    dropDatabase(dbName)
}
t = table(1..3 as id)
db = database(dbName, VALUE, 1..3)
pt = db.createPartitionedTable(t, `pt, `id)
pt.append!(t)

select id from pt group by id limit 1,1

对于不符合要求的 context by 查询,目前会报另一个错误:

When LIMIT clause uses together with CONTEXT BY clause in SQL query, one can't specify row offset in LIMIT clause

解决办法

根据语义改写查询语句,如上例,先将 id 列从分布式表 pt 中查询到一个临时内存表中,再对该内存表应用 limit 指定起始位置。上述查询语句可修改为:

tmp = select id from pt group by id limit 2
select * from tmp limit 1,1