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.ql.security.authorization.plugin.HiveOperationType;
0022 import org.apache.hive.service.cli.FetchOrientation;
0023 import org.apache.hive.service.cli.HiveSQLException;
0024 import org.apache.hive.service.cli.OperationState;
0025 import org.apache.hive.service.cli.OperationType;
0026 import org.apache.hive.service.cli.RowSet;
0027 import org.apache.hive.service.cli.RowSetFactory;
0028 import org.apache.hive.service.cli.TableSchema;
0029 import org.apache.hive.service.cli.session.HiveSession;
0030 
0031 /**
0032  * GetCatalogsOperation.
0033  *
0034  */
0035 public class GetCatalogsOperation extends MetadataOperation {
0036   private static final TableSchema RESULT_SET_SCHEMA = new TableSchema()
0037   .addStringColumn("TABLE_CAT", "Catalog name. NULL if not applicable.");
0038 
0039   protected final RowSet rowSet;
0040 
0041   protected GetCatalogsOperation(HiveSession parentSession) {
0042     super(parentSession, OperationType.GET_CATALOGS);
0043     rowSet = RowSetFactory.create(RESULT_SET_SCHEMA, getProtocolVersion());
0044   }
0045 
0046   @Override
0047   public void runInternal() throws HiveSQLException {
0048     setState(OperationState.RUNNING);
0049     try {
0050       if (isAuthV2Enabled()) {
0051         authorizeMetaGets(HiveOperationType.GET_CATALOGS, null);
0052       }
0053       setState(OperationState.FINISHED);
0054     } catch (HiveSQLException e) {
0055       setState(OperationState.ERROR);
0056       throw e;
0057     }
0058 
0059   }
0060 
0061   /* (non-Javadoc)
0062    * @see org.apache.hive.service.cli.Operation#getResultSetSchema()
0063    */
0064   @Override
0065   public TableSchema getResultSetSchema() throws HiveSQLException {
0066     return RESULT_SET_SCHEMA;
0067   }
0068 
0069   /* (non-Javadoc)
0070    * @see org.apache.hive.service.cli.Operation#getNextRowSet(org.apache.hive.service.cli.FetchOrientation, long)
0071    */
0072   @Override
0073   public RowSet getNextRowSet(FetchOrientation orientation, long maxRows) throws HiveSQLException {
0074     assertState(OperationState.FINISHED);
0075     validateDefaultFetchOrientation(orientation);
0076     if (orientation.equals(FetchOrientation.FETCH_FIRST)) {
0077       rowSet.setStartOffset(0);
0078     }
0079     return rowSet.extractSubset((int)maxRows);
0080   }
0081 }