Repository navigation
More granular type widening and stricter type checking - #16912
Conversation
| small | ||
| .into_iter() | ||
| .filter_map(|(col, typ)| { | ||
| big.iter() | ||
| .find_map(|(b_col, b_typ)| (&col == b_col).then(|| b_typ.clone())) | ||
| .map(|b_typ| (col, typ, b_typ)) | ||
| }) | ||
| .map(|(col, t, u)| (col, t.widen(u))) | ||
| .collect() |
There was a problem hiding this comment.
How about internally sorting those fields for collection types? Then we can make this O(n).
Probably we can do it for oneof type/sytaxshape too, #16445 should be easy to fix then.
There was a problem hiding this comment.
@Bahex Any response to this? How about some TODO comments for the potential optimization and maybe the cellpath type checking as well?
Sorry to infest on this topic, the fact that a table is just a list of records in nushell makes it very sensitive to the perf of this kind of basic building blocks to scale on large datasets.
There was a problem hiding this comment.
Sorry, I forgot about this one.
I think it might be better as an issue rather than a TODO since it needs some discussion.
Also, I don't expect a significant difference, since getting a type like table<a: string, b: int> from a value is pretty much the same before and after this PR since checking all rows match type-wise was necessary to get a table<> type.
There was a problem hiding this comment.
I think it might be better as an issue rather than a TODO since it needs some discussion.
I can manage that, but which one do you mean?
- Potential optimization of this part
- A new internal data structure for table
- Cellpath type other than a OneOf mixture with int and string
Also, I don't expect a significant difference, since getting a type like
table<a: string, b: int>from a value is pretty much the same before and after this PR since checking all rows match type-wise was necessary to get atable<>type.
Probably true, I don't have a clear view of previous implementation of this.
Sorry for not making it clear, I'm just saying that there's plenty room of optimization here given this O(RC^2) algo.
TBC, personally I don't do any serious data analysis in nushell, so O(RC^2) is good enough for me. But actually it's quite easy to make it O(RC), that's why I suggested a TODO here.
Easier for new comers to spot, if they find it laggy for some really large datasets and want to improve.
There was a problem hiding this comment.
For the potential optimization. Table data structure is a recurring discussion with no clear answer.
It seems more natural to me to change the However, it will be a breaking change for cellpath typed user defined arguments, a mild one, I hope. |
|
@blindFS changing the command signature itself to allow int and string arguments does seem like a better solution in the long term, but i think we should stick with the relaxed type checking for now. |
| (Type::OneOf(oneof), Type::CellPath) => { | ||
| oneof.iter().all(|t| t.is_subtype_of(&Type::CellPath)) | ||
| } |
There was a problem hiding this comment.
shouldn't this already be handled by the general case OneOf arm below?
There was a problem hiding this comment.
The general case below has the subtyping relation reversed:
match (self, other) {
(this, Type::OneOf(that)) => that.iter().any(|t| this.is_subtype_of(t)),
...
}If this == Type::CellPath, it would be checking if cell-path is subtype of the oneof<..>.
(Type::OneOf(oneof), Type::CellPath) => { .. }The relation here is the opposite, cell-path is the supertype, oneof is being checked to see if it consist solely of cell-path's subtypes (cell-path, string, int).
It's a little strange, but we need it to avoid breaking get $col/get $row kind of uses.
Type::OneOfcorresponding toSyntax::OneOf. It's a super type of all of its type parameters.Type::widen(T, U):anywhen one of its inputs isanyoneof<T, U>anyasintandfloatare not subtypes of each other:Type::widenoneofs and redundant type parameters are avoided.cell-pathis now type checked asoneof<cell-path, string, int>instead ofany. Permittingstringandintis to make usingget,selectand other similar commands with variables convenient. Also avoid a breaking change.Release notes summary - What our users need to know
TODO
Tasks after submitting