I went through add, subtract, divide and multiply. Here is a patch of
my changes. I skipped the date functions, since we have not talked
about the date format and the Pointable classes are just stubbed out.
The XSDecimalPointable has been updated off a copy of DoublePointable
and just renamed. Not sure if this is correct, but now all the
Integer, Float and Double all used the same functions when doing the
operations.
When you have time I would like your feedback.
Thanks
Preston
On Fri, Jun 15, 2012 at 5:24 PM, Till Westmann <till@westmann.org> wrote:
>
> On Jun 15, 2012, at 5:06 PM, Eldon Carman wrote:
>
>> Ok. Now for these mixed types that are added together, there is a
>> promotion order. Basically the largest numeric type gets used. I have
>> been trying to find documentation on the promotion order. Is that what
>> I listed before? (size order)
>>
>> 1. double (doubleprecision 64bit floating point type)  Java type double
>> 2. float (singleprecision 32bit floating point type)  Java type float
>> 3. decimal (a minimum of 18 decimal digits)  Java type double ???
>> 4. integer (a decimal type with a fixed decimal point)  Java type long
>>
>> Also do you know where that is in the xquery specification?
>
> Here it is:
> http://www.w3.org/TR/xquery/#idtypepromotionandoperatormapping
>
>> On Fri, Jun 15, 2012 at 4:39 PM, Vinayak Borkar <vborky@yahoo.com> wrote:
>>> Lexicographical order is text sort order. So:
>>>
>>> decimal
>>> double
>>> float
>>> integer
>>>
>>> xs:integer is supposed to be infinite precision, but we represent it as a 64
>>> bit fixedprecision signedinteger which is a long in java.
>>>
>>> Vinayak
>>>
>>>
>>>
>>> On 6/15/12 3:11 PM, Eldon Carman wrote:
>>>>
>>>> Thanks for the scaffolding. I have two questions. Is this the correct
>>>> lexicographical order?
>>>> 1. double
>>>> 2. float
>>>> 3. decimal
>>>> 4. integer
>>>>
>>>> Also do we always referrer to a integer as a long for this implementation?
>>>>
>>>> Preston
>>>>
>>>> On Fri, Jun 15, 2012 at 7:09 AM, Vinayak Borkar<vborky@yahoo.com> wrote:
>>>>>
>>>>> Preston,
>>>>>
>>>>>
>>>>> 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 endtoend.
>>>>>
>>>>> Look at the AddScalarEvaluatorFactory class. You will be creating a class
>>>>> like that for each of Subtract, Multiply, and Divide by extending
>>>>> AbstractArithmeticScalarEvaluatorFactory.
>>>>>
>>>>> The only method that you have to implement when you extend
>>>>> AbstractArithmeticScalarEvaluatorFactory is the
>>>>> createArithmeticOperation()
>>>>> method that creates an instance of AbstractArithmeticOperation.
>>>>>
>>>>> For example, the one for Add looks like this:
>>>>>
>>>>> @Override
>>>>> 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
>>>>> Multiply.
>>>>>
>>>>> Let us know how it goes with implementing the unimplemented methods in
>>>>> AddOperation and then implemnting the other arithmetic operation classes.
>>>>>
>>>>> Vinayak
>>>>
>>>>
>>>
>
