com.facebook.presto.atop.AtopMetadata 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.atop;
import com.facebook.presto.atop.AtopTable.AtopColumn;
import com.facebook.presto.common.predicate.Domain;
import com.facebook.presto.common.type.TypeManager;
import com.facebook.presto.spi.ColumnHandle;
import com.facebook.presto.spi.ColumnMetadata;
import com.facebook.presto.spi.ColumnNotFoundException;
import com.facebook.presto.spi.ConnectorSession;
import com.facebook.presto.spi.ConnectorTableHandle;
import com.facebook.presto.spi.ConnectorTableLayout;
import com.facebook.presto.spi.ConnectorTableLayoutHandle;
import com.facebook.presto.spi.ConnectorTableLayoutResult;
import com.facebook.presto.spi.ConnectorTableMetadata;
import com.facebook.presto.spi.Constraint;
import com.facebook.presto.spi.SchemaTableName;
import com.facebook.presto.spi.SchemaTablePrefix;
import com.facebook.presto.spi.connector.ConnectorMetadata;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableMap;
import javax.inject.Inject;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import static com.facebook.presto.atop.AtopTable.AtopColumn.END_TIME;
import static com.facebook.presto.atop.AtopTable.AtopColumn.START_TIME;
import static com.facebook.presto.common.type.TimestampWithTimeZoneType.TIMESTAMP_WITH_TIME_ZONE;
import static java.util.Objects.requireNonNull;
public class AtopMetadata
implements ConnectorMetadata
{
private static final AtopColumnHandle START_TIME_HANDLE = new AtopColumnHandle(START_TIME.getName());
private static final AtopColumnHandle END_TIME_HANDLE = new AtopColumnHandle(END_TIME.getName());
private final TypeManager typeManager;
private final String environment;
@Inject
public AtopMetadata(TypeManager typeManager, Environment environment)
{
this.typeManager = requireNonNull(typeManager, "typeManager is null");
this.environment = requireNonNull(environment, "environment is null").toString();
}
@Override
public List listSchemaNames(ConnectorSession session)
{
return ImmutableList.of("default", environment);
}
@Override
public ConnectorTableHandle getTableHandle(ConnectorSession session, SchemaTableName tableName)
{
requireNonNull(tableName, "tableName is null");
String schemaName = tableName.getSchemaName();
if (!listSchemaNames(session).contains(schemaName)) {
return null;
}
try {
AtopTable table = AtopTable.valueOf(tableName.getTableName().toUpperCase());
return new AtopTableHandle(schemaName, table);
}
catch (IllegalArgumentException e) {
return null;
}
}
@Override
public List getTableLayouts(ConnectorSession session,
ConnectorTableHandle table,
Constraint constraint,
Optional> desiredColumns)
{
AtopTableHandle tableHandle = (AtopTableHandle) table;
Optional
© 2015 - 2025 Weber Informatics LLC | Privacy Policy