Back to home page

OSCL-LXR

 
 

    


0001 /**
0002  * Licensed to the Apache Software Foundation (ASF) under one
0003  * or more contributor license agreements.  See the NOTICE file
0004  * distributed with this work for additional information
0005  * regarding copyright ownership.  The ASF licenses this file
0006  * to you under the Apache License, Version 2.0 (the
0007  * "License"); you may not use this file except in compliance
0008  * with the License.  You may obtain a copy of the License at
0009  *
0010  *     http://www.apache.org/licenses/LICENSE-2.0
0011  *
0012  * Unless required by applicable law or agreed to in writing, software
0013  * distributed under the License is distributed on an "AS IS" BASIS,
0014  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
0015  * See the License for the specific language governing permissions and
0016  * limitations under the License.
0017  */
0018 
0019 package org.apache.hive.service.cli.operation;
0020 
0021 import java.util.HashMap;
0022 import java.util.HashSet;
0023 import java.util.Map;
0024 import java.util.Set;
0025 
0026 import org.apache.hadoop.hive.metastore.TableType;
0027 
0028 /**
0029  * ClassicTableTypeMapping.
0030  * Classic table type mapping :
0031  *  Managed Table to Table
0032  *  External Table to Table
0033  *  Virtual View to View
0034  */
0035 public class ClassicTableTypeMapping implements TableTypeMapping {
0036 
0037   public enum ClassicTableTypes {
0038     TABLE,
0039     VIEW,
0040   }
0041 
0042   private final Map<String, String> hiveToClientMap = new HashMap<String, String>();
0043   private final Map<String, String> clientToHiveMap = new HashMap<String, String>();
0044 
0045   public ClassicTableTypeMapping() {
0046     hiveToClientMap.put(TableType.MANAGED_TABLE.toString(),
0047         ClassicTableTypes.TABLE.toString());
0048     hiveToClientMap.put(TableType.EXTERNAL_TABLE.toString(),
0049         ClassicTableTypes.TABLE.toString());
0050     hiveToClientMap.put(TableType.VIRTUAL_VIEW.toString(),
0051         ClassicTableTypes.VIEW.toString());
0052 
0053     clientToHiveMap.put(ClassicTableTypes.TABLE.toString(),
0054         TableType.MANAGED_TABLE.toString());
0055     clientToHiveMap.put(ClassicTableTypes.VIEW.toString(),
0056         TableType.VIRTUAL_VIEW.toString());
0057   }
0058 
0059   @Override
0060   public String mapToHiveType(String clientTypeName) {
0061     if (clientToHiveMap.containsKey(clientTypeName)) {
0062       return clientToHiveMap.get(clientTypeName);
0063     } else {
0064       return clientTypeName;
0065     }
0066   }
0067 
0068   @Override
0069   public String mapToClientType(String hiveTypeName) {
0070     if (hiveToClientMap.containsKey(hiveTypeName)) {
0071       return hiveToClientMap.get(hiveTypeName);
0072     } else {
0073       return hiveTypeName;
0074     }
0075   }
0076 
0077   @Override
0078   public Set<String> getTableTypeNames() {
0079     Set<String> typeNameSet = new HashSet<String>();
0080     for (ClassicTableTypes typeNames : ClassicTableTypes.values()) {
0081       typeNameSet.add(typeNames.toString());
0082     }
0083     return typeNameSet;
0084   }
0085 
0086 }