Skip to content
Permalink
Browse files
Merge branch 'gerrit/neo'
Change-Id: Id189559017248b3c9ecdfd54fa7c6d84aa21be08
  • Loading branch information
mblow committed Feb 11, 2022
2 parents 412de58 + 706406d commit b3fb199b4a7dd9a5aabdcdff5b3a7c203bb85684
Showing 55 changed files with 759 additions and 437 deletions.
@@ -90,7 +90,7 @@ public void setRunning() {

@Override
public String toJson() {
return JSONUtil.convertNodeOrThrow(asJson());
return JSONUtil.convertNodeUnchecked(asJson());
}

protected ObjectNode asJson() {
@@ -18,11 +18,9 @@
*/
package org.apache.asterix.translator;

import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Deque;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
@@ -125,6 +123,7 @@
import org.apache.hyracks.algebricks.core.algebra.operators.logical.AggregateOperator;
import org.apache.hyracks.algebricks.core.algebra.operators.logical.AssignOperator;
import org.apache.hyracks.algebricks.core.algebra.operators.logical.DistinctOperator;
import org.apache.hyracks.algebricks.core.algebra.operators.logical.EmptyTupleSourceOperator;
import org.apache.hyracks.algebricks.core.algebra.operators.logical.InnerJoinOperator;
import org.apache.hyracks.algebricks.core.algebra.operators.logical.LeftOuterUnnestOperator;
import org.apache.hyracks.algebricks.core.algebra.operators.logical.NestedTupleSourceOperator;
@@ -155,7 +154,6 @@ public class SqlppExpressionToPlanTranslator extends LangExpressionToPlanTransla
public static final String REWRITE_IN_AS_OR_OPTION = "rewrite_in_as_or";
private static final boolean REWRITE_IN_AS_OR_OPTION_DEFAULT = true;

private Deque<Mutable<ILogicalOperator>> uncorrelatedRightBranchStack = new ArrayDeque<>();
private final Map<VarIdentifier, IAObject> externalVars;
private final boolean translateInAsOr;

@@ -303,12 +301,10 @@ public Pair<ILogicalOperator, LogicalVariable> visit(FromClause fromClause, Muta
throws CompilationException {
Mutable<ILogicalOperator> inputSrc = arg;
Pair<ILogicalOperator, LogicalVariable> topUnnest = null;
uncorrelatedRightBranchStack.push(inputSrc);
for (FromTerm fromTerm : fromClause.getFromTerms()) {
topUnnest = fromTerm.accept(this, inputSrc);
inputSrc = new MutableObject<>(topUnnest.first);
}
uncorrelatedRightBranchStack.pop();
return topUnnest;
}

@@ -345,8 +341,10 @@ public Pair<ILogicalOperator, LogicalVariable> visit(FromTerm fromTerm, Mutable<
public Pair<ILogicalOperator, LogicalVariable> visit(JoinClause joinClause, Mutable<ILogicalOperator> leftInputRef)
throws CompilationException {
SourceLocation sourceLoc = joinClause.getSourceLocation();
if (joinClause.getJoinType() == JoinType.INNER && !context.inSubplan()) {
Mutable<ILogicalOperator> rightInputRef = uncorrelatedRightBranchStack.peek();
if (joinClause.getJoinType() == JoinType.INNER && !hasFreeVariables(joinClause.getRightExpression())) {
EmptyTupleSourceOperator ets = new EmptyTupleSourceOperator();
ets.setSourceLocation(joinClause.getSourceLocation());
Mutable<ILogicalOperator> rightInputRef = new MutableObject<>(ets);
Pair<ILogicalOperator, LogicalVariable> rightBranch =
generateUnnestForBinaryCorrelateRightBranch(joinClause, rightInputRef, false, null);
// A join operator with condition TRUE.
@@ -509,6 +507,16 @@ public Pair<ILogicalOperator, LogicalVariable> visit(JoinClause joinClause, Muta
}
}

private boolean hasFreeVariables(Expression expr) throws CompilationException {
Set<VariableExpr> freeVars = SqlppRewriteUtil.getFreeVariable(expr);
for (VariableExpr varRef : freeVars) {
if (!SqlppVariableUtil.isExternalVariableReference(varRef)) {
return true;
}
}
return false;
}

private static IAlgebricksConstantValue translateLeftOuterMissingValue(Literal.Type type)
throws CompilationException {
switch (type) {
@@ -236,7 +236,7 @@ public static void validateIndexFieldType(IndexType indexType, IAType fieldType,
break;
default:
throw new CompilationException(ErrorCode.COMPILATION_ERROR, sourceLoc,
"The field \"" + displayFieldName + "\" which is of type " + fieldType.getTypeTag()
"The field '" + displayFieldName + "' which is of type " + fieldType.getTypeTag()
+ " cannot be indexed using the BTree index.");
}
break;
@@ -251,14 +251,14 @@ public static void validateIndexFieldType(IndexType indexType, IAType fieldType,
break;
default:
throw new CompilationException(ErrorCode.COMPILATION_ERROR, sourceLoc,
"The field \"" + displayFieldName + "\" which is of type " + fieldType.getTypeTag()
"The field '" + displayFieldName + "' which is of type " + fieldType.getTypeTag()
+ " cannot be indexed using the RTree index.");
}
break;
case LENGTH_PARTITIONED_NGRAM_INVIX:
if (fieldType.getTypeTag() != ATypeTag.STRING) {
throw new CompilationException(ErrorCode.COMPILATION_ERROR, sourceLoc,
"The field \"" + displayFieldName + "\" which is of type " + fieldType.getTypeTag()
"The field '" + displayFieldName + "' which is of type " + fieldType.getTypeTag()
+ " cannot be indexed using the Length Partitioned N-Gram index.");
}
break;
@@ -270,14 +270,14 @@ public static void validateIndexFieldType(IndexType indexType, IAType fieldType,
break;
default:
throw new CompilationException(ErrorCode.COMPILATION_ERROR, sourceLoc,
"The field \"" + displayFieldName + "\" which is of type " + fieldType.getTypeTag()
"The field '" + displayFieldName + "' which is of type " + fieldType.getTypeTag()
+ " cannot be indexed using the Length Partitioned Keyword index.");
}
break;
case SINGLE_PARTITION_NGRAM_INVIX:
if (fieldType.getTypeTag() != ATypeTag.STRING) {
throw new CompilationException(ErrorCode.COMPILATION_ERROR, sourceLoc,
"The field \"" + displayFieldName + "\" which is of type " + fieldType.getTypeTag()
"The field '" + displayFieldName + "' which is of type " + fieldType.getTypeTag()
+ " cannot be indexed using the N-Gram index.");
}
break;
@@ -289,7 +289,7 @@ public static void validateIndexFieldType(IndexType indexType, IAType fieldType,
break;
default:
throw new CompilationException(ErrorCode.COMPILATION_ERROR, sourceLoc,
"The field \"" + displayFieldName + "\" which is of type " + fieldType.getTypeTag()
"The field '" + displayFieldName + "' which is of type " + fieldType.getTypeTag()
+ " cannot be indexed using the Keyword index.");
}
break;
@@ -83,7 +83,7 @@ protected void get(IServletRequest request, IServletResponse response) throws IO
}
JSONUtil.writeNode(responseWriter, json);
} catch (IllegalArgumentException e) { // NOSONAR - exception not logged or rethrown
response.setStatus(HttpResponseStatus.NOT_FOUND);
sendError(response, HttpResponseStatus.NOT_FOUND);
} catch (Exception e) {
LOGGER.log(Level.INFO, "exception thrown for " + request, e);
response.setStatus(HttpResponseStatus.INTERNAL_SERVER_ERROR);
@@ -79,10 +79,10 @@ protected void get(IServletRequest request, IServletResponse response) throws IO
} catch (RejectedExecutionException e) {
// we must be shutting down, return 503
LOGGER.info("RejectedExecutionException while servicing request; returning 503", e);
sendError(response, HttpResponseStatus.SERVICE_UNAVAILABLE, null);
sendError(response, HttpResponseStatus.SERVICE_UNAVAILABLE);
} catch (Exception e) {
LOGGER.warn("exception while servicing request; returning 500", e);
sendError(response, HttpResponseStatus.INTERNAL_SERVER_ERROR, e.toString());
sendError(response, HttpResponseStatus.INTERNAL_SERVER_ERROR);
}
responseWriter.flush();
}
@@ -295,7 +295,8 @@ private void writeException(Exception e, IServletResponse response) {
responseWriter.flush();
}

protected boolean isRequestPermittedForWrite(IServletRequest request, IServletResponse response) {
protected boolean isRequestPermittedForWrite(IServletRequest request, IServletResponse response)
throws IOException {
if (!isRequestOnLoopback(request)) {
rejectForbidden(response);
return false;
@@ -313,20 +314,21 @@ protected boolean isRequestOnLoopback(IServletRequest request) {
}
}

protected static void rejectForbidden(IServletResponse response) {
response.setStatus(HttpResponseStatus.FORBIDDEN);
response.writer().write("{ \"error\": \"Forbidden\" }");
protected void rejectForbidden(IServletResponse response) throws IOException {
// TODO: why this JSON format, do we use this anywhere else?
sendError(response, HttpUtil.ContentType.APPLICATION_JSON, HttpResponseStatus.FORBIDDEN,
"{ \"error\": \"Forbidden\" }");
}

@Override
protected void post(IServletRequest request, IServletResponse response) {
protected void post(IServletRequest request, IServletResponse response) throws IOException {
if (isRequestPermittedForWrite(request, response)) {
handleModification(request, response, LibraryOperation.UPSERT);
}
}

@Override
protected void delete(IServletRequest request, IServletResponse response) {
protected void delete(IServletRequest request, IServletResponse response) throws IOException {
if (isRequestPermittedForWrite(request, response)) {
handleModification(request, response, LibraryOperation.DELETE);
}
@@ -181,10 +181,9 @@ public IActiveEntityEventsListener getListener(EntityId entityId) {
@Override
public synchronized IActiveEntityEventsListener[] getEventListeners() {
if (LOGGER.isTraceEnabled()) {
LOGGER.trace("getEventListeners() was called");
LOGGER.trace("returning " + entityEventListeners.size() + " Listeners");
LOGGER.trace("getEventListeners() returning {} listeners", entityEventListeners.size());
}
return entityEventListeners.values().toArray(new IActiveEntityEventsListener[entityEventListeners.size()]);
return entityEventListeners.values().toArray(IActiveEntityEventsListener[]::new);
}

@Override
@@ -26,6 +26,9 @@
import org.apache.asterix.common.api.IResponseFieldPrinter;
import org.apache.hyracks.util.JSONUtil;

import com.fasterxml.jackson.databind.node.ArrayNode;
import com.fasterxml.jackson.databind.node.ObjectNode;

public abstract class AbstractCodedMessagePrinter implements IResponseFieldPrinter {

private enum CodedMessageField {
@@ -68,4 +71,14 @@ public void print(PrintWriter pw) {
}
pw.print("]");
}

public ObjectNode appendTo(ObjectNode objectNode) {
ArrayNode array = objectNode.putArray(getName());
messages.forEach(codedMessage -> {
ObjectNode error = array.addObject();
error.put(CodedMessageField.CODE.str(), codedMessage.getCode());
error.put(CodedMessageField.MSG.str(), codedMessage.getMessage());
});
return objectNode;
}
}
@@ -1248,8 +1248,8 @@ protected void doCreateIndex(MetadataProvider metadataProvider, CreateIndexState
// allow overriding the type of the closed-field only if CAST modifier is used
if (!stmtCreateIndex.hasCastDefaultNull()) {
throw new CompilationException(ErrorCode.COMPILATION_ERROR,
indexedElement.getSourceLocation(), "Typed index on \"" + projectPath
+ "\" field could be created only for open datatype");
indexedElement.getSourceLocation(), "Typed index on '" + projectPath
+ "' field could be created only for open datatype");
}
}
}
@@ -1631,9 +1631,9 @@ private void doCreateIndexImpl(IHyracksClientConnection hcc, MetadataProvider me
&& !existingIndexKeyFieldTypes.equals(indexKeyFieldTypes)) {
throw new CompilationException(ErrorCode.COMPILATION_ERROR, sourceLoc,
"Cannot create index " + index.getIndexName() + " , enforced index "
+ existingIndex.getIndexName() + " on field \""
+ StringUtils.join(indexKeyFieldNames, ',')
+ "\" is already defined with type \"" + existingIndexKeyFieldTypes + "\"");
+ existingIndex.getIndexName() + " on field '"
+ StringUtils.join(indexKeyFieldNames, ',') + "' is already defined with type '"
+ existingIndexKeyFieldTypes + "'");
}
}
}
@@ -227,7 +227,7 @@ private static ExtractedResult extract(InputStream resultStream, EnumSet<ResultF
final String fieldName = fieldNameIter.next();
final ResultField fieldKind = ResultField.ofFieldName(fieldName.split("-")[0]);
if (fieldKind == null) {
throw new AsterixException("Unanticipated field \"" + fieldName + "\"");
throw new AsterixException("Unanticipated field '" + fieldName + "'");
}
if (!resultFields.contains(fieldKind)) {
continue;
@@ -498,7 +498,7 @@
<test-case FilePath="exception">
<compilation-unit name="issue_255_create_dataset_error_1">
<output-dir compare="Text">none</output-dir>
<expected-error>ASX1014: Field "name" is not found (in line 34, at column 1)</expected-error>
<expected-error>ASX1014: Field 'name' is not found (in line 34, at column 1)</expected-error>
</compilation-unit>
</test-case>
<test-case FilePath="exception">
@@ -511,56 +511,56 @@
<test-case FilePath="exception">
<compilation-unit name="issue_255_create_feed_error">
<output-dir compare="Text">none</output-dir>
<expected-error>org.json.JSONException: JSONObject["summary"] not found</expected-error>
<expected-error>org.json.JSONException: JSONObject['summary'] not found</expected-error>
</compilation-unit>
</test-case> -->
<!-- This case should be fixed to return a proper message rather than NPE -->
<test-case FilePath="exception">
<compilation-unit name="issue_266_create_dataset_error_1">
<output-dir compare="Text">none</output-dir>
<expected-error>ASX1014: Field "point" is not found (in line 34, at column 1)</expected-error>
<expected-error>ASX1014: Field 'point' is not found (in line 34, at column 1)</expected-error>
</compilation-unit>
</test-case>
<test-case FilePath="exception">
<compilation-unit name="issue_266_create_dataset_error_2">
<output-dir compare="Text">none</output-dir>
<expected-error>ASX1021: The primary key field "id" cannot be nullable (in line 34, at column 1)</expected-error>
<expected-error>ASX1021: The primary key field 'id' cannot be nullable (in line 34, at column 1)</expected-error>
</compilation-unit>
</test-case>
<test-case FilePath="exception">
<compilation-unit name="issue_384_create_index_error_1">
<output-dir compare="Text">none</output-dir>
<expected-error>ASX1079: Compilation error: The field "[loc]" which is of type point cannot be indexed using the BTree index. (in line 37, at column 33)</expected-error>
<expected-error>ASX1079: Compilation error: The field '[loc]' which is of type point cannot be indexed using the BTree index. (in line 37, at column 33)</expected-error>
</compilation-unit>
</test-case>
<test-case FilePath="exception">
<compilation-unit name="issue_384_create_index_error_2">
<output-dir compare="Text">none</output-dir>
<expected-error>ASX1079: Compilation error: The field "[age]" which is of type integer cannot be indexed using the RTree index. (in line 37, at column 33)</expected-error>
<expected-error>ASX1079: Compilation error: The field '[age]' which is of type integer cannot be indexed using the RTree index. (in line 37, at column 33)</expected-error>
</compilation-unit>
</test-case>
<test-case FilePath="exception">
<compilation-unit name="issue_384_create_index_error_3">
<output-dir compare="Text">none</output-dir>
<expected-error>ASX1079: Compilation error: The field "[loc]" which is of type point cannot be indexed using the Length Partitioned Keyword index. (in line 37, at column 33)</expected-error>
<expected-error>ASX1079: Compilation error: The field '[loc]' which is of type point cannot be indexed using the Length Partitioned Keyword index. (in line 37, at column 33)</expected-error>
</compilation-unit>
</test-case>
<test-case FilePath="exception">
<compilation-unit name="issue_384_create_index_error_4">
<output-dir compare="Text">none</output-dir>
<expected-error>ASX1079: Compilation error: The field "[loc]" which is of type point cannot be indexed using the Length Partitioned Keyword index. (in line 37, at column 33)</expected-error>
<expected-error>ASX1079: Compilation error: The field '[loc]' which is of type point cannot be indexed using the Length Partitioned Keyword index. (in line 37, at column 33)</expected-error>
</compilation-unit>
</test-case>
<test-case FilePath="exception">
<compilation-unit name="issue_384_create_index_error_5">
<output-dir compare="Text">none</output-dir>
<expected-error>ASX1079: Compilation error: The field "[loc]" which is of type point cannot be indexed using the Length Partitioned N-Gram index. (in line 37, at column 33)</expected-error>
<expected-error>ASX1079: Compilation error: The field '[loc]' which is of type point cannot be indexed using the Length Partitioned N-Gram index. (in line 37, at column 33)</expected-error>
</compilation-unit>
</test-case>
<test-case FilePath="exception">
<compilation-unit name="issue_384_create_index_error_6">
<output-dir compare="Text">none</output-dir>
<expected-error>ASX1079: Compilation error: The field "[loc]" which is of type point cannot be indexed using the Length Partitioned N-Gram index. (in line 37, at column 33)</expected-error>
<expected-error>ASX1079: Compilation error: The field '[loc]' which is of type point cannot be indexed using the Length Partitioned N-Gram index. (in line 37, at column 33)</expected-error>
</compilation-unit>
</test-case>
</test-group>

0 comments on commit b3fb199

Please sign in to comment.