use of org.sirix.api.Axis in project sirix by sirixdb.
the class PipelineBuilder method addIntExcExpression.
/**
* Adds a intersect or a exception expression to the pipeline.
*
* @param mTransaction Transaction to operate with.
* @param mIsIntersect true, if expression is an intersection
*/
public void addIntExcExpression(final XdmNodeReadTrx mTransaction, final boolean mIsIntersect) {
assert getPipeStack().size() >= 2;
final XdmNodeReadTrx rtx = mTransaction;
final Axis mOperand2 = getPipeStack().pop().getExpr();
final Axis mOperand1 = getPipeStack().pop().getExpr();
final Axis axis = mIsIntersect ? new IntersectAxis(rtx, mOperand1, mOperand2) : new ExceptAxis(rtx, mOperand1, mOperand2);
if (getPipeStack().empty() || getExpression().getSize() != 0) {
addExpressionSingle();
}
getExpression().add(axis);
}
use of org.sirix.api.Axis in project sirix by sirixdb.
the class PipelineBuilder method addPredicate.
/**
* Adds a predicate to the pipeline.
*
* @param pRtx transaction to operate with
*/
public void addPredicate(final XdmNodeReadTrx pRtx) {
assert getPipeStack().size() >= 2;
final Axis predicate = getPipeStack().pop().getExpr();
if (predicate instanceof LiteralExpr) {
predicate.hasNext();
// if is numeric literal -> abbrev for position()
final int type = pRtx.getTypeKey();
if (type == pRtx.keyForName("xs:integer") || type == pRtx.keyForName("xs:double") || type == pRtx.keyForName("xs:float") || type == pRtx.keyForName("xs:decimal")) {
throw new IllegalStateException("function fn:position() is not implemented yet.");
// getExpression().add(
// new PosFilter(transaction, (int)
// Double.parseDouble(transaction
// .getValue())));
// return; // TODO: YES! it is dirty!
// AtomicValue pos =
// new AtomicValue(mTransaction.getItem().getRawValue(),
// mTransaction
// .keyForName("xs:integer"));
// long position = mTransaction.getItemList().addItem(pos);
// mPredicate.reset(mTransaction.getItem().getKey());
// IAxis function =
// new FNPosition(mTransaction, new ArrayList<IAxis>(),
// FuncDef.POS.getMin(), FuncDef.POS
// .getMax(),
// mTransaction.keyForName(FuncDef.POS.getReturnType()));
// IAxis expectedPos = new LiteralExpr(mTransaction, position);
//
// mPredicate = new ValueComp(mTransaction, function,
// expectedPos, CompKind.EQ);
}
}
getExpression().add(new PredicateFilterAxis(pRtx, predicate));
}
use of org.sirix.api.Axis in project sirix by sirixdb.
the class PipelineBuilder method finishExpr.
/**
* Ends an expression. This means that the currently used pipeline stack will be emptied and the
* singleExpressions that were on the stack are combined by a sequence expression, which is lated
* added to the next pipeline stack.
*
* @param mTransaction transaction to operate on
* @param mNum number of singleExpressions that will be added to the sequence
*/
public void finishExpr(final XdmNodeReadTrx mTransaction, final int mNum) {
// of the stack containing these SingleExpressions have to be the same.
if (getPipeStack().size() != mNum) {
// this should never happen
throw new IllegalStateException("The query has not been processed correctly");
}
int no = mNum;
Axis[] axis;
if (no > 1) {
axis = new Axis[no];
// add all SingleExpression to a list
while (no-- > 0) {
axis[no] = getPipeStack().pop().getExpr();
}
if (mExprStack.size() > 1) {
assert mExprStack.peek().empty();
mExprStack.pop();
}
if (getPipeStack().empty() || getExpression().getSize() != 0) {
addExpressionSingle();
}
getExpression().add(new SequenceAxis(mTransaction, axis));
} else if (no == 1) {
// only one expression does not need to be capsled by a seq
axis = new Axis[1];
axis[0] = getPipeStack().pop().getExpr();
if (mExprStack.size() > 1) {
assert mExprStack.peek().empty();
mExprStack.pop();
}
if (getPipeStack().empty() || getExpression().getSize() != 0) {
addExpressionSingle();
}
final Axis iAxis;
if (mExprStack.size() == 1 && getPipeStack().size() == 1 && getExpression().getSize() == 0) {
iAxis = new SequenceAxis(mTransaction, axis);
} else {
iAxis = axis[0];
}
getExpression().add(iAxis);
} else {
mExprStack.pop();
}
}
use of org.sirix.api.Axis in project sirix by sirixdb.
the class PipelineBuilder method addVariableExpr.
/**
* Adds a variable expression to the pipeline. Adds the expression that will evaluate the results
* the variable holds.
*
* @param mTransaction Transaction to operate with.
* @param mVarName name of the variable
*/
public void addVariableExpr(final XdmNodeReadTrx mTransaction, final String mVarName) {
assert getPipeStack().size() >= 1;
final Axis bindingSeq = getPipeStack().pop().getExpr();
final Axis axis = new VariableAxis(mTransaction, bindingSeq);
mVarRefMap.put(mVarName, axis);
if (getPipeStack().empty() || getExpression().getSize() != 0) {
addExpressionSingle();
}
getExpression().add(axis);
}
use of org.sirix.api.Axis in project sirix by sirixdb.
the class PipelineBuilder method addCastExpr.
/**
* Adds a cast expression to the pipeline.
*
* @param mTransaction Transaction to operate with.
* @param mSingleType single type the context item will be casted to.
*/
public void addCastExpr(final XdmNodeReadTrx mTransaction, final SingleType mSingleType) {
assert getPipeStack().size() >= 1;
final Axis candidate = getPipeStack().pop().getExpr();
final Axis axis = new CastExpr(mTransaction, candidate, mSingleType);
if (getPipeStack().empty() || getExpression().getSize() != 0) {
addExpressionSingle();
}
getExpression().add(axis);
}
Aggregations