You are correct that all of these casts can be done. We omitted them explicitly because of what you said that we did not want to loose precision. We should be able to downcast when users ask explicitly for it, but we don't want to do this implicitly.

Alan.

On Mar 24, 2010, at 2:47 PM, Anil Chawla wrote:



Hi,
I know that Pig has logic for casting inputs to the expected data types
when invoking a UDF and I understand that this logic resides in the
TypeCheckingVisitor class. I am curious to know why certain casts have been omitted from the "castLookup" map. Specifically, I do not see any entries for casting a more precise numeric type (e.g. Double) to a less precise numeric type (e.g. Integer). Any reason why all down conversions of numeric
types have been omitted? Is it because we do not want to perform any
automatic casts that lead to a loss of precision (loss of data)?

In my situation, we are trying to abstract all numeric data types into a single "number" type. If a UDF takes a numeric parameter, we want Pig to
invoke that UDF with any numeric argument, regardless of whether the
argument must be upconverted or downconverted. We are OK with the loss of precision in that circumstance. As a result, we added the following to the
"castLookup" map:

castLookup.put(DataType.LONG, DataType.INTEGER);
castLookup.put(DataType.FLOAT, DataType.LONG);
castLookup.put(DataType.FLOAT, DataType.INTEGER);
castLookup.put(DataType.DOUBLE, DataType.FLOAT);
castLookup.put(DataType.DOUBLE, DataType.LONG);
castLookup.put(DataType.DOUBLE, DataType.INTEGER);

All of these casts seem to work fine our tests. Other than loss of
precision, is there any reason why adding these casts might be a bad idea?

Thanks,
-Anil

Reply via email to