mirror of https://github.com/apache/druid.git
Add CalciteSysQueryTest to enable some testing of bindable plans. (#15070)
This commit is contained in:
parent
2164dafb99
commit
36d7b3cc65
|
@ -0,0 +1,63 @@
|
||||||
|
/*
|
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one
|
||||||
|
* or more contributor license agreements. See the NOTICE file
|
||||||
|
* distributed with this work for additional information
|
||||||
|
* regarding copyright ownership. The ASF licenses this file
|
||||||
|
* to you under the Apache License, Version 2.0 (the
|
||||||
|
* "License"); you may not use this file except in compliance
|
||||||
|
* with the License. You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing,
|
||||||
|
* software distributed under the License is distributed on an
|
||||||
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
* KIND, either express or implied. See the License for the
|
||||||
|
* specific language governing permissions and limitations
|
||||||
|
* under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.apache.druid.sql.calcite;
|
||||||
|
|
||||||
|
import com.google.common.collect.ImmutableList;
|
||||||
|
import org.apache.druid.sql.calcite.DecoupledIgnore.DecoupledIgnoreProcessor;
|
||||||
|
import org.apache.druid.sql.calcite.DecoupledIgnore.Modes;
|
||||||
|
import org.junit.Rule;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
public class CalciteSysQueryTest extends BaseCalciteQueryTest
|
||||||
|
{
|
||||||
|
@Rule(order = 0)
|
||||||
|
public DecoupledIgnoreProcessor decoupledIgnoreProcessor = new DecoupledIgnoreProcessor();
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testTasksSum()
|
||||||
|
{
|
||||||
|
notMsqCompatible();
|
||||||
|
|
||||||
|
testBuilder()
|
||||||
|
.sql("select datasource, sum(duration) from sys.tasks group by datasource")
|
||||||
|
.expectedResults(ImmutableList.of(
|
||||||
|
new Object[]{"foo", 11L},
|
||||||
|
new Object[]{"foo2", 22L}))
|
||||||
|
.expectedLogicalPlan("LogicalAggregate(group=[{0}], EXPR$1=[SUM($1)])\n"
|
||||||
|
+ " LogicalProject(exprs=[[$3, $8]])\n"
|
||||||
|
+ " LogicalTableScan(table=[[sys, tasks]])\n")
|
||||||
|
.run();
|
||||||
|
}
|
||||||
|
|
||||||
|
@DecoupledIgnore(mode = Modes.EXPRESSION_NOT_GROUPED)
|
||||||
|
@Test
|
||||||
|
public void testTasksSumOver()
|
||||||
|
{
|
||||||
|
notMsqCompatible();
|
||||||
|
|
||||||
|
testBuilder()
|
||||||
|
.sql("select datasource, sum(duration) over () from sys.tasks group by datasource")
|
||||||
|
.expectedResults(ImmutableList.of(
|
||||||
|
new Object[]{"foo", 11L},
|
||||||
|
new Object[]{"foo2", 22L}))
|
||||||
|
// please add expectedLogicalPlan if this test starts passing!
|
||||||
|
.run();
|
||||||
|
}
|
||||||
|
}
|
|
@ -52,7 +52,8 @@ public @interface DecoupledIgnore
|
||||||
PLAN_MISMATCH(AssertionError.class, "AssertionError: query #"),
|
PLAN_MISMATCH(AssertionError.class, "AssertionError: query #"),
|
||||||
NOT_ENOUGH_RULES(DruidException.class, "not enough rules"),
|
NOT_ENOUGH_RULES(DruidException.class, "not enough rules"),
|
||||||
CANNOT_CONVERT(DruidException.class, "Cannot convert query parts"),
|
CANNOT_CONVERT(DruidException.class, "Cannot convert query parts"),
|
||||||
ERROR_HANDLING(AssertionError.class, "(is <ADMIN> was <OPERATOR>|is <INVALID_INPUT> was <UNCATEGORIZED>|with message a string containing)");
|
ERROR_HANDLING(AssertionError.class, "(is <ADMIN> was <OPERATOR>|is <INVALID_INPUT> was <UNCATEGORIZED>|with message a string containing)"),
|
||||||
|
EXPRESSION_NOT_GROUPED(DruidException.class, "Expression '[a-z]+' is not being grouped");
|
||||||
|
|
||||||
public Class<? extends Throwable> throwableClass;
|
public Class<? extends Throwable> throwableClass;
|
||||||
public String regex;
|
public String regex;
|
||||||
|
|
|
@ -39,7 +39,14 @@ import org.apache.druid.discovery.DruidNodeDiscovery;
|
||||||
import org.apache.druid.discovery.DruidNodeDiscoveryProvider;
|
import org.apache.druid.discovery.DruidNodeDiscoveryProvider;
|
||||||
import org.apache.druid.discovery.NodeRole;
|
import org.apache.druid.discovery.NodeRole;
|
||||||
import org.apache.druid.guice.annotations.Json;
|
import org.apache.druid.guice.annotations.Json;
|
||||||
|
import org.apache.druid.indexer.RunnerTaskState;
|
||||||
|
import org.apache.druid.indexer.TaskLocation;
|
||||||
|
import org.apache.druid.indexer.TaskState;
|
||||||
|
import org.apache.druid.indexer.TaskStatusPlus;
|
||||||
|
import org.apache.druid.java.util.common.CloseableIterators;
|
||||||
|
import org.apache.druid.java.util.common.DateTimes;
|
||||||
import org.apache.druid.java.util.common.Pair;
|
import org.apache.druid.java.util.common.Pair;
|
||||||
|
import org.apache.druid.java.util.common.parsers.CloseableIterator;
|
||||||
import org.apache.druid.java.util.http.client.HttpClient;
|
import org.apache.druid.java.util.http.client.HttpClient;
|
||||||
import org.apache.druid.java.util.http.client.Request;
|
import org.apache.druid.java.util.http.client.Request;
|
||||||
import org.apache.druid.java.util.http.client.response.HttpResponseHandler;
|
import org.apache.druid.java.util.http.client.response.HttpResponseHandler;
|
||||||
|
@ -82,9 +89,11 @@ import javax.annotation.Nullable;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
import java.net.URISyntaxException;
|
import java.net.URISyntaxException;
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.concurrent.Executor;
|
import java.util.concurrent.Executor;
|
||||||
|
@ -368,6 +377,38 @@ public class CalciteTests
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ListenableFuture<CloseableIterator<TaskStatusPlus>> taskStatuses(
|
||||||
|
@Nullable String state,
|
||||||
|
@Nullable String dataSource,
|
||||||
|
@Nullable Integer maxCompletedTasks
|
||||||
|
)
|
||||||
|
{
|
||||||
|
List<TaskStatusPlus> tasks = new ArrayList<TaskStatusPlus>();
|
||||||
|
tasks.add(createTaskStatus("id1", DATASOURCE1, 10L));
|
||||||
|
tasks.add(createTaskStatus("id1", DATASOURCE1, 1L));
|
||||||
|
tasks.add(createTaskStatus("id2", DATASOURCE2, 20L));
|
||||||
|
tasks.add(createTaskStatus("id2", DATASOURCE2, 2L));
|
||||||
|
return Futures.immediateFuture(CloseableIterators.withEmptyBaggage(tasks.iterator()));
|
||||||
|
}
|
||||||
|
|
||||||
|
private TaskStatusPlus createTaskStatus(String id, String datasource, Long duration)
|
||||||
|
{
|
||||||
|
return new TaskStatusPlus(
|
||||||
|
id,
|
||||||
|
"testGroupId",
|
||||||
|
"testType",
|
||||||
|
DateTimes.nowUtc(),
|
||||||
|
DateTimes.nowUtc(),
|
||||||
|
TaskState.RUNNING,
|
||||||
|
RunnerTaskState.RUNNING,
|
||||||
|
duration,
|
||||||
|
TaskLocation.create("testHost", 1010, -1),
|
||||||
|
datasource,
|
||||||
|
null
|
||||||
|
);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
return new SystemSchema(
|
return new SystemSchema(
|
||||||
|
|
Loading…
Reference in New Issue