All Downloads are FREE. Search and download functionalities are using the official Maven repository.
Please wait. This can take some minutes ...
Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance.
Project price only 1 $
You can buy this project and download/modify it how often you want.
io.trino.server.QueryStateInfo Maven / Gradle / Ivy
/*
* Licensed 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 io.trino.server;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.google.common.collect.ImmutableList;
import io.trino.execution.QueryState;
import io.trino.spi.QueryId;
import io.trino.spi.resourcegroups.ResourceGroupId;
import org.joda.time.DateTime;
import java.util.List;
import java.util.Optional;
import static io.trino.execution.QueryState.QUEUED;
import static io.trino.server.QueryProgressStats.createQueryProgressStats;
import static java.util.Objects.requireNonNull;
public class QueryStateInfo
{
private final QueryState queryState;
private final QueryId queryId;
private final Optional resourceGroupId;
private final String query;
private final DateTime createTime;
private final String user;
private final Optional source;
private final Optional clientInfo;
private final Optional catalog;
private final Optional schema;
private final Optional> pathToRoot;
private final Optional progress;
@JsonCreator
public QueryStateInfo(
@JsonProperty("queryId") QueryId queryId,
@JsonProperty("queryState") QueryState queryState,
@JsonProperty("resourceGroupId") Optional resourceGroupId,
@JsonProperty("query") String query,
@JsonProperty("createTime") DateTime createTime,
@JsonProperty("user") String user,
@JsonProperty("source") Optional source,
@JsonProperty("clientInfo") Optional clientInfo,
@JsonProperty("catalog") Optional catalog,
@JsonProperty("schema") Optional schema,
@JsonProperty("pathToRoot") Optional> pathToRoot,
@JsonProperty("progress") Optional progress)
{
this.queryId = requireNonNull(queryId, "queryId is null");
this.queryState = requireNonNull(queryState, "queryState is null");
this.resourceGroupId = requireNonNull(resourceGroupId, "resourceGroupId is null");
this.query = requireNonNull(query, "query text is null");
this.createTime = requireNonNull(createTime, "createTime is null");
this.user = requireNonNull(user, "user is null");
this.source = requireNonNull(source, "source is null");
this.clientInfo = requireNonNull(clientInfo, "clientInfo is null");
this.catalog = requireNonNull(catalog, "catalog is null");
this.schema = requireNonNull(schema, "schema is null");
requireNonNull(pathToRoot, "pathToRoot is null");
this.pathToRoot = pathToRoot.map(ImmutableList::copyOf);
this.progress = requireNonNull(progress, "progress is null");
}
public static QueryStateInfo createQueuedQueryStateInfo(BasicQueryInfo queryInfo, Optional group, Optional> pathToRoot)
{
return createQueryStateInfo(queryInfo, group, pathToRoot, Optional.empty());
}
public static QueryStateInfo createQueryStateInfo(BasicQueryInfo queryInfo, Optional group)
{
Optional progress = Optional.empty();
if (!queryInfo.getState().isDone() && queryInfo.getState() != QUEUED) {
progress = Optional.of(createQueryProgressStats(queryInfo.getQueryStats()));
}
return createQueryStateInfo(queryInfo, group, Optional.empty(), progress);
}
private static QueryStateInfo createQueryStateInfo(
BasicQueryInfo queryInfo,
Optional groupId,
Optional> pathToRoot,
Optional progress)
{
return new QueryStateInfo(
queryInfo.getQueryId(),
queryInfo.getState(),
groupId,
queryInfo.getQuery(),
queryInfo.getQueryStats().getCreateTime(),
queryInfo.getSession().getUser(),
queryInfo.getSession().getSource(),
queryInfo.getSession().getClientInfo(),
queryInfo.getSession().getCatalog(),
queryInfo.getSession().getSchema(),
pathToRoot,
progress);
}
@JsonProperty
public QueryId getQueryId()
{
return queryId;
}
@JsonProperty
public QueryState getQueryState()
{
return queryState;
}
@JsonProperty
public Optional getResourceGroupId()
{
return resourceGroupId;
}
@JsonProperty
public String getQuery()
{
return query;
}
@JsonProperty
public String getUser()
{
return user;
}
@JsonProperty
public Optional getSource()
{
return source;
}
@JsonProperty
public Optional getClientInfo()
{
return clientInfo;
}
@JsonProperty
public Optional getCatalog()
{
return catalog;
}
@JsonProperty
public Optional getSchema()
{
return schema;
}
@JsonProperty
public Optional> getPathToRoot()
{
return pathToRoot;
}
@JsonProperty
public DateTime getCreateTime()
{
return createTime;
}
@JsonProperty
public Optional getProgress()
{
return progress;
}
}