org.apache.tajo.QueryId - java examples

Here are the examples of the java api org.apache.tajo.QueryId taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

139 Examples 7

19 View Complete Implementation : TajoClientImpl.java
Copyright Apache License 2.0
Author : apache
public void closeNonForwardQuery(final QueryId queryId) {
    queryClient.closeNonForwardQuery(queryId);
}

19 View Complete Implementation : ReturnStateUtil.java
Copyright Apache License 2.0
Author : apache
public static ReturnState errNoSuchQueryId(QueryId queryId) {
    return returnError(ResultCode.QUERY_NOT_FOUND, queryId.toString());
}

19 View Complete Implementation : QueryClientImpl.java
Copyright Apache License 2.0
Author : apache
public ResultSet getQueryResultAndWait(QueryId queryId) throws QueryNotFoundException, QueryKilledException, QueryFailedException {
    if (queryId.equals(QueryIdFactory.NULL_QUERY_ID)) {
        return createNullResultSet(queryId);
    }
    QueryStatus status = TajoClientUtil.waitCompletion(this, queryId);
    if (status.getState() == QueryState.QUERY_SUCCEEDED) {
        if (status.hasResult()) {
            return getQueryResult(queryId);
        } else {
            return createNullResultSet(queryId);
        }
    } else if (status.getState() == QueryState.QUERY_KILLED) {
        throw new QueryKilledException();
    } else if (status.getState() == QueryState.QUERY_FAILED) {
        throw new QueryFailedException(status.getErrorMessage());
    } else {
        throw new TajoInternalError("Illegal query status: " + status.getState().name() + ", cause: " + status.getErrorMessage());
    }
}

19 View Complete Implementation : TajoClientImpl.java
Copyright Apache License 2.0
Author : apache
public QueryInfoProto getQueryInfo(final QueryId queryId) throws QueryNotFoundException {
    return queryClient.getQueryInfo(queryId);
}

19 View Complete Implementation : QueryClientImpl.java
Copyright Apache License 2.0
Author : apache
@Override
public QueryStatus killQuery(final QueryId queryId) throws QueryNotFoundException {
    final BlockingInterface stub = conn.getTMStub();
    QueryStatus status = getQueryStatus(queryId);
    /* send a kill to the TM */
    final QueryIdRequest request = buildQueryIdRequest(queryId);
    try {
        stub.killQuery(null, request);
    } catch (ServiceException e) {
        throw new RuntimeException(e);
    }
    long currentTimeMillis = System.currentTimeMillis();
    long timeKillIssued = currentTimeMillis;
    while ((currentTimeMillis < timeKillIssued + 10000L) && ((status.getState() != QueryState.QUERY_KILLED) || (status.getState() == QueryState.QUERY_KILL_WAIT))) {
        try {
            Thread.sleep(100L);
        } catch (InterruptedException ie) {
            break;
        }
        currentTimeMillis = System.currentTimeMillis();
        status = getQueryStatus(queryId);
    }
    return status;
}

19 View Complete Implementation : TajoWorkerResourceManager.java
Copyright Apache License 2.0
Author : apache
@Override
public void stopQueryMaster(QueryId queryId) {
    WorkerResource resource = null;
    if (!rmContext.getQueryMasterContainer().containsKey(queryId)) {
        LOG.warn("No QueryMaster resource info for " + queryId);
        return;
    } else {
        ContainerIdProto containerId = rmContext.getQueryMasterContainer().remove(queryId);
        releaseWorkerResource(containerId);
        LOG.info(String.format("Released QueryMaster (%s) resource:" + resource, queryId.toString()));
    }
}

19 View Complete Implementation : TajoClientUtil.java
Copyright Apache License 2.0
Author : apache
public static TajoMemoryResultSet createNullResultSet(QueryId queryId) {
    return new TajoMemoryResultSet(queryId, SchemaBuilder.empty(), null, null);
}

19 View Complete Implementation : QueryJobManager.java
Copyright Apache License 2.0
Author : apache
private void catchException(QueryId queryId, Exception e) {
    LOG.error(e.getMessage(), e);
    QueryInProgress queryInProgress = runningQueries.get(queryId);
    queryInProgress.catchException(e);
}

19 View Complete Implementation : QueryStopEvent.java
Copyright Apache License 2.0
Author : apache
/**
 * This event is conveyed to QueryMaster.
 */
public clreplaced QueryStopEvent extends AbstractEvent {

    public enum EventType {

        QUERY_STOP
    }

    private final QueryId queryId;

    public QueryStopEvent(QueryId queryId) {
        super(EventType.QUERY_STOP);
        this.queryId = queryId;
    }

    public QueryId getQueryId() {
        return queryId;
    }

    @Override
    public String toString() {
        return getClreplaced().getName() + "," + getType() + "," + queryId;
    }
}

19 View Complete Implementation : QueryJobManager.java
Copyright Apache License 2.0
Author : apache
public QueryInfo createNewQueryJob(QueryContext queryContext, String sql, LogicalRootNode plan) throws Exception {
    QueryId queryId = QueryIdFactory.newQueryId(masterContext.getResourceManager().getSeedQueryId());
    QueryInProgress queryInProgress = new QueryInProgress(masterContext, queryContext, queryId, sql, plan);
    synchronized (runningQueries) {
        runningQueries.put(queryId, queryInProgress);
    }
    addService(queryInProgress);
    queryInProgress.init(getConfig());
    queryInProgress.start();
    if (!queryInProgress.startQueryMaster()) {
        return null;
    }
    return queryInProgress.getQueryInfo();
}

19 View Complete Implementation : TajoClientImpl.java
Copyright Apache License 2.0
Author : apache
public QueryStatus getQueryStatus(QueryId queryId) throws QueryNotFoundException {
    return queryClient.getQueryStatus(queryId);
}

19 View Complete Implementation : QueryClientImpl.java
Copyright Apache License 2.0
Author : apache
@Override
public ResultSet executeQueryAndGetResult(String sql) throws TajoException {
    SubmitQueryResponse response = executeQuery(sql);
    throwIfError(response.getState());
    QueryId queryId = new QueryId(response.getQueryId());
    switch(response.getResultType()) {
        case ENCLOSED:
            return TajoClientUtil.createResultSet(this, response, defaultFetchRows);
        case FETCH:
            return this.getQueryResultAndWait(queryId);
        default:
            return this.createNullResultSet(queryId);
    }
}

19 View Complete Implementation : TajoWorkerResourceManager.java
Copyright Apache License 2.0
Author : apache
@Override
public boolean isQueryMasterStopped(QueryId queryId) {
    return !rmContext.getQueryMasterContainer().containsKey(queryId);
}

19 View Complete Implementation : TajoClientImpl.java
Copyright Apache License 2.0
Author : apache
public ResultSet getQueryResult(QueryId queryId) throws TajoException {
    return queryClient.getQueryResult(queryId);
}

19 View Complete Implementation : QueryInfo.java
Copyright Apache License 2.0
Author : apache
public clreplaced QueryInfo {

    private QueryId queryId;

    private String sql;

    private TajoProtos.QueryState queryState;

    private float progress;

    private long startTime;

    private long finishTime;

    private String lastMessage;

    private String hostNameOfQM;

    private int queryMasterPort;

    private int queryMasterClientPort;

    public QueryInfo(QueryId queryId) {
        this(queryId, null);
    }

    public QueryInfo(QueryId queryId, String sql) {
        this.queryId = queryId;
        this.sql = sql;
        this.queryState = TajoProtos.QueryState.QUERY_MASTER_INIT;
    }

    public QueryId getQueryId() {
        return queryId;
    }

    public String getSql() {
        return sql;
    }

    public String getQueryMasterHost() {
        return hostNameOfQM;
    }

    public void setQueryMaster(String hostName) {
        this.hostNameOfQM = hostName;
    }

    public void setQueryMasterPort(int port) {
        this.queryMasterPort = port;
    }

    public int getQueryMasterPort() {
        return queryMasterPort;
    }

    public void setQueryMasterclientPort(int port) {
        queryMasterClientPort = port;
    }

    public int getQueryMasterClientPort() {
        return queryMasterClientPort;
    }

    public TajoProtos.QueryState getQueryState() {
        return queryState;
    }

    public void setQueryState(TajoProtos.QueryState queryState) {
        this.queryState = queryState;
    }

    public long getStartTime() {
        return startTime;
    }

    public void setStartTime(long startTime) {
        this.startTime = startTime;
    }

    public long getFinishTime() {
        return finishTime;
    }

    public void setFinishTime(long finishTime) {
        this.finishTime = finishTime;
    }

    public String getLastMessage() {
        return lastMessage;
    }

    public void setLastMessage(String lastMessage) {
        this.lastMessage = lastMessage;
    }

    public float getProgress() {
        return progress;
    }

    public void setProgress(float progress) {
        this.progress = progress;
    }

    @Override
    public String toString() {
        return queryId.toString() + "state=" + queryState + ",progress=" + progress + ", queryMaster=" + getQueryMasterHost();
    }
}

19 View Complete Implementation : TajoClientImpl.java
Copyright Apache License 2.0
Author : apache
public QueryHistoryProto getQueryHistory(final QueryId queryId) throws QueryNotFoundException {
    return queryClient.getQueryHistory(queryId);
}

19 View Complete Implementation : ApplicationIdUtils.java
Copyright Apache License 2.0
Author : apache
public static ApplicationAttemptId createApplicationAttemptId(QueryId queryId) {
    return BuilderUtils.newApplicationAttemptId(queryIdToAppId(queryId), 1);
}

19 View Complete Implementation : LegacyClientDelegate.java
Copyright Apache License 2.0
Author : apache
@Override
public QueryFuture executeSQLAsync(String sql) throws TajoException {
    ClientProtos.SubmitQueryResponse response = queryClient.executeQuery(sql);
    ExceptionUtil.throwIfError(response.getState());
    QueryId queryId = new QueryId(response.getQueryId());
    switch(response.getResultType()) {
        case ENCLOSED:
            return new QueryFutureForEnclosed(queryId, TajoClientUtil.createResultSet(this.queryClient, response, 200));
        case FETCH:
            AsyncQueryFuture future = new AsyncQueryFuture(queryId);
            executor.execute(future);
            return future;
        default:
            return new QueryFutureForNoFetch(queryId);
    }
}

19 View Complete Implementation : TajoClient.java
Copyright Apache License 2.0
Author : apache
public ResultSet createNullResultSet(QueryId queryId) throws IOException {
    return new TajoResultSet(this, queryId);
}

19 View Complete Implementation : ReturnStateUtil.java
Copyright Apache License 2.0
Author : apache
public static ReturnState errIncompleteQuery(QueryId queryId) {
    return returnError(ResultCode.INCOMPLETE_QUERY, queryId.toString());
}

19 View Complete Implementation : QueryClientImpl.java
Copyright Apache License 2.0
Author : apache
@Override
public ResultSet createNullResultSet(QueryId queryId) {
    return TajoClientUtil.createNullResultSet(queryId);
}

19 View Complete Implementation : QueryClientImpl.java
Copyright Apache License 2.0
Author : apache
@Override
public Future<TajoMemoryResultSet> fetchNextQueryResultAsync(final QueryId queryId, final int fetchRowNum) {
    final SettableFuture<TajoMemoryResultSet> future = SettableFuture.create();
    executor.submit(new Runnable() {

        @Override
        public void run() {
            try {
                future.set(fetchNextQueryResult(queryId, fetchRowNum));
            } catch (Throwable e) {
                future.setException(e);
            }
        }
    });
    return future;
}

19 View Complete Implementation : QueryEvent.java
Copyright Apache License 2.0
Author : apache
public clreplaced QueryEvent extends AbstractEvent<QueryEventType> {

    private final QueryId id;

    public QueryEvent(final QueryId id, final QueryEventType queryEvent) {
        super(queryEvent);
        this.id = id;
    }

    public QueryId getQueryId() {
        return id;
    }
}

19 View Complete Implementation : QueryClientImpl.java
Copyright Apache License 2.0
Author : apache
@Override
public ResultSet getQueryResult(QueryId queryId) throws QueryNotFoundException {
    if (queryId.equals(QueryIdFactory.NULL_QUERY_ID)) {
        return createNullResultSet(queryId);
    }
    GetQueryResultResponse response = getResultResponse(queryId);
    TableDesc tableDesc = new TableDesc(response.getTableDesc());
    return new FetchResultSet(this, tableDesc.getLogicalSchema(), queryId, defaultFetchRows);
}

19 View Complete Implementation : QueryMaster.java
Copyright Apache License 2.0
Author : apache
public Query getQuery(QueryId queryId) {
    return queryMasterTasks.get(queryId).getQuery();
}

19 View Complete Implementation : QueryClientImpl.java
Copyright Apache License 2.0
Author : apache
@Override
public void closeQuery(QueryId queryId) {
    closeNonForwardQuery(queryId);
}

19 View Complete Implementation : QueryClientImpl.java
Copyright Apache License 2.0
Author : apache
@Override
public ResultSet executeJsonQueryAndGetResult(final String json) throws TajoException {
    SubmitQueryResponse response = executeQueryWithJson(json);
    throwIfError(response.getState());
    QueryId queryId = new QueryId(response.getQueryId());
    switch(response.getResultType()) {
        case ENCLOSED:
            return TajoClientUtil.createResultSet(this, response, defaultFetchRows);
        case FETCH:
            return this.getQueryResultAndWait(queryId);
        default:
            return this.createNullResultSet(queryId);
    }
}

19 View Complete Implementation : QueryMaster.java
Copyright Apache License 2.0
Author : apache
public QueryMasterTask getQueryMasterTask(QueryId queryId, boolean includeFinished) {
    QueryMasterTask queryMasterTask = queryMasterTasks.get(queryId);
    if (queryMasterTask != null) {
        return queryMasterTask;
    } else {
        if (includeFinished) {
            return finishedQueryMasterTasks.get(queryId);
        } else {
            return null;
        }
    }
}

19 View Complete Implementation : TajoClientImpl.java
Copyright Apache License 2.0
Author : apache
public GetQueryResultResponse getResultResponse(QueryId queryId) throws TajoException {
    return queryClient.getResultResponse(queryId);
}

19 View Complete Implementation : QueryStartEvent.java
Copyright Apache License 2.0
Author : apache
/**
 * This event is conveyed to QueryMaster.
 */
public clreplaced QueryStartEvent extends AbstractEvent {

    public enum EventType {

        QUERY_START
    }

    private QueryId queryId;

    private QueryContext queryContext;

    private String sql;

    private String logicalPlanJson;

    public QueryStartEvent(QueryId queryId, QueryContext queryContext, String sql, String logicalPlanJson) {
        super(EventType.QUERY_START);
        this.queryId = queryId;
        this.queryContext = queryContext;
        this.sql = sql;
        this.logicalPlanJson = logicalPlanJson;
    }

    public QueryId getQueryId() {
        return queryId;
    }

    public QueryContext getQueryContext() {
        return this.queryContext;
    }

    public String getSql() {
        return this.sql;
    }

    public String getLogicalPlanJson() {
        return logicalPlanJson;
    }

    @Override
    public String toString() {
        return getClreplaced().getName() + "," + getType() + "," + queryId;
    }
}

19 View Complete Implementation : TajoClientImpl.java
Copyright Apache License 2.0
Author : apache
@Override
public Future<TajoMemoryResultSet> fetchNextQueryResultAsync(QueryId queryId, int fetchRowNum) {
    return queryClient.fetchNextQueryResultAsync(queryId, fetchRowNum);
}

19 View Complete Implementation : TajoWorkerResourceManager.java
Copyright Apache License 2.0
Author : apache
private void registerQueryMaster(QueryId queryId, ContainerIdProto containerId) {
    rmContext.getQueryMasterContainer().putIfAbsent(queryId, containerId);
}

19 View Complete Implementation : TajoClientImpl.java
Copyright Apache License 2.0
Author : apache
/*------------------------------------------------------------------------*/
// QueryClient wrappers
/*------------------------------------------------------------------------*/
public void closeQuery(final QueryId queryId) {
    queryClient.closeQuery(queryId);
}

19 View Complete Implementation : TajoClient.java
Copyright Apache License 2.0
Author : apache
public ResultSet getQueryResultAndWait(QueryId queryId) throws ServiceException, IOException {
    if (queryId.equals(QueryIdFactory.NULL_QUERY_ID)) {
        return createNullResultSet(queryId);
    }
    QueryStatus status = getQueryStatus(queryId);
    while (status != null && isQueryRunnning(status.getState())) {
        try {
            Thread.sleep(500);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        status = getQueryStatus(queryId);
    }
    if (status.getState() == QueryState.QUERY_SUCCEEDED) {
        if (status.hasResult()) {
            return getQueryResult(queryId);
        } else {
            return createNullResultSet(queryId);
        }
    } else {
        LOG.warn("Query (" + status.getQueryId() + ") failed: " + status.getState());
        // TODO throw SQLException(?)
        return createNullResultSet(queryId);
    }
}

19 View Complete Implementation : TajoClientImpl.java
Copyright Apache License 2.0
Author : apache
public ResultSet createNullResultSet(QueryId queryId) {
    return TajoClientUtil.createNullResultSet(queryId);
}

19 View Complete Implementation : YarnTajoResourceManager.java
Copyright Apache License 2.0
Author : apache
private ApplicationAttemptId allocateAndLaunchQueryMaster(QueryInProgress queryInProgress) throws IOException, YarnException {
    QueryId queryId = queryInProgress.getQueryId();
    ApplicationId appId = ApplicationIdUtils.queryIdToAppId(queryId);
    LOG.info("Allocate and launch ApplicationMaster for QueryMaster: queryId=" + queryId + ", appId=" + appId);
    ApplicationSubmissionContext appContext = Records.newRecord(ApplicationSubmissionContext.clreplaced);
    // set the application id
    appContext.setApplicationId(appId);
    // set the application name
    appContext.setApplicationName("Tajo");
    Priority pri = Records.newRecord(Priority.clreplaced);
    pri.setPriority(5);
    appContext.setPriority(pri);
    // Set the queue to which this application is to be submitted in the RM
    appContext.setQueue("default");
    ContainerLaunchContext commonContainerLaunchContext = YarnContainerProxy.createCommonContainerLaunchContext(masterContext.getConf(), queryId.toString(), true);
    // Setup environment by cloning from common env.
    Map<String, String> env = commonContainerLaunchContext.getEnvironment();
    Map<String, String> myEnv = new HashMap<String, String>(env.size());
    myEnv.putAll(env);
    // //////////////////////////////////////////////////////////////////////////
    // Set the local resources
    // //////////////////////////////////////////////////////////////////////////
    // Set the necessary command to execute the application master
    Vector<CharSequence> vargs = new Vector<CharSequence>(30);
    // Set java executable command
    // LOG.info("Setting up app master command");
    vargs.add("${JAVA_HOME}" + "/bin/java");
    // Set Xmx based on am memory size
    String jvmOptions = masterContext.getConf().get("tajo.rm.yarn.querymaster.jvm.option", "-Xmx2000m");
    for (String eachToken : jvmOptions.split((" "))) {
        vargs.add(eachToken);
    }
    // Set Remote Debugging
    // if (!context.getQuery().getSubQuery(event.getExecutionBlockId()).isLeafQuery()) {
    // vargs.add("-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=5005");
    // }
    // Set clreplaced name
    vargs.add(TajoWorker.clreplaced.getCanonicalName());
    vargs.add("qm");
    // queryId
    vargs.add(queryId.toString());
    vargs.add(masterContext.getTajoMasterService().getBindAddress().getHostName() + ":" + masterContext.getTajoMasterService().getBindAddress().getPort());
    vargs.add("1>" + ApplicationConstants.LOG_DIR_EXPANSION_VAR + "/stdout");
    vargs.add("2>" + ApplicationConstants.LOG_DIR_EXPANSION_VAR + "/stderr");
    // Get final commmand
    StringBuilder command = new StringBuilder();
    for (CharSequence str : vargs) {
        command.append(str).append(" ");
    }
    LOG.info("Completed setting up QueryMasterRunner command " + command.toString());
    List<String> commands = new ArrayList<String>();
    commands.add(command.toString());
    final Resource resource = Records.newRecord(Resource.clreplaced);
    // TODO - get default value from conf
    resource.setMemory(2000);
    resource.setVirtualCores(1);
    Map<String, ByteBuffer> myServiceData = new HashMap<String, ByteBuffer>();
    ContainerLaunchContext masterContainerContext = BuilderUtils.newContainerLaunchContext(commonContainerLaunchContext.getLocalResources(), myEnv, commands, myServiceData, null, new HashMap<ApplicationAccessType, String>(2));
    appContext.setAMContainerSpec(masterContainerContext);
    LOG.info("Submitting QueryMaster to ResourceManager");
    yarnClient.submitApplication(appContext);
    ApplicationReport appReport = monitorApplication(appId, EnumSet.of(YarnApplicationState.ACCEPTED));
    ApplicationAttemptId attemptId = appReport.getCurrentApplicationAttemptId();
    LOG.info("Launching QueryMaster with appAttemptId: " + attemptId);
    return attemptId;
}

19 View Complete Implementation : TajoClientImpl.java
Copyright Apache License 2.0
Author : apache
public QueryStatus killQuery(final QueryId queryId) throws QueryNotFoundException {
    return queryClient.killQuery(queryId);
}

19 View Complete Implementation : QueryJobManager.java
Copyright Apache License 2.0
Author : apache
public QueryInProgress getQueryInProgress(QueryId queryId) {
    synchronized (runningQueries) {
        return runningQueries.get(queryId);
    }
}

19 View Complete Implementation : TajoClientUtil.java
Copyright Apache License 2.0
Author : apache
public static QueryStatus waitCompletion(QueryClient client, QueryId queryId) throws QueryNotFoundException {
    QueryStatus status = client.getQueryStatus(queryId);
    while (!isQueryComplete(status.getState())) {
        try {
            Thread.sleep(500);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        status = client.getQueryStatus(queryId);
    }
    return status;
}

19 View Complete Implementation : ApplicationIdUtils.java
Copyright Apache License 2.0
Author : apache
public static ApplicationAttemptId createApplicationAttemptId(QueryId queryId, int attemptId) {
    return BuilderUtils.newApplicationAttemptId(queryIdToAppId(queryId), attemptId);
}

19 View Complete Implementation : TajoConf.java
Copyright Apache License 2.0
Author : apache
/**
 * It returns the temporal query directory
 * An example dir is <pre>/{staging-dir}/{queryId}/RESULT</pre>.
 *
 * @param conf TajoConf
 * @param queryId queryId
 * @throws IOException
 */
public static Path getTemporalResultDir(TajoConf conf, QueryId queryId) throws IOException {
    Path queryDir = new Path(getDefaultRootStagingDir(conf), queryId.toString());
    return new Path(queryDir, TajoConstants.RESULT_DIR_NAME);
}

19 View Complete Implementation : TajoCli.java
Copyright Apache License 2.0
Author : apache
public int executeStatements(String line) throws Exception {
    // TODO - comment handling and multi line queries should be improved
    // remove comments
    String filtered = line.replaceAll("--[^\\r\\n]*", "").trim();
    String stripped;
    for (String statement : filtered.split(";")) {
        stripped = StringUtils.chomp(statement);
        if (StringUtils.isBlank(stripped)) {
            continue;
        }
        String[] cmds = stripped.split(" ");
        if (cmds[0].equalsIgnoreCase("exit") || cmds[0].equalsIgnoreCase("quit")) {
            sout.println("\n\nbye!");
            sout.flush();
            ((PersistentHistory) this.reader.getHistory()).flush();
            System.exit(0);
        } else if (cmds[0].equalsIgnoreCase("detach") && cmds.length > 1 && cmds[1].equalsIgnoreCase("table")) {
            // this command should be moved to GlobalEngine
            invokeCommand(cmds);
        } else if (cmds[0].equalsIgnoreCase("explain") && cmds.length > 1) {
            String sql = stripped.substring(8);
            ClientProtos.ExplainQueryResponse response = client.explainQuery(sql);
            if (response == null) {
                sout.println("response is null");
            } else {
                if (response.hasExplain()) {
                    sout.println(response.getExplain());
                } else {
                    if (response.hasErrorMessage()) {
                        sout.println(response.getErrorMessage());
                    } else {
                        sout.println("No Explain");
                    }
                }
            }
        } else {
            // submit a query to TajoMaster
            ClientProtos.GetQueryStatusResponse response = client.executeQuery(stripped);
            if (response == null) {
                sout.println("response is null");
            } else if (response.getResultCode() == ClientProtos.ResultCode.OK) {
                QueryId queryId = null;
                try {
                    queryId = new QueryId(response.getQueryId());
                    if (queryId.equals(QueryIdFactory.NULL_QUERY_ID)) {
                        sout.println("OK");
                    } else {
                        waitForQueryCompleted(queryId);
                    }
                } finally {
                    if (queryId != null) {
                        client.closeQuery(queryId);
                    }
                }
            } else {
                if (response.hasErrorMessage()) {
                    sout.println(response.getErrorMessage());
                }
            }
        }
    }
    return 0;
}

19 View Complete Implementation : ReturnStateUtil.java
Copyright Apache License 2.0
Author : apache
public static ReturnState errNoData(QueryId queryId) {
    return returnError(ResultCode.NO_DATA, queryId.toString());
}

19 View Complete Implementation : QueryClientImpl.java
Copyright Apache License 2.0
Author : apache
public QueryInfoProto getQueryInfo(final QueryId queryId) throws QueryNotFoundException {
    final BlockingInterface stub = conn.getTMStub();
    final QueryIdRequest request = buildQueryIdRequest(queryId);
    GetQueryInfoResponse res;
    try {
        res = stub.getQueryInfo(null, request);
    } catch (ServiceException e) {
        throw new RuntimeException(e);
    }
    throwsIfThisError(res.getState(), QueryNotFoundException.clreplaced);
    ensureOk(res.getState());
    return res.getQueryInfo();
}

19 View Complete Implementation : QueryJobManager.java
Copyright Apache License 2.0
Author : apache
public void stopQuery(QueryId queryId) {
    LOG.info("Stop QueryInProgress:" + queryId);
    QueryInProgress queryInProgress = getQueryInProgress(queryId);
    if (queryInProgress != null) {
        queryInProgress.stop();
        synchronized (runningQueries) {
            runningQueries.remove(queryId);
            finishedQueries.put(queryId, queryInProgress);
        }
    } else {
        LOG.warn("No QueryInProgress while query stopping: " + queryId);
    }
}

19 View Complete Implementation : TajoCli.java
Copyright Apache License 2.0
Author : apache
private void waitForQueryCompleted(QueryId queryId) {
    // if query is empty string
    if (queryId.equals(QueryIdFactory.NULL_QUERY_ID)) {
        return;
    }
    // query execute
    try {
        QueryStatus status;
        int initRetries = 0;
        int progressRetries = 0;
        while (true) {
            // TODO - configurabl
            status = client.getQueryStatus(queryId);
            if (status.getState() == QueryState.QUERY_MASTER_INIT || status.getState() == QueryState.QUERY_MASTER_LAUNCHED) {
                Thread.sleep(Math.min(20 * initRetries, 1000));
                initRetries++;
                continue;
            }
            if (status.getState() == QueryState.QUERY_RUNNING || status.getState() == QueryState.QUERY_SUCCEEDED) {
                sout.println("Progress: " + (int) (status.getProgress() * 100.0f) + "%, response time: " + ((float) (status.getFinishTime() - status.getSubmitTime()) / 1000.0) + " sec");
                sout.flush();
            }
            if (status.getState() != QueryState.QUERY_RUNNING && status.getState() != QueryState.QUERY_NOT_replacedIGNED && status.getState() != QueryState.QUERY_KILL_WAIT) {
                break;
            } else {
                Thread.sleep(Math.min(200 * progressRetries, 1000));
                progressRetries += 2;
            }
        }
        if (status.getState() == QueryState.QUERY_ERROR) {
            sout.println("Internal error!");
        } else if (status.getState() == QueryState.QUERY_FAILED) {
            sout.println("Query failed!");
        } else if (status.getState() == QueryState.QUERY_KILLED) {
            sout.println(queryId + " is killed.");
        } else {
            if (status.getState() == QueryState.QUERY_SUCCEEDED) {
                sout.println("final state: " + status.getState() + ", response time: " + (((float) (status.getFinishTime() - status.getSubmitTime()) / 1000.0) + " sec"));
                if (status.hasResult()) {
                    ResultSet res = null;
                    TableDesc desc = null;
                    if (queryId.equals(QueryIdFactory.NULL_QUERY_ID)) {
                        res = client.createNullResultSet(queryId);
                    } else {
                        ClientProtos.GetQueryResultResponse response = client.getResultResponse(queryId);
                        desc = CatalogUtil.newTableDesc(response.getTableDesc());
                        conf.setVar(ConfVars.USERNAME, response.getTajoUserName());
                        res = new TajoResultSet(client, queryId, conf, desc);
                    }
                    try {
                        if (res == null) {
                            sout.println("OK");
                            return;
                        }
                        ResultSetMetaData rsmd = res.getMetaData();
                        TableStats stat = desc.getStats();
                        String volume = FileUtil.humanReadableByteCount(stat.getNumBytes(), false);
                        long resultRows = stat.getNumRows();
                        sout.println("result: " + desc.getPath() + ", " + resultRows + " rows (" + volume + ")");
                        int numOfColumns = rsmd.getColumnCount();
                        for (int i = 1; i <= numOfColumns; i++) {
                            if (i > 1)
                                sout.print(",  ");
                            String columnName = rsmd.getColumnName(i);
                            sout.print(columnName);
                        }
                        sout.println("\n-------------------------------");
                        int numOfPrintedRows = 0;
                        while (res.next()) {
                            // TODO - to be improved to print more formatted text
                            for (int i = 1; i <= numOfColumns; i++) {
                                if (i > 1)
                                    sout.print(",  ");
                                String columnValue = res.getObject(i).toString();
                                if (res.wasNull()) {
                                    sout.print("null");
                                } else {
                                    sout.print(columnValue);
                                }
                            }
                            sout.println();
                            sout.flush();
                            numOfPrintedRows++;
                            if (numOfPrintedRows >= PRINT_LIMIT) {
                                sout.print("continue... ('q' is quit)");
                                sout.flush();
                                if (sin.read() == 'q') {
                                    sout.println();
                                    break;
                                }
                                numOfPrintedRows = 0;
                                sout.println();
                            }
                        }
                    } finally {
                        if (res != null) {
                            res.close();
                        }
                    }
                } else {
                    sout.println("OK");
                }
            }
        }
    } catch (Throwable t) {
        t.printStackTrace();
        System.err.println(t.getMessage());
    }
}

19 View Complete Implementation : TajoClient.java
Copyright Apache License 2.0
Author : apache
/**
 * It submits a query statement and get a response.
 * The main difference from {@link #executeQuery(String)}
 * is a blocking method. So, this method is wait for
 * the finish of the submitted query.
 *
 * @return If failed, return null.
 */
public ResultSet executeQueryAndGetResult(final String sql) throws ServiceException, IOException {
    GetQueryStatusResponse response = new ServerCallable<GetQueryStatusResponse>(connPool, tajoMasterAddr, TajoMasterClientProtocol.clreplaced, false, true) {

        public GetQueryStatusResponse call(NettyClientBase client) throws ServiceException {
            final QueryRequest.Builder builder = QueryRequest.newBuilder();
            builder.setQuery(sql);
            TajoMasterClientProtocolService.BlockingInterface tajoMasterService = client.getStub();
            return tajoMasterService.submitQuery(null, builder.build());
        }
    }.withRetries();
    QueryId queryId = new QueryId(response.getQueryId());
    if (queryId.equals(QueryIdFactory.NULL_QUERY_ID)) {
        return this.createNullResultSet(queryId);
    } else {
        return this.getQueryResultAndWait(queryId);
    }
}

19 View Complete Implementation : QueryMasterQueryCompletedEvent.java
Copyright Apache License 2.0
Author : apache
public clreplaced QueryMasterQueryCompletedEvent extends AbstractEvent<QueryMasterQueryCompletedEvent.EventType> {

    public enum EventType {

        QUERY_FINISH
    }

    private final QueryId queryId;

    public QueryMasterQueryCompletedEvent(QueryId queryId) {
        super(EventType.QUERY_FINISH);
        this.queryId = queryId;
    }

    public QueryId getQueryId() {
        return this.queryId;
    }
}

19 View Complete Implementation : QueryMaster.java
Copyright Apache License 2.0
Author : apache
public QueryMasterTask getQueryMasterTask(QueryId queryId) {
    return queryMasterTasks.get(queryId);
}

19 View Complete Implementation : QueryClientImpl.java
Copyright Apache License 2.0
Author : apache
@Override
public void closeNonForwardQuery(QueryId queryId) {
    try {
        ensureOk(conn.getTMStub().closeNonForwardQuery(null, buildQueryIdRequest(queryId)));
    } catch (ServiceException e) {
        throw new RuntimeException(e);
    }
}