use of org.sirix.service.xml.xpath.expr.LiteralExpr 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.service.xml.xpath.expr.LiteralExpr in project sirix by sirixdb.
the class AbstractComparator method hasNext.
@Override
public final boolean hasNext() {
resetToLastKey();
if (mIsFirst) {
mIsFirst = false;
// TODO: why?
if (!(mOperand1 instanceof LiteralExpr)) {
mOperand1.reset(getTrx().getNodeKey());
}
// TODO: why?
if (!(mOperand2 instanceof LiteralExpr)) {
mOperand2.reset(getTrx().getNodeKey());
}
/*
* Evaluates the comparison. First atomizes both operands and then executes the comparison on
* them. At the end, the transaction is set to the retrieved result item.
*/
if (mOperand1.hasNext()) {
mKey = mOperand1.next();
try {
// atomize operands
final AtomicValue[] operandOne = atomize(mOperand1);
if (mOperand2.hasNext()) {
mKey = mOperand2.next();
final AtomicValue[] operandTwo = atomize(mOperand2);
hook(operandOne, operandTwo);
try {
// get comparison result
final boolean resultValue = compare(operandOne, operandTwo);
final AtomicValue result = new AtomicValue(resultValue);
// add retrieved AtomicValue to item list
final int itemKey = getTrx().getItemList().addItem(result);
mKey = itemKey;
} catch (SirixXPathException e) {
throw new RuntimeException(e);
}
return true;
}
} catch (final SirixXPathException exc) {
throw new RuntimeException(exc);
}
}
}
// return empty sequence or function called more than once
resetToStartKey();
return false;
}
use of org.sirix.service.xml.xpath.expr.LiteralExpr in project sirix by sirixdb.
the class NodeCompTest method testCompare.
@Test
public void testCompare() throws SirixXPathException {
AtomicValue[] op1 = { new AtomicValue(2, Type.INTEGER) };
AtomicValue[] op2 = { new AtomicValue(3, Type.INTEGER) };
AtomicValue[] op3 = { new AtomicValue(3, Type.INTEGER) };
assertEquals(false, comparator.compare(op1, op2));
assertEquals(true, comparator.compare(op3, op2));
try {
comparator = new NodeComp(holder.getReader(), new LiteralExpr(holder.getReader(), -2), new LiteralExpr(holder.getReader(), -1), CompKind.PRE);
comparator.compare(op1, op2);
fail("Expexcted not yet implemented exception.");
} catch (IllegalStateException e) {
assertEquals("Evaluation of node comparisons not possible", e.getMessage());
}
try {
comparator = new NodeComp(holder.getReader(), new LiteralExpr(holder.getReader(), -2), new LiteralExpr(holder.getReader(), -1), CompKind.FO);
comparator.compare(op1, op2);
fail("Expexcted not yet implemented exception.");
} catch (IllegalStateException e) {
assertEquals("Evaluation of node comparisons not possible", e.getMessage());
}
}
use of org.sirix.service.xml.xpath.expr.LiteralExpr in project sirix by sirixdb.
the class DivOpAxisTest method testOperate.
@Test
public final void testOperate() throws SirixException {
AtomicValue item1 = new AtomicValue(1.0, Type.DOUBLE);
AtomicValue item2 = new AtomicValue(2.0, Type.DOUBLE);
AbstractAxis op1 = new LiteralExpr(holder.getReader(), holder.getReader().getItemList().addItem(item1));
AbstractAxis op2 = new LiteralExpr(holder.getReader(), holder.getReader().getItemList().addItem(item2));
AbstractObAxis axis = new DivOpAxis(holder.getReader(), op1, op2);
assertEquals(true, axis.hasNext());
axis.next();
assertThat(0.5, is(Double.parseDouble(holder.getReader().getValue())));
assertEquals(holder.getReader().keyForName("xs:double"), holder.getReader().getTypeKey());
assertEquals(false, axis.hasNext());
}
use of org.sirix.service.xml.xpath.expr.LiteralExpr in project sirix by sirixdb.
the class IDivOpAxisTest method testOperate.
@Test
public final void testOperate() throws SirixException {
AtomicValue item1 = new AtomicValue(3.0, Type.DOUBLE);
AtomicValue item2 = new AtomicValue(2.0, Type.DOUBLE);
AbstractAxis op1 = new LiteralExpr(holder.getReader(), holder.getReader().getItemList().addItem(item1));
AbstractAxis op2 = new LiteralExpr(holder.getReader(), holder.getReader().getItemList().addItem(item2));
AbstractObAxis axis = new IDivOpAxis(holder.getReader(), op1, op2);
assertEquals(true, axis.hasNext());
axis.next();
// note: although getRawValue() returns [1], parseString returns ""
// assertEquals(1,
// Integer.parseInt(TypedValue.parseString(holder.getRtx().getRawValue())));
assertEquals(holder.getReader().keyForName("xs:integer"), holder.getReader().getTypeKey());
assertEquals(false, axis.hasNext());
}
Aggregations