You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@asterixdb.apache.org by am...@apache.org on 2016/03/26 21:27:37 UTC
[06/13] incubator-asterixdb git commit: Improve Error Handling in
Local Directory Feeds
http://git-wip-us.apache.org/repos/asf/incubator-asterixdb/blob/121e1d9a/asterix-external-data/src/test/java/org/apache/asterix/external/classad/ClassAd.java
----------------------------------------------------------------------
diff --git a/asterix-external-data/src/test/java/org/apache/asterix/external/classad/ClassAd.java b/asterix-external-data/src/test/java/org/apache/asterix/external/classad/ClassAd.java
index df6ae0d..4f27cd8 100644
--- a/asterix-external-data/src/test/java/org/apache/asterix/external/classad/ClassAd.java
+++ b/asterix-external-data/src/test/java/org/apache/asterix/external/classad/ClassAd.java
@@ -27,7 +27,7 @@ import java.util.Map.Entry;
import java.util.TreeSet;
import org.apache.asterix.external.classad.Value.NumberFactor;
-import org.apache.asterix.external.classad.object.pool.CaseInsensitiveStringPool;
+import org.apache.asterix.external.classad.object.pool.ClassAdObjectPool;
import org.apache.asterix.external.library.ClassAdParser;
import org.apache.asterix.om.base.AMutableDouble;
import org.apache.asterix.om.base.AMutableInt32;
@@ -97,7 +97,6 @@ public class ClassAd extends ExprTree {
private static final int CLASSAD_VERSION_PATCH = 0;
private static final String CLASSAD_VERSION = "8.0.0";
public static final ArrayList<String> specialAttrNames = new ArrayList<String>();
- private final CaseInsensitiveStringPool StringPool = new CaseInsensitiveStringPool();
static {
specialAttrNames.add(ATTR_TOPLEVEL);
@@ -106,42 +105,22 @@ public class ClassAd extends ExprTree {
specialAttrNames.add(ATTR_PARENT);
}
- public static final FunctionCall curr_time_expr = FunctionCall.createFunctionCall("time", new ExprList());
+ public static final FunctionCall curr_time_expr = FunctionCall.createFunctionCall("time",
+ new ExprList(new ClassAdObjectPool()), new ClassAdObjectPool());
private ClassAd alternateScope;
- //private boolean doDirtyTracking;
- private Map<CaseInsensitiveString, ExprTree> attrList = new HashMap<CaseInsensitiveString, ExprTree>();
+ private final Map<CaseInsensitiveString, ExprTree> attrList;
private ClassAd chainedParentAd;
private ClassAdParser parser = null;
- private ClassAd newAd = null;
+ private ClassAd newAd;
/*
* Constructors
*/
- public ClassAd() {
- chainedParentAd = null;
- alternateScope = null;
- newAd = new ClassAd(false, false);
- parser = new ClassAdParser(null, false, true, false, null, null, null);
- }
-
- public ClassAd(boolean initializeParser, boolean initializeNewAd) {
- chainedParentAd = null;
- alternateScope = null;
- if (initializeNewAd) {
- newAd = new ClassAd(false, false);
- }
- if (initializeParser) {
- parser = new ClassAdParser(null, false, true, false, null, null, null);
- }
- }
-
- public ClassAd(ClassAd ad) throws HyracksDataException {
- if (ad == null) {
- clear();
- } else {
- copyFrom(ad);
- }
+ public ClassAd(ClassAdObjectPool objectPool) {
+ super(objectPool);
+ parser = new ClassAdParser(this.objectPool);
+ attrList = new HashMap<CaseInsensitiveString, ExprTree>();
}
@Override
@@ -165,10 +144,6 @@ public class ClassAd extends ExprTree {
return attrList;
}
- public void setAttrList(Map<CaseInsensitiveString, ExprTree> attrList) {
- this.attrList = attrList;
- }
-
public void classAdLibraryVersion(AMutableInt32 major, AMutableInt32 minor, AMutableInt32 patch) {
major.setValue(CLASSAD_VERSION_MAJOR);
minor.setValue(CLASSAD_VERSION_MINOR);
@@ -187,21 +162,6 @@ public class ClassAd extends ExprTree {
return curr_time_expr;
}
- //public TreeSet<CaseInsensitiveString> dirtyAttrList = new TreeSet<CaseInsensitiveString>();
-
- /*
- * Reference is an ordered set of Strings <The ordering uses less than ignore case>. Example
- * below
- * TreeSet<String> references = new TreeSet<String>(
- * new Comparator<String>(){
- * public int compare(String o1, String o2) {
- * return o1.compareToIgnoreCase(o2);
- * }
- * });
- *
- * // PortReferences is a Map<ClassAd,OrderedSet<Strings>>
- */
-
public boolean copyFrom(ClassAd ad) throws HyracksDataException {
boolean succeeded = true;
@@ -211,38 +171,26 @@ public class ClassAd extends ExprTree {
clear();
// copy scoping attributes
super.copyFrom(ad);
- if (ad.chainedParentAd != null) {
- if (chainedParentAd == null) {
- chainedParentAd = new ClassAd();
- }
- chainedParentAd.setValue(ad.chainedParentAd);
- }
- if (ad.alternateScope != null) {
- if (alternateScope == null) {
- alternateScope = new ClassAd();
- }
- alternateScope.setValue(ad.alternateScope);
- }
- //this.doDirtyTracking = false;
+ chainedParentAd = ad.chainedParentAd;
+ alternateScope = ad.alternateScope;
for (Entry<CaseInsensitiveString, ExprTree> attr : ad.attrList.entrySet()) {
- ExprTree tree = attr.getValue().copy();
- attrList.put(attr.getKey(), tree);
- // if (ad.doDirtyTracking && ad.IsAttributeDirty(attr.getKey())) {
- // dirtyAttrList.add(attr.getKey());
- //}
+ ExprTree tree = objectPool.mutableExprPool.get();
+ CaseInsensitiveString key = objectPool.caseInsensitiveStringPool.get();
+ tree.copyFrom(attr.getValue());
+ key.set(attr.getKey().get());
+ attrList.put(key, tree);
}
- //doDirtyTracking = ad.doDirtyTracking;
}
return succeeded;
}
public boolean update(ClassAd ad) throws HyracksDataException {
for (Entry<CaseInsensitiveString, ExprTree> attr : ad.attrList.entrySet()) {
- ExprTree tree = attr.getValue().copy();
- attrList.put(attr.getKey(), tree);
- // if (ad.doDirtyTracking && ad.IsAttributeDirty(attr.getKey())) {
- // dirtyAttrList.add(attr.getKey());
- //}
+ ExprTree tree = objectPool.mutableExprPool.get();
+ CaseInsensitiveString key = objectPool.caseInsensitiveStringPool.get();
+ tree.copyFrom(attr.getValue());
+ key.set(attr.getKey().get());
+ attrList.put(key, tree);
}
return true;
}
@@ -306,9 +254,6 @@ public class ClassAd extends ExprTree {
if (alternateScope != null) {
alternateScope.clear();
}
- if (parser != null) {
- parser.reset();
- }
}
public void unchain() {
@@ -317,18 +262,24 @@ public class ClassAd extends ExprTree {
}
}
- public void getComponents(Map<CaseInsensitiveString, ExprTree> attrs) {
+ public void getComponents(Map<CaseInsensitiveString, ExprTree> attrs, ClassAdObjectPool objectPool)
+ throws HyracksDataException {
attrs.clear();
for (Entry<CaseInsensitiveString, ExprTree> attr : this.attrList.entrySet()) {
- attrs.put(attr.getKey(), attr.getValue());
+ ExprTree tree = objectPool.mutableExprPool.get();
+ CaseInsensitiveString key = objectPool.caseInsensitiveStringPool.get();
+ tree.copyFrom(attr.getValue());
+ key.set(attr.getKey().get());
+ attrs.put(key, tree);
}
}
public ClassAd privateGetDeepScope(ExprTree tree) throws HyracksDataException {
- ClassAd scope = new ClassAd();
- Value val = new Value();
- if (tree == null)
+ if (tree == null) {
return (null);
+ }
+ ClassAd scope = objectPool.classAdPool.get();
+ Value val = objectPool.valuePool.get();
tree.setParentScope(this);
if (!tree.publicEvaluate(val) || !val.isClassAdValue(scope)) {
return (null);
@@ -339,9 +290,9 @@ public class ClassAd extends ExprTree {
// --- begin integer attribute insertion ----
public boolean insertAttr(String name, int value, NumberFactor f) throws HyracksDataException {
ExprTree plit;
- Value val = new Value();
+ Value val = objectPool.valuePool.get();
val.setIntegerValue(value);
- plit = Literal.createLiteral(val, f);
+ plit = Literal.createLiteral(val, f, objectPool);
return insert(name, plit);
}
@@ -351,10 +302,10 @@ public class ClassAd extends ExprTree {
public boolean insertAttr(String name, long value, NumberFactor f) throws HyracksDataException {
ExprTree plit;
- Value val = new Value();
+ Value val = objectPool.valuePool.get();
val.setIntegerValue(value);
- plit = Literal.createLiteral(val, f);
+ plit = Literal.createLiteral(val, f, objectPool);
return (insert(name, plit));
}
@@ -365,16 +316,18 @@ public class ClassAd extends ExprTree {
public boolean deepInsertAttr(ExprTree scopeExpr, String name, int value, NumberFactor f)
throws HyracksDataException {
ClassAd ad = privateGetDeepScope(scopeExpr);
- if (ad == null)
+ if (ad == null) {
return (false);
+ }
return (ad.insertAttr(name, value, f));
}
public boolean deepInsertAttr(ExprTree scopeExpr, String name, long value, NumberFactor f)
throws HyracksDataException {
ClassAd ad = privateGetDeepScope(scopeExpr);
- if (ad == null)
+ if (ad == null) {
return (false);
+ }
return (ad.insertAttr(name, value, f));
}
@@ -383,17 +336,18 @@ public class ClassAd extends ExprTree {
// --- begin real attribute insertion ---
public boolean insertAttr(String name, double value, NumberFactor f) throws HyracksDataException {
ExprTree plit;
- Value val = new Value();
+ Value val = objectPool.valuePool.get();
val.setRealValue(value);
- plit = Literal.createLiteral(val, f);
+ plit = Literal.createLiteral(val, f, objectPool);
return (insert(name, plit));
}
public boolean deepInsertAttr(ExprTree scopeExpr, String name, double value, NumberFactor f)
throws HyracksDataException {
ClassAd ad = privateGetDeepScope(scopeExpr);
- if (ad == null)
+ if (ad == null) {
return (false);
+ }
return (ad.insertAttr(name, value, f));
}
@@ -402,16 +356,17 @@ public class ClassAd extends ExprTree {
// --- begin boolean attribute insertion
public boolean insertAttr(String name, boolean value) throws HyracksDataException {
ExprTree plit;
- Value val = new Value();
+ Value val = objectPool.valuePool.get();
val.setBooleanValue(value);
- plit = Literal.createLiteral(val);
+ plit = Literal.createLiteral(val, objectPool);
return (insert(name, plit));
}
public boolean deepInsertAttr(ExprTree scopeExpr, String name, boolean value) throws HyracksDataException {
ClassAd ad = privateGetDeepScope(scopeExpr);
- if (ad == null)
+ if (ad == null) {
return (false);
+ }
return (ad.insertAttr(name, value));
}
@@ -420,33 +375,35 @@ public class ClassAd extends ExprTree {
// --- begin string attribute insertion
public boolean insertAttr(String name, AMutableCharArrayString value) throws HyracksDataException {
ExprTree plit;
- Value val = new Value();
+ Value val = objectPool.valuePool.get();
val.setStringValue(value);
- plit = Literal.createLiteral(val);
+ plit = Literal.createLiteral(val, objectPool);
return (insert(name, plit));
}
public boolean deepInsertAttr(ExprTree scopeExpr, String name, AMutableCharArrayString value)
throws HyracksDataException {
ClassAd ad = privateGetDeepScope(scopeExpr);
- if (ad == null)
+ if (ad == null) {
return (false);
+ }
return (ad.insertAttr(name, value));
}
public boolean insertAttr(String name, String value) throws HyracksDataException {
ExprTree plit;
- Value val = new Value();
+ Value val = objectPool.valuePool.get();
val.setStringValue(value);
- plit = Literal.createLiteral(val);
+ plit = Literal.createLiteral(val, objectPool);
return (insert(name, plit));
}
public boolean deepInsertAttr(ExprTree scopeExpr, String name, String value) throws HyracksDataException {
ClassAd ad = privateGetDeepScope(scopeExpr);
- if (ad == null)
+ if (ad == null) {
return (false);
+ }
return (ad.insertAttr(name, value));
}
@@ -498,7 +455,7 @@ public class ClassAd extends ExprTree {
// cache doesn't already have an entry for this name:value, so add
// it to the cache now.
if (newTree.getKind() != NodeKind.LITERAL_NODE) {
- Literal lit = parser.getLiteral();
+ Literal lit = objectPool.literalPool.get();
lit.getValue().setStringValue(szValue);
bRet = insert(name, lit, false);
} else {
@@ -511,7 +468,8 @@ public class ClassAd extends ExprTree {
}
public boolean insert(String attrName, ExprTree expr) throws HyracksDataException {
- boolean result = insert(attrName, expr.isTreeHolder() ? ((ExprTreeHolder) expr).getInnerTree() : expr, false);
+ ExprTree tree = expr.copy();
+ boolean result = insert(attrName, tree.isTreeHolder() ? ((ExprTreeHolder) tree).getInnerTree() : tree, false);
return result;
}
@@ -522,13 +480,14 @@ public class ClassAd extends ExprTree {
if (attrName.isEmpty() || pRef == null) {
throw new HyracksDataException();
}
- CaseInsensitiveString pstrAttr = StringPool.get();
- pstrAttr.set(attrName);
-
if (tree != null) {
+ CaseInsensitiveString pstrAttr = objectPool.caseInsensitiveStringPool.get();
+ pstrAttr.set(attrName);
+ ExprTreeHolder mutableTree = objectPool.mutableExprPool.get();
+ mutableTree.copyFrom(tree);
// parent of the expression is this classad
tree.setParentScope(this);
- attrList.put(pstrAttr, tree);
+ attrList.put(pstrAttr, mutableTree);
bRet = true;
}
return (bRet);
@@ -536,8 +495,9 @@ public class ClassAd extends ExprTree {
public boolean deepInsert(ExprTree scopeExpr, String name, ExprTree tree) throws HyracksDataException {
ClassAd ad = privateGetDeepScope(scopeExpr);
- if (ad == null)
+ if (ad == null) {
return (false);
+ }
return (ad.insert(name, tree));
}
@@ -545,10 +505,9 @@ public class ClassAd extends ExprTree {
// --- begin lookup methods
public ExprTree lookup(String name) {
- CaseInsensitiveString aString = StringPool.get();
+ CaseInsensitiveString aString = objectPool.caseInsensitiveStringPool.get();
aString.set(name);
ExprTree expr = lookup(aString);
- StringPool.put(aString);
return expr;
}
@@ -569,9 +528,9 @@ public class ClassAd extends ExprTree {
}
}
- public ExprTree lookupInScope(AMutableCharArrayString name, ClassAd finalScope) {
- EvalState state = new EvalState();
- ExprTreeHolder tree = new ExprTreeHolder();
+ public ExprTree lookupInScope(AMutableCharArrayString name, ClassAd finalScope) throws HyracksDataException {
+ EvalState state = objectPool.evalStatePool.get();
+ ExprTreeHolder tree = objectPool.mutableExprPool.get();
int rval;
state.setScopes(this);
rval = lookupInScope(name.toString(), tree, state);
@@ -583,10 +542,10 @@ public class ClassAd extends ExprTree {
return null;
}
- public int lookupInScope(String name, ExprTreeHolder expr, EvalState state) {
+ public int lookupInScope(String name, ExprTreeHolder expr, EvalState state) throws HyracksDataException {
ClassAd current = this;
- ClassAd superScope = new ClassAd();
+ ClassAd superScope = objectPool.classAdPool.get();
expr.setInnerTree(null);
while (expr.getInnerTree() == null && current != null) {
@@ -598,11 +557,17 @@ public class ClassAd extends ExprTree {
if ((expr.getInnerTree() != null)) {
return EvalResult.EVAL_OK.ordinal();
}
-
- if (state.getRootAd().equals(current)) {
- superScope = null;
- } else {
- superScope = current.parentScope;
+ try {
+ if (state.getRootAd() == null) {
+ return (EvalResult.EVAL_UNDEF.ordinal());
+ } else if (state.getRootAd().equals(current)) {
+ superScope = null;
+ } else {
+ superScope = current.parentScope;
+ }
+ } catch (Throwable th) {
+ th.printStackTrace();
+ throw th;
}
if (!getSpecialAttrNames().contains(name)) {
// continue searching from the superScope ...
@@ -638,10 +603,9 @@ public class ClassAd extends ExprTree {
// --- begin deletion methods
public boolean delete(String name) throws HyracksDataException {
- CaseInsensitiveString aString = StringPool.get();
+ CaseInsensitiveString aString = objectPool.caseInsensitiveStringPool.get();
aString.set(name);
boolean success = delete(aString);
- StringPool.put(aString);
return success;
}
@@ -657,10 +621,10 @@ public class ClassAd extends ExprTree {
// behavior copied from old ClassAds. It's also one reason you
// probably don't want to use this feature in the future.
if (chainedParentAd != null && chainedParentAd.lookup(name) != null) {
- Value undefined_value = new Value();
+ Value undefined_value = objectPool.valuePool.get();
undefined_value.setUndefinedValue();
deleted_attribute = true;
- ExprTree plit = Literal.createLiteral(undefined_value);
+ ExprTree plit = Literal.createLiteral(undefined_value, objectPool);
insert(name.get(), plit);
}
return deleted_attribute;
@@ -668,12 +632,12 @@ public class ClassAd extends ExprTree {
public boolean deepDelete(ExprTree scopeExpr, String name) throws HyracksDataException {
ClassAd ad = privateGetDeepScope(scopeExpr);
- if (ad == null)
+ if (ad == null) {
return (false);
- CaseInsensitiveString aString = StringPool.get();
+ }
+ CaseInsensitiveString aString = objectPool.caseInsensitiveStringPool.get();
aString.set(name);;
boolean success = ad.delete(aString);
- StringPool.put(aString);
return success;
}
@@ -694,9 +658,9 @@ public class ClassAd extends ExprTree {
if (tree == null) {
tree = chainedParentAd.lookup(name);
}
- Value undefined_value = new Value();
+ Value undefined_value = objectPool.valuePool.get();
undefined_value.setUndefinedValue();
- ExprTree plit = Literal.createLiteral(undefined_value);
+ ExprTree plit = Literal.createLiteral(undefined_value, objectPool);
//why??
insert(name, plit);
}
@@ -705,8 +669,9 @@ public class ClassAd extends ExprTree {
public ExprTree deepRemove(ExprTree scopeExpr, String name) throws HyracksDataException {
ClassAd ad = privateGetDeepScope(scopeExpr);
- if (ad == null)
+ if (ad == null) {
return (null);
+ }
return (ad.remove(name));
}
@@ -721,7 +686,7 @@ public class ClassAd extends ExprTree {
public void modify(ClassAd mod) throws HyracksDataException {
ClassAd ctx;
ExprTree expr;
- Value val = new Value();
+ Value val = objectPool.valuePool.get();
// Step 0: Determine Context
if ((expr = mod.lookup(Common.ATTR_CONTEXT)) != null) {
@@ -734,7 +699,7 @@ public class ClassAd extends ExprTree {
// Step 1: Process Replace attribute
if ((expr = mod.lookup(Common.ATTR_REPLACE)) != null) {
- ClassAd ad = new ClassAd();
+ ClassAd ad = objectPool.classAdPool.get();
if (expr.publicEvaluate(val) && val.isClassAdValue(ad)) {
ctx.clear();
ctx.update(ad);
@@ -743,7 +708,7 @@ public class ClassAd extends ExprTree {
// Step 2: Process Updates attribute
if ((expr = mod.lookup(Common.ATTR_UPDATES)) != null) {
- ClassAd ad = new ClassAd();
+ ClassAd ad = objectPool.classAdPool.get();
if (expr.publicEvaluate(val) && val.isClassAdValue(ad)) {
ctx.update(ad);
}
@@ -751,8 +716,8 @@ public class ClassAd extends ExprTree {
// Step 3: Process Deletes attribute
if ((expr = mod.lookup(Common.ATTR_DELETES)) != null) {
- ExprList list = new ExprList();
- AMutableCharArrayString attrName = new AMutableCharArrayString();
+ ExprList list = objectPool.exprListPool.get();
+ AMutableCharArrayString attrName = objectPool.strPool.get();
// make a first pass to check that it is a list of strings ...
if (!expr.publicEvaluate(val) || !val.isListValue(list)) {
@@ -774,18 +739,18 @@ public class ClassAd extends ExprTree {
@Override
public ExprTree copy() throws HyracksDataException {
- ClassAd newAd = new ClassAd();
- newAd.parentScope = parentScope;
- newAd.chainedParentAd = chainedParentAd;
+ ClassAd newAd = objectPool.classAdPool.get();
+ newAd.parentScope = (parentScope == null) ? null : (ClassAd) parentScope.copy();
+ newAd.chainedParentAd = chainedParentAd == null ? null : (ClassAd) chainedParentAd.copy();
for (Entry<CaseInsensitiveString, ExprTree> entry : attrList.entrySet()) {
- newAd.insert(entry.getKey().get(), entry.getValue().copy(), false);
+ newAd.insert(entry.getKey().get(), entry.getValue(), false);
}
return newAd;
}
@Override
- public boolean publicEvaluate(EvalState state, Value val) {
+ public boolean publicEvaluate(EvalState state, Value val) throws HyracksDataException {
val.setClassAdValue(this);
return (true);
}
@@ -800,9 +765,9 @@ public class ClassAd extends ExprTree {
@Override
public boolean privateFlatten(EvalState state, Value val, ExprTreeHolder tree, AMutableInt32 i)
throws HyracksDataException {
- ClassAd newAd = new ClassAd();
- Value eval = new Value();
- ExprTreeHolder etree = new ExprTreeHolder();
+ ClassAd newAd = objectPool.classAdPool.get();
+ Value eval = objectPool.valuePool.get();
+ ExprTreeHolder etree = objectPool.mutableExprPool.get();;
ClassAd oldAd;
tree.setInnerTree(null); // Just to be safe... wenger 2003-12-11.
@@ -814,23 +779,27 @@ public class ClassAd extends ExprTree {
// flatten expression
if (!entry.getValue().publicFlatten(state, eval, etree)) {
tree.setInnerTree(null);;
- eval.clear();
+ eval.setUndefinedValue();
state.setCurAd(oldAd);
return false;
}
// if a value was obtained, convert it to a literal
if (etree.getInnerTree() == null) {
- etree.setInnerTree(Literal.createLiteral(eval));
+ etree.setInnerTree(Literal.createLiteral(eval, objectPool));
if (etree.getInnerTree() == null) {
tree.setInnerTree(null);
- eval.clear();
+ eval.setUndefinedValue();
state.setCurAd(oldAd);
return false;
}
}
- newAd.attrList.put(entry.getKey(), etree);
- eval.clear();
+ CaseInsensitiveString key = objectPool.caseInsensitiveStringPool.get();
+ ExprTreeHolder value = objectPool.mutableExprPool.get();
+ key.set(entry.getKey().get());
+ value.copyFrom(etree);
+ newAd.attrList.put(key, value);
+ eval.setUndefinedValue();
}
tree.setInnerTree(newAd);
@@ -839,8 +808,8 @@ public class ClassAd extends ExprTree {
}
public boolean evaluateAttr(String attr, Value val) throws HyracksDataException {
- EvalState state = new EvalState();
- ExprTreeHolder tree = new ExprTreeHolder();
+ EvalState state = objectPool.evalStatePool.get();
+ ExprTreeHolder tree = objectPool.mutableExprPool.get();
state.setScopes(this);
switch (lookupInScope(attr, tree, state)) {
case ExprTree.EVAL_FAIL_Int:
@@ -860,8 +829,8 @@ public class ClassAd extends ExprTree {
public boolean evaluateExpr(String buf, Value result) throws HyracksDataException {
boolean successfully_evaluated;
- ExprTreeHolder tree = new ExprTreeHolder();
- ClassAdParser parser = new ClassAdParser(null, false, true, false, null, null, null);
+ ExprTreeHolder tree = objectPool.mutableExprPool.get();
+ ClassAdParser parser = objectPool.classAdParserPool.get();
try {
if (parser.parseExpression(buf, tree)) {
@@ -876,54 +845,54 @@ public class ClassAd extends ExprTree {
}
public boolean evaluateExpr(ExprTreeHolder tree, Value val) throws HyracksDataException {
- EvalState state = new EvalState();
+ EvalState state = objectPool.evalStatePool.get();
state.setScopes(this);
return (tree.publicEvaluate(state, val));
}
public boolean evaluateExpr(ExprTreeHolder tree, Value val, ExprTreeHolder sig) throws HyracksDataException {
- EvalState state = new EvalState();
+ EvalState state = objectPool.evalStatePool.get();
state.setScopes(this);
return (tree.publicEvaluate(state, val, sig));
}
public boolean evaluateAttrInt(String attr, AMutableInt64 i) throws HyracksDataException {
- Value val = new Value();
+ Value val = objectPool.valuePool.get();
return (evaluateAttr(attr, val) && val.isIntegerValue(i));
}
public boolean evaluateAttrReal(String attr, AMutableDouble r) throws HyracksDataException {
- Value val = new Value();
+ Value val = objectPool.valuePool.get();
return (evaluateAttr(attr, val) && val.isRealValue(r));
}
public boolean evaluateAttrNumber(String attr, AMutableInt64 i) throws HyracksDataException {
- Value val = new Value();
+ Value val = objectPool.valuePool.get();
return (evaluateAttr(attr, val) && val.isNumber(i));
}
public boolean evaluateAttrNumber(String attr, AMutableDouble r) throws HyracksDataException {
- Value val = new Value();
+ Value val = objectPool.valuePool.get();
return (evaluateAttr(attr, val) && val.isNumber(r));
}
public boolean evaluateAttrString(String attr, AMutableCharArrayString buf, int len) throws HyracksDataException {
- Value val = new Value();
+ Value val = objectPool.valuePool.get();
return (evaluateAttr(attr, val) && val.isStringValue(buf, len));
}
public boolean evaluateAttrString(String attr, AMutableCharArrayString buf) throws HyracksDataException {
- Value val = new Value();
+ Value val = objectPool.valuePool.get();
return (evaluateAttr(attr, val) && val.isStringValue(buf));
}
public boolean evaluateAttrBool(String attr, MutableBoolean b) throws HyracksDataException {
- Value val = new Value();
+ Value val = objectPool.valuePool.get();
return (evaluateAttr(attr, val) && val.isBooleanValue(b));
}
public boolean evaluateAttrBoolEquiv(String attr, MutableBoolean b) throws HyracksDataException {
- Value val = new Value();
+ Value val = objectPool.valuePool.get();
return (evaluateAttr(attr, val) && val.isBooleanValueEquiv(b));
}
@@ -942,7 +911,7 @@ public class ClassAd extends ExprTree {
public boolean getExternalReferences(ExprTree tree, TreeSet<String> refs, boolean fullNames)
throws HyracksDataException {
- EvalState state = new EvalState();
+ EvalState state = objectPool.evalStatePool.get();
// Treat this ad as the root of the tree for reference tracking.
// If an attribute is only present in a parent scope of this ad,
// then we want to treat it as an external reference.
@@ -962,12 +931,12 @@ public class ClassAd extends ExprTree {
return (true);
case ATTRREF_NODE: {
- ClassAd start = new ClassAd();
- ExprTreeHolder tree = new ExprTreeHolder();
- ExprTreeHolder result = new ExprTreeHolder();
- AMutableCharArrayString attr = new AMutableCharArrayString();
- Value val = new Value();
- MutableBoolean abs = new MutableBoolean();
+ ClassAd start = objectPool.classAdPool.get();
+ ExprTreeHolder tree = objectPool.mutableExprPool.get();
+ ExprTreeHolder result = objectPool.mutableExprPool.get();
+ AMutableCharArrayString attr = objectPool.strPool.get();
+ Value val = objectPool.valuePool.get();
+ MutableBoolean abs = objectPool.boolPool.get();
((AttributeReference) expr).getComponents(tree, attr, abs);
// establish starting point for attribute search
@@ -984,9 +953,9 @@ public class ClassAd extends ExprTree {
// are in the tree part
if (val.isUndefinedValue()) {
if (fullNames) {
- AMutableCharArrayString fullName = new AMutableCharArrayString();
+ AMutableCharArrayString fullName = objectPool.strPool.get();
if (tree.getInnerTree() != null) {
- ClassAdUnParser unparser = new PrettyPrint();
+ ClassAdUnParser unparser = objectPool.prettyPrintPool.get();
unparser.unparse(fullName, tree);
fullName.appendChar('.');
}
@@ -1041,10 +1010,10 @@ public class ClassAd extends ExprTree {
}
case OP_NODE: {
// recurse on subtrees
- AMutableInt32 opKind = new AMutableInt32(0);
- ExprTreeHolder t1 = new ExprTreeHolder();
- ExprTreeHolder t2 = new ExprTreeHolder();
- ExprTreeHolder t3 = new ExprTreeHolder();
+ AMutableInt32 opKind = objectPool.int32Pool.get();
+ ExprTreeHolder t1 = objectPool.mutableExprPool.get();
+ ExprTreeHolder t2 = objectPool.mutableExprPool.get();
+ ExprTreeHolder t3 = objectPool.mutableExprPool.get();
((Operation) expr).getComponents(opKind, t1, t2, t3);
if (t1.getInnerTree() != null && !privateGetExternalReferences(t1, ad, state, refs, fullNames)) {
@@ -1060,8 +1029,8 @@ public class ClassAd extends ExprTree {
}
case FN_CALL_NODE: {
// recurse on subtrees
- AMutableCharArrayString fnName = new AMutableCharArrayString();
- ExprList args = new ExprList();
+ AMutableCharArrayString fnName = objectPool.strPool.get();
+ ExprList args = objectPool.exprListPool.get();
((FunctionCall) expr).getComponents(fnName, args);
for (ExprTree tree : args.getExprList()) {
if (!privateGetExternalReferences(tree, ad, state, refs, fullNames)) {
@@ -1072,8 +1041,8 @@ public class ClassAd extends ExprTree {
}
case CLASSAD_NODE: {
// recurse on subtrees
- Map<CaseInsensitiveString, ExprTree> attrs = new HashMap<CaseInsensitiveString, ExprTree>();
- ((ClassAd) expr).getComponents(attrs);
+ Map<CaseInsensitiveString, ExprTree> attrs = objectPool.strToExprPool.get();
+ ((ClassAd) expr).getComponents(attrs, objectPool);
for (Entry<CaseInsensitiveString, ExprTree> entry : attrs.entrySet()) {
if (state.getDepthRemaining() <= 0) {
return false;
@@ -1089,7 +1058,7 @@ public class ClassAd extends ExprTree {
}
case EXPR_LIST_NODE: {
// recurse on subtrees
- ExprList exprs = new ExprList();
+ ExprList exprs = objectPool.exprListPool.get();
((ExprList) expr).getComponents(exprs);
for (ExprTree exprTree : exprs.getExprList()) {
@@ -1115,7 +1084,7 @@ public class ClassAd extends ExprTree {
// PortReferences is a Map<ClassAd,TreeSet<Strings>>
public boolean getExternalReferences(ExprTree tree, Map<ClassAd, TreeSet<String>> refs)
throws HyracksDataException {
- EvalState state = new EvalState();
+ EvalState state = objectPool.evalStatePool.get();
// Treat this ad as the root of the tree for reference tracking.
// If an attribute is only present in a parent scope of this ad,
// then we want to treat it as an external reference.
@@ -1133,12 +1102,12 @@ public class ClassAd extends ExprTree {
return (true);
case ATTRREF_NODE: {
- ClassAd start = new ClassAd();
- ExprTreeHolder tree = new ExprTreeHolder();
- ExprTreeHolder result = new ExprTreeHolder();
- AMutableCharArrayString attr = new AMutableCharArrayString();
- Value val = new Value();
- MutableBoolean abs = new MutableBoolean();
+ ClassAd start = objectPool.classAdPool.get();
+ ExprTreeHolder tree = objectPool.mutableExprPool.get();
+ ExprTreeHolder result = objectPool.mutableExprPool.get();
+ AMutableCharArrayString attr = objectPool.strPool.get();
+ Value val = objectPool.valuePool.get();
+ MutableBoolean abs = objectPool.boolPool.get();
((AttributeReference) expr).getComponents(tree, attr, abs);
// establish starting point for attribute search
@@ -1148,8 +1117,9 @@ public class ClassAd extends ExprTree {
return false; // NAC
} // NAC
} else {
- if (!tree.publicEvaluate(state, val))
+ if (!tree.publicEvaluate(state, val)) {
return (false);
+ }
// if the tree evals to undefined, the external references
// are in the tree part
if (val.isUndefinedValue()) {
@@ -1157,8 +1127,9 @@ public class ClassAd extends ExprTree {
}
// otherwise, if the tree didn't evaluate to a classad,
// we have a problem
- if (!val.isClassAdValue(start))
+ if (!val.isClassAdValue(start)) {
return (false);
+ }
// make sure that we are starting from a "valid" scope
if (!refs.containsKey(start) && start != this) {
@@ -1169,7 +1140,7 @@ public class ClassAd extends ExprTree {
ClassAd curAd = state.getCurAd();
TreeSet<String> pitr = refs.get(start);
if (pitr == null) {
- pitr = new TreeSet<String>();
+ pitr = objectPool.strSetPool.get();
refs.put(start, pitr);
}
switch (start.lookupInScope(attr.toString(), result, state)) {
@@ -1198,10 +1169,10 @@ public class ClassAd extends ExprTree {
case OP_NODE: {
// recurse on subtrees
- AMutableInt32 opKind = new AMutableInt32(0);
- ExprTreeHolder t1 = new ExprTreeHolder();
- ExprTreeHolder t2 = new ExprTreeHolder();
- ExprTreeHolder t3 = new ExprTreeHolder();
+ AMutableInt32 opKind = objectPool.int32Pool.get();
+ ExprTreeHolder t1 = objectPool.mutableExprPool.get();
+ ExprTreeHolder t2 = objectPool.mutableExprPool.get();
+ ExprTreeHolder t3 = objectPool.mutableExprPool.get();
((Operation) expr).getComponents(opKind, t1, t2, t3);
if (t1.getInnerTree() != null && !privateGetExternalReferences(t1, ad, state, refs)) {
return (false);
@@ -1217,8 +1188,8 @@ public class ClassAd extends ExprTree {
case FN_CALL_NODE: {
// recurse on subtrees
- AMutableCharArrayString fnName = new AMutableCharArrayString();
- ExprList args = new ExprList();
+ AMutableCharArrayString fnName = objectPool.strPool.get();
+ ExprList args = objectPool.exprListPool.get();
((FunctionCall) expr).getComponents(fnName, args);
for (ExprTree exprTree : args.getExprList()) {
@@ -1231,9 +1202,9 @@ public class ClassAd extends ExprTree {
case CLASSAD_NODE: {
// recurse on subtrees
- HashMap<CaseInsensitiveString, ExprTree> attrs = new HashMap<CaseInsensitiveString, ExprTree>();
+ HashMap<CaseInsensitiveString, ExprTree> attrs = objectPool.strToExprPool.get();
- ((ClassAd) expr).getComponents(attrs);
+ ((ClassAd) expr).getComponents(attrs, objectPool);
for (Entry<CaseInsensitiveString, ExprTree> entry : attrs.entrySet()) {
if (!privateGetExternalReferences(entry.getValue(), ad, state, refs)) {
return (false);
@@ -1244,7 +1215,7 @@ public class ClassAd extends ExprTree {
case EXPR_LIST_NODE: {
// recurse on subtrees
- ExprList exprs = new ExprList();
+ ExprList exprs = objectPool.exprListPool.get();
((ExprList) expr).getComponents(exprs);
for (ExprTree exprTree : exprs.getExprList()) {
if (!privateGetExternalReferences(exprTree, ad, state, refs)) {
@@ -1273,7 +1244,7 @@ public class ClassAd extends ExprTree {
*/
public boolean getInternalReferences(ExprTree tree, TreeSet<String> refs, boolean fullNames)
throws HyracksDataException {
- EvalState state = new EvalState();
+ EvalState state = objectPool.evalStatePool.get();
// Treat this ad as the root of the tree for reference tracking.
// If an attribute is only present in a parent scope of this ad,
@@ -1295,12 +1266,12 @@ public class ClassAd extends ExprTree {
}
case ATTRREF_NODE: {
- ClassAd start = new ClassAd();
- ExprTreeHolder tree = new ExprTreeHolder();
- ExprTreeHolder result = new ExprTreeHolder();
- AMutableCharArrayString attr = new AMutableCharArrayString();
- Value val = new Value();
- MutableBoolean abs = new MutableBoolean();
+ ClassAd start = objectPool.classAdPool.get();;
+ ExprTreeHolder tree = objectPool.mutableExprPool.get();
+ ExprTreeHolder result = objectPool.mutableExprPool.get();
+ AMutableCharArrayString attr = objectPool.strPool.get();
+ Value val = objectPool.valuePool.get();
+ MutableBoolean abs = objectPool.boolPool.get();
((AttributeReference) expr).getComponents(tree, attr, abs);
@@ -1393,10 +1364,10 @@ public class ClassAd extends ExprTree {
case OP_NODE: {
//recurse on subtrees
- AMutableInt32 op = new AMutableInt32(0);
- ExprTreeHolder t1 = new ExprTreeHolder();
- ExprTreeHolder t2 = new ExprTreeHolder();
- ExprTreeHolder t3 = new ExprTreeHolder();
+ AMutableInt32 op = objectPool.int32Pool.get();
+ ExprTreeHolder t1 = objectPool.mutableExprPool.get();
+ ExprTreeHolder t2 = objectPool.mutableExprPool.get();
+ ExprTreeHolder t3 = objectPool.mutableExprPool.get();
((Operation) expr).getComponents(op, t1, t2, t3);
if (t1.getInnerTree() != null && !privateGetInternalReferences(t1, ad, state, refs, fullNames)) {
return false;
@@ -1414,8 +1385,8 @@ public class ClassAd extends ExprTree {
case FN_CALL_NODE: {
//recurse on the subtrees!
- AMutableCharArrayString fnName = new AMutableCharArrayString();
- ExprList args = new ExprList();
+ AMutableCharArrayString fnName = objectPool.strPool.get();
+ ExprList args = objectPool.exprListPool.get();
((FunctionCall) expr).getComponents(fnName, args);
for (ExprTree exprTree : args.getExprList()) {
@@ -1429,7 +1400,7 @@ public class ClassAd extends ExprTree {
case CLASSAD_NODE: {
//also recurse on subtrees...
- HashMap<CaseInsensitiveString, ExprTree> attrs = new HashMap<CaseInsensitiveString, ExprTree>();
+ HashMap<CaseInsensitiveString, ExprTree> attrs = objectPool.strToExprPool.get();
// If this ClassAd is only being used here as the scoping
// for an attribute reference, don't recurse into all of
@@ -1438,7 +1409,7 @@ public class ClassAd extends ExprTree {
return true;
}
- ((ClassAd) expr).getComponents(attrs);
+ ((ClassAd) expr).getComponents(attrs, objectPool);
for (Entry<CaseInsensitiveString, ExprTree> entry : attrs.entrySet()) {
if (state.getDepthRemaining() <= 0) {
return false;
@@ -1457,7 +1428,7 @@ public class ClassAd extends ExprTree {
}
case EXPR_LIST_NODE: {
- ExprList exprs = new ExprList();
+ ExprList exprs = objectPool.exprListPool.get();
((ExprList) expr).getComponents(exprs);
for (ExprTree exprTree : exprs.getExprList()) {
@@ -1484,14 +1455,14 @@ public class ClassAd extends ExprTree {
}
public boolean publicFlatten(ExprTree tree, Value val, ExprTreeHolder fexpr) throws HyracksDataException {
- EvalState state = new EvalState();
+ EvalState state = objectPool.evalStatePool.get();
state.setScopes(this);
return (tree.publicFlatten(state, val, fexpr));
}
public boolean flattenAndInline(ExprTree tree, Value val, ExprTreeHolder fexpr) throws HyracksDataException {
- EvalState state = new EvalState();
+ EvalState state = objectPool.evalStatePool.get();
state.setScopes(this);
state.setFlattenAndInline(true);
@@ -1529,12 +1500,8 @@ public class ClassAd extends ExprTree {
return chainedParentAd;
}
- public void setValue(ClassAd value) {
- this.attrList = value.attrList;
- this.alternateScope = value.alternateScope;
- this.chainedParentAd = value.chainedParentAd;
- this.parentScope = value.parentScope;
- this.size = value.size;
+ public void setValue(ClassAd value) throws HyracksDataException {
+ copyFrom(value);
}
@Override
@@ -1566,6 +1533,6 @@ public class ClassAd extends ExprTree {
}
public void createParser() {
- parser = new ClassAdParser(null, false, true, false, null, null, null);
+ parser = objectPool.classAdParserPool.get();
}
}
http://git-wip-us.apache.org/repos/asf/incubator-asterixdb/blob/121e1d9a/asterix-external-data/src/test/java/org/apache/asterix/external/classad/ClassAdFunc.java
----------------------------------------------------------------------
diff --git a/asterix-external-data/src/test/java/org/apache/asterix/external/classad/ClassAdFunc.java b/asterix-external-data/src/test/java/org/apache/asterix/external/classad/ClassAdFunc.java
index 4e77bc0..8a951ad 100644
--- a/asterix-external-data/src/test/java/org/apache/asterix/external/classad/ClassAdFunc.java
+++ b/asterix-external-data/src/test/java/org/apache/asterix/external/classad/ClassAdFunc.java
@@ -18,8 +18,10 @@
*/
package org.apache.asterix.external.classad;
+import org.apache.asterix.external.classad.object.pool.ClassAdObjectPool;
import org.apache.hyracks.api.exceptions.HyracksDataException;
public interface ClassAdFunc {
- public boolean call(String name, ExprList argList, EvalState state, Value val) throws HyracksDataException;
+ public boolean call(String name, ExprList argList, EvalState state, Value val, ClassAdObjectPool objectPool)
+ throws HyracksDataException;
}
http://git-wip-us.apache.org/repos/asf/incubator-asterixdb/blob/121e1d9a/asterix-external-data/src/test/java/org/apache/asterix/external/classad/ClassAdTime.java
----------------------------------------------------------------------
diff --git a/asterix-external-data/src/test/java/org/apache/asterix/external/classad/ClassAdTime.java b/asterix-external-data/src/test/java/org/apache/asterix/external/classad/ClassAdTime.java
index 66c5f56..359511b 100644
--- a/asterix-external-data/src/test/java/org/apache/asterix/external/classad/ClassAdTime.java
+++ b/asterix-external-data/src/test/java/org/apache/asterix/external/classad/ClassAdTime.java
@@ -92,6 +92,7 @@ public class ClassAdTime {
}
public void setRelativeTime(long ms) {
+ this.isAbsolute = false;
timeZoneCalendar.setTimeInMillis(ms);
}
@@ -141,6 +142,17 @@ public class ClassAdTime {
this.timeZoneCalendar.setTimeInMillis(0);
}
+ public void setCurrentAbsolute() {
+ this.isAbsolute = true;
+ this.timeZoneCalendar = Calendar.getInstance();
+ this.timeZoneCalendar.setTimeInMillis(0);
+ }
+
+ public void setTimeZone(String timeZoneId) {
+ this.timeZoneCalendar = Calendar.getInstance(TimeZone.getTimeZone(timeZoneId));
+ this.timeZoneCalendar.setTimeInMillis(0);
+ }
+
public ClassAdTime(String timeZoneId) {
this.isAbsolute = true;
this.timeZoneCalendar = Calendar.getInstance(TimeZone.getTimeZone(timeZoneId));
http://git-wip-us.apache.org/repos/asf/incubator-asterixdb/blob/121e1d9a/asterix-external-data/src/test/java/org/apache/asterix/external/classad/ClassAdUnParser.java
----------------------------------------------------------------------
diff --git a/asterix-external-data/src/test/java/org/apache/asterix/external/classad/ClassAdUnParser.java b/asterix-external-data/src/test/java/org/apache/asterix/external/classad/ClassAdUnParser.java
index 4689612..41333c5 100644
--- a/asterix-external-data/src/test/java/org/apache/asterix/external/classad/ClassAdUnParser.java
+++ b/asterix-external-data/src/test/java/org/apache/asterix/external/classad/ClassAdUnParser.java
@@ -18,12 +18,12 @@
*/
package org.apache.asterix.external.classad;
-import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import org.apache.asterix.external.classad.Value.NumberFactor;
+import org.apache.asterix.external.classad.object.pool.ClassAdObjectPool;
import org.apache.asterix.om.base.AMutableDouble;
import org.apache.asterix.om.base.AMutableInt32;
import org.apache.asterix.om.base.AMutableInt64;
@@ -38,8 +38,11 @@ public class ClassAdUnParser {
" >>> ", " () ", " [] ", " ?: " };
protected static char delimiter = '\"';
+ protected final ClassAdObjectPool objectPool;
+
/// Constructor
- public ClassAdUnParser() {
+ public ClassAdUnParser(ClassAdObjectPool objectPool) {
+ this.objectPool = objectPool;
}
// The default delimiter for strings is '\"'
@@ -64,7 +67,7 @@ public class ClassAdUnParser {
break;
case STRING_VALUE: {
- AMutableCharArrayString s = new AMutableCharArrayString();
+ AMutableCharArrayString s = objectPool.strPool.get();
val.isStringValue(s);
buffer.appendChar('"');
for (int i = 0; i < s.getLength(); i++) {
@@ -118,13 +121,13 @@ public class ClassAdUnParser {
return;
}
case INTEGER_VALUE: {
- AMutableInt64 i = new AMutableInt64(0);
+ AMutableInt64 i = objectPool.int64Pool.get();
val.isIntegerValue(i);
buffer.appendString(String.valueOf(i.getLongValue()));
return;
}
case REAL_VALUE: {
- AMutableDouble real = new AMutableDouble(0);
+ AMutableDouble real = objectPool.doublePool.get();
val.isRealValue(real);
if (real.getDoubleValue() == 0.0) {
// It might be positive or negative and it's
@@ -145,7 +148,7 @@ public class ClassAdUnParser {
return;
}
case BOOLEAN_VALUE: {
- MutableBoolean b = new MutableBoolean();
+ MutableBoolean b = objectPool.boolPool.get();
val.isBooleanValue(b);
buffer.appendString(b.booleanValue() ? "true" : "false");
return;
@@ -159,7 +162,7 @@ public class ClassAdUnParser {
return;
}
case ABSOLUTE_TIME_VALUE: {
- ClassAdTime asecs = new ClassAdTime();
+ ClassAdTime asecs = objectPool.classAdTimePool.get();
val.isAbsoluteTimeValue(asecs);
buffer.appendString("absTime(\"");
@@ -168,7 +171,7 @@ public class ClassAdUnParser {
return;
}
case RELATIVE_TIME_VALUE: {
- ClassAdTime rsecs = new ClassAdTime();
+ ClassAdTime rsecs = objectPool.classAdTimePool.get();
val.isRelativeTimeValue(rsecs);
buffer.appendString("relTime(\"");
Util.relTimeToString(rsecs.getRelativeTime(), buffer);
@@ -177,16 +180,16 @@ public class ClassAdUnParser {
return;
}
case CLASSAD_VALUE: {
- ClassAd ad = new ClassAd();
- Map<CaseInsensitiveString, ExprTree> attrs = new HashMap<CaseInsensitiveString, ExprTree>();
+ ClassAd ad = objectPool.classAdPool.get();
+ Map<CaseInsensitiveString, ExprTree> attrs = objectPool.strToExprPool.get();
val.isClassAdValue(ad);
- ad.getComponents(attrs);
+ ad.getComponents(attrs, objectPool);
unparseAux(buffer, attrs);
return;
}
case SLIST_VALUE:
case LIST_VALUE: {
- ExprList el = new ExprList();
+ ExprList el = objectPool.exprListPool.get();
val.isListValue(el);
unparseAux(buffer, el);
return;
@@ -211,49 +214,49 @@ public class ClassAdUnParser {
switch (tree.getKind()) {
case LITERAL_NODE: { // value
- Value val = new Value();
- AMutableNumberFactor factor = new AMutableNumberFactor();
- ((Literal) tree.self()).getComponents(val, factor);
+ Value val = objectPool.valuePool.get();
+ AMutableNumberFactor factor = objectPool.numFactorPool.get();
+ ((Literal) tree.getTree()).getComponents(val, factor);
unparseAux(buffer, val, factor.getFactor());
return;
}
case ATTRREF_NODE: { // string
- ExprTreeHolder expr = new ExprTreeHolder(); //needs initialization
- AMutableCharArrayString ref = new AMutableCharArrayString();
- MutableBoolean absolute = new MutableBoolean();
- ((AttributeReference) tree.self()).getComponents(expr, ref, absolute);
+ ExprTreeHolder expr = objectPool.mutableExprPool.get(); //needs initialization
+ AMutableCharArrayString ref = objectPool.strPool.get();
+ MutableBoolean absolute = objectPool.boolPool.get();
+ ((AttributeReference) tree.getTree()).getComponents(expr, ref, absolute);
unparseAux(buffer, expr, ref, absolute.booleanValue());
return;
}
case OP_NODE: { //string
- AMutableInt32 op = new AMutableInt32(0);
- ExprTreeHolder t1 = new ExprTreeHolder();
- ExprTreeHolder t2 = new ExprTreeHolder();
- ExprTreeHolder t3 = new ExprTreeHolder();
- ((Operation) tree.self()).getComponents(op, t1, t2, t3);
+ AMutableInt32 op = objectPool.int32Pool.get();
+ ExprTreeHolder t1 = objectPool.mutableExprPool.get();
+ ExprTreeHolder t2 = objectPool.mutableExprPool.get();
+ ExprTreeHolder t3 = objectPool.mutableExprPool.get();
+ ((Operation) tree.getTree()).getComponents(op, t1, t2, t3);
unparseAux(buffer, op.getIntegerValue().intValue(), t1, t2, t3);
return;
}
case FN_CALL_NODE: { // string
- AMutableCharArrayString fnName = new AMutableCharArrayString();
- ExprList args = new ExprList();
- ((FunctionCall) tree.self()).getComponents(fnName, args);
+ AMutableCharArrayString fnName = objectPool.strPool.get();
+ ExprList args = objectPool.exprListPool.get();
+ ((FunctionCall) tree.getTree()).getComponents(fnName, args);
unparseAux(buffer, fnName, args);
return;
}
case CLASSAD_NODE: { // nested record
- Map<CaseInsensitiveString, ExprTree> attrs = new HashMap<CaseInsensitiveString, ExprTree>();
- ((ClassAd) tree.self()).getComponents(attrs);
+ Map<CaseInsensitiveString, ExprTree> attrs = objectPool.strToExprPool.get();
+ ((ClassAd) tree.getTree()).getComponents(attrs, objectPool);
unparseAux(buffer, attrs);
return;
}
case EXPR_LIST_NODE: { // list
- ExprList exprs = new ExprList();
- ((ExprList) tree.self()).getComponents(exprs);
+ ExprList exprs = objectPool.exprListPool.get();
+ ((ExprList) tree.getTree()).getComponents(exprs);
unparseAux(buffer, exprs);
return;
}
@@ -345,8 +348,8 @@ public class ClassAdUnParser {
// to unparse attribute names (quoted & unquoted attributes)
public void unparseAux(AMutableCharArrayString buffer, AMutableCharArrayString identifier)
throws HyracksDataException {
- Value val = new Value();
- AMutableCharArrayString idstr = new AMutableCharArrayString();
+ Value val = objectPool.valuePool.get();
+ AMutableCharArrayString idstr = objectPool.strPool.get();
val.setStringValue(identifier);
setDelimiter('\''); // change the delimiter from string-literal mode to quoted attribute mode
@@ -386,8 +389,9 @@ public class ClassAdUnParser {
buffer.appendString("." + attrName);
return;
}
- if (absolute)
+ if (absolute) {
buffer.appendChar('.');
+ }
unparseAux(buffer, attrName);
}
@@ -474,8 +478,8 @@ public class ClassAdUnParser {
* it's unparsed either as a quoted attribute or non-quoted attribute
*/
public void unparseAux(AMutableCharArrayString buffer, String identifier) throws HyracksDataException {
- Value val = new Value();
- AMutableCharArrayString idstr = new AMutableCharArrayString();
+ Value val = objectPool.valuePool.get();
+ AMutableCharArrayString idstr = objectPool.strPool.get();
val.setStringValue(identifier);
setDelimiter('\''); // change the delimiter from string-literal mode to quoted attribute mode
http://git-wip-us.apache.org/repos/asf/incubator-asterixdb/blob/121e1d9a/asterix-external-data/src/test/java/org/apache/asterix/external/classad/EvalState.java
----------------------------------------------------------------------
diff --git a/asterix-external-data/src/test/java/org/apache/asterix/external/classad/EvalState.java b/asterix-external-data/src/test/java/org/apache/asterix/external/classad/EvalState.java
index 0719fd8..41f34bc 100644
--- a/asterix-external-data/src/test/java/org/apache/asterix/external/classad/EvalState.java
+++ b/asterix-external-data/src/test/java/org/apache/asterix/external/classad/EvalState.java
@@ -18,6 +18,9 @@
*/
package org.apache.asterix.external.classad;
+import org.apache.asterix.external.classad.object.pool.ClassAdObjectPool;
+import org.apache.hyracks.api.exceptions.HyracksDataException;
+
public class EvalState {
private int depthRemaining; // max recursion depth - current depth
@@ -27,10 +30,13 @@ public class EvalState {
// It can be set to a closer parent scope. Then that ClassAd is
// treated like it has no parent scope for LookupInScope() and
// Evaluate().
+ private final ClassAd rootAdTemp;
+ private final ClassAd curAdTemp;
private ClassAd rootAd;
private ClassAd curAd;
private boolean flattenAndInline; // NAC
private boolean inAttrRefScope;
+ private final ClassAdObjectPool objectPool;
public boolean isInAttrRefScope() {
return inAttrRefScope;
@@ -44,12 +50,15 @@ public class EvalState {
this.inAttrRefScope = inAttrRefScope;
}
- public EvalState() {
- rootAd = new ClassAd();
- curAd = new ClassAd();
+ public EvalState(ClassAdObjectPool objectPool) {
+ this.objectPool = objectPool;
+ rootAd = new ClassAd(this.objectPool);
+ curAd = new ClassAd(this.objectPool);
depthRemaining = ExprTree.MAX_CLASSAD_RECURSION;
flattenAndInline = false; // NAC
inAttrRefScope = false;
+ rootAdTemp = rootAd;
+ curAdTemp = curAd;
}
public boolean isFlattenAndInline() {
@@ -76,13 +85,14 @@ public class EvalState {
prevScope = curScope;
curScope = curScope.getParentScope();
}
-
rootAd = prevScope;
}
return;
}
public void reset() {
+ rootAd = rootAdTemp;
+ curAd = curAdTemp;
rootAd.reset();
curAd.reset();
depthRemaining = ExprTree.MAX_CLASSAD_RECURSION;
@@ -117,4 +127,16 @@ public class EvalState {
public void setRootAd(ClassAd classAd) {
this.rootAd = classAd;
}
+
+ public void set(EvalState state) throws HyracksDataException {
+ rootAd = rootAdTemp;
+ curAd = curAdTemp;
+ rootAd.reset();
+ curAd.reset();
+ rootAd.copyFrom(state.rootAd);
+ curAd.copyFrom(state.curAd);
+ depthRemaining = state.depthRemaining;
+ flattenAndInline = state.flattenAndInline;
+ inAttrRefScope = state.inAttrRefScope;
+ }
}
http://git-wip-us.apache.org/repos/asf/incubator-asterixdb/blob/121e1d9a/asterix-external-data/src/test/java/org/apache/asterix/external/classad/ExprList.java
----------------------------------------------------------------------
diff --git a/asterix-external-data/src/test/java/org/apache/asterix/external/classad/ExprList.java b/asterix-external-data/src/test/java/org/apache/asterix/external/classad/ExprList.java
index e9376e2..3c8405f 100644
--- a/asterix-external-data/src/test/java/org/apache/asterix/external/classad/ExprList.java
+++ b/asterix-external-data/src/test/java/org/apache/asterix/external/classad/ExprList.java
@@ -22,20 +22,41 @@ import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
+import org.apache.asterix.external.classad.object.pool.ClassAdObjectPool;
import org.apache.asterix.om.base.AMutableInt32;
import org.apache.hyracks.api.exceptions.HyracksDataException;
public class ExprList extends ExprTree {
- private List<ExprTree> exprList;
- private EvalState state = new EvalState();
+ private final List<ExprTree> exprList;
+ private final EvalState state;
public boolean isShared = false;
+ public ExprList(List<ExprTree> exprs, ClassAdObjectPool objectPool) {
+ super(objectPool);
+ exprList = new ArrayList<ExprTree>();
+ this.state = new EvalState(this.objectPool);
+ copyList(exprs);
+ return;
+ }
+
+ public ExprList(ClassAdObjectPool objectPool) {
+ super(objectPool);
+ this.state = new EvalState(this.objectPool);
+ this.exprList = new ArrayList<ExprTree>();
+ }
+
+ public ExprList(boolean b, ClassAdObjectPool objectPool) {
+ super(objectPool);
+ this.state = new EvalState(this.objectPool);
+ this.exprList = new ArrayList<ExprTree>();
+ this.isShared = b;
+ }
+
public boolean copyFrom(ExprList exprList) throws HyracksDataException {
this.exprList.clear();
- for (ExprTree expr : exprList.exprList) {
- this.exprList.add(expr.copy());
- }
+ copyList(exprList.getExprList());
+ this.state.set(exprList.state);
return true;
}
@@ -86,28 +107,8 @@ public class ExprList extends ExprTree {
}
public void setExprList(List<ExprTree> exprList) {
- this.exprList = exprList;
- }
-
- public ExprList(List<ExprTree> exprs) {
- exprList = new ArrayList<ExprTree>();
- copyList(exprs);
- return;
- }
-
- public ExprList(ExprList other_list) throws HyracksDataException {
- exprList = new ArrayList<ExprTree>();
- copyFrom(other_list);
- return;
- }
-
- public ExprList() {
- exprList = new ArrayList<ExprTree>();
- }
-
- public ExprList(boolean b) {
- this.exprList = new ArrayList<ExprTree>();
- this.isShared = b;
+ this.exprList.clear();
+ this.exprList.addAll(exprList);
}
public void clear() {
@@ -116,7 +117,7 @@ public class ExprList extends ExprTree {
@Override
public ExprTree copy() throws HyracksDataException {
- ExprList newList = new ExprList();
+ ExprList newList = objectPool.exprListPool.get();
newList.copyFrom(this);
return newList;
}
@@ -129,7 +130,7 @@ public class ExprList extends ExprTree {
} else if (tree.getKind() != NodeKind.EXPR_LIST_NODE) {
is_same = false;
} else {
- ExprList other_list = (ExprList) tree;
+ ExprList other_list = (ExprList) tree.getTree();
if (exprList.size() != other_list.size()) {
is_same = false;
} else {
@@ -145,14 +146,14 @@ public class ExprList extends ExprTree {
return is_same;
}
- public static ExprList createExprList(List<ExprTree> exprs) {
- ExprList el = new ExprList();
+ public static ExprList createExprList(List<ExprTree> exprs, ClassAdObjectPool objectPool) {
+ ExprList el = objectPool.exprListPool.get();
el.copyList(exprs);
return el;
}
- public static ExprList createExprList(ExprList exprs) {
- ExprList el = new ExprList();
+ public static ExprList createExprList(ExprList exprs, ClassAdObjectPool objectPool) {
+ ExprList el = objectPool.exprListPool.get();
el.copyList(exprs.exprList);
return el;
}
@@ -217,9 +218,9 @@ public class ExprList extends ExprTree {
@Override
public boolean privateFlatten(EvalState state, Value val, ExprTreeHolder tree, AMutableInt32 aInt)
throws HyracksDataException {
- ExprTreeHolder nexpr = new ExprTreeHolder();
- Value tempVal = new Value();
- ExprList newList = new ExprList();
+ ExprTreeHolder nexpr = objectPool.mutableExprPool.get();
+ Value tempVal = objectPool.valuePool.get();
+ ExprList newList = objectPool.exprListPool.get();
tree.setInnerTree(null);; // Just to be safe... wenger 2003-12-11.
@@ -230,7 +231,7 @@ public class ExprList extends ExprTree {
}
// if only a value was obtained, convert to an expression
if (nexpr.getInnerTree() == null) {
- nexpr.setInnerTree(Literal.createLiteral(tempVal));
+ nexpr.setInnerTree(Literal.createLiteral(tempVal, objectPool));
if (nexpr.getInnerTree() == null) {
return false;
}
@@ -249,10 +250,11 @@ public class ExprList extends ExprTree {
}
public boolean getValue(Value val, ExprTree tree, EvalState es) throws HyracksDataException {
- EvalState currentState = new EvalState();
+ EvalState currentState = objectPool.evalStatePool.get();
- if (tree == null)
+ if (tree == null) {
return false;
+ }
// if called from user code, es == NULL so we use &state instead
currentState = (es != null) ? es : state;
@@ -276,5 +278,6 @@ public class ExprList extends ExprTree {
@Override
public void reset() {
exprList.clear();
+ state.reset();
}
}
http://git-wip-us.apache.org/repos/asf/incubator-asterixdb/blob/121e1d9a/asterix-external-data/src/test/java/org/apache/asterix/external/classad/ExprTree.java
----------------------------------------------------------------------
diff --git a/asterix-external-data/src/test/java/org/apache/asterix/external/classad/ExprTree.java b/asterix-external-data/src/test/java/org/apache/asterix/external/classad/ExprTree.java
index ccbfd8b..2b5af38 100644
--- a/asterix-external-data/src/test/java/org/apache/asterix/external/classad/ExprTree.java
+++ b/asterix-external-data/src/test/java/org/apache/asterix/external/classad/ExprTree.java
@@ -18,6 +18,7 @@
*/
package org.apache.asterix.external.classad;
+import org.apache.asterix.external.classad.object.pool.ClassAdObjectPool;
import org.apache.asterix.om.base.AMutableDouble;
import org.apache.asterix.om.base.AMutableInt32;
import org.apache.asterix.om.base.AMutableInt64;
@@ -71,15 +72,24 @@ public abstract class ExprTree {
public ClassAd parentScope;
private CallableDebugFunction userDebugFunction;
+ protected final ClassAdObjectPool objectPool;
public abstract void reset();
- public ExprTree() {
+ public ExprTree(ClassAdObjectPool objectPool) {
+ if (objectPool == null) {
+ System.out.println();
+ }
+ this.objectPool = objectPool;
this.parentScope = null;
this.size = 0;
}
- public ExprTree(ExprTree expr) {
+ public ExprTree(ExprTree expr, ClassAdObjectPool objectPool) {
+ if (objectPool == null) {
+ System.out.println();
+ }
+ this.objectPool = objectPool;
this.size = expr.size;
}
@@ -112,14 +122,7 @@ public abstract class ExprTree {
* into a ClassAd.
*/
public void setParentScope(ClassAd scope) {
- if (scope == null) {
- parentScope = null;
- return;
- }
- if (parentScope == null) {
- parentScope = new ClassAd();
- }
- parentScope.setValue(scope);
+ parentScope = scope;
privateSetParentScope(scope);
}
@@ -169,8 +172,8 @@ public abstract class ExprTree {
/// A debugging method; send expression to stdout
public void puke() throws HyracksDataException {
- PrettyPrint unp = new PrettyPrint();
- AMutableCharArrayString buffer = new AMutableCharArrayString();
+ PrettyPrint unp = objectPool.prettyPrintPool.get();
+ AMutableCharArrayString buffer = objectPool.strPool.get();
unp.unparse(buffer, this);
System.out.println(buffer.toString());
}
@@ -193,16 +196,17 @@ public abstract class ExprTree {
}
public void debugFormatValue(Value value, double time) throws HyracksDataException {
- MutableBoolean boolValue = new MutableBoolean(false);
- AMutableInt64 intValue = new AMutableInt64(0);
- AMutableDouble doubleValue = new AMutableDouble(0.0);
- AMutableCharArrayString stringValue = new AMutableCharArrayString();
+ MutableBoolean boolValue = objectPool.boolPool.get();
+ AMutableInt64 intValue = objectPool.int64Pool.get();
+ AMutableDouble doubleValue = objectPool.doublePool.get();
+ AMutableCharArrayString stringValue = objectPool.strPool.get();
- if (NodeKind.CLASSAD_NODE == getKind())
+ if (NodeKind.CLASSAD_NODE == getKind()) {
return;
+ }
- PrettyPrint unp = new PrettyPrint();
- AMutableCharArrayString buffer = new AMutableCharArrayString();
+ PrettyPrint unp = objectPool.prettyPrintPool.get();
+ AMutableCharArrayString buffer = objectPool.strPool.get();
unp.unparse(buffer, this);
String result = "Classad debug: ";
@@ -230,8 +234,9 @@ public abstract class ExprTree {
result += "UNDEFINED\n";
break;
case BOOLEAN_VALUE:
- if (value.isBooleanValue(boolValue))
+ if (value.isBooleanValue(boolValue)) {
result += boolValue.booleanValue() ? "TRUE\n" : "FALSE\n";
+ }
break;
case INTEGER_VALUE:
if (value.isIntegerValue(intValue)) {
@@ -305,7 +310,7 @@ public abstract class ExprTree {
* @throws HyracksDataException
*/
public boolean publicEvaluate(Value val) throws HyracksDataException {
- EvalState state = new EvalState();
+ EvalState state = objectPool.evalStatePool.get();
if (parentScope == null) {
val.setErrorValue();
return false;
@@ -340,13 +345,13 @@ public abstract class ExprTree {
}
public boolean publicEvaluate(Value val, ExprTreeHolder sig) throws HyracksDataException {
- EvalState state = new EvalState();
+ EvalState state = objectPool.evalStatePool.get();
state.setScopes(parentScope);
return (publicEvaluate(state, val, sig));
}
public boolean publicFlatten(Value val, ExprTreeHolder tree) throws HyracksDataException {
- EvalState state = new EvalState();
+ EvalState state = objectPool.evalStatePool.get();
state.setScopes(parentScope);
return (publicFlatten(state, val, tree));
}
@@ -375,8 +380,9 @@ public abstract class ExprTree {
@Override
public String toString() {
- ClassAdUnParser unparser = new PrettyPrint();
- AMutableCharArrayString string_representation = new AMutableCharArrayString();
+ ClassAdObjectPool objectPool = new ClassAdObjectPool();
+ ClassAdUnParser unparser = new ClassAdUnParser(objectPool);
+ AMutableCharArrayString string_representation = objectPool.strPool.get();
try {
unparser.unparse(string_representation, this);
http://git-wip-us.apache.org/repos/asf/incubator-asterixdb/blob/121e1d9a/asterix-external-data/src/test/java/org/apache/asterix/external/classad/ExprTreeHolder.java
----------------------------------------------------------------------
diff --git a/asterix-external-data/src/test/java/org/apache/asterix/external/classad/ExprTreeHolder.java b/asterix-external-data/src/test/java/org/apache/asterix/external/classad/ExprTreeHolder.java
index 89c5c0b..0e2f894 100644
--- a/asterix-external-data/src/test/java/org/apache/asterix/external/classad/ExprTreeHolder.java
+++ b/asterix-external-data/src/test/java/org/apache/asterix/external/classad/ExprTreeHolder.java
@@ -18,6 +18,7 @@
*/
package org.apache.asterix.external.classad;
+import org.apache.asterix.external.classad.object.pool.ClassAdObjectPool;
import org.apache.asterix.om.base.AMutableInt32;
import org.apache.hyracks.api.exceptions.HyracksDataException;
@@ -34,9 +35,6 @@ public class ExprTreeHolder extends ExprTree {
if (tree == null) {
innerTree = null;
} else {
- if (tree.isTreeHolder()) {
- tree = ((ExprTreeHolder) tree).innerTree;
- }
if (innerTree == null) {
innerTree = tree.copy();
} else {
@@ -52,8 +50,8 @@ public class ExprTreeHolder extends ExprTree {
@Override
public void puke() throws HyracksDataException {
- PrettyPrint unp = new PrettyPrint();
- AMutableCharArrayString buffer = new AMutableCharArrayString();
+ PrettyPrint unp = objectPool.prettyPrintPool.get();
+ AMutableCharArrayString buffer = objectPool.strPool.get();
unp.unparse(buffer, innerTree);
System.out.println(buffer.toString());
}
@@ -78,11 +76,13 @@ public class ExprTreeHolder extends ExprTree {
return true;
}
- public ExprTreeHolder() {
+ public ExprTreeHolder(ClassAdObjectPool objectPool) {
+ super(objectPool);
innerTree = null;
}
- public ExprTreeHolder(ExprTree tree) {
+ public ExprTreeHolder(ExprTree tree, ClassAdObjectPool objectPool) {
+ super(objectPool);
setInnerTree(tree);
}
@@ -100,7 +100,10 @@ public class ExprTreeHolder extends ExprTree {
@Override
public ExprTree copy() throws HyracksDataException {
- return innerTree.copy();
+ if (innerTree != null) {
+ return innerTree.copy();
+ }
+ return null;
}
@Override
@@ -118,18 +121,18 @@ public class ExprTreeHolder extends ExprTree {
@Override
public boolean privateEvaluate(EvalState state, Value val) throws HyracksDataException {
- return innerTree.privateEvaluate(state, val);
+ return innerTree == null ? false : innerTree.privateEvaluate(state, val);
}
@Override
public boolean privateEvaluate(EvalState state, Value val, ExprTreeHolder tree) throws HyracksDataException {
- return innerTree.privateEvaluate(state, val, tree);
+ return innerTree == null ? false : innerTree.privateEvaluate(state, val, tree);
}
@Override
public boolean privateFlatten(EvalState state, Value val, ExprTreeHolder tree, AMutableInt32 op)
throws HyracksDataException {
- return innerTree.privateFlatten(state, val, tree, op);
+ return innerTree == null ? false : innerTree.privateFlatten(state, val, tree, op);
}
@Override
@@ -139,6 +142,8 @@ public class ExprTreeHolder extends ExprTree {
@Override
protected void privateSetParentScope(ClassAd scope) {
- innerTree.privateSetParentScope(scope);
+ if (innerTree != null) {
+ innerTree.privateSetParentScope(scope);
+ }
}
}
http://git-wip-us.apache.org/repos/asf/incubator-asterixdb/blob/121e1d9a/asterix-external-data/src/test/java/org/apache/asterix/external/classad/FunctionCall.java
----------------------------------------------------------------------
diff --git a/asterix-external-data/src/test/java/org/apache/asterix/external/classad/FunctionCall.java b/asterix-external-data/src/test/java/org/apache/asterix/external/classad/FunctionCall.java
index bbc0e7a..234ba20 100644
--- a/asterix-external-data/src/test/java/org/apache/asterix/external/classad/FunctionCall.java
+++ b/asterix-external-data/src/test/java/org/apache/asterix/external/classad/FunctionCall.java
@@ -20,6 +20,7 @@ package org.apache.asterix.external.classad;
import java.util.HashMap;
+import org.apache.asterix.external.classad.object.pool.ClassAdObjectPool;
import org.apache.asterix.om.base.AMutableInt32;
import org.apache.asterix.om.base.AMutableString;
import org.apache.commons.lang3.mutable.MutableBoolean;
@@ -28,7 +29,7 @@ import org.apache.hyracks.api.exceptions.HyracksDataException;
public class FunctionCall extends ExprTree {
public static boolean initialized = false;
-
+ public static final HashMap<String, ClassAdFunc> funcTable = new HashMap<String, ClassAdFunc>();
public static final ClassAdFunc[] ClassAdBuiltinFunc = { BuiltinClassAdFunctions.IsType,
BuiltinClassAdFunctions.TestMember, BuiltinClassAdFunctions.Size, BuiltinClassAdFunctions.SumAvg,
BuiltinClassAdFunctions.MinMax, BuiltinClassAdFunctions.ListCompare, BuiltinClassAdFunctions.debug,
@@ -43,12 +44,6 @@ public class FunctionCall extends ExprTree {
BuiltinClassAdFunctions.ifThenElse, BuiltinClassAdFunctions.stringListsIntersect,
BuiltinClassAdFunctions.interval, BuiltinClassAdFunctions.eval };
- // function call specific information
- private String functionName;
- private ClassAdFunc function;
- private ExprList arguments;
- public static final HashMap<String, ClassAdFunc> funcTable = new HashMap<String, ClassAdFunc>();
-
static {
// load up the function dispatch table
// type predicates
@@ -144,47 +139,53 @@ public class FunctionCall extends ExprTree {
initialized = true;
}
- /**
- * Returns true if the function expression points to a valid
- * function in the ClassAd library.
- */
- public boolean functionIsDefined() {
- return function != null;
- }
-
- public void copyFrom(FunctionCall copiedFrom) throws HyracksDataException {
- this.function = copiedFrom.function;
- this.functionName = copiedFrom.functionName;
- if (this.arguments == null) {
- this.arguments = (ExprList) copiedFrom.arguments.copy();
- } else {
- this.arguments.copyFrom(copiedFrom.arguments);
- }
- }
+ // function call specific information
+ private final CaseInsensitiveString functionName;
+ private ClassAdFunc function;
+ private final ExprList arguments;
- public FunctionCall() {
- functionName = null;
+ public FunctionCall(ClassAdObjectPool objectPool) {
+ super(objectPool);
+ functionName = new CaseInsensitiveString();
+ arguments = new ExprList(objectPool);
function = null;
- arguments = null;
}
- public static FunctionCall createFunctionCall(String functionName, ExprList args) {
- FunctionCall fc = new FunctionCall();
+ public static FunctionCall createFunctionCall(String functionName, ExprList args, ClassAdObjectPool objectPool) {
+ FunctionCall fc = objectPool != null ? objectPool.funcPool.get() : new FunctionCall(null);
fc.function = funcTable.get(functionName.toLowerCase());
- fc.functionName = functionName;
- fc.arguments = args;
+ fc.functionName.set(functionName);
+ fc.arguments.setExprList(args.getExprList());
return fc;
}
// start up with an argument list of size 4
- public FunctionCall(FunctionCall functioncall) throws HyracksDataException {
+ public FunctionCall(FunctionCall functioncall, ClassAdObjectPool objectPool) throws HyracksDataException {
+ super(objectPool);
+ functionName = new CaseInsensitiveString();
+ arguments = new ExprList(objectPool);
+ function = null;
copyFrom(functioncall);
}
+ /**
+ * Returns true if the function expression points to a valid
+ * function in the ClassAd library.
+ */
+ public boolean functionIsDefined() {
+ return function != null;
+ }
+
+ public void copyFrom(FunctionCall copiedFrom) throws HyracksDataException {
+ this.function = copiedFrom.function;
+ this.functionName.set(copiedFrom.functionName.get());
+ this.arguments.setExprList(copiedFrom.arguments.getExprList());
+ }
+
@Override
public ExprTree copy() throws HyracksDataException {
- FunctionCall newTree = new FunctionCall();
+ FunctionCall newTree = objectPool.funcPool.get();
newTree.copyFrom(this);
return newTree;
}
@@ -192,7 +193,7 @@ public class FunctionCall extends ExprTree {
@Override
public void copyFrom(ExprTree tree) throws HyracksDataException {
FunctionCall functioncall = (FunctionCall) tree;
- functionName = functioncall.functionName;
+ functionName.set(functioncall.functionName.get());
function = functioncall.function;
arguments.copyFrom(arguments);
super.copyFrom(functioncall);
@@ -209,13 +210,17 @@ public class FunctionCall extends ExprTree {
} else if (pSelfTree.getKind() != NodeKind.FN_CALL_NODE) {
is_same = false;
} else {
- other_fn = (FunctionCall) pSelfTree;
- if (functionName == other_fn.functionName && function.equals(other_fn.function)
- && arguments.equals(other_fn.arguments)) {
- is_same = true;
+ try {
+ other_fn = (FunctionCall) pSelfTree;
+ if (functionName == other_fn.functionName && function.equals(other_fn.function)
+ && arguments.equals(other_fn.arguments)) {
+ is_same = true;
- } else {
- is_same = false;
+ } else {
+ is_same = false;
+ }
+ } catch (Exception e) {
+ e.printStackTrace();
}
}
return is_same;
@@ -242,14 +247,14 @@ public class FunctionCall extends ExprTree {
//This will move pointers to objects (not create clones)
public void getComponents(AMutableString fn, ExprList exprList) {
- fn.setValue(functionName);
+ fn.setValue(functionName.get());
for (ExprTree tree : arguments.getExprList()) {
exprList.add(tree);
}
}
public void getComponents(AMutableCharArrayString fn, ExprList exprList) {
- fn.setValue(functionName);
+ fn.setValue(functionName.get());
for (ExprTree tree : arguments.getExprList()) {
exprList.add(tree);
}
@@ -258,7 +263,7 @@ public class FunctionCall extends ExprTree {
@Override
public boolean privateEvaluate(EvalState state, Value value) throws HyracksDataException {
if (function != null) {
- return function.call(functionName, arguments, state, value);
+ return function.call(functionName.get(), arguments, state, value, objectPool);
} else {
value.setErrorValue();
return (true);
@@ -267,19 +272,20 @@ public class FunctionCall extends ExprTree {
@Override
public boolean privateEvaluate(EvalState state, Value value, ExprTreeHolder tree) throws HyracksDataException {
- FunctionCall tmpSig = new FunctionCall();
- Value tmpVal = new Value();
- ExprTreeHolder argSig = new ExprTreeHolder();
- MutableBoolean rval = new MutableBoolean();
+ FunctionCall tmpSig = objectPool.funcPool.get();
+ Value tmpVal = objectPool.valuePool.get();
+ ExprTreeHolder argSig = objectPool.mutableExprPool.get();
+ MutableBoolean rval = objectPool.boolPool.get();
if (!privateEvaluate(state, value)) {
return false;
}
- tmpSig.functionName = functionName;
+ tmpSig.functionName.set(functionName.get());
rval.setValue(true);
for (ExprTree i : arguments.getExprList()) {
rval.setValue(i.publicEvaluate(state, tmpVal, argSig));
- if (rval.booleanValue())
+ if (rval.booleanValue()) {
tmpSig.arguments.add(argSig.getInnerTree());
+ }
}
tree.setInnerTree(tmpSig);
return rval.booleanValue();
@@ -288,11 +294,10 @@ public class FunctionCall extends ExprTree {
@Override
public boolean privateFlatten(EvalState state, Value value, ExprTreeHolder tree, AMutableInt32 i)
throws HyracksDataException {
- FunctionCall newCall = new FunctionCall();
- ExprTreeHolder argTree = new ExprTreeHolder();
- Value argValue = new Value();
+ FunctionCall newCall = objectPool.funcPool.get();
+ ExprTreeHolder argTree = objectPool.mutableExprPool.get();
+ Value argValue = objectPool.valuePool.get();
boolean fold = true;
-
tree.setInnerTree(null); // Just to be safe... wenger 2003-12-11.
// if the function cannot be resolved, the value is "error"
@@ -301,7 +306,7 @@ public class FunctionCall extends ExprTree {
return true;
}
- newCall.functionName = functionName;
+ newCall.functionName.set(functionName.get());
newCall.function = function;
// flatten the arguments
@@ -313,7 +318,7 @@ public class FunctionCall extends ExprTree {
continue;
} else {
// Assert: argTree == NULL
- argTree.setInnerTree(Literal.createLiteral(argValue));
+ argTree.setInnerTree(Literal.createLiteral(argValue, objectPool));
if (argTree.getInnerTree() != null) {
newCall.arguments.add(argTree.getInnerTree());
continue;
@@ -330,7 +335,7 @@ public class FunctionCall extends ExprTree {
// assume all functions are "pure" (i.e., side-affect free)
if (fold) {
// flattened to a value
- if (!function.call(functionName, arguments, state, value)) {
+ if (!function.call(functionName.get(), arguments, state, value, objectPool)) {
return false;
}
tree.setInnerTree(null);
@@ -349,6 +354,6 @@ public class FunctionCall extends ExprTree {
public void reset() {
this.arguments.clear();
this.function = null;
- this.functionName = "";
+ this.functionName.set("");;
}
}
http://git-wip-us.apache.org/repos/asf/incubator-asterixdb/blob/121e1d9a/asterix-external-data/src/test/java/org/apache/asterix/external/classad/Lexer.java
----------------------------------------------------------------------
diff --git a/asterix-external-data/src/test/java/org/apache/asterix/external/classad/Lexer.java b/asterix-external-data/src/test/java/org/apache/asterix/external/classad/Lexer.java
index 97b7ea8..2ef9620 100644
--- a/asterix-external-data/src/test/java/org/apache/asterix/external/classad/Lexer.java
+++ b/asterix-external-data/src/test/java/org/apache/asterix/external/classad/Lexer.java
@@ -433,8 +433,9 @@ public class Lexer {
if (och == '.' || ch == '.') {
// fraction part of real or selection operator
- if (ch == '.')
+ if (ch == '.') {
wind();
+ }
if (Character.isDigit(ch)) {
// real; get digits after decimal point
numberType = NumberType.REAL;
@@ -459,8 +460,9 @@ public class Lexer {
// i.e., [eE][+-]?[0-9]+
if (numberType == NumberType.REAL && Character.toLowerCase(ch) == 'e') {
wind();
- if (ch == '+' || ch == '-')
+ if (ch == '+' || ch == '-') {
wind();
+ }
if (!Character.isDigit(ch)) {
cut();
tokenType = TokenType.LEX_TOKEN_ERROR;