-
Notifications
You must be signed in to change notification settings - Fork 25.2k
SQL: Remove the deprecated AttributeMap(Map)
calls
#64664
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
Conversation
Pinging @elastic/es-ql (:Query Languages/SQL) |
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Aaah. It seems that IDEA rereads the settings from .editorconfig
all the time.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Left some comments. Don't forget to list the reviewers otherwise there's little notification.
procs.put(attr, proc); | ||
qContainer = qContainer.withScalarProcessors(new AttributeMap<>(procs)); | ||
qContainer = qContainer.withScalarProcessors( | ||
AttributeMap.<Pipe>builder().putAll(qContainer.scalarFunctions).put(attr, proc).build()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
AttributeMap.builder(qContainer.scalarFunctions()).put().build()
attr.nestedParent().name(), name, | ||
SqlDataTypes.format(attr.field().getDataType()), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please format only the touched lines - there's a plugin/setting for IDEA that does that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For those such changes that touch code lines, it adds some more effort when checking the git history, or simply "blame". On the other hand, personally I have no problem when deleting whitespaces from empty lines, as long as it's in the touched files.
queryC = queryC.withAliases(new AttributeMap<>(newAliases)); | ||
List<Alias> aliases = a.aggregates().stream() | ||
.filter(ne -> ne instanceof Alias) | ||
.map(ne -> (Alias)ne) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Extra space missing, should be (Alias) ne
List<Alias> aliases = a.aggregates().stream() | ||
.filter(ne -> ne instanceof Alias) | ||
.map(ne -> (Alias)ne) | ||
.collect(Collectors.toList()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The initial code was using a Map
of attributes, the change uses a List
of Alias
es which are then converted into a Map
.
The use of streams doesn't seem to simplify things either - instead of one iteration there are too.
This needs reworking - just create an AttributeMap
with the children and then combine that with the existing aliases.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, now that there is no chance of overwrite that makes more sense.
@@ -171,7 +171,7 @@ public QueryContainer(Query query, | |||
|
|||
sortingColumns.add(new Tuple<>(Integer.valueOf(atIndex), comp)); | |||
} | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Again, unneeded formatting.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems I have to disable the EditorConfig, otherwise IDEA is too clever the resets these settings.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If a micro-optimization starts leaking into a class definition, avoid it.
public boolean isEmpty() { | ||
return map.isEmpty(); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A builder should just assemble a state, not question it's in-transit state.
if (aliases.isEmpty() == false) { | ||
aliases.putAll(queryC.aliases()); | ||
queryC = queryC.withAliases(aliases.build()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't be called on a builder. Optimizations are good but in this case they simply get in the way.
Create two AttributeMap
s if needed.
Alias alias = (Alias) ne; | ||
aliases.put(alias.toAttribute(), alias.child()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change is not needed - there's no value in holding the alias reference.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Left a comment. LGTM otherwise.
// copy, in case someone would do a .build, .put, .build sequence | ||
AttributeMap<E> m = new AttributeMap<>(); | ||
m.addAll(map); | ||
return m; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not return the map directly? AttributeMap
is immutable.
To guarantee that the builder is not used after build()
is called, a flag could be used instead of copying things over.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Changed, won't copy on .build()
, only will copy once on the first .put()
after a .build()
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed the defensive copy completely: c4e3fc4
Use the `AttributeMap.builder()` instead of the `AttributeMap(Map)` to construct immutable `AttributeMap`s. Clean up after the `ctor` deprecation in elastic#63710
Uses the
AttributeMap.builder()
instead of theAttributeMap(Map)
toconstruct immutable
AttributeMap
s.Cleans up after the
ctor
deprecation in #63710.