![JAR search and dependency download from the Maven repository](/logo.png)
io.trino.metadata.MaterializedViewDefinition 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.metadata;
import com.google.common.collect.ImmutableMap;
import io.trino.spi.connector.CatalogSchemaName;
import io.trino.spi.connector.CatalogSchemaTableName;
import io.trino.spi.connector.ConnectorMaterializedViewDefinition;
import io.trino.spi.security.Identity;
import java.time.Duration;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import static com.google.common.base.MoreObjects.toStringHelper;
import static com.google.common.base.Preconditions.checkArgument;
import static com.google.common.collect.ImmutableList.toImmutableList;
import static java.util.Objects.requireNonNull;
public class MaterializedViewDefinition
extends ViewDefinition
{
private final Optional gracePeriod;
private final Optional storageTable;
private final Map properties;
public MaterializedViewDefinition(
String originalSql,
Optional catalog,
Optional schema,
List columns,
Optional gracePeriod,
Optional comment,
Identity owner,
List path,
Optional storageTable,
Map properties)
{
super(originalSql, catalog, schema, columns, comment, Optional.of(owner), path);
checkArgument(gracePeriod.isEmpty() || !gracePeriod.get().isNegative(), "gracePeriod cannot be negative: %s", gracePeriod);
this.gracePeriod = gracePeriod;
this.storageTable = requireNonNull(storageTable, "storageTable is null");
this.properties = ImmutableMap.copyOf(requireNonNull(properties, "properties is null"));
}
public Optional getGracePeriod()
{
return gracePeriod;
}
public Optional getStorageTable()
{
return storageTable;
}
public Map getProperties()
{
return properties;
}
public ConnectorMaterializedViewDefinition toConnectorMaterializedViewDefinition()
{
return new ConnectorMaterializedViewDefinition(
getOriginalSql(),
storageTable,
getCatalog(),
getSchema(),
getColumns().stream()
.map(column -> new ConnectorMaterializedViewDefinition.Column(column.getName(), column.getType(), column.getComment()))
.collect(toImmutableList()),
getGracePeriod(),
getComment(),
getRunAsIdentity().map(Identity::getUser),
getPath(),
properties);
}
@Override
public String toString()
{
return toStringHelper(this).omitNullValues()
.add("originalSql", getOriginalSql())
.add("catalog", getCatalog().orElse(null))
.add("schema", getSchema().orElse(null))
.add("columns", getColumns())
.add("gracePeriod", gracePeriod.orElse(null))
.add("comment", getComment().orElse(null))
.add("runAsIdentity", getRunAsIdentity())
.add("path", getPath())
.add("storageTable", storageTable.orElse(null))
.add("properties", properties)
.toString();
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy