Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * 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.connector.system;
 
 
 import java.util.List;
 import java.util.Map;
 
 import static com.facebook.presto.connector.system.SystemColumnHandle.toSystemColumnHandles;
 import static com.facebook.presto.metadata.MetadataUtil.findColumnMetadata;
 import static com.facebook.presto.util.Types.checkType;
 import static com.google.common.base.Preconditions.checkArgument;
 import static com.google.common.base.Preconditions.checkNotNull;
 import static com.google.common.base.Predicates.compose;
 import static com.google.common.base.Predicates.equalTo;
 import static com.google.common.collect.Iterables.filter;
 import static com.google.common.collect.Iterables.transform;
 
 public class SystemTablesMetadata
         extends ReadOnlyConnectorMetadata
 {
 
     public void addTable(ConnectorTableMetadata tableMetadata)
     {
         checkArgument(.putIfAbsent(tableMetadata.getTable(), tableMetadata) == null"Table %s is already registered"tableMetadata.getTable());
     }
 
     {
         SystemTableHandle systemTableHandle = checkType(tableHandleSystemTableHandle.class"tableHandle");
         checkArgument(.containsKey(systemTableHandle.getSchemaTableName()));
         return systemTableHandle;
     }
 
     @Override
     public List<StringlistSchemaNames(ConnectorSession session)
     {
         // remove duplicates
         ImmutableSet<StringschemaNames = ImmutableSet.copyOf(transform(.keySet(), SchemaTableName::getSchemaName));
         return ImmutableList.copyOf(schemaNames);
     }
 
     @Override
     public ConnectorTableHandle getTableHandle(ConnectorSession sessionSchemaTableName tableName)
     {
         if (!.containsKey(tableName)) {
             return null;
         }
         return new SystemTableHandle(tableName);
     }
 
     @Override
     {
         SystemTableHandle systemTableHandle = checkTableHandle(tableHandle);
         return .get(systemTableHandle.getSchemaTableName());
     }
 
     @Override
     public List<SchemaTableNamelistTables(ConnectorSession sessionString schemaNameOrNull)
     {
         if (schemaNameOrNull == null) {
             return ImmutableList.copyOf(.keySet());
         }
 
         return ImmutableList.copyOf(filter(.keySet(), compose(equalTo(schemaNameOrNull), SchemaTableName::getSchemaName)));
     }
 
     @Override
     {
         return null;
     }
    @Override
    public ColumnMetadata getColumnMetadata(ConnectorTableHandle tableHandleConnectorColumnHandle columnHandle)
    {
        SystemTableHandle systemTableHandle = checkTableHandle(tableHandle);
        ConnectorTableMetadata tableMetadata = .get(systemTableHandle.getSchemaTableName());
        String columnName = checkType(columnHandleSystemColumnHandle.class"columnHandle").getColumnName();
        ColumnMetadata columnMetadata = findColumnMetadata(tableMetadatacolumnName);
        checkArgument(columnMetadata != null"Column %s on table %s does not exist"columnNametableMetadata.getTable());
        return columnMetadata;
    }
    @Override
    {
        SystemTableHandle systemTableHandle = checkTableHandle(tableHandle);
        return toSystemColumnHandles(.get(systemTableHandle.getSchemaTableName()));
    }
    @Override
    {
        checkNotNull(prefix"prefix is null");
        ImmutableMap.Builder<SchemaTableNameList<ColumnMetadata>> builder = ImmutableMap.builder();
        for (Entry<SchemaTableNameConnectorTableMetadataentry : .entrySet()) {
            if (prefix.matches(entry.getKey())) {
                builder.put(entry.getKey(), entry.getValue().getColumns());
            }
        }
        return builder.build();
    }
New to GrepCode? Check out our FAQ X