Skip to content

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

Merged
merged 9 commits into from
Nov 9, 2020

Conversation

palesz
Copy link
Contributor

@palesz palesz commented Nov 5, 2020

Uses the AttributeMap.builder() instead of the AttributeMap(Map) to
construct immutable AttributeMaps.

Cleans up after the ctor deprecation in #63710.

@palesz palesz added >non-issue :Analytics/SQL SQL querying v8.0.0 Team:QL (Deprecated) Meta label for query languages team v7.11.0 labels Nov 5, 2020
@elasticmachine
Copy link
Collaborator

Pinging @elastic/es-ql (:Query Languages/SQL)

}
Copy link
Contributor Author

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.

Copy link
Member

@costin costin left a 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());
Copy link
Member

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()

Comment on lines 369 to 370
attr.nestedParent().name(), name,
SqlDataTypes.format(attr.field().getDataType()),
Copy link
Member

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.

Copy link
Contributor

@matriv matriv Nov 5, 2020

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)
Copy link
Member

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

Comment on lines 427 to 430
List<Alias> aliases = a.aggregates().stream()
.filter(ne -> ne instanceof Alias)
.map(ne -> (Alias)ne)
.collect(Collectors.toList());
Copy link
Member

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 Aliases 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.

Copy link
Contributor Author

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));
}

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again, unneeded formatting.

Copy link
Contributor Author

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.

Copy link
Member

@costin costin left a 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.

Comment on lines 381 to 384
public boolean isEmpty() {
return map.isEmpty();
}

Copy link
Member

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.

Comment on lines 434 to 436
if (aliases.isEmpty() == false) {
aliases.putAll(queryC.aliases());
queryC = queryC.withAliases(aliases.build());
Copy link
Member

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 AttributeMaps if needed.

Comment on lines 429 to 430
Alias alias = (Alias) ne;
aliases.put(alias.toAttribute(), alias.child());
Copy link
Member

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.

@palesz palesz requested a review from costin November 6, 2020 14:18
Copy link
Member

@costin costin left a 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.

Comment on lines 382 to 385
// copy, in case someone would do a .build, .put, .build sequence
AttributeMap<E> m = new AttributeMap<>();
m.addAll(map);
return m;
Copy link
Member

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.

Copy link
Contributor Author

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().

Copy link
Contributor Author

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

@palesz palesz merged commit 658e26d into elastic:master Nov 9, 2020
@palesz palesz deleted the fix/56013-attributemap-cleanup branch November 9, 2020 17:46
palesz pushed a commit to palesz/elasticsearch that referenced this pull request Nov 9, 2020
Use the `AttributeMap.builder()` instead of the `AttributeMap(Map)` to
construct immutable `AttributeMap`s.

Clean up after the `ctor` deprecation in elastic#63710
palesz pushed a commit that referenced this pull request Nov 10, 2020
* SQL: Remove the deprecated `AttributeMap(Map)` calls (#64664)

Use the `AttributeMap.builder()` instead of the `AttributeMap(Map)` to
construct immutable `AttributeMap`s.

Clean up after the `ctor` deprecation in #63710
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants