0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
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
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());
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
0072
0073
0074 @Override
0075 public TableSchema getResultSetSchema() throws HiveSQLException {
0076 assertState(OperationState.FINISHED);
0077 return RESULT_SET_SCHEMA;
0078 }
0079
0080
0081
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 }