@Override public void execute( QueryMaster.QueryMasterContext context, QueryContext queryContext, Query query, ExecutionBlockId finalExecBlockId, Path finalOutputDir) throws Exception { CatalogService catalog = context.getWorkerContext().getCatalog(); SubQuery lastStage = query.getSubQuery(finalExecBlockId); TableMeta meta = lastStage.getTableMeta(); TableStats stats = lastStage.getTableStat(); CreateTableNode createTableNode = (CreateTableNode) lastStage.getBlock().getPlan(); TableDesc tableDescTobeCreated = new TableDesc( createTableNode.getTableName(), createTableNode.getTableSchema(), meta, finalOutputDir); if (createTableNode.hasPartition()) { tableDescTobeCreated.setPartitionMethod(createTableNode.getPartitionMethod()); } stats.setNumBytes(getTableVolume(query.systemConf, finalOutputDir)); tableDescTobeCreated.setStats(stats); query.setResultDesc(tableDescTobeCreated); catalog.addTable(tableDescTobeCreated); }
@Override public void transition(Query query, QueryEvent event) { synchronized (query.subqueries) { for (SubQuery subquery : query.subqueries.values()) { query.eventHandler.handle(new SubQueryEvent(subquery.getId(), SubQueryEventType.SQ_KILL)); } } }
@Override public boolean isEligible( QueryContext queryContext, Query query, ExecutionBlockId finalExecBlockId, Path finalOutputDir) { SubQuery lastStage = query.getSubQuery(finalExecBlockId); return lastStage.getBlock().getPlan().getType() == NodeType.INSERT; }
@Override public void transition(Query query, QueryEvent queryEvent) { query.setStartTime(); SubQuery subQuery = new SubQuery( query.context, query.getPlan(), query.getExecutionBlockCursor().nextBlock(), query.sm); subQuery.setPriority(query.priority--); query.addSubQuery(subQuery); subQuery.handle(new SubQueryEvent(subQuery.getId(), SubQueryEventType.SQ_INIT)); LOG.debug("Schedule unit plan: \n" + subQuery.getBlock().getPlan()); }
@Override public void execute( QueryMaster.QueryMasterContext context, QueryContext queryContext, Query query, ExecutionBlockId finalExecBlockId, Path finalOutputDir) throws Exception { SubQuery lastStage = query.getSubQuery(finalExecBlockId); TableMeta meta = lastStage.getTableMeta(); TableStats stats = lastStage.getTableStat(); TableDesc resultTableDesc = new TableDesc(query.getId().toString(), lastStage.getSchema(), meta, finalOutputDir); stats.setNumBytes(getTableVolume(query.systemConf, finalOutputDir)); resultTableDesc.setStats(stats); query.setResultDesc(resultTableDesc); }
public float getProgress() { QueryState state = getStateMachine().getCurrentState(); if (state == QueryState.QUERY_SUCCEEDED) { return 1.0f; } else { int idx = 0; List<SubQuery> tempSubQueries = new ArrayList<SubQuery>(); synchronized (subqueries) { tempSubQueries.addAll(subqueries.values()); } float[] subProgresses = new float[tempSubQueries.size()]; boolean finished = true; for (SubQuery subquery : tempSubQueries) { if (subquery.getState() != SubQueryState.NEW) { subProgresses[idx] = subquery.getProgress(); if (finished && subquery.getState() != SubQueryState.SUCCEEDED) { finished = false; } } else { subProgresses[idx] = 0.0f; } idx++; } if (finished) { return 1.0f; } float totalProgress = 0; float proportion = 1.0f / (float) (getExecutionBlockCursor().size() - 1); // minus one is due to for (int i = 0; i < subProgresses.length; i++) { totalProgress += subProgresses[i] * proportion; } return totalProgress; } }
@Override public void execute( QueryMaster.QueryMasterContext context, QueryContext queryContext, Query query, ExecutionBlockId finalExecBlockId, Path finalOutputDir) throws Exception { CatalogService catalog = context.getWorkerContext().getCatalog(); SubQuery lastStage = query.getSubQuery(finalExecBlockId); TableMeta meta = lastStage.getTableMeta(); TableStats stats = lastStage.getTableStat(); InsertNode insertNode = (InsertNode) lastStage.getBlock().getPlan(); TableDesc finalTable; if (insertNode.hasTargetTable()) { String tableName = insertNode.getTableName(); finalTable = catalog.getTableDesc(tableName); } else { String tableName = query.getId().toString(); finalTable = new TableDesc(tableName, lastStage.getSchema(), meta, finalOutputDir); } long volume = getTableVolume(query.systemConf, finalOutputDir); stats.setNumBytes(volume); finalTable.setStats(stats); if (insertNode.hasTargetTable()) { catalog.deleteTable(insertNode.getTableName()); catalog.addTable(finalTable); } query.setResultDesc(finalTable); }
private void executeNextBlock(Query query) { ExecutionBlockCursor cursor = query.getExecutionBlockCursor(); ExecutionBlock nextBlock = cursor.nextBlock(); SubQuery nextSubQuery = new SubQuery(query.context, query.getPlan(), nextBlock, query.sm); nextSubQuery.setPriority(query.priority--); query.addSubQuery(nextSubQuery); nextSubQuery.handle(new SubQueryEvent(nextSubQuery.getId(), SubQueryEventType.SQ_INIT)); LOG.info("Scheduling SubQuery:" + nextSubQuery.getId()); if (LOG.isDebugEnabled()) { LOG.debug("Scheduling SubQuery's Priority: " + nextSubQuery.getPriority()); LOG.debug("Scheduling SubQuery's Plan: \n" + nextSubQuery.getBlock().getPlan()); } }
public void addSubQuery(SubQuery subquery) { subqueries.put(subquery.getId(), subquery); }