Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add CalciteSysQueryTest to enable some testing of bindable plans. #15070

Merged
merged 1 commit into from
Oct 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@ enum Modes
PLAN_MISMATCH(AssertionError.class, "AssertionError: query #"),
NOT_ENOUGH_RULES(DruidException.class, "not enough rules"),
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 String regex;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,14 @@
import org.apache.druid.discovery.DruidNodeDiscoveryProvider;
import org.apache.druid.discovery.NodeRole;
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.parsers.CloseableIterator;
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.response.HttpResponseHandler;
Expand Down Expand Up @@ -82,9 +89,11 @@
import java.io.File;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.Executor;
Expand Down Expand Up @@ -368,6 +377,38 @@ public ListenableFuture<URI> findCurrentLeader()
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(
Expand Down