com.facebook.presto.jdbc.internal.spi.analyzer.ViewDefinition 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 com.facebook.presto.jdbc.internal.spi.analyzer;
import com.facebook.presto.jdbc.internal.common.type.Type;
import com.facebook.presto.jdbc.internal.jackson.annotation.JsonCreator;
import com.facebook.presto.jdbc.internal.jackson.annotation.JsonProperty;
import java.util.List;
import java.util.Optional;
import static java.util.Collections.unmodifiableList;
import static java.util.Objects.requireNonNull;
public final class ViewDefinition
{
private final String originalSql;
private final Optional catalog;
private final Optional schema;
private final List columns;
private final Optional owner;
private final boolean runAsInvoker;
@JsonCreator
public ViewDefinition(
@JsonProperty("originalSql") String originalSql,
@JsonProperty("catalog") Optional catalog,
@JsonProperty("schema") Optional schema,
@JsonProperty("columns") List columns,
@JsonProperty("owner") Optional owner,
@JsonProperty("runAsInvoker") boolean runAsInvoker)
{
this.originalSql = requireNonNull(originalSql, "originalSql is null");
this.catalog = requireNonNull(catalog, "catalog is null");
this.schema = requireNonNull(schema, "schema is null");
this.columns = unmodifiableList(requireNonNull(columns, "columns is null"));
this.owner = requireNonNull(owner, "owner is null");
this.runAsInvoker = runAsInvoker;
if (runAsInvoker && owner.isPresent()) {
throw new IllegalArgumentException("owner cannot be present with runAsInvoker");
}
}
@JsonProperty
public String getOriginalSql()
{
return originalSql;
}
@JsonProperty
public Optional getCatalog()
{
return catalog;
}
@JsonProperty
public Optional getSchema()
{
return schema;
}
@JsonProperty
public List getColumns()
{
return columns;
}
@JsonProperty
public Optional getOwner()
{
return owner;
}
@JsonProperty
public boolean isRunAsInvoker()
{
return runAsInvoker;
}
@Override
public String toString()
{
return "ViewDefinition{" +
"originalSql='" + originalSql + '\'' +
", catalog=" + catalog.orElse(null) +
", schema=" + schema.orElse(null) +
", columns=" + columns +
", owner=" + owner.orElse(null) +
", runAsInvoker=" + runAsInvoker +
'}';
}
public ViewDefinition withOwner(String owner)
{
return new ViewDefinition(originalSql, catalog, schema, columns, Optional.of(owner), runAsInvoker);
}
public static final class ViewColumn
{
private final String name;
private final Type type;
@JsonCreator
public ViewColumn(
@JsonProperty("name") String name,
@JsonProperty("type") Type type)
{
this.name = requireNonNull(name, "name is null");
this.type = requireNonNull(type, "type is null");
}
@JsonProperty
public String getName()
{
return name;
}
@JsonProperty
public Type getType()
{
return type;
}
@Override
public String toString()
{
return name + ":" + type;
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy