New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
SQL: Do not lift types unless explicitly asked for #209
Comments
This is also an issue due to X6Decimal: #169 (comment) |
This is not a big deal, and can be omitted if difficult to implement.
This one is a real problem, since |
It sort of is, when it comes to build generic methods ontop of the API. |
From your description, it seems like the type is just lifted one level, when running aggregates in SQL queries, it seems like it lifts the type several levels: using Starcounter;
using System.Linq;
[Database]
public class Person
{
public int Age { get; set; }
}
class Program
{
static void Main()
{
Db.Transact(() =>
{
new Person { Age = 1 };
new Person { Age = 2 };
new Person { Age = 4 };
});
Db.SQL("SELECT AVG(p.Age) FROM Person p").FirstOrDefault(); // ScErrCLRDecToX6DecRangeError
}
} Is there any workaround for this? It would be good to document |
What the case for this? Looks that there is no issues with Double type - |
Shouldn't |
Also, I propose to leave |
Sounds like the right decision for me. @bigwad?
Same here. |
We can prefer to adhere to SQL standard here. p 6.5.9 says:
in other words, |
Seems it doesn't: https://msdn.microsoft.com/en-us/library/bb354760(v=vs.110).aspx public static decimal Average(
this IEnumerable<decimal> source
) which makes perfect sense as overwise it would ruin decimal's accuracy. |
I have added tests for each aggregation operator (except COUNT) and input type combination here https://github.com/Starcounter/level1/compare/v2.3-Home209.
In the "* changes" rows I wrote result types which I suppose should be implemented for the case. @bigwad @miyconst please correct me or approve the proposal. |
After talking with Kostiantyn, I'm going to update and fix the table with required changes. |
|
I was getting an exception when did the tests with unsigned integers. I'll re-check this and do updates here or will create a new GH issue for that |
Except the fact, that our decimal range is less than int64, then AVG should be int64 also. At least when the result exceeds decimal limit. |
|
Created an issue #385 for the error with unsigned integer types. |
I need an approval to this conclusion before starting the work.
|
@bigwad what do you say? I think the final table looks correct, but we need an option to cast smaller data types to bigger ones, in case of the overflow exception. |
Don't get your point on overflow. Are we discussing the latest table with MIN and MAX functions? |
Apparently I was not fully awake, |
Spent some time on this upon @un-tone's request to figure out the best way to refactor Anton's latest changes. My conclusion is simple - let's keep away from this. Unless we have guts to redesign half of the query processor, including Prolog parser. Why is that? [Database]
public class Bar
{
public float f { get; set; }
public int i { get; set; }
public Foo b { get; set; }
} Following queries will also return double instead of float and they are not fixed by Anton's PR Second, this PR has broken some queries that worked before: So, ad hoc fixes don't work as they just add a mess to the query processor and miss the whole picture. And I'm sure I've missed a lot of corner cases myself. |
Thank you, @bigwad, for the investigation. Agree with your conclusion. |
We still shouldn't forget about the issue reported by @Mackiovello earlier in this thread: #209 (comment) Though it is not about inappropriate type conversion - it's about we not respecting our own decimal limitations when performing calculations. I think we should do it in a separate issue. Also, timebomb icon can be removed I think, as the most severe issue (converting decimal to double) is not confirmed. Also2, while working on this I found out we don't have tests for |
https://github.com/Starcounter/level1/issues/4631
|
@miyconst can we specify the status of the issue? Should we move it to another project board or a release? Maybe even close it? |
@un-tone I move it to |
When running aggregating SQL queries over numeric fields, SC will lift the underlying type to a bigger one.
Int32 is lifted to Int64, Double is lifted to Decimal.
This is unintuitive and feels weird, especially lifting Double to Decimal which is not even the same kind of floating point mechanics.
This has implications for e.g. the Linq provider as when you do
.Sum(x => x.Int32Prop)
,Starcounter will actually return a Int64, we have to have special hacks that check if the generic T returned is of int32, then run the query expecting an int64, cast and return.
I get that operations like
Sum
can overflow their type, but this still applies to whatever type we lift to, its just a matter of volume.I'd much rather see that we get the type of the property itself. and add the ability to specify a larger type if you need.
The text was updated successfully, but these errors were encountered: