未验证 提交 57aefacd 编写于 作者: J Jaromir Hamala 提交者: GitHub

fix(sql): fix SAMPLE BY queries with ORDER BY timestamp DESC (#3662)

上级 3995c312
...@@ -2759,7 +2759,7 @@ public class SqlOptimiser implements Mutable { ...@@ -2759,7 +2759,7 @@ public class SqlOptimiser implements Mutable {
for (int i = 0, k = jm.size(); i < k; i++) { for (int i = 0, k = jm.size(); i < k; i++) {
QueryModel qm = jm.getQuick(i).getNestedModel(); QueryModel qm = jm.getQuick(i).getNestedModel();
if (qm != null) { if (qm != null) {
if (model.getGroupBy().size() == 0) {//order by should not copy through group by if (model.getGroupBy().size() == 0 && model.getSampleBy() == null) { // order by should not copy through group by or sample by
qm.setOrderByAdviceMnemonic(orderByMnemonic); qm.setOrderByAdviceMnemonic(orderByMnemonic);
qm.copyOrderByAdvice(orderByAdvice); qm.copyOrderByAdvice(orderByAdvice);
qm.copyOrderByDirectionAdvice(orderByDirectionAdvice); qm.copyOrderByDirectionAdvice(orderByDirectionAdvice);
......
...@@ -9830,6 +9830,32 @@ public class SampleByTest extends AbstractCairoTest { ...@@ -9830,6 +9830,32 @@ public class SampleByTest extends AbstractCairoTest {
); );
} }
@Test
public void testSampleByWithOrderByDescTimestamp() throws Exception {
assertQuery(
"created_at\tfirst\n" +
"1970-01-01T08:00:00.000000Z\t42.17768841969397\n" +
"1970-01-01T06:00:00.000000Z\t34.91070363730514\n" +
"1970-01-01T04:00:00.000000Z\t79.05675319675964\n" +
"1970-01-01T02:00:00.000000Z\t8.43832076262595\n" +
"1970-01-01T00:00:00.000000Z\t80.43224099968394\n",
"select created_at, first(price)" +
" from trades" +
" sample by 2h" +
" order by created_at desc",
"create table trades as " +
"(" +
"select" +
" rnd_double(0) * 100 price," +
" timestamp_sequence(0, 3600000000) created_at" + // 1 hour step
" from long_sequence(10)" + // 10 rows
") timestamp(created_at) partition by day",
"created_at###DESC",
true,
false
);
}
@Test @Test
public void testSamplePeriodInvalidWithNoUnits() throws Exception { public void testSamplePeriodInvalidWithNoUnits() throws Exception {
testSampleByPeriodFails( testSampleByPeriodFails(
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册