@Override public OperationHandle getTables(String catalogName, String schemaName, String tableName, List<String> tableTypes) throws HiveSQLException { acquire(true, true); OperationManager operationManager = getOperationManager(); MetadataOperation operation = operationManager.newGetTablesOperation(getSession(), catalogName, schemaName, tableName, tableTypes); OperationHandle opHandle = operation.getHandle(); try { addOpHandle(opHandle); operation.run(); return opHandle; } catch (HiveSQLException e) { removeOpHandle(opHandle); operationManager.closeOperation(opHandle); throw e; } finally { release(true, true); } }
public GetTableTypesOperation newGetTableTypesOperation(HiveSession parentSession) { GetTableTypesOperation operation = new GetTableTypesOperation(parentSession); addOperation(operation); return operation; }
/** * Cancel the running operation unless it is already in a terminal state * @param opHandle * @throws HiveSQLException */ public void cancelOperation(OperationHandle opHandle) throws HiveSQLException { cancelOperation(opHandle, ""); }
@Override public RowSet fetchResults(OperationHandle opHandle, FetchOrientation orientation, long maxRows, FetchType fetchType) throws HiveSQLException { acquire(true, false); try { if (fetchType == FetchType.QUERY_OUTPUT) { return operationManager.getOperationNextRowSet(opHandle, orientation, maxRows); } return operationManager.getOperationLogRowSet(opHandle, orientation, maxRows, sessionConf); } finally { release(true, false); } }
/** * Cancel the running operation unless it is already in a terminal state * @param opHandle operation handle * @param errMsg error message * @throws HiveSQLException */ public void cancelOperation(OperationHandle opHandle, String errMsg) throws HiveSQLException { Operation operation = getOperation(opHandle); OperationState opState = operation.getStatus().getState(); if (opState.isTerminal()) { // Cancel should be a no-op in either cases LOG.debug(opHandle + ": Operation is already aborted in state - " + opState); } else { LOG.debug(opHandle + ": Attempting to cancel from state - " + opState); OperationState operationState = OperationState.CANCELED; operationState.setErrorMessage(errMsg); operation.cancel(operationState); if (operation instanceof SQLOperation) { removeSafeQueryInfo(opHandle); } } }
public RowSet getOperationLogRowSet(OperationHandle opHandle, FetchOrientation orientation, long maxRows, HiveConf hConf) throws HiveSQLException { TableSchema tableSchema = new TableSchema(getLogSchema()); RowSet rowSet = RowSetFactory.create(tableSchema, getOperation(opHandle).getProtocolVersion(), false); if (hConf.getBoolVar(ConfVars.HIVE_SERVER2_LOGGING_OPERATION_ENABLED) == false) { LOG.warn("Try to get operation log when hive.server2.logging.operation.enabled is false, no log will be returned. "); return rowSet; } // get the OperationLog object from the operation OperationLog operationLog = getOperation(opHandle).getOperationLog(); if (operationLog == null) { throw new HiveSQLException("Couldn't find log associated with operation handle: " + opHandle); } // read logs List<String> logs; try { logs = operationLog.readOperationLog(isFetchFirst(orientation), maxRows); } catch (SQLException e) { throw new HiveSQLException(e.getMessage(), e.getCause()); } // convert logs to RowSet for (String log : logs) { rowSet.addRow(new String[] { log }); } return rowSet; }
public TableSchema getOperationResultSetSchema(OperationHandle opHandle) throws HiveSQLException { return getOperation(opHandle).getResultSetSchema(); }
@Override public OperationHandle getCatalogs() throws HiveSQLException { acquire(true, true); OperationManager operationManager = getOperationManager(); GetCatalogsOperation operation = operationManager.newGetCatalogsOperation(getSession()); OperationHandle opHandle = operation.getHandle(); try { addOpHandle(opHandle); operation.run(); return opHandle; } catch (HiveSQLException e) { removeOpHandle(opHandle); operationManager.closeOperation(opHandle); throw e; } finally { release(true, true); } }
@Override public void closeOperation(OperationHandle opHandle) throws HiveSQLException { acquire(true, false); try { operationManager.closeOperation(opHandle); synchronized (opHandleSet) { opHandleSet.remove(opHandle); } } finally { release(true, false); } }
@Override public OperationHandle getTypeInfo() throws HiveSQLException { acquire(true, true); OperationManager operationManager = getOperationManager(); GetTypeInfoOperation operation = operationManager.newGetTypeInfoOperation(getSession()); OperationHandle opHandle = operation.getHandle(); try { addOpHandle(opHandle); operation.run(); return opHandle; } catch (HiveSQLException e) { removeOpHandle(opHandle); operationManager.closeOperation(opHandle); throw e; } finally { release(true, true); } }
@Override public OperationHandle getTableTypes() throws HiveSQLException { acquire(true, true); OperationManager operationManager = getOperationManager(); GetTableTypesOperation operation = operationManager.newGetTableTypesOperation(getSession()); OperationHandle opHandle = operation.getHandle(); try { addOpHandle(opHandle); operation.run(); return opHandle; } catch (HiveSQLException e) { removeOpHandle(opHandle); operationManager.closeOperation(opHandle); throw e; } finally { release(true, true); } }
@Override public OperationHandle getSchemas(String catalogName, String schemaName) throws HiveSQLException { acquire(true, true); OperationManager operationManager = getOperationManager(); GetSchemasOperation operation = operationManager.newGetSchemasOperation(getSession(), catalogName, schemaName); OperationHandle opHandle = operation.getHandle(); try { addOpHandle(opHandle); operation.run(); return opHandle; } catch (HiveSQLException e) { removeOpHandle(opHandle); operationManager.closeOperation(opHandle); throw e; } finally { release(true, true); } }
@Override public OperationHandle getFunctions(String catalogName, String schemaName, String functionName) throws HiveSQLException { acquire(true, true); OperationManager operationManager = getOperationManager(); GetFunctionsOperation operation = operationManager .newGetFunctionsOperation(getSession(), catalogName, schemaName, functionName); OperationHandle opHandle = operation.getHandle(); try { addOpHandle(opHandle); operation.run(); return opHandle; } catch (HiveSQLException e) { removeOpHandle(opHandle); operationManager.closeOperation(opHandle); throw e; } finally { release(true, true); } }
@Override public TableSchema getResultSetMetadata(OperationHandle opHandle) throws HiveSQLException { acquire(true, true); try { return sessionManager.getOperationManager().getOperationResultSetSchema(opHandle); } finally { release(true, true); } }
public Operation getOperation(OperationHandle operationHandle) throws HiveSQLException { Operation operation = getOperationInternal(operationHandle); if (operation == null) { throw new HiveSQLException("Invalid OperationHandle: " + operationHandle); } return operation; }
@Override public OperationHandle getColumns(String catalogName, String schemaName, String tableName, String columnName) throws HiveSQLException { acquire(true, true); String addedJars = Utilities.getResourceFiles(sessionConf, SessionState.ResourceType.JAR); if (StringUtils.isNotBlank(addedJars)) { IMetaStoreClient metastoreClient = getSession().getMetaStoreClient(); metastoreClient.setHiveAddedJars(addedJars); } OperationManager operationManager = getOperationManager(); GetColumnsOperation operation = operationManager.newGetColumnsOperation(getSession(), catalogName, schemaName, tableName, columnName); OperationHandle opHandle = operation.getHandle(); try { addOpHandle(opHandle); operation.run(); return opHandle; } catch (HiveSQLException e) { removeOpHandle(opHandle); operationManager.closeOperation(opHandle); throw e; } finally { release(true, true); } }
private OperationHandle executeStatementInternal(String statement, Map<String, String> confOverlay, boolean runAsync, long queryTimeout) throws HiveSQLException { acquire(true, true); LOG.info("executing " + statement); ExecuteStatementOperation operation = null; OperationHandle opHandle = null; try { operation = getOperationManager().newExecuteStatementOperation(getSession(), statement, confOverlay, runAsync, queryTimeout); opHandle = operation.getHandle(); addOpHandle(opHandle); operation.run(); return opHandle; } catch (HiveSQLException e) { // Refering to SQLOperation.java, there is no chance that a HiveSQLException throws and the // async background operation submits to thread pool successfully at the same time. So, Cleanup // opHandle directly when got HiveSQLException if (opHandle != null) { removeOpHandle(opHandle); getOperationManager().closeOperation(opHandle); } throw e; } finally { if (operation == null || operation.getBackgroundHandle() == null) { release(true, true); // Not async, or wasn't submitted for some reason (failure, etc.) } else { releaseBeforeOpLock(true); // Release, but keep the lock (if present). } } }
OperationManager operationManager = mock(OperationManager.class); when(operationManager. newGetTablesOperation(session, "catalog", "schema", "table", null)) .thenReturn(new BlockingOperation(session, OperationType.GET_TABLES, ready, completed)); session.setOperationManager(operationManager);
@Override public OperationHandle getPrimaryKeys(String catalog, String schema, String table) throws HiveSQLException { acquire(true, true); OperationManager operationManager = getOperationManager(); GetPrimaryKeysOperation operation = operationManager .newGetPrimaryKeysOperation(getSession(), catalog, schema, table); OperationHandle opHandle = operation.getHandle(); try { addOpHandle(opHandle); operation.run(); return opHandle; } catch (HiveSQLException e) { removeOpHandle(opHandle); operationManager.closeOperation(opHandle); throw e; } finally { release(true, true); } }
@Override public OperationHandle getCrossReference(String primaryCatalog, String primarySchema, String primaryTable, String foreignCatalog, String foreignSchema, String foreignTable) throws HiveSQLException { acquire(true, true); OperationManager operationManager = getOperationManager(); GetCrossReferenceOperation operation = operationManager .newGetCrossReferenceOperation(getSession(), primaryCatalog, primarySchema, primaryTable, foreignCatalog, foreignSchema, foreignTable); OperationHandle opHandle = operation.getHandle(); try { addOpHandle(opHandle); operation.run(); return opHandle; } catch (HiveSQLException e) { removeOpHandle(opHandle); operationManager.closeOperation(opHandle); throw e; } finally { release(true, true); } }