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 org.apache.hadoop.hive.conf.HiveConf;
0022 import org.apache.hadoop.hive.metastore.TableType;
0023 import org.apache.hadoop.hive.ql.security.authorization.plugin.HiveOperationType;
0024 import org.apache.hive.service.cli.FetchOrientation;
0025 import org.apache.hive.service.cli.HiveSQLException;
0026 import org.apache.hive.service.cli.OperationState;
0027 import org.apache.hive.service.cli.OperationType;
0028 import org.apache.hive.service.cli.RowSet;
0029 import org.apache.hive.service.cli.RowSetFactory;
0030 import org.apache.hive.service.cli.TableSchema;
0031 import org.apache.hive.service.cli.session.HiveSession;
0032 
0033 /**
0034  * GetTableTypesOperation.
0035  *
0036  */
0037 public class GetTableTypesOperation extends MetadataOperation {
0038 
0039   protected static TableSchema RESULT_SET_SCHEMA = new TableSchema()
0040   .addStringColumn("TABLE_TYPE", "Table type name.");
0041 
0042   protected final RowSet rowSet;
0043   private final TableTypeMapping tableTypeMapping;
0044 
0045   protected GetTableTypesOperation(HiveSession parentSession) {
0046     super(parentSession, OperationType.GET_TABLE_TYPES);
0047     String tableMappingStr = getParentSession().getHiveConf()
0048       .getVar(HiveConf.ConfVars.HIVE_SERVER2_TABLE_TYPE_MAPPING);
0049     tableTypeMapping =
0050       TableTypeMappingFactory.getTableTypeMapping(tableMappingStr);
0051     rowSet = RowSetFactory.create(RESULT_SET_SCHEMA, getProtocolVersion(), false);
0052   }
0053 
0054   @Override
0055   public void runInternal() throws HiveSQLException {
0056     setState(OperationState.RUNNING);
0057     if (isAuthV2Enabled()) {
0058       authorizeMetaGets(HiveOperationType.GET_TABLETYPES, null);
0059     }
0060     try {
0061       for (TableType type : TableType.values()) {
0062         rowSet.addRow(new String[] {tableTypeMapping.mapToClientType(type.toString())});
0063       }
0064       setState(OperationState.FINISHED);
0065     } catch (Exception e) {
0066       setState(OperationState.ERROR);
0067       throw new HiveSQLException(e);
0068     }
0069   }
0070 
0071   /* (non-Javadoc)
0072    * @see org.apache.hive.service.cli.Operation#getResultSetSchema()
0073    */
0074   @Override
0075   public TableSchema getResultSetSchema() throws HiveSQLException {
0076     assertState(OperationState.FINISHED);
0077     return RESULT_SET_SCHEMA;
0078   }
0079 
0080   /* (non-Javadoc)
0081    * @see org.apache.hive.service.cli.Operation#getNextRowSet(org.apache.hive.service.cli.FetchOrientation, long)
0082    */
0083   @Override
0084   public RowSet getNextRowSet(FetchOrientation orientation, long maxRows) throws HiveSQLException {
0085     assertState(OperationState.FINISHED);
0086     validateDefaultFetchOrientation(orientation);
0087     if (orientation.equals(FetchOrientation.FETCH_FIRST)) {
0088       rowSet.setStartOffset(0);
0089     }
0090     return rowSet.extractSubset((int)maxRows);
0091   }
0092 
0093 }