incubator-vxquery-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Vinayak Borkar <>
Subject Arithmetic Functions
Date Fri, 15 Jun 2012 14:09:22 GMT

I have now added some scaffolding so that implementing the arithmetic 
functions will be easier.

I have also added the code for xs:integer + xs:integer which is needed 
for the 1 + 1 example, ant it works end-to-end.

Look at the AddScalarEvaluatorFactory class. You will be creating a 
class like that for each of Subtract, Multiply, and Divide by extending 

The only method that you have to implement when you extend 
AbstractArithmeticScalarEvaluatorFactory is the 
createArithmeticOperation() method that creates an instance of 

For example, the one for Add looks like this:

     protected AbstractArithmeticOperation createArithmeticOperation() {
         return new AddOperation();

The AddOperation implements all the logic for what it means to add two 
values of various types.

The AbstractArithmeticScalarEvaluatorFactory has all the logic to 
correctly dispatch to the correct method in AbstractArithmeticOperation 
based on XQuery rules.

As your next step, please implement all the methods in AddOperation. The 
methods in this class look like

void operateXY(X x, Y y, DataOutput dOut)

where X and Y are type names.

For example the method that computes the result for xs:integer and 
xs:double would read:

void operateIntegerDouble(LongPointable longp, DoublePointable doublep, 
DataOutput dOut)

Since Add is commutative, you can implement about half of the methods by 
delegating to the other half (by switching the arguments). The 
convention you should follow is have operateXY delegate to operateYX 
when X is lexicographically greater than Y.

So in the above example, operateIntegerDouble will delegate to 
operateDoubleInteger in the AddOperation class.

Note that this trick does not apply to Minus and Divide, but applied to 

Let us know how it goes with implementing the unimplemented methods in 
AddOperation and then implemnting the other arithmetic operation classes.


View raw message