@Override public String getQueryId(TOperationHandle opHandle) throws HiveSQLException { Operation operation = sessionManager.getOperationManager().getOperation( new OperationHandle(opHandle)); final String queryId = operation.getQueryId(); LOG.debug(opHandle + ": getQueryId() " + queryId); return queryId; }
@Override public TCancelOperationResp CancelOperation(TCancelOperationReq req) throws TException { TCancelOperationResp resp = new TCancelOperationResp(); try { cliService.cancelOperation(new OperationHandle(req.getOperationHandle())); resp.setStatus(OK_STATUS); } catch (Exception e) { LOG.warn("Error cancelling operation: ", e); resp.setStatus(HiveSQLException.toTStatus(e)); } return resp; }
@Override public TCloseOperationResp CloseOperation(TCloseOperationReq req) throws TException { TCloseOperationResp resp = new TCloseOperationResp(); try { cliService.closeOperation(new OperationHandle(req.getOperationHandle())); resp.setStatus(OK_STATUS); } catch (Exception e) { LOG.warn("Error closing operation: ", e); resp.setStatus(HiveSQLException.toTStatus(e)); } return resp; }
protected Operation(HiveSession parentSession, Map<String, String> confOverlay, OperationType opType) { this.parentSession = parentSession; this.opHandle = new OperationHandle(opType, parentSession.getProtocolVersion()); opTerminateMonitorLatch = new CountDownLatch(1); beginTime = System.currentTimeMillis(); lastAccessTime = beginTime; operationTimeout = HiveConf.getTimeVar(parentSession.getHiveConf(), HiveConf.ConfVars.HIVE_SERVER2_IDLE_OPERATION_TIMEOUT, TimeUnit.MILLISECONDS); scheduledExecutorService = Executors.newScheduledThreadPool(1); currentStateScope = updateOperationStateMetrics(null, MetricsConstant.OPERATION_PREFIX, MetricsConstant.COMPLETED_OPERATION_PREFIX, state); queryState = new QueryState.Builder() .withConfOverlay(confOverlay) .withGenerateNewQueryId(true) .withHiveConf(parentSession.getHiveConf()) .build(); }
@Override public TGetResultSetMetadataResp GetResultSetMetadata(TGetResultSetMetadataReq req) throws TException { TGetResultSetMetadataResp resp = new TGetResultSetMetadataResp(); try { TableSchema schema = cliService.getResultSetMetadata(new OperationHandle(req.getOperationHandle())); resp.setSchema(schema.toTTableSchema()); resp.setStatus(OK_STATUS); } catch (Exception e) { LOG.warn("Error getting result set metadata: ", e); resp.setStatus(HiveSQLException.toTStatus(e)); } return resp; }
@Override public OperationHandle getTypeInfo(SessionHandle sessionHandle) throws HiveSQLException { try { TGetTypeInfoReq req = new TGetTypeInfoReq(sessionHandle.toTSessionHandle()); TGetTypeInfoResp resp = cliService.GetTypeInfo(req); checkStatus(resp.getStatus()); TProtocolVersion protocol = sessionHandle.getProtocolVersion(); return new OperationHandle(resp.getOperationHandle(), protocol); } catch (HiveSQLException e) { throw e; } catch (Exception e) { throw new HiveSQLException(e); } }
@Override public OperationHandle getCatalogs(SessionHandle sessionHandle) throws HiveSQLException { try { TGetCatalogsReq req = new TGetCatalogsReq(sessionHandle.toTSessionHandle()); TGetCatalogsResp resp = cliService.GetCatalogs(req); checkStatus(resp.getStatus()); TProtocolVersion protocol = sessionHandle.getProtocolVersion(); return new OperationHandle(resp.getOperationHandle(), protocol); } catch (HiveSQLException e) { throw e; } catch (Exception e) { throw new HiveSQLException(e); } }
@Override public OperationHandle getTableTypes(SessionHandle sessionHandle) throws HiveSQLException { try { TGetTableTypesReq req = new TGetTableTypesReq(sessionHandle.toTSessionHandle()); TGetTableTypesResp resp = cliService.GetTableTypes(req); checkStatus(resp.getStatus()); TProtocolVersion protocol = sessionHandle.getProtocolVersion(); return new OperationHandle(resp.getOperationHandle(), protocol); } catch (HiveSQLException e) { throw e; } catch (Exception e) { throw new HiveSQLException(e); } }
@Override public OperationHandle getFunctions(SessionHandle sessionHandle, String catalogName, String schemaName, String functionName) throws HiveSQLException { try { TGetFunctionsReq req = new TGetFunctionsReq(sessionHandle.toTSessionHandle(), functionName); req.setCatalogName(catalogName); req.setSchemaName(schemaName); TGetFunctionsResp resp = cliService.GetFunctions(req); checkStatus(resp.getStatus()); TProtocolVersion protocol = sessionHandle.getProtocolVersion(); return new OperationHandle(resp.getOperationHandle(), protocol); } catch (HiveSQLException e) { throw e; } catch (Exception e) { throw new HiveSQLException(e); } }
@Override public OperationHandle getSchemas(SessionHandle sessionHandle, String catalogName, String schemaName) throws HiveSQLException { try { TGetSchemasReq req = new TGetSchemasReq(sessionHandle.toTSessionHandle()); req.setCatalogName(catalogName); req.setSchemaName(schemaName); TGetSchemasResp resp = cliService.GetSchemas(req); checkStatus(resp.getStatus()); TProtocolVersion protocol = sessionHandle.getProtocolVersion(); return new OperationHandle(resp.getOperationHandle(), protocol); } catch (HiveSQLException e) { throw e; } catch (Exception e) { throw new HiveSQLException(e); } }
@Override public OperationHandle getPrimaryKeys(SessionHandle sessionHandle, String catalog, String schema, String table) throws HiveSQLException { try { TGetPrimaryKeysReq req = new TGetPrimaryKeysReq(sessionHandle.toTSessionHandle()); req.setCatalogName(catalog); req.setSchemaName(schema); req.setTableName(table); TGetPrimaryKeysResp resp = cliService.GetPrimaryKeys(req); checkStatus(resp.getStatus()); TProtocolVersion protocol = sessionHandle.getProtocolVersion(); return new OperationHandle(resp.getOperationHandle(), protocol); } catch (HiveSQLException e) { throw e; } catch (Exception e) { throw new HiveSQLException(e); } }
private OperationHandle executeStatementInternal(SessionHandle sessionHandle, String statement, Map<String, String> confOverlay, boolean isAsync, long queryTimeout) throws HiveSQLException { try { TExecuteStatementReq req = new TExecuteStatementReq(sessionHandle.toTSessionHandle(), statement); req.setConfOverlay(confOverlay); req.setRunAsync(isAsync); req.setQueryTimeout(queryTimeout); TExecuteStatementResp resp = cliService.ExecuteStatement(req); checkStatus(resp.getStatus()); TProtocolVersion protocol = sessionHandle.getProtocolVersion(); return new OperationHandle(resp.getOperationHandle(), protocol); } catch (HiveSQLException e) { throw e; } catch (Exception e) { throw new HiveSQLException(e); } }
@Override public OperationHandle getTables(SessionHandle sessionHandle, String catalogName, String schemaName, String tableName, List<String> tableTypes) throws HiveSQLException { try { TGetTablesReq req = new TGetTablesReq(sessionHandle.toTSessionHandle()); req.setTableName(tableName); req.setTableTypes(tableTypes); req.setSchemaName(schemaName); TGetTablesResp resp = cliService.GetTables(req); checkStatus(resp.getStatus()); TProtocolVersion protocol = sessionHandle.getProtocolVersion(); return new OperationHandle(resp.getOperationHandle(), protocol); } catch (HiveSQLException e) { throw e; } catch (Exception e) { throw new HiveSQLException(e); } }
@Override public TFetchResultsResp FetchResults(TFetchResultsReq req) throws TException { TFetchResultsResp resp = new TFetchResultsResp(); try { // Set fetch size int maxFetchSize = hiveConf.getIntVar(HiveConf.ConfVars.HIVE_SERVER2_THRIFT_RESULTSET_MAX_FETCH_SIZE); if (req.getMaxRows() > maxFetchSize) { req.setMaxRows(maxFetchSize); } RowSet rowSet = cliService.fetchResults( new OperationHandle(req.getOperationHandle()), FetchOrientation.getFetchOrientation(req.getOrientation()), req.getMaxRows(), FetchType.getFetchType(req.getFetchType())); resp.setResults(rowSet.toTRowSet()); resp.setHasMoreRows(false); resp.setStatus(OK_STATUS); } catch (Exception e) { LOG.warn("Error fetching results: ", e); resp.setStatus(HiveSQLException.toTStatus(e)); } return resp; }
@Override public OperationHandle getColumns(SessionHandle sessionHandle, String catalogName, String schemaName, String tableName, String columnName) throws HiveSQLException { try { TGetColumnsReq req = new TGetColumnsReq(); req.setSessionHandle(sessionHandle.toTSessionHandle()); req.setCatalogName(catalogName); req.setSchemaName(schemaName); req.setTableName(tableName); req.setColumnName(columnName); TGetColumnsResp resp = cliService.GetColumns(req); checkStatus(resp.getStatus()); TProtocolVersion protocol = sessionHandle.getProtocolVersion(); return new OperationHandle(resp.getOperationHandle(), protocol); } catch (HiveSQLException e) { throw e; } catch (Exception e) { throw new HiveSQLException(e); } }
@Override public OperationHandle getCrossReference(SessionHandle sessionHandle, String primaryCatalog, String primarySchema, String primaryTable, String foreignCatalog, String foreignSchema, String foreignTable) throws HiveSQLException { try { TGetCrossReferenceReq req = new TGetCrossReferenceReq(sessionHandle.toTSessionHandle()); req.setParentCatalogName(primaryCatalog); req.setParentSchemaName(primarySchema); req.setParentTableName(primaryTable); req.setForeignCatalogName(foreignCatalog); req.setForeignSchemaName(foreignSchema); req.setForeignTableName(foreignTable); TGetCrossReferenceResp resp = cliService.GetCrossReference(req); checkStatus(resp.getStatus()); TProtocolVersion protocol = sessionHandle.getProtocolVersion(); return new OperationHandle(resp.getOperationHandle(), protocol); } catch (HiveSQLException e) { throw e; } catch (Exception e) { throw new HiveSQLException(e); } }
@Override public TGetOperationStatusResp GetOperationStatus(TGetOperationStatusReq req) throws TException { TGetOperationStatusResp resp = new TGetOperationStatusResp(); OperationHandle operationHandle = new OperationHandle(req.getOperationHandle()); try { OperationStatus operationStatus =
protected Operation(HiveSession parentSession, OperationType opType, boolean runInBackground) { this.parentSession = parentSession; this.runAsync = runInBackground; this.opHandle = new OperationHandle(opType, parentSession.getProtocolVersion()); lastAccessTime = System.currentTimeMillis(); operationTimeout = HiveConf.getTimeVar(parentSession.getHiveConf(), HiveConf.ConfVars.HIVE_SERVER2_IDLE_OPERATION_TIMEOUT, TimeUnit.MILLISECONDS); }
protected Operation(HiveSession parentSession, OperationType opType, boolean runInBackground) { this.parentSession = parentSession; this.runAsync = runInBackground; this.opHandle = new OperationHandle(opType, parentSession.getProtocolVersion()); lastAccessTime = System.currentTimeMillis(); operationTimeout = HiveConf.getTimeVar(parentSession.getHiveConf(), HiveConf.ConfVars.HIVE_SERVER2_IDLE_OPERATION_TIMEOUT, TimeUnit.MILLISECONDS); }
@Override public String getQueryId(TOperationHandle opHandle) throws HiveSQLException { Operation operation = sessionManager.getOperationManager().getOperation( new OperationHandle(opHandle)); final String queryId = operation.getParentSession().getHiveConf().getVar(ConfVars.HIVEQUERYID); LOG.debug(opHandle + ": getQueryId() " + queryId); return queryId; }