[NO ISSUE] small cleanup in type inferencing
Change-Id: I89e74b1f3176d3edd8e41fc63538a3b37326923c
Reviewed-on: https://asterix-gerrit.ics.uci.edu/2732
Sonar-Qube: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Tested-by: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Contrib: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Integration-Tests: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Reviewed-by: abdullah alamoudi <bamousaa@gmail.com>
diff --git a/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/typecomputer/base/IResultTypeComputer.java b/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/typecomputer/base/IResultTypeComputer.java
index 04f9c96..e9dfe90 100644
--- a/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/typecomputer/base/IResultTypeComputer.java
+++ b/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/typecomputer/base/IResultTypeComputer.java
@@ -24,7 +24,8 @@
import org.apache.hyracks.algebricks.core.algebra.expressions.IVariableTypeEnvironment;
import org.apache.hyracks.algebricks.core.algebra.metadata.IMetadataProvider;
+@FunctionalInterface
public interface IResultTypeComputer {
- public IAType computeType(ILogicalExpression expression, IVariableTypeEnvironment env,
+ IAType computeType(ILogicalExpression expression, IVariableTypeEnvironment env,
IMetadataProvider<?, ?> metadataProvider) throws AlgebricksException;
}
diff --git a/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/typecomputer/impl/ListConstructorTypeComputer.java b/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/typecomputer/impl/ListConstructorTypeComputer.java
index 2528697..4916fc1 100644
--- a/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/typecomputer/impl/ListConstructorTypeComputer.java
+++ b/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/typecomputer/impl/ListConstructorTypeComputer.java
@@ -47,26 +47,21 @@
if (reqType != null) {
return reqType;
}
- return computeTypeFromItems(env, f);
+ final IAType currentType = computeContentType(env, f);
+ return getListType(currentType == null ? BuiltinType.ANY : currentType);
}
- private IAType computeTypeFromItems(IVariableTypeEnvironment env, AbstractFunctionCallExpression f)
+ private IAType computeContentType(IVariableTypeEnvironment env, AbstractFunctionCallExpression f)
throws AlgebricksException {
IAType currentType = null;
- boolean any = false;
for (int k = 0; k < f.getArguments().size(); k++) {
IAType type = (IAType) env.getType(f.getArguments().get(k).getValue());
if (type.getTypeTag() == ATypeTag.UNION || (currentType != null && !currentType.equals(type))) {
- any = true;
- break;
+ return null;
}
currentType = type;
}
- if (any || currentType == null) {
- return getListType(BuiltinType.ANY);
- } else {
- return getListType(currentType);
- }
+ return currentType;
}
protected abstract IAType getListType(IAType itemType);
diff --git a/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/types/ARecordType.java b/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/types/ARecordType.java
index 26cbf1f..7d5e4c0 100644
--- a/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/types/ARecordType.java
+++ b/asterixdb/asterix-om/src/main/java/org/apache/asterix/om/types/ARecordType.java
@@ -137,25 +137,21 @@
@Override
public String toString() {
- StringBuilder sb = new StringBuilder();
- sb.append(typeName + ": ");
- if (isOpen) {
- sb.append("open ");
- } else {
- sb.append("closed ");
+ return append(new StringBuilder()).toString();
+ }
+
+ private StringBuilder append(StringBuilder sb) {
+ if (typeName != null) {
+ sb.append(typeName).append(": ");
}
- sb.append("{\n");
+ sb.append(isOpen ? "open" : "closed");
+ sb.append(" {\n");
int n = fieldNames.length;
for (int i = 0; i < n; i++) {
- sb.append(" " + fieldNames[i] + ": " + fieldTypes[i].toString());
- if (i < (n - 1)) {
- sb.append(",\n");
- } else {
- sb.append("\n");
- }
+ sb.append(" ").append(fieldNames[i]).append(": ").append(fieldTypes[i]);
+ sb.append(i < (n - 1) ? ",\n" : "\n");
}
- sb.append("}\n");
- return sb.toString();
+ return sb.append("}\n");
}
@Override