Invalid numeric value
See original GitHub issueLibrary Version
.NET Runtime
Xamarin Forms UWP / Android / iOS
Log Output
The following QueryBuilder expression gives a “Invalid numeric valu” (spelling is wrong too) message (note that the Latitude and Longitude properties are double and that the N1QL version of this query runs perfectly on the server):
var srcLat = Expression.Double(41.482343);//zip.Latitude); var srcLong = Expression.Double(-81.794563);//zip.Longitude);
//AND acos(sin(radians(srcLat)) * sin(RADIANS(Latitude)) + cos(RADIANS(srcLat)) * cos(RADIANS(Latitude)) * cos(RADIANS(srcLong) - RADIANS(Longitude))) * 3955
var formula = Function.Acos(Function.Sin(Function.Radians(srcLat))
.Multiply(Function.Sin(Function.Radians(Expression.Property(nameof(Directory.Latitude)))))
.Add(Function.Cos(Function.Radians(srcLat)))
.Multiply(Function.Cos(Function.Radians(Expression.Property(nameof(Directory.Latitude)))))
.Multiply(Function.Cos(Function.Radians(srcLong).Subtract(Function.Radians(Expression.Property(nameof(Directory.Longitude)))))))
.Multiply(Expression.Double(3955));
where = where.And(formula.LessThanOrEqualTo(Expression.Double(10)));//(int)PostalCodeRadius)));
Output of query.Explain() is: SELECT fl_result(key) FROM kv_default WHERE ((((fl_value(body, ‘Type’) = ‘Directory’ AND fl_value(body, ‘GroupGuid’) = ‘cb87110f-94e1-e511-80e5-002590701742’) AND fl_value(body, ‘CountryGuid’) = ‘2c48717e-f7e5-e511-80e5-002590701742’) AND fl_value(body, ‘BusinessTypeGuid’) = ‘5045717e-f7e5-e511-80e5-002590701742’) AND acos(((sin(radians(41.482343)) * sin(radians(fl_value(body, ‘Latitude’))) + cos(radians(41.482343))) * cos(radians(fl_value(body, ‘Latitude’)))) * cos(radians(-81.794562999999997) - radians(fl_value(body, ‘Longitude’)))) * 3955 <= 10) AND (flags & 1) = 0 0|0|0| SEARCH TABLE kv_default USING INDEX IX_Type_RowId (<expr>=?)
Expected behavior
This should result in a valid query.
Actual behavior
Exception thrown
Issue Analytics
- State:
- Created 4 years ago
- Comments:10 (5 by maintainers)
Thanks @Sandychuang8 that works perfectly!
Hi @blimkemann, Try this one. I modified your expression a bit to get it to work.
var formula = Function.Acos(Function.Sin(Function.Radians(srcLat)) .Multiply(Function.Sin(Function.Radians(Expression.Property(Latitude)))) .Add(Function.Cos(Function.Radians(srcLat)).Multiply(Function.Cos(Function.Radians(Expression.Property(Latitude)))) .Multiply(Function.Cos(Function.Radians(srcLong).Subtract(Function.Radians(Expression.Property(Longitude))))))) .Multiply(Expression.Double(3955));
You will need to move Multiple into Add() otherwise you will add first then multiply…