Fix async result delivery

- add new result status "started" for async requests
- add support for result status to the test framework
- stabilize result distribution for error in async requests
- add support for "pollget" to test async execution
- add sleep function
- allow inject-failure function to return any first argument
- use URIs instead on Strings in the TestExecutor to ensure that URIs are
  correctly escaped
- add a few tests

Change-Id: Iafba65d9c7bd8643c42e5126c8d89164ae328908
Reviewed-on: https://asterix-gerrit.ics.uci.edu/1394
Tested-by: Jenkins <[email protected]>
Integration-Tests: Jenkins <[email protected]>
Reviewed-by: Michael Blow <[email protected]>


Project: http://git-wip-us.apache.org/repos/asf/asterixdb/repo
Commit: http://git-wip-us.apache.org/repos/asf/asterixdb/commit/392bbbc0
Tree: http://git-wip-us.apache.org/repos/asf/asterixdb/tree/392bbbc0
Diff: http://git-wip-us.apache.org/repos/asf/asterixdb/diff/392bbbc0

Branch: refs/heads/master
Commit: 392bbbc009685b92ddeeb4db747577b0325eef99
Parents: 19e0c22
Author: Till Westmann <[email protected]>
Authored: Thu Feb 9 10:31:44 2017 -0800
Committer: Till Westmann <[email protected]>
Committed: Fri Feb 10 09:37:47 2017 -0800

----------------------------------------------------------------------
 .../translator/util/FunctionCollection.java     |   4 +
 .../common/AsterixHyracksIntegrationUtil.java   |   4 +-
 .../api/http/server/QueryServiceServlet.java    |  15 +-
 .../api/http/server/QueryStatusApiServlet.java  |  14 +-
 .../asterix/app/cc/CCExtensionManager.java      |  19 +-
 .../app/cc/IStatementExecutorExtension.java     |  11 +
 .../DefaultStatementExecutorFactory.java        |  19 +-
 .../asterix/app/translator/QueryTranslator.java | 224 ++++---
 .../bootstrap/CCApplicationEntryPoint.java      |  26 +-
 .../queries/flwor/at00/at00.4.asyncdefer.aql    |  32 -
 .../queries/flwor/at00/at00.4.deferred.aql      |  34 ++
 .../queries/flwor/at00/at00.5.async.aql         |  32 -
 .../queries/flwor/at00/at00.5.get.http          |  20 +
 .../queries/flwor/at00/at00.6.async.aql         |  34 ++
 .../queries/flwor/at00/at00.7.pollget.http      |  22 +
 .../queries/flwor/at00/at00.8.get.http          |  20 +
 .../async-failed/async-failed.1.async.sqlpp     |  23 +
 .../async-failed/async-failed.2.pollget.http    |  22 +
 .../async-failed/async-failed.3.get.http        |  20 +
 .../async-running/async-running.1.async.sqlpp   |  22 +
 .../async-running/async-running.2.pollget.http  |  22 +
 .../async-running/async-running.3.pollget.http  |  22 +
 .../async-running/async-running.4.get.http      |  20 +
 .../async-deferred/async/async.1.async.sqlpp    |  22 +
 .../async-deferred/async/async.2.pollget.http   |  22 +
 .../async-deferred/async/async.3.get.http       |  20 +
 .../deferred/deferred.1.deferred.sqlpp          |  22 +
 .../async-deferred/deferred/deferred.2.get.http |  20 +
 .../flwor/at00/at00.4.asyncdefer.sqlpp          |  38 --
 .../flwor/at00/at00.4.deferred.sqlpp            |  37 ++
 .../queries_sqlpp/flwor/at00/at00.5.async.sqlpp |  36 --
 .../queries_sqlpp/flwor/at00/at00.5.get.http    |  20 +
 .../queries_sqlpp/flwor/at00/at00.6.async.sqlpp |  37 ++
 .../flwor/at00/at00.7.pollget.http              |  22 +
 .../queries_sqlpp/flwor/at00/at00.8.get.http    |  20 +
 .../async-failed/async-failed.1.ignore          |   0
 .../async-failed/async-failed.2.json            |   1 +
 .../async-running/async-running.1.ignore        |   0
 .../async-running/async-running.2.json          |   1 +
 .../async-running/async-running.3.json          |   1 +
 .../async-running/async-running.4.json          |   1 +
 .../results/async-deferred/async/async.1.ignore |   0
 .../results/async-deferred/async/async.2.json   |   1 +
 .../results/async-deferred/async/async.3.json   |  10 +
 .../async-deferred/deferred/deferred.1.ignore   |   0
 .../async-deferred/deferred/deferred.2.json     |  10 +
 .../runtimets/results/flwor/at00/at00.2.adm     | 600 -------------------
 .../runtimets/results/flwor/at00/at00.2.ignore  |   0
 .../runtimets/results/flwor/at00/at00.4.ignore  |   0
 .../runtimets/results/flwor/at00/at00.5.json    |   1 +
 .../runtimets/results/flwor/at00/at00.6.adm     | 600 +++++++++++++++++++
 .../results_parser_sqlpp/flwor/at00/at00.1.ast  |  22 -
 .../results_parser_sqlpp/flwor/at00/at00.2.ast  |   1 -
 .../results_parser_sqlpp/flwor/at00/at00.3.ast  | 111 ----
 .../results_parser_sqlpp/flwor/at00/at00.4.ast  | 111 ----
 .../results_parser_sqlpp/flwor/at00/at00.5.ast  | 111 ----
 .../resources/runtimets/testsuite_sqlpp.xml     |  23 +
 .../runtimets/testsuite_sqlpp_parser.xml        |   5 -
 .../apache/asterix/common/utils/JobUtils.java   |  22 +-
 .../apache/asterix/test/aql/TestExecutor.java   | 279 +++++----
 .../installer/test/ManagixSqlppExecutionIT.java |   5 +-
 .../asterix/om/functions/BuiltinFunctions.java  |   4 +
 .../impl/InjectFailureTypeComputer.java         |  20 +-
 .../om/typecomputer/impl/SleepTypeComputer.java |  51 ++
 .../functions/InjectFailureDescriptor.java      |   7 +
 .../evaluators/functions/SleepDescriptor.java   |  90 +++
 .../server/test/SampleLocalClusterIT.java       |   4 +-
 .../testframework/context/TestFileContext.java  |  10 +-
 .../api/dataset/DatasetDirectoryRecord.java     |  13 +-
 .../hyracks/api/dataset/DatasetJobRecord.java   |  76 ++-
 .../hyracks/api/dataset/ResultSetMetaData.java  |  16 +-
 .../hyracks/api/exceptions/ErrorCode.java       |   4 +
 .../api/exceptions/HyracksDataException.java    |   5 +
 .../java/org/apache/hyracks/api/job/JobId.java  |   3 +
 .../src/main/resources/errormsg/en.properties   |   4 +
 .../control/cc/ClusterControllerService.java    |   6 +-
 .../cc/dataset/DatasetDirectoryService.java     | 188 +++---
 .../cc/dataset/IDatasetDirectoryService.java    |   6 +-
 .../RegisterResultPartitionLocationWork.java    |  13 +-
 ...eportResultPartitionWriteCompletionWork.java |   7 +-
 .../common/dataset/ResultStateSweeper.java      |  14 +-
 .../control/common/utils/ExceptionUtils.java    |   8 +-
 .../nc/dataset/DatasetPartitionManager.java     | 102 +---
 .../nc/dataset/DatasetPartitionWriter.java      |  17 +-
 .../control/nc/dataset/ResultSetMap.java        | 122 ++++
 85 files changed, 2128 insertions(+), 1575 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/asterixdb/blob/392bbbc0/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/translator/util/FunctionCollection.java
----------------------------------------------------------------------
diff --git 
a/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/translator/util/FunctionCollection.java
 
b/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/translator/util/FunctionCollection.java
index d14b8e2..6f24fc5 100644
--- 
a/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/translator/util/FunctionCollection.java
+++ 
b/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/translator/util/FunctionCollection.java
@@ -205,6 +205,7 @@ import 
org.apache.asterix.runtime.evaluators.functions.SimilarityJaccardPrefixCh
 import 
org.apache.asterix.runtime.evaluators.functions.SimilarityJaccardPrefixDescriptor;
 import 
org.apache.asterix.runtime.evaluators.functions.SimilarityJaccardSortedCheckDescriptor;
 import 
org.apache.asterix.runtime.evaluators.functions.SimilarityJaccardSortedDescriptor;
+import org.apache.asterix.runtime.evaluators.functions.SleepDescriptor;
 import org.apache.asterix.runtime.evaluators.functions.SpatialAreaDescriptor;
 import org.apache.asterix.runtime.evaluators.functions.SpatialCellDescriptor;
 import 
org.apache.asterix.runtime.evaluators.functions.SpatialDistanceDescriptor;
@@ -412,6 +413,9 @@ public class FunctionCollection {
         temp.add(OrderedListConstructorDescriptor.FACTORY);
         temp.add(UnorderedListConstructorDescriptor.FACTORY);
 
+        // Sleep function
+        temp.add(SleepDescriptor.FACTORY);
+
         // Inject failure function
         temp.add(InjectFailureDescriptor.FACTORY);
 

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/392bbbc0/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/common/AsterixHyracksIntegrationUtil.java
----------------------------------------------------------------------
diff --git 
a/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/common/AsterixHyracksIntegrationUtil.java
 
b/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/common/AsterixHyracksIntegrationUtil.java
index bdce0ca..83233f1 100644
--- 
a/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/common/AsterixHyracksIntegrationUtil.java
+++ 
b/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/common/AsterixHyracksIntegrationUtil.java
@@ -111,7 +111,7 @@ public class AsterixHyracksIntegrationUtil {
         ccConfig.clientNetPort = DEFAULT_HYRACKS_CC_CLIENT_PORT;
         ccConfig.clusterNetPort = DEFAULT_HYRACKS_CC_CLUSTER_PORT;
         ccConfig.defaultMaxJobAttempts = 0;
-        ccConfig.resultTTL = 30000;
+        ccConfig.resultTTL = 120000;
         ccConfig.resultSweepThreshold = 1000;
         ccConfig.appCCMainClass = CCApplicationEntryPoint.class.getName();
         return ccConfig;
@@ -126,7 +126,7 @@ public class AsterixHyracksIntegrationUtil {
         ncConfig.resultIPAddress = 
Inet4Address.getLoopbackAddress().getHostAddress();
         ncConfig.messagingIPAddress = 
Inet4Address.getLoopbackAddress().getHostAddress();
         ncConfig.nodeId = ncName;
-        ncConfig.resultTTL = 30000;
+        ncConfig.resultTTL = 120000;
         ncConfig.resultSweepThreshold = 1000;
         ncConfig.appArgs = Collections.singletonList("-virtual-NC");
         ncConfig.appNCMainClass = NCApplicationEntryPoint.class.getName();

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/392bbbc0/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/http/server/QueryServiceServlet.java
----------------------------------------------------------------------
diff --git 
a/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/http/server/QueryServiceServlet.java
 
b/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/http/server/QueryServiceServlet.java
index 410fd1e..744b929 100644
--- 
a/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/http/server/QueryServiceServlet.java
+++ 
b/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/http/server/QueryServiceServlet.java
@@ -20,6 +20,7 @@ package org.apache.asterix.api.http.server;
 
 import static 
org.apache.asterix.api.http.servlet.ServletConstants.HYRACKS_CONNECTION_ATTR;
 import static 
org.apache.asterix.api.http.servlet.ServletConstants.HYRACKS_DATASET_ATTR;
+import static org.apache.asterix.translator.IStatementExecutor.ResultDelivery;
 
 import java.io.IOException;
 import java.io.PrintWriter;
@@ -33,7 +34,6 @@ import java.util.logging.Logger;
 
 import org.apache.asterix.app.result.ResultReader;
 import org.apache.asterix.app.result.ResultUtil;
-import org.apache.asterix.app.translator.QueryTranslator;
 import org.apache.asterix.common.api.IClusterManagementWork;
 import org.apache.asterix.common.config.GlobalConfig;
 import org.apache.asterix.common.context.IStorageComponentProvider;
@@ -156,6 +156,7 @@ public class QueryServiceServlet extends AbstractServlet {
     }
 
     public enum ResultStatus {
+        STARTED("started"),
         SUCCESS("success"),
         TIMEOUT("timeout"),
         ERRORS("errors"),
@@ -458,13 +459,13 @@ public class QueryServiceServlet extends AbstractServlet {
         return 
request.getHttpRequest().content().toString(StandardCharsets.UTF_8);
     }
 
-    private static QueryTranslator.ResultDelivery parseResultDelivery(String 
mode) {
+    private static ResultDelivery parseResultDelivery(String mode) {
         if ("async".equals(mode)) {
-            return QueryTranslator.ResultDelivery.ASYNC;
+            return ResultDelivery.ASYNC;
         } else if ("deferred".equals(mode)) {
-            return QueryTranslator.ResultDelivery.DEFERRED;
+            return ResultDelivery.DEFERRED;
         } else {
-            return QueryTranslator.ResultDelivery.IMMEDIATE;
+            return ResultDelivery.IMMEDIATE;
         }
     }
 
@@ -474,7 +475,7 @@ public class QueryServiceServlet extends AbstractServlet {
         final StringWriter stringWriter = new StringWriter();
         final PrintWriter resultWriter = new PrintWriter(stringWriter);
 
-        QueryTranslator.ResultDelivery delivery = 
parseResultDelivery(param.mode);
+        ResultDelivery delivery = parseResultDelivery(param.mode);
 
         SessionConfig sessionConfig = createSessionConfig(param, resultWriter);
         ServletUtils.setContentType(response, 
IServlet.ContentType.APPLICATION_JSON, IServlet.Encoding.UTF8);
@@ -517,7 +518,7 @@ public class QueryServiceServlet extends AbstractServlet {
             execStart = System.nanoTime();
             translator.compileAndExecute(hcc, hds, delivery, stats);
             execEnd = System.nanoTime();
-            printStatus(resultWriter, ResultStatus.SUCCESS);
+            printStatus(resultWriter, ResultDelivery.ASYNC == delivery ? 
ResultStatus.STARTED : ResultStatus.SUCCESS);
         } catch (AsterixException | TokenMgrError | 
org.apache.asterix.aqlplus.parser.TokenMgrError pe) {
             GlobalConfig.ASTERIX_LOGGER.log(Level.SEVERE, pe.getMessage(), pe);
             printError(resultWriter, pe);

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/392bbbc0/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/http/server/QueryStatusApiServlet.java
----------------------------------------------------------------------
diff --git 
a/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/http/server/QueryStatusApiServlet.java
 
b/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/http/server/QueryStatusApiServlet.java
index 039c740..3d31616 100644
--- 
a/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/http/server/QueryStatusApiServlet.java
+++ 
b/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/http/server/QueryStatusApiServlet.java
@@ -94,19 +94,7 @@ public class QueryStatusApiServlet extends AbstractServlet {
             resultReader.open(jobId, rsId);
 
             ObjectNode jsonResponse = om.createObjectNode();
-            String status;
-            switch (resultReader.getStatus()) {
-                case RUNNING:
-                    status = "RUNNING";
-                    break;
-                case SUCCESS:
-                    status = "SUCCESS";
-                    break;
-                default:
-                    status = "ERROR";
-                    break;
-            }
-            jsonResponse.put("status", status);
+            jsonResponse.put("status", resultReader.getStatus().name());
             out.write(jsonResponse.toString());
 
         } catch (Exception e) {

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/392bbbc0/asterixdb/asterix-app/src/main/java/org/apache/asterix/app/cc/CCExtensionManager.java
----------------------------------------------------------------------
diff --git 
a/asterixdb/asterix-app/src/main/java/org/apache/asterix/app/cc/CCExtensionManager.java
 
b/asterixdb/asterix-app/src/main/java/org/apache/asterix/app/cc/CCExtensionManager.java
index 31ace22..f7e70a3 100644
--- 
a/asterixdb/asterix-app/src/main/java/org/apache/asterix/app/cc/CCExtensionManager.java
+++ 
b/asterixdb/asterix-app/src/main/java/org/apache/asterix/app/cc/CCExtensionManager.java
@@ -21,6 +21,7 @@ package org.apache.asterix.app.cc;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
+import java.util.concurrent.ExecutorService;
 
 import org.apache.asterix.algebra.base.ILangExtension;
 import org.apache.asterix.algebra.base.ILangExtension.Language;
@@ -50,12 +51,13 @@ public class CCExtensionManager implements 
IAlgebraExtensionManager {
     private final IStatementExecutorExtension statementExecutorExtension;
     private final ILangCompilationProvider aqlCompilationProvider;
     private final ILangCompilationProvider sqlppCompilationProvider;
-    private final DefaultStatementExecutorFactory 
defaultQueryTranslatorFactory;
+    private transient IStatementExecutorFactory statementExecutorFactory;
 
     /**
      * Initialize {@code CompilerExtensionManager} from configuration
      *
      * @param list
+     *            a list of extensions
      * @throws InstantiationException
      * @throws IllegalAccessException
      * @throws ClassNotFoundException
@@ -66,7 +68,6 @@ public class CCExtensionManager implements 
IAlgebraExtensionManager {
         Pair<ExtensionId, ILangCompilationProvider> aqlcp = null;
         Pair<ExtensionId, ILangCompilationProvider> sqlppcp = null;
         IStatementExecutorExtension see = null;
-        defaultQueryTranslatorFactory = new DefaultStatementExecutorFactory();
         if (list != null) {
             for (AsterixExtension extensionConf : list) {
                 IExtension extension = (IExtension) 
Class.forName(extensionConf.getClassName()).newInstance();
@@ -94,9 +95,19 @@ public class CCExtensionManager implements 
IAlgebraExtensionManager {
         this.sqlppCompilationProvider = sqlppcp == null ? new 
SqlppCompilationProvider() : sqlppcp.second;
     }
 
+    /** @deprecated use getStatementExecutorFactory instead */
+    @Deprecated
     public IStatementExecutorFactory getQueryTranslatorFactory() {
-        return statementExecutorExtension == null ? 
defaultQueryTranslatorFactory
-                : statementExecutorExtension.getQueryTranslatorFactory();
+        return getStatementExecutorFactory(null);
+    }
+
+    public IStatementExecutorFactory 
getStatementExecutorFactory(ExecutorService executorService) {
+        if (statementExecutorFactory == null) {
+            statementExecutorFactory = statementExecutorExtension == null
+                    ? new DefaultStatementExecutorFactory(executorService)
+                    : 
statementExecutorExtension.getStatementExecutorFactory(executorService);
+        }
+        return statementExecutorFactory;
     }
 
     public ILangCompilationProvider getAqlCompilationProvider() {

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/392bbbc0/asterixdb/asterix-app/src/main/java/org/apache/asterix/app/cc/IStatementExecutorExtension.java
----------------------------------------------------------------------
diff --git 
a/asterixdb/asterix-app/src/main/java/org/apache/asterix/app/cc/IStatementExecutorExtension.java
 
b/asterixdb/asterix-app/src/main/java/org/apache/asterix/app/cc/IStatementExecutorExtension.java
index f7b6842..f77b25b 100644
--- 
a/asterixdb/asterix-app/src/main/java/org/apache/asterix/app/cc/IStatementExecutorExtension.java
+++ 
b/asterixdb/asterix-app/src/main/java/org/apache/asterix/app/cc/IStatementExecutorExtension.java
@@ -18,6 +18,8 @@
  */
 package org.apache.asterix.app.cc;
 
+import java.util.concurrent.ExecutorService;
+
 import org.apache.asterix.common.api.IExtension;
 import org.apache.asterix.translator.IStatementExecutorFactory;
 
@@ -33,6 +35,15 @@ public interface IStatementExecutorExtension extends 
IExtension {
 
     /**
      * @return The extension implementation of the {@code 
IStatementExecutorFactory}
+     * @deprecated use getStatementExecutorFactory instead
      */
+    @Deprecated
     IStatementExecutorFactory getQueryTranslatorFactory();
+
+    /**
+     * @return The extension implementation of the {@code 
IStatementExecutorFactory}
+     */
+    default IStatementExecutorFactory 
getStatementExecutorFactory(ExecutorService executorService) {
+        return getQueryTranslatorFactory();
+    }
 }

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/392bbbc0/asterixdb/asterix-app/src/main/java/org/apache/asterix/app/translator/DefaultStatementExecutorFactory.java
----------------------------------------------------------------------
diff --git 
a/asterixdb/asterix-app/src/main/java/org/apache/asterix/app/translator/DefaultStatementExecutorFactory.java
 
b/asterixdb/asterix-app/src/main/java/org/apache/asterix/app/translator/DefaultStatementExecutorFactory.java
index 99dcc83..15ed1b4 100644
--- 
a/asterixdb/asterix-app/src/main/java/org/apache/asterix/app/translator/DefaultStatementExecutorFactory.java
+++ 
b/asterixdb/asterix-app/src/main/java/org/apache/asterix/app/translator/DefaultStatementExecutorFactory.java
@@ -19,6 +19,8 @@
 package org.apache.asterix.app.translator;
 
 import java.util.List;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
 
 import org.apache.asterix.common.context.IStorageComponentProvider;
 import org.apache.asterix.compiler.provider.ILangCompilationProvider;
@@ -26,12 +28,27 @@ import org.apache.asterix.lang.common.base.Statement;
 import org.apache.asterix.translator.IStatementExecutor;
 import org.apache.asterix.translator.IStatementExecutorFactory;
 import org.apache.asterix.translator.SessionConfig;
+import org.apache.hyracks.control.common.utils.HyracksThreadFactory;
 
 public class DefaultStatementExecutorFactory implements 
IStatementExecutorFactory {
 
+    protected final ExecutorService executorService;
+
+    /*
+     * @deprecated use other constructor
+     */
+    public DefaultStatementExecutorFactory() {
+        this(Executors.newSingleThreadExecutor(
+                new 
HyracksThreadFactory(DefaultStatementExecutorFactory.class.getSimpleName())));
+    }
+
+    public DefaultStatementExecutorFactory(ExecutorService executorService) {
+        this.executorService = executorService;
+    }
+
     @Override
     public IStatementExecutor create(List<Statement> statements, SessionConfig 
conf,
             ILangCompilationProvider compilationProvider, 
IStorageComponentProvider storageComponentProvider) {
-        return new QueryTranslator(statements, conf, compilationProvider, 
storageComponentProvider);
+        return new QueryTranslator(statements, conf, compilationProvider, 
storageComponentProvider, executorService);
     }
 }

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/392bbbc0/asterixdb/asterix-app/src/main/java/org/apache/asterix/app/translator/QueryTranslator.java
----------------------------------------------------------------------
diff --git 
a/asterixdb/asterix-app/src/main/java/org/apache/asterix/app/translator/QueryTranslator.java
 
b/asterixdb/asterix-app/src/main/java/org/apache/asterix/app/translator/QueryTranslator.java
index 6fbf2a5..3c69d83 100644
--- 
a/asterixdb/asterix-app/src/main/java/org/apache/asterix/app/translator/QueryTranslator.java
+++ 
b/asterixdb/asterix-app/src/main/java/org/apache/asterix/app/translator/QueryTranslator.java
@@ -34,6 +34,7 @@ import java.util.Map;
 import java.util.Map.Entry;
 import java.util.Properties;
 import java.util.Random;
+import java.util.concurrent.ExecutorService;
 import java.util.logging.Level;
 import java.util.logging.Logger;
 
@@ -218,9 +219,10 @@ public class QueryTranslator extends 
AbstractLangTranslator implements IStatemen
     protected final APIFramework apiFramework;
     protected final IRewriterFactory rewriterFactory;
     protected final IStorageComponentProvider componentProvider;
+    protected final ExecutorService executorService;
 
-    public QueryTranslator(List<Statement> statements, SessionConfig conf,
-            ILangCompilationProvider compliationProvider, 
IStorageComponentProvider componentProvider) {
+    public QueryTranslator(List<Statement> statements, SessionConfig conf, 
ILangCompilationProvider compliationProvider,
+            IStorageComponentProvider componentProvider, ExecutorService 
executorService) {
         this.statements = statements;
         this.sessionConfig = conf;
         this.componentProvider = componentProvider;
@@ -228,6 +230,7 @@ public class QueryTranslator extends AbstractLangTranslator 
implements IStatemen
         apiFramework = new APIFramework(compliationProvider);
         rewriterFactory = compliationProvider.getRewriterFactory();
         activeDataverse = MetadataBuiltinEntities.DEFAULT_DATAVERSE;
+        this.executorService = executorService;
     }
 
     protected List<FunctionDecl> getDeclaredFunctions(List<Statement> 
statements) {
@@ -1327,11 +1330,6 @@ public class QueryTranslator extends 
AbstractLangTranslator implements IStatemen
         }
     }
 
-    protected Dataset getDataset(MetadataTransactionContext mdTxnCtx, String 
dataverseName, String datasetName)
-            throws MetadataException {
-        return MetadataManager.INSTANCE.getDataset(mdTxnCtx, dataverseName, 
datasetName);
-    }
-
     public void handleDatasetDropStatement(MetadataProvider metadataProvider, 
Statement stmt,
             IHyracksClientConnection hcc) throws Exception {
         DropDatasetStatement stmtDelete = (DropDatasetStatement) stmt;
@@ -1826,41 +1824,60 @@ public class QueryTranslator extends 
AbstractLangTranslator implements IStatemen
         }
     }
 
-    public JobSpecification handleInsertUpsertStatement(MetadataProvider 
metadataProvider, Statement stmt,
+    public void handleInsertUpsertStatement(MetadataProvider metadataProvider, 
Statement stmt,
             IHyracksClientConnection hcc, IHyracksDataset hdc, ResultDelivery 
resultDelivery,
             IStatementExecutor.Stats stats, boolean compileOnly) throws 
Exception {
 
         InsertStatement stmtInsertUpsert = (InsertStatement) stmt;
         String dataverseName = 
getActiveDataverse(stmtInsertUpsert.getDataverseName());
         Query query = stmtInsertUpsert.getQuery();
-        MetadataTransactionContext mdTxnCtx = 
MetadataManager.INSTANCE.beginTransaction();
-        boolean bActiveTxn = true;
-        metadataProvider.setMetadataTxnContext(mdTxnCtx);
-        MetadataLockManager.INSTANCE.insertDeleteUpsertBegin(dataverseName,
-                dataverseName + "." + stmtInsertUpsert.getDatasetName(), 
query.getDataverses(), query.getDatasets());
-        try {
-            metadataProvider.setWriteTransaction(true);
-            JobSpecification jobSpec = rewriteCompileInsertUpsert(hcc, 
metadataProvider, stmtInsertUpsert);
-            MetadataManager.INSTANCE.commitTransaction(mdTxnCtx);
-            bActiveTxn = false;
 
-            if (jobSpec != null && !compileOnly) {
-                if (stmtInsertUpsert.getReturnExpression() != null) {
-                    handleQueryResult(metadataProvider, hcc, hdc, jobSpec, 
resultDelivery, stats);
-                } else {
-                    JobUtils.runJob(hcc, jobSpec, true);
+        final IMetadataLocker locker = new IMetadataLocker() {
+            @Override
+            public void lock() {
+                
MetadataLockManager.INSTANCE.insertDeleteUpsertBegin(dataverseName,
+                        dataverseName + "." + 
stmtInsertUpsert.getDatasetName(), query.getDataverses(),
+                        query.getDatasets());
+            }
+
+            @Override
+            public void unlock() {
+                
MetadataLockManager.INSTANCE.insertDeleteUpsertEnd(dataverseName,
+                        dataverseName + "." + 
stmtInsertUpsert.getDatasetName(), query.getDataverses(),
+                        query.getDatasets());
+            }
+        };
+        final IStatementCompiler compiler = () -> {
+            MetadataTransactionContext mdTxnCtx = 
MetadataManager.INSTANCE.beginTransaction();
+            boolean bActiveTxn = true;
+            metadataProvider.setMetadataTxnContext(mdTxnCtx);
+            try {
+                metadataProvider.setWriteTransaction(true);
+                final JobSpecification jobSpec = 
rewriteCompileInsertUpsert(hcc, metadataProvider, stmtInsertUpsert);
+                MetadataManager.INSTANCE.commitTransaction(mdTxnCtx);
+                bActiveTxn = false;
+                return compileOnly ? null : jobSpec;
+            } catch (Exception e) {
+                if (bActiveTxn) {
+                    abort(e, e, mdTxnCtx);
                 }
+                throw e;
             }
-            return jobSpec;
-        } catch (Exception e) {
-            if (bActiveTxn) {
-                abort(e, e, mdTxnCtx);
+        };
+
+        if (stmtInsertUpsert.getReturnExpression() != null) {
+            deliverResult(hcc, hdc, compiler, metadataProvider, locker, 
resultDelivery, stats);
+        } else {
+            locker.lock();
+            try {
+                final JobSpecification jobSpec = compiler.compile();
+                if (jobSpec == null) {
+                    return;
+                }
+                JobUtils.runJob(hcc, jobSpec, true);
+            } finally {
+                locker.unlock();
             }
-            throw e;
-        } finally {
-            MetadataLockManager.INSTANCE.insertDeleteUpsertEnd(dataverseName,
-                    dataverseName + "." + stmtInsertUpsert.getDatasetName(), 
query.getDataverses(),
-                    query.getDatasets());
         }
     }
 
@@ -2515,69 +2532,124 @@ public class QueryTranslator extends 
AbstractLangTranslator implements IStatemen
                 new StorageComponentProvider()));
     }
 
-    protected JobSpecification handleQuery(MetadataProvider metadataProvider, 
Query query,
-            IHyracksClientConnection hcc, IHyracksDataset hdc, ResultDelivery 
resultDelivery, Stats stats)
-            throws Exception {
-        MetadataTransactionContext mdTxnCtx = 
MetadataManager.INSTANCE.beginTransaction();
-        boolean bActiveTxn = true;
-        metadataProvider.setMetadataTxnContext(mdTxnCtx);
-        MetadataLockManager.INSTANCE.queryBegin(activeDataverse, 
query.getDataverses(), query.getDatasets());
-        try {
-            JobSpecification jobSpec = rewriteCompileQuery(hcc, 
metadataProvider, query, null);
+    private interface IMetadataLocker {
+        void lock();
 
-            MetadataManager.INSTANCE.commitTransaction(mdTxnCtx);
-            bActiveTxn = false;
+        void unlock();
+    }
+
+    private interface IResultPrinter {
+        void print(JobId jobId) throws HyracksDataException, 
AlgebricksException;
+    }
+
+    private interface IStatementCompiler {
+        JobSpecification compile() throws AlgebricksException, 
RemoteException, ACIDException;
+    }
 
-            if (query.isExplain()) {
-                sessionConfig.out().flush();
-                return jobSpec;
-            } else if (sessionConfig.isExecuteQuery() && jobSpec != null) {
-                handleQueryResult(metadataProvider, hcc, hdc, jobSpec, 
resultDelivery, stats);
+    protected void handleQuery(MetadataProvider metadataProvider, Query query, 
IHyracksClientConnection hcc,
+            IHyracksDataset hdc, ResultDelivery resultDelivery, Stats stats) 
throws Exception {
+        final IMetadataLocker locker = new IMetadataLocker() {
+            @Override
+            public void lock() {
+                MetadataLockManager.INSTANCE.queryBegin(activeDataverse, 
query.getDataverses(), query.getDatasets());
             }
-            return jobSpec;
-        } catch (Exception e) {
-            LOGGER.log(Level.INFO, e.getMessage(), e);
-            if (bActiveTxn) {
-                abort(e, e, mdTxnCtx);
+
+            @Override
+            public void unlock() {
+                MetadataLockManager.INSTANCE.queryEnd(query.getDataverses(), 
query.getDatasets());
+                // release external datasets' locks acquired during 
compilation of the query
+                
ExternalDatasetsRegistry.INSTANCE.releaseAcquiredLocks(metadataProvider);
             }
-            throw e;
-        } finally {
-            MetadataLockManager.INSTANCE.queryEnd(query.getDataverses(), 
query.getDatasets());
-            // release external datasets' locks acquired during compilation of 
the query
-            
ExternalDatasetsRegistry.INSTANCE.releaseAcquiredLocks(metadataProvider);
-        }
+        };
+        final IStatementCompiler compiler = () -> {
+            MetadataTransactionContext mdTxnCtx = 
MetadataManager.INSTANCE.beginTransaction();
+            boolean bActiveTxn = true;
+            metadataProvider.setMetadataTxnContext(mdTxnCtx);
+            try {
+                final JobSpecification jobSpec = rewriteCompileQuery(hcc, 
metadataProvider, query, null);
+                MetadataManager.INSTANCE.commitTransaction(mdTxnCtx);
+                bActiveTxn = false;
+                return query.isExplain() || !sessionConfig.isExecuteQuery() ? 
null : jobSpec;
+            } catch (Exception e) {
+                LOGGER.log(Level.INFO, e.getMessage(), e);
+                if (bActiveTxn) {
+                    abort(e, e, mdTxnCtx);
+                }
+                throw e;
+            }
+        };
+        deliverResult(hcc, hdc, compiler, metadataProvider, locker, 
resultDelivery, stats);
     }
 
-    private void handleQueryResult(MetadataProvider metadataProvider, 
IHyracksClientConnection hcc,
-            IHyracksDataset hdc, JobSpecification jobSpec, ResultDelivery 
resultDelivery, Stats stats)
+    private void deliverResult(IHyracksClientConnection hcc, IHyracksDataset 
hdc, IStatementCompiler compiler,
+            MetadataProvider metadataProvider, IMetadataLocker locker, 
ResultDelivery resultDelivery, Stats stats)
             throws Exception {
-        JobId jobId = JobUtils.runJob(hcc, jobSpec, false);
-
-        ResultHandle hand;
+        final ResultSetId resultSetId = metadataProvider.getResultSetId();
         switch (resultDelivery) {
             case ASYNC:
-                hand = new ResultHandle(jobId, 
metadataProvider.getResultSetId());
-                ResultUtil.printResultHandle(hand, sessionConfig);
-                hcc.waitForCompletion(jobId);
-                sessionConfig.out().flush();
+                MutableBoolean printed = new MutableBoolean(false);
+                executorService.submit(() -> {
+                    JobId jobId = null;
+                    try {
+                        jobId = createAndRunJob(hcc, compiler, locker, 
resultDelivery, id -> {
+                            final ResultHandle handle = new ResultHandle(id, 
resultSetId);
+                            ResultUtil.printResultHandle(handle, 
sessionConfig);
+                            synchronized (printed) {
+                                printed.setTrue();
+                                printed.notify();
+                            }
+                        });
+                    } catch (Exception e) {
+                        GlobalConfig.ASTERIX_LOGGER.log(Level.SEVERE,
+                                resultDelivery.name() + " job " + "with id " + 
jobId + " failed", e);
+                    }
+                });
+                synchronized (printed) {
+                    while (!printed.booleanValue()) {
+                        printed.wait();
+                    }
+                }
                 break;
             case IMMEDIATE:
-                hcc.waitForCompletion(jobId);
-                ResultReader resultReader = new ResultReader(hdc);
-                resultReader.open(jobId, metadataProvider.getResultSetId());
-                ResultUtil.printResults(resultReader, sessionConfig, stats, 
metadataProvider.findOutputRecordType());
+                createAndRunJob(hcc, compiler, locker, resultDelivery, id -> {
+                    final ResultReader resultReader = new ResultReader(hdc);
+                    resultReader.open(id, resultSetId);
+                    ResultUtil.printResults(resultReader, sessionConfig, stats,
+                            metadataProvider.findOutputRecordType());
+                });
                 break;
             case DEFERRED:
-                hcc.waitForCompletion(jobId);
-                hand = new ResultHandle(jobId, 
metadataProvider.getResultSetId());
-                ResultUtil.printResultHandle(hand, sessionConfig);
-                sessionConfig.out().flush();
+                createAndRunJob(hcc, compiler, locker, resultDelivery, id -> {
+                    ResultUtil.printResultHandle(new ResultHandle(id, 
resultSetId), sessionConfig);
+                });
                 break;
             default:
                 break;
         }
     }
 
+    private static JobId createAndRunJob(IHyracksClientConnection hcc, 
IStatementCompiler compiler,
+            IMetadataLocker locker, ResultDelivery resultDelivery, 
IResultPrinter printer) throws Exception {
+        locker.lock();
+        try {
+            final JobSpecification jobSpec = compiler.compile();
+            if (jobSpec == null) {
+                return JobId.INVALID;
+            }
+            final JobId jobId = JobUtils.runJob(hcc, jobSpec, false);
+            if (ResultDelivery.ASYNC == resultDelivery) {
+                printer.print(jobId);
+                hcc.waitForCompletion(jobId);
+            } else {
+                hcc.waitForCompletion(jobId);
+                printer.print(jobId);
+            }
+            return jobId;
+        } finally {
+            locker.unlock();
+        }
+    }
+
     protected void handleCreateNodeGroupStatement(MetadataProvider 
metadataProvider, Statement stmt) throws Exception {
 
         NodegroupDecl stmtCreateNodegroup = (NodegroupDecl) stmt;

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/392bbbc0/asterixdb/asterix-app/src/main/java/org/apache/asterix/hyracks/bootstrap/CCApplicationEntryPoint.java
----------------------------------------------------------------------
diff --git 
a/asterixdb/asterix-app/src/main/java/org/apache/asterix/hyracks/bootstrap/CCApplicationEntryPoint.java
 
b/asterixdb/asterix-app/src/main/java/org/apache/asterix/hyracks/bootstrap/CCApplicationEntryPoint.java
index 92f3501..8ea4193 100644
--- 
a/asterixdb/asterix-app/src/main/java/org/apache/asterix/hyracks/bootstrap/CCApplicationEntryPoint.java
+++ 
b/asterixdb/asterix-app/src/main/java/org/apache/asterix/hyracks/bootstrap/CCApplicationEntryPoint.java
@@ -63,6 +63,7 @@ import 
org.apache.asterix.metadata.bootstrap.AsterixStateProxy;
 import org.apache.asterix.metadata.cluster.ClusterManagerProvider;
 import org.apache.asterix.runtime.job.resource.JobCapacityController;
 import org.apache.asterix.runtime.utils.AppContextInfo;
+import org.apache.asterix.translator.IStatementExecutorFactory;
 import org.apache.hyracks.api.application.ICCApplicationContext;
 import org.apache.hyracks.api.application.ICCApplicationEntryPoint;
 import org.apache.hyracks.api.client.HyracksConnection;
@@ -164,7 +165,7 @@ public class CCApplicationEntryPoint implements 
ICCApplicationEntryPoint {
         webServer.setAttribute(HYRACKS_CONNECTION_ATTR, hcc);
         webServer.addLet(new ApiServlet(webServer.ctx(), new String[] { "/*" },
                 ccExtensionManager.getAqlCompilationProvider(), 
ccExtensionManager.getSqlppCompilationProvider(),
-                ccExtensionManager.getQueryTranslatorFactory(), 
componentProvider));
+                getStatementExecutorFactory(), componentProvider));
         return webServer;
     }
 
@@ -228,35 +229,35 @@ public class CCApplicationEntryPoint implements 
ICCApplicationEntryPoint {
         switch (key) {
             case AQL:
                 return new FullApiServlet(server.ctx(), paths, 
ccExtensionManager.getAqlCompilationProvider(),
-                        ccExtensionManager.getQueryTranslatorFactory(), 
componentProvider);
+                        getStatementExecutorFactory(), componentProvider);
             case AQL_QUERY:
                 return new QueryApiServlet(server.ctx(), paths, 
ccExtensionManager.getAqlCompilationProvider(),
-                        ccExtensionManager.getQueryTranslatorFactory(), 
componentProvider);
+                        getStatementExecutorFactory(), componentProvider);
             case AQL_UPDATE:
                 return new UpdateApiServlet(server.ctx(), paths, 
ccExtensionManager.getAqlCompilationProvider(),
-                        ccExtensionManager.getQueryTranslatorFactory(), 
componentProvider);
+                        getStatementExecutorFactory(), componentProvider);
             case AQL_DDL:
                 return new DdlApiServlet(server.ctx(), paths, 
ccExtensionManager.getAqlCompilationProvider(),
-                        ccExtensionManager.getQueryTranslatorFactory(), 
componentProvider);
+                        getStatementExecutorFactory(), componentProvider);
             case SQLPP:
                 return new FullApiServlet(server.ctx(), paths, 
ccExtensionManager.getSqlppCompilationProvider(),
-                        ccExtensionManager.getQueryTranslatorFactory(), 
componentProvider);
+                        getStatementExecutorFactory(), componentProvider);
             case SQLPP_QUERY:
                 return new QueryApiServlet(server.ctx(), paths, 
ccExtensionManager.getSqlppCompilationProvider(),
-                        ccExtensionManager.getQueryTranslatorFactory(), 
componentProvider);
+                        getStatementExecutorFactory(), componentProvider);
             case SQLPP_UPDATE:
                 return new UpdateApiServlet(server.ctx(), paths, 
ccExtensionManager.getSqlppCompilationProvider(),
-                        ccExtensionManager.getQueryTranslatorFactory(), 
componentProvider);
+                        getStatementExecutorFactory(), componentProvider);
             case SQLPP_DDL:
                 return new DdlApiServlet(server.ctx(), paths, 
ccExtensionManager.getSqlppCompilationProvider(),
-                        ccExtensionManager.getQueryTranslatorFactory(), 
componentProvider);
+                        getStatementExecutorFactory(), componentProvider);
             case QUERY_STATUS:
                 return new QueryStatusApiServlet(server.ctx(), paths);
             case QUERY_RESULT:
                 return new QueryResultApiServlet(server.ctx(), paths);
             case QUERY_SERVICE:
                 return new QueryServiceServlet(server.ctx(), paths, 
ccExtensionManager.getSqlppCompilationProvider(),
-                        ccExtensionManager.getQueryTranslatorFactory(), 
componentProvider);
+                        getStatementExecutorFactory(), componentProvider);
             case CONNECTOR:
                 return new ConnectorApiServlet(server.ctx(), paths);
             case SHUTDOWN:
@@ -276,6 +277,11 @@ public class CCApplicationEntryPoint implements 
ICCApplicationEntryPoint {
         }
     }
 
+    private IStatementExecutorFactory getStatementExecutorFactory() {
+        return ccExtensionManager.getStatementExecutorFactory(
+                ((ClusterControllerService) 
appCtx.getControllerService()).getExecutorService());
+    }
+
     @Override
     public void startupCompleted() throws Exception {
         ClusterManagerProvider.getClusterManager().notifyStartupCompleted();

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/392bbbc0/asterixdb/asterix-app/src/test/resources/runtimets/queries/flwor/at00/at00.4.asyncdefer.aql
----------------------------------------------------------------------
diff --git 
a/asterixdb/asterix-app/src/test/resources/runtimets/queries/flwor/at00/at00.4.asyncdefer.aql
 
b/asterixdb/asterix-app/src/test/resources/runtimets/queries/flwor/at00/at00.4.asyncdefer.aql
deleted file mode 100644
index 29f8eab..0000000
--- 
a/asterixdb/asterix-app/src/test/resources/runtimets/queries/flwor/at00/at00.4.asyncdefer.aql
+++ /dev/null
@@ -1,32 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *   http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-/*
- * Description      :  Test for clause of the position variable in FLWOR 
expression
- * Expected Result  :  Success
- * Date             :  09/17/2013
- */
-
-use dataverse test;
-
-for $i in dataset LineItem
-group by $partkey := $i.l_partkey with $i
-for $j at $p in ( for $x in $i order by $x.l_shipdate return $x)
-where $p < 4
-order by $partkey
-return { "partkey": $partkey, "pid": $p, "shipdate": $j.l_shipdate }

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/392bbbc0/asterixdb/asterix-app/src/test/resources/runtimets/queries/flwor/at00/at00.4.deferred.aql
----------------------------------------------------------------------
diff --git 
a/asterixdb/asterix-app/src/test/resources/runtimets/queries/flwor/at00/at00.4.deferred.aql
 
b/asterixdb/asterix-app/src/test/resources/runtimets/queries/flwor/at00/at00.4.deferred.aql
new file mode 100644
index 0000000..e7ad205
--- /dev/null
+++ 
b/asterixdb/asterix-app/src/test/resources/runtimets/queries/flwor/at00/at00.4.deferred.aql
@@ -0,0 +1,34 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+/*
+ * Description      :  Test for clause of the position variable in FLWOR 
expression
+ * Expected Result  :  Success
+ * Date             :  09/17/2013
+ */
+
+//handlevariable=handle
+
+use dataverse test;
+
+for $i in dataset LineItem
+group by $partkey := $i.l_partkey with $i
+for $j at $p in ( for $x in $i order by $x.l_shipdate return $x)
+where $p < 4
+order by $partkey
+return { "partkey": $partkey, "pid": $p, "shipdate": $j.l_shipdate }

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/392bbbc0/asterixdb/asterix-app/src/test/resources/runtimets/queries/flwor/at00/at00.5.async.aql
----------------------------------------------------------------------
diff --git 
a/asterixdb/asterix-app/src/test/resources/runtimets/queries/flwor/at00/at00.5.async.aql
 
b/asterixdb/asterix-app/src/test/resources/runtimets/queries/flwor/at00/at00.5.async.aql
deleted file mode 100644
index 29f8eab..0000000
--- 
a/asterixdb/asterix-app/src/test/resources/runtimets/queries/flwor/at00/at00.5.async.aql
+++ /dev/null
@@ -1,32 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *   http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-/*
- * Description      :  Test for clause of the position variable in FLWOR 
expression
- * Expected Result  :  Success
- * Date             :  09/17/2013
- */
-
-use dataverse test;
-
-for $i in dataset LineItem
-group by $partkey := $i.l_partkey with $i
-for $j at $p in ( for $x in $i order by $x.l_shipdate return $x)
-where $p < 4
-order by $partkey
-return { "partkey": $partkey, "pid": $p, "shipdate": $j.l_shipdate }

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/392bbbc0/asterixdb/asterix-app/src/test/resources/runtimets/queries/flwor/at00/at00.5.get.http
----------------------------------------------------------------------
diff --git 
a/asterixdb/asterix-app/src/test/resources/runtimets/queries/flwor/at00/at00.5.get.http
 
b/asterixdb/asterix-app/src/test/resources/runtimets/queries/flwor/at00/at00.5.get.http
new file mode 100644
index 0000000..a88991c
--- /dev/null
+++ 
b/asterixdb/asterix-app/src/test/resources/runtimets/queries/flwor/at00/at00.5.get.http
@@ -0,0 +1,20 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+/query/result?handle=$handle

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/392bbbc0/asterixdb/asterix-app/src/test/resources/runtimets/queries/flwor/at00/at00.6.async.aql
----------------------------------------------------------------------
diff --git 
a/asterixdb/asterix-app/src/test/resources/runtimets/queries/flwor/at00/at00.6.async.aql
 
b/asterixdb/asterix-app/src/test/resources/runtimets/queries/flwor/at00/at00.6.async.aql
new file mode 100644
index 0000000..e7ad205
--- /dev/null
+++ 
b/asterixdb/asterix-app/src/test/resources/runtimets/queries/flwor/at00/at00.6.async.aql
@@ -0,0 +1,34 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+/*
+ * Description      :  Test for clause of the position variable in FLWOR 
expression
+ * Expected Result  :  Success
+ * Date             :  09/17/2013
+ */
+
+//handlevariable=handle
+
+use dataverse test;
+
+for $i in dataset LineItem
+group by $partkey := $i.l_partkey with $i
+for $j at $p in ( for $x in $i order by $x.l_shipdate return $x)
+where $p < 4
+order by $partkey
+return { "partkey": $partkey, "pid": $p, "shipdate": $j.l_shipdate }

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/392bbbc0/asterixdb/asterix-app/src/test/resources/runtimets/queries/flwor/at00/at00.7.pollget.http
----------------------------------------------------------------------
diff --git 
a/asterixdb/asterix-app/src/test/resources/runtimets/queries/flwor/at00/at00.7.pollget.http
 
b/asterixdb/asterix-app/src/test/resources/runtimets/queries/flwor/at00/at00.7.pollget.http
new file mode 100644
index 0000000..5d59ca3
--- /dev/null
+++ 
b/asterixdb/asterix-app/src/test/resources/runtimets/queries/flwor/at00/at00.7.pollget.http
@@ -0,0 +1,22 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+//polltimeoutsecs=10
+
+/query/status?handle=$handle

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/392bbbc0/asterixdb/asterix-app/src/test/resources/runtimets/queries/flwor/at00/at00.8.get.http
----------------------------------------------------------------------
diff --git 
a/asterixdb/asterix-app/src/test/resources/runtimets/queries/flwor/at00/at00.8.get.http
 
b/asterixdb/asterix-app/src/test/resources/runtimets/queries/flwor/at00/at00.8.get.http
new file mode 100644
index 0000000..a88991c
--- /dev/null
+++ 
b/asterixdb/asterix-app/src/test/resources/runtimets/queries/flwor/at00/at00.8.get.http
@@ -0,0 +1,20 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+/query/result?handle=$handle

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/392bbbc0/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/async-deferred/async-failed/async-failed.1.async.sqlpp
----------------------------------------------------------------------
diff --git 
a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/async-deferred/async-failed/async-failed.1.async.sqlpp
 
b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/async-deferred/async-failed/async-failed.1.async.sqlpp
new file mode 100644
index 0000000..89ef35e
--- /dev/null
+++ 
b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/async-deferred/async-failed/async-failed.1.async.sqlpp
@@ -0,0 +1,23 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+#handlevariable=handle
+
+set `import-private-functions` `true`;
+select value inject_failure(sleep("result", 5000), true);

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/392bbbc0/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/async-deferred/async-failed/async-failed.2.pollget.http
----------------------------------------------------------------------
diff --git 
a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/async-deferred/async-failed/async-failed.2.pollget.http
 
b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/async-deferred/async-failed/async-failed.2.pollget.http
new file mode 100644
index 0000000..916aadf
--- /dev/null
+++ 
b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/async-deferred/async-failed/async-failed.2.pollget.http
@@ -0,0 +1,22 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+#polltimeoutsecs=10
+
+/query/status?handle=$handle

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/392bbbc0/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/async-deferred/async-failed/async-failed.3.get.http
----------------------------------------------------------------------
diff --git 
a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/async-deferred/async-failed/async-failed.3.get.http
 
b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/async-deferred/async-failed/async-failed.3.get.http
new file mode 100644
index 0000000..a88991c
--- /dev/null
+++ 
b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/async-deferred/async-failed/async-failed.3.get.http
@@ -0,0 +1,20 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+/query/result?handle=$handle

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/392bbbc0/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/async-deferred/async-running/async-running.1.async.sqlpp
----------------------------------------------------------------------
diff --git 
a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/async-deferred/async-running/async-running.1.async.sqlpp
 
b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/async-deferred/async-running/async-running.1.async.sqlpp
new file mode 100644
index 0000000..866b388
--- /dev/null
+++ 
b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/async-deferred/async-running/async-running.1.async.sqlpp
@@ -0,0 +1,22 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+#handlevariable=handle
+
+select value sleep("result", 3000);

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/392bbbc0/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/async-deferred/async-running/async-running.2.pollget.http
----------------------------------------------------------------------
diff --git 
a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/async-deferred/async-running/async-running.2.pollget.http
 
b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/async-deferred/async-running/async-running.2.pollget.http
new file mode 100644
index 0000000..916aadf
--- /dev/null
+++ 
b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/async-deferred/async-running/async-running.2.pollget.http
@@ -0,0 +1,22 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+#polltimeoutsecs=10
+
+/query/status?handle=$handle

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/392bbbc0/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/async-deferred/async-running/async-running.3.pollget.http
----------------------------------------------------------------------
diff --git 
a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/async-deferred/async-running/async-running.3.pollget.http
 
b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/async-deferred/async-running/async-running.3.pollget.http
new file mode 100644
index 0000000..916aadf
--- /dev/null
+++ 
b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/async-deferred/async-running/async-running.3.pollget.http
@@ -0,0 +1,22 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+#polltimeoutsecs=10
+
+/query/status?handle=$handle

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/392bbbc0/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/async-deferred/async-running/async-running.4.get.http
----------------------------------------------------------------------
diff --git 
a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/async-deferred/async-running/async-running.4.get.http
 
b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/async-deferred/async-running/async-running.4.get.http
new file mode 100644
index 0000000..a88991c
--- /dev/null
+++ 
b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/async-deferred/async-running/async-running.4.get.http
@@ -0,0 +1,20 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+/query/result?handle=$handle

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/392bbbc0/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/async-deferred/async/async.1.async.sqlpp
----------------------------------------------------------------------
diff --git 
a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/async-deferred/async/async.1.async.sqlpp
 
b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/async-deferred/async/async.1.async.sqlpp
new file mode 100644
index 0000000..a44b911
--- /dev/null
+++ 
b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/async-deferred/async/async.1.async.sqlpp
@@ -0,0 +1,22 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+#handlevariable=handle
+
+select i, i * i as i2 from range(1, 10) i;

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/392bbbc0/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/async-deferred/async/async.2.pollget.http
----------------------------------------------------------------------
diff --git 
a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/async-deferred/async/async.2.pollget.http
 
b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/async-deferred/async/async.2.pollget.http
new file mode 100644
index 0000000..916aadf
--- /dev/null
+++ 
b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/async-deferred/async/async.2.pollget.http
@@ -0,0 +1,22 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+#polltimeoutsecs=10
+
+/query/status?handle=$handle

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/392bbbc0/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/async-deferred/async/async.3.get.http
----------------------------------------------------------------------
diff --git 
a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/async-deferred/async/async.3.get.http
 
b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/async-deferred/async/async.3.get.http
new file mode 100644
index 0000000..a88991c
--- /dev/null
+++ 
b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/async-deferred/async/async.3.get.http
@@ -0,0 +1,20 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+/query/result?handle=$handle

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/392bbbc0/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/async-deferred/deferred/deferred.1.deferred.sqlpp
----------------------------------------------------------------------
diff --git 
a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/async-deferred/deferred/deferred.1.deferred.sqlpp
 
b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/async-deferred/deferred/deferred.1.deferred.sqlpp
new file mode 100644
index 0000000..a44b911
--- /dev/null
+++ 
b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/async-deferred/deferred/deferred.1.deferred.sqlpp
@@ -0,0 +1,22 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+#handlevariable=handle
+
+select i, i * i as i2 from range(1, 10) i;

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/392bbbc0/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/async-deferred/deferred/deferred.2.get.http
----------------------------------------------------------------------
diff --git 
a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/async-deferred/deferred/deferred.2.get.http
 
b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/async-deferred/deferred/deferred.2.get.http
new file mode 100644
index 0000000..a88991c
--- /dev/null
+++ 
b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/async-deferred/deferred/deferred.2.get.http
@@ -0,0 +1,20 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+/query/result?handle=$handle

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/392bbbc0/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/flwor/at00/at00.4.asyncdefer.sqlpp
----------------------------------------------------------------------
diff --git 
a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/flwor/at00/at00.4.asyncdefer.sqlpp
 
b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/flwor/at00/at00.4.asyncdefer.sqlpp
deleted file mode 100644
index 7bae0d4..0000000
--- 
a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/flwor/at00/at00.4.asyncdefer.sqlpp
+++ /dev/null
@@ -1,38 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *   http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-/*
- * Description      :  Test for clause of the position variable in FLWOR 
expression
- * Expected Result  :  Success
- * Date             :  09/17/2013
- */
-
-use test;
-
-
-select element {'partkey':gen0.partkey,'pid':p,'shipdate':j.l_shipdate}
-from
-    ( select element {'partkey':i.l_partkey, 'i': (select value x.i from g as 
x order by x.i.l_shipdate) }
-      from  LineItem as i
-      group by i.l_partkey group as g
-    ) as gen0,
-    gen0.i as j at p
-where p < 4
-order by partkey, shipdate;
-
-

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/392bbbc0/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/flwor/at00/at00.4.deferred.sqlpp
----------------------------------------------------------------------
diff --git 
a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/flwor/at00/at00.4.deferred.sqlpp
 
b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/flwor/at00/at00.4.deferred.sqlpp
new file mode 100644
index 0000000..df7826f
--- /dev/null
+++ 
b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/flwor/at00/at00.4.deferred.sqlpp
@@ -0,0 +1,37 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+/*
+ * Description      :  Test for clause of the position variable in FLWOR 
expression
+ * Expected Result  :  Success
+ * Date             :  09/17/2013
+ */
+
+#handlevariable=handle
+
+use test;
+
+select element {'partkey':gen0.partkey,'pid':p,'shipdate':j.l_shipdate}
+from
+    ( select element {'partkey':i.l_partkey, 'i': (select value x.i from g as 
x order by x.i.l_shipdate) }
+      from  LineItem as i
+      group by i.l_partkey group as g
+    ) as gen0,
+    gen0.i as j at p
+where p < 4
+order by partkey, shipdate;

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/392bbbc0/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/flwor/at00/at00.5.async.sqlpp
----------------------------------------------------------------------
diff --git 
a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/flwor/at00/at00.5.async.sqlpp
 
b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/flwor/at00/at00.5.async.sqlpp
deleted file mode 100644
index cb47163..0000000
--- 
a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/flwor/at00/at00.5.async.sqlpp
+++ /dev/null
@@ -1,36 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License.  You may obtain a copy of the License at
- *
- *   http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied.  See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-/*
- * Description      :  Test for clause of the position variable in FLWOR 
expression
- * Expected Result  :  Success
- * Date             :  09/17/2013
- */
-
-use test;
-
-
-select element {'partkey':gen0.partkey,'pid':p,'shipdate':j.l_shipdate}
-from
-    ( select element {'partkey':i.l_partkey, 'i': (select value x.i from g as 
x order by x.i.l_shipdate) }
-      from  LineItem as i
-      group by i.l_partkey group as g
-    ) as gen0,
-    gen0.i as j at p
-where p < 4
-order by partkey, shipdate;

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/392bbbc0/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/flwor/at00/at00.5.get.http
----------------------------------------------------------------------
diff --git 
a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/flwor/at00/at00.5.get.http
 
b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/flwor/at00/at00.5.get.http
new file mode 100644
index 0000000..a88991c
--- /dev/null
+++ 
b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/flwor/at00/at00.5.get.http
@@ -0,0 +1,20 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+/query/result?handle=$handle

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/392bbbc0/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/flwor/at00/at00.6.async.sqlpp
----------------------------------------------------------------------
diff --git 
a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/flwor/at00/at00.6.async.sqlpp
 
b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/flwor/at00/at00.6.async.sqlpp
new file mode 100644
index 0000000..df7826f
--- /dev/null
+++ 
b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/flwor/at00/at00.6.async.sqlpp
@@ -0,0 +1,37 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+/*
+ * Description      :  Test for clause of the position variable in FLWOR 
expression
+ * Expected Result  :  Success
+ * Date             :  09/17/2013
+ */
+
+#handlevariable=handle
+
+use test;
+
+select element {'partkey':gen0.partkey,'pid':p,'shipdate':j.l_shipdate}
+from
+    ( select element {'partkey':i.l_partkey, 'i': (select value x.i from g as 
x order by x.i.l_shipdate) }
+      from  LineItem as i
+      group by i.l_partkey group as g
+    ) as gen0,
+    gen0.i as j at p
+where p < 4
+order by partkey, shipdate;

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/392bbbc0/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/flwor/at00/at00.7.pollget.http
----------------------------------------------------------------------
diff --git 
a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/flwor/at00/at00.7.pollget.http
 
b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/flwor/at00/at00.7.pollget.http
new file mode 100644
index 0000000..916aadf
--- /dev/null
+++ 
b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/flwor/at00/at00.7.pollget.http
@@ -0,0 +1,22 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+#polltimeoutsecs=10
+
+/query/status?handle=$handle

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/392bbbc0/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/flwor/at00/at00.8.get.http
----------------------------------------------------------------------
diff --git 
a/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/flwor/at00/at00.8.get.http
 
b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/flwor/at00/at00.8.get.http
new file mode 100644
index 0000000..a88991c
--- /dev/null
+++ 
b/asterixdb/asterix-app/src/test/resources/runtimets/queries_sqlpp/flwor/at00/at00.8.get.http
@@ -0,0 +1,20 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+/query/result?handle=$handle

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/392bbbc0/asterixdb/asterix-app/src/test/resources/runtimets/results/async-deferred/async-failed/async-failed.1.ignore
----------------------------------------------------------------------
diff --git 
a/asterixdb/asterix-app/src/test/resources/runtimets/results/async-deferred/async-failed/async-failed.1.ignore
 
b/asterixdb/asterix-app/src/test/resources/runtimets/results/async-deferred/async-failed/async-failed.1.ignore
new file mode 100644
index 0000000..e69de29

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/392bbbc0/asterixdb/asterix-app/src/test/resources/runtimets/results/async-deferred/async-failed/async-failed.2.json
----------------------------------------------------------------------
diff --git 
a/asterixdb/asterix-app/src/test/resources/runtimets/results/async-deferred/async-failed/async-failed.2.json
 
b/asterixdb/asterix-app/src/test/resources/runtimets/results/async-deferred/async-failed/async-failed.2.json
new file mode 100644
index 0000000..dd665eb
--- /dev/null
+++ 
b/asterixdb/asterix-app/src/test/resources/runtimets/results/async-deferred/async-failed/async-failed.2.json
@@ -0,0 +1 @@
+{"status":"FAILED"}

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/392bbbc0/asterixdb/asterix-app/src/test/resources/runtimets/results/async-deferred/async-running/async-running.1.ignore
----------------------------------------------------------------------
diff --git 
a/asterixdb/asterix-app/src/test/resources/runtimets/results/async-deferred/async-running/async-running.1.ignore
 
b/asterixdb/asterix-app/src/test/resources/runtimets/results/async-deferred/async-running/async-running.1.ignore
new file mode 100644
index 0000000..e69de29

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/392bbbc0/asterixdb/asterix-app/src/test/resources/runtimets/results/async-deferred/async-running/async-running.2.json
----------------------------------------------------------------------
diff --git 
a/asterixdb/asterix-app/src/test/resources/runtimets/results/async-deferred/async-running/async-running.2.json
 
b/asterixdb/asterix-app/src/test/resources/runtimets/results/async-deferred/async-running/async-running.2.json
new file mode 100644
index 0000000..6cffe65
--- /dev/null
+++ 
b/asterixdb/asterix-app/src/test/resources/runtimets/results/async-deferred/async-running/async-running.2.json
@@ -0,0 +1 @@
+{"status":"RUNNING"}

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/392bbbc0/asterixdb/asterix-app/src/test/resources/runtimets/results/async-deferred/async-running/async-running.3.json
----------------------------------------------------------------------
diff --git 
a/asterixdb/asterix-app/src/test/resources/runtimets/results/async-deferred/async-running/async-running.3.json
 
b/asterixdb/asterix-app/src/test/resources/runtimets/results/async-deferred/async-running/async-running.3.json
new file mode 100644
index 0000000..6213a6b
--- /dev/null
+++ 
b/asterixdb/asterix-app/src/test/resources/runtimets/results/async-deferred/async-running/async-running.3.json
@@ -0,0 +1 @@
+{"status":"SUCCESS"}

http://git-wip-us.apache.org/repos/asf/asterixdb/blob/392bbbc0/asterixdb/asterix-app/src/test/resources/runtimets/results/async-deferred/async-running/async-running.4.json
----------------------------------------------------------------------
diff --git 
a/asterixdb/asterix-app/src/test/resources/runtimets/results/async-deferred/async-running/async-running.4.json
 
b/asterixdb/asterix-app/src/test/resources/runtimets/results/async-deferred/async-running/async-running.4.json
new file mode 100644
index 0000000..859d906
--- /dev/null
+++ 
b/asterixdb/asterix-app/src/test/resources/runtimets/results/async-deferred/async-running/async-running.4.json
@@ -0,0 +1 @@
+"result"

Reply via email to