[NO ISSUE][*DB] pass max-warnings via session config

- user model changes: no
- storage format changes: no
- interface changes: yes

Details:
Pass max-warnings from servlet to APIFramework
and QueryTranslator through the session config instead
of creating an internal parameter (REQUEST_MAX_WARNINGS)
and storing it in the metadata provider.

Change-Id: I4145bcccc2702fae4b0c33872f1b98c47ab299f7
Reviewed-on: https://asterix-gerrit.ics.uci.edu/3569
Contrib: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Tested-by: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Integration-Tests: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Reviewed-by: Ali Alsuliman <ali.al.solaiman@gmail.com>
Reviewed-by: Murtadha Hubail <mhubail@apache.org>
diff --git a/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/translator/IRequestParameters.java b/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/translator/IRequestParameters.java
index 0cec738..e242258 100644
--- a/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/translator/IRequestParameters.java
+++ b/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/translator/IRequestParameters.java
@@ -60,9 +60,4 @@
      *   {@code 0} if all categories are allowed
      */
     int getStatementCategoryRestrictionMask();
-
-    /**
-     * @return the maximum number of warnings to be reported.
-     */
-    long getMaxWarnings();
 }
diff --git a/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/translator/SessionConfig.java b/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/translator/SessionConfig.java
index 45a5ae1..8077172 100644
--- a/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/translator/SessionConfig.java
+++ b/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/translator/SessionConfig.java
@@ -135,6 +135,7 @@
     private final boolean executeQuery;
     private final boolean generateJobSpec;
     private final boolean optimize;
+    private long maxWarnings;
 
     // Flags.
     private final Map<String, Boolean> flags;
@@ -198,6 +199,17 @@
     }
 
     /**
+     * Retrieve the maximum number of warnings to be reported.
+     */
+    public long getMaxWarnings() {
+        return maxWarnings;
+    }
+
+    public void setMaxWarnings(long maxWarnings) {
+        this.maxWarnings = maxWarnings;
+    }
+
+    /**
      * Retrieve the value of the "execute query" flag.
      */
     public boolean isExecuteQuery() {
diff --git a/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/common/APIFramework.java b/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/common/APIFramework.java
index a31c1b2..5069b9f 100644
--- a/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/common/APIFramework.java
+++ b/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/common/APIFramework.java
@@ -33,7 +33,6 @@
 
 import org.apache.asterix.algebra.base.ILangExpressionToPlanTranslator;
 import org.apache.asterix.algebra.base.ILangExpressionToPlanTranslatorFactory;
-import org.apache.asterix.api.http.server.QueryServiceRequestParameters;
 import org.apache.asterix.app.result.fields.ExplainOnlyResultsPrinter;
 import org.apache.asterix.common.api.INodeJobTracker;
 import org.apache.asterix.common.api.IResponsePrinter;
@@ -130,7 +129,6 @@
     private static final ObjectWriter OBJECT_WRITER = new ObjectMapper().writerWithDefaultPrettyPrinter();
 
     public static final String PREFIX_INTERNAL_PARAMETERS = "_internal";
-    public static final String REQUEST_MAX_WARNINGS = PREFIX_INTERNAL_PARAMETERS + "_max_warn";
 
     // A white list of supported configurable parameters.
     private static final Set<String> CONFIGURABLE_PARAMETER_NAMES =
@@ -246,9 +244,7 @@
         builder.setMissableTypeComputer(MissableTypeComputer.INSTANCE);
         builder.setConflictingTypeResolver(ConflictingTypeResolver.INSTANCE);
         builder.setWarningCollector(warningCollector);
-        String maxWarnings = metadataProvider.getProperty(APIFramework.REQUEST_MAX_WARNINGS);
-        builder.setMaxWarnings(
-                maxWarnings != null ? Long.parseLong(maxWarnings) : QueryServiceRequestParameters.DEFAULT_MAX_WARNINGS);
+        builder.setMaxWarnings(conf.getMaxWarnings());
 
         int parallelism = getParallelism((String) querySpecificConfig.get(CompilerProperties.COMPILER_PARALLELISM_KEY),
                 compilerProperties.getParallelism());
diff --git a/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/http/server/NCQueryServiceServlet.java b/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/http/server/NCQueryServiceServlet.java
index 033bb16..69d5c70 100644
--- a/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/http/server/NCQueryServiceServlet.java
+++ b/asterixdb/asterix-app/src/main/java/org/apache/asterix/api/http/server/NCQueryServiceServlet.java
@@ -88,11 +88,11 @@
             }
             int stmtCategoryRestrictionMask = org.apache.asterix.app.translator.RequestParameters
                     .getStatementCategoryRestrictionMask(param.isReadOnly());
-            ExecuteStatementRequestMessage requestMsg = new ExecuteStatementRequestMessage(ncCtx.getNodeId(),
-                    responseFuture.getFutureId(), queryLanguage, statementsText, sessionOutput.config(),
-                    resultProperties.getNcToCcResultProperties(), param.getClientContextID(), handleUrl,
-                    optionalParameters, statementParameters, param.isMultiStatement(), param.isProfile(),
-                    stmtCategoryRestrictionMask, requestReference, param.getMaxWarnings());
+            ExecuteStatementRequestMessage requestMsg =
+                    new ExecuteStatementRequestMessage(ncCtx.getNodeId(), responseFuture.getFutureId(), queryLanguage,
+                            statementsText, sessionOutput.config(), resultProperties.getNcToCcResultProperties(),
+                            param.getClientContextID(), handleUrl, optionalParameters, statementParameters,
+                            param.isMultiStatement(), param.isProfile(), stmtCategoryRestrictionMask, requestReference);
             execution.start();
             ncMb.sendMessageToPrimaryCC(requestMsg);
             try {
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 8dc788c..c82bac2 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
@@ -625,7 +625,7 @@
         }
         IParser parser = compilationProvider.getParserFactory().createParser(statementsText);
         List<Statement> statements = parser.parse();
-        long maxWarnings = param.getMaxWarnings();
+        long maxWarnings = sessionOutput.config().getMaxWarnings();
         parser.getWarnings(warnings, maxWarnings);
         long parserTotalWarningsCount = parser.getTotalWarningsCount();
         MetadataManager.INSTANCE.init();
@@ -638,7 +638,7 @@
                 .getStatementCategoryRestrictionMask(param.isReadOnly());
         IRequestParameters requestParameters = new org.apache.asterix.app.translator.RequestParameters(requestReference,
                 statementsText, getResultSet(), resultProperties, stats, null, param.getClientContextID(),
-                optionalParameters, stmtParams, param.isMultiStatement(), stmtCategoryRestriction, maxWarnings);
+                optionalParameters, stmtParams, param.isMultiStatement(), stmtCategoryRestriction);
         translator.compileAndExecute(getHyracksClientConnection(), requestParameters);
         execution.end();
         translator.getWarnings(warnings, maxWarnings - warnings.size());
@@ -698,6 +698,7 @@
                 SessionConfig.PlanFormat.JSON, LOGGER);
         sessionConfig.setFmt(format);
         sessionConfig.setPlanFormat(planFormat);
+        sessionConfig.setMaxWarnings(param.getMaxWarnings());
         sessionConfig.set(SessionConfig.FORMAT_WRAPPER_ARRAY, true);
         sessionConfig.set(SessionConfig.OOB_EXPR_TREE, param.isExpressionTree());
         sessionConfig.set(SessionConfig.OOB_REWRITTEN_EXPR_TREE, param.isRewrittenExpressionTree());
diff --git a/asterixdb/asterix-app/src/main/java/org/apache/asterix/app/message/ExecuteStatementRequestMessage.java b/asterixdb/asterix-app/src/main/java/org/apache/asterix/app/message/ExecuteStatementRequestMessage.java
index 7396035..e58ad06 100644
--- a/asterixdb/asterix-app/src/main/java/org/apache/asterix/app/message/ExecuteStatementRequestMessage.java
+++ b/asterixdb/asterix-app/src/main/java/org/apache/asterix/app/message/ExecuteStatementRequestMessage.java
@@ -89,13 +89,12 @@
     private final int statementCategoryRestrictionMask;
     private final boolean profile;
     private final IRequestReference requestReference;
-    private final long maxWarnings;
 
     public ExecuteStatementRequestMessage(String requestNodeId, long requestMessageId, ILangExtension.Language lang,
             String statementsText, SessionConfig sessionConfig, ResultProperties resultProperties,
             String clientContextID, String handleUrl, Map<String, String> optionalParameters,
             Map<String, byte[]> statementParameters, boolean multiStatement, boolean profile,
-            int statementCategoryRestrictionMask, IRequestReference requestReference, long maxWarnings) {
+            int statementCategoryRestrictionMask, IRequestReference requestReference) {
         this.requestNodeId = requestNodeId;
         this.requestMessageId = requestMessageId;
         this.lang = lang;
@@ -110,7 +109,6 @@
         this.statementCategoryRestrictionMask = statementCategoryRestrictionMask;
         this.profile = profile;
         this.requestReference = requestReference;
-        this.maxWarnings = maxWarnings;
     }
 
     @Override
@@ -133,6 +131,7 @@
             List<Warning> warnings = new ArrayList<>();
             IParser parser = compilationProvider.getParserFactory().createParser(statementsText);
             List<Statement> statements = parser.parse();
+            long maxWarnings = sessionConfig.getMaxWarnings();
             parser.getWarnings(warnings, maxWarnings);
             long parserTotalWarningsCount = parser.getTotalWarningsCount();
             StringWriter outWriter = new StringWriter(256);
@@ -152,7 +151,7 @@
             Map<String, IAObject> stmtParams = RequestParameters.deserializeParameterValues(statementParameters);
             final IRequestParameters requestParameters = new RequestParameters(requestReference, statementsText, null,
                     resultProperties, stats, outMetadata, clientContextID, optionalParameters, stmtParams,
-                    multiStatement, statementCategoryRestrictionMask, maxWarnings);
+                    multiStatement, statementCategoryRestrictionMask);
             translator.compileAndExecute(ccApp.getHcc(), requestParameters);
             translator.getWarnings(warnings, maxWarnings - warnings.size());
             stats.updateTotalWarningsCount(parserTotalWarningsCount);
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 72bc2e7..aed358e 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
@@ -290,9 +290,7 @@
         final Stats stats = requestParameters.getStats();
         final ResultMetadata outMetadata = requestParameters.getOutMetadata();
         final Map<String, IAObject> stmtParams = requestParameters.getStatementParameters();
-        final long requestMaxWarnings = requestParameters.getMaxWarnings();
-        config.put(APIFramework.REQUEST_MAX_WARNINGS, String.valueOf(requestMaxWarnings));
-        warningCollector.setMaxWarnings(requestMaxWarnings);
+        warningCollector.setMaxWarnings(sessionConfig.getMaxWarnings());
         try {
             for (Statement stmt : statements) {
                 if (sessionConfig.is(SessionConfig.FORMAT_HTML)) {
diff --git a/asterixdb/asterix-app/src/main/java/org/apache/asterix/app/translator/RequestParameters.java b/asterixdb/asterix-app/src/main/java/org/apache/asterix/app/translator/RequestParameters.java
index 3b15e1c..90602e7 100644
--- a/asterixdb/asterix-app/src/main/java/org/apache/asterix/app/translator/RequestParameters.java
+++ b/asterixdb/asterix-app/src/main/java/org/apache/asterix/app/translator/RequestParameters.java
@@ -23,7 +23,6 @@
 import java.util.HashMap;
 import java.util.Map;
 
-import org.apache.asterix.api.http.server.QueryServiceRequestParameters;
 import org.apache.asterix.common.api.IRequestReference;
 import org.apache.asterix.external.parser.JSONDataParser;
 import org.apache.asterix.formats.nontagged.SerializerDeserializerProvider;
@@ -57,21 +56,19 @@
     private final boolean multiStatement;
     private final int statementCategoryRestrictionMask;
     private final String statement;
-    private final long maxWarnings;
 
     public RequestParameters(IRequestReference requestReference, String statement, IResultSet resultSet,
             ResultProperties resultProperties, Stats stats, IStatementExecutor.ResultMetadata outMetadata,
             String clientContextId, Map<String, String> optionalParameters, Map<String, IAObject> statementParameters,
             boolean multiStatement) {
         this(requestReference, statement, resultSet, resultProperties, stats, outMetadata, clientContextId,
-                optionalParameters, statementParameters, multiStatement, NO_CATEGORY_RESTRICTION_MASK,
-                QueryServiceRequestParameters.DEFAULT_MAX_WARNINGS);
+                optionalParameters, statementParameters, multiStatement, NO_CATEGORY_RESTRICTION_MASK);
     }
 
     public RequestParameters(IRequestReference requestReference, String statement, IResultSet resultSet,
             ResultProperties resultProperties, Stats stats, IStatementExecutor.ResultMetadata outMetadata,
             String clientContextId, Map<String, String> optionalParameters, Map<String, IAObject> statementParameters,
-            boolean multiStatement, int statementCategoryRestrictionMask, long maxWarnings) {
+            boolean multiStatement, int statementCategoryRestrictionMask) {
         this.requestReference = requestReference;
         this.statement = statement;
         this.resultSet = resultSet;
@@ -83,7 +80,6 @@
         this.statementParameters = statementParameters;
         this.multiStatement = multiStatement;
         this.statementCategoryRestrictionMask = statementCategoryRestrictionMask;
-        this.maxWarnings = maxWarnings;
     }
 
     @Override
@@ -127,11 +123,6 @@
     }
 
     @Override
-    public long getMaxWarnings() {
-        return maxWarnings;
-    }
-
-    @Override
     public Map<String, IAObject> getStatementParameters() {
         return statementParameters;
     }