SQL: Make Literal a NamedExpression#33583
Conversation
Literal now is a NamedExpression reducing the need for Aliases for folded expressions leading to simpler optimization rules. Fix elastic#33523
|
Pinging @elastic/es-search-aggs |
matriv
left a comment
There was a problem hiding this comment.
Nice to simplify the code! Left some comments and suggestions.
| @Override | ||
| public String toString() { | ||
| return Objects.toString(value); | ||
| String s = String.valueOf(value); |
There was a problem hiding this comment.
Does it make sense to store the String value to a class attribute (minor perf improv if multiple calls on toString())
There was a problem hiding this comment.
toString isn't called outside debugging (so few if any calls) and the value -> string is fairly straight.
| name = foldable instanceof NamedExpression ? ((NamedExpression) foldable).name() : String.valueOf(fold); | ||
| } | ||
|
|
||
| return new Literal(foldable.location(), name, foldable.fold(), foldable.dataType()); |
There was a problem hiding this comment.
You can replace foldable.fold() with fold.
|
|
||
| private static final Expression DUMMY_EXPRESSION = new DummyBooleanExpression(EMPTY, 0); | ||
|
|
||
| private static Literal ONE = L(1); |
There was a problem hiding this comment.
Minor: you can also make them final
x-pack/plugin/sql/src/test/java/org/elasticsearch/xpack/sql/optimizer/OptimizerTests.java
Outdated
Show resolved
Hide resolved
| c = ((Alias) result).child(); | ||
| assertTrue(c instanceof Literal); | ||
| assertEquals(5, ((Literal) c).value()); | ||
| assertEquals(5, ((Literal) result).value()); |
There was a problem hiding this comment.
I think you can use the unwrapAlias() here.
There was a problem hiding this comment.
I've removed the method since it provide much value (if any) and was used in only one place.
x-pack/plugin/sql/src/main/java/org/elasticsearch/xpack/sql/expression/Attribute.java
Outdated
Show resolved
Hide resolved
x-pack/plugin/sql/src/main/java/org/elasticsearch/xpack/sql/expression/Attribute.java
Outdated
Show resolved
Hide resolved
x-pack/plugin/sql/src/main/java/org/elasticsearch/xpack/sql/expression/Attribute.java
Outdated
Show resolved
Hide resolved
x-pack/plugin/sql/src/main/java/org/elasticsearch/xpack/sql/expression/Attribute.java
Show resolved
Hide resolved
x-pack/plugin/sql/src/main/java/org/elasticsearch/xpack/sql/expression/Attribute.java
Outdated
Show resolved
Hide resolved
| /** | ||
| * {@link Expression}s that can be materlized to the user, representing the result | ||
| * columns. Typically are converted into constants, functions or Elasticsearch order-bys, | ||
| * {@link Expression}s that can be materialized and represent the result columns sent to the clien. |
matriv
left a comment
There was a problem hiding this comment.
Left one more comment on the fixup. LGTM otherwise.
| * {@link Expression}s that can be converted into Elasticsearch | ||
| * sorts, aggregations, or queries. They can also be extracted | ||
| * from the result of a search. | ||
| * {@link Expression}s that can be materialized and represent the result columns sent to the clien. |
* master: Remove debug logging in full cluster restart tests (elastic#33612) Expose CCR to the transport client (elastic#33608) Mute testIndexDeletionWhenNodeRejoins SQL: Make Literal a NamedExpression (elastic#33583) [DOCS] Adds missing built-in user information (elastic#33585) Improves doc values format deprecation message (elastic#33576)
* master: (43 commits) [HLRC][ML] Add ML put datafeed API to HLRC (elastic#33603) Update AWS SDK to 1.11.406 in repository-s3 (elastic#30723) Expose CCR stats to monitoring (elastic#33617) [Docs] Update match-query.asciidoc (elastic#33610) TEST: Adjust rollback condition when shard is empty [CCR] Improve shard follow task's retryable error handling (elastic#33371) Forbid negative `weight` in Function Score Query (elastic#33390) Clarify context suggestions filtering and boosting (elastic#33601) Disable CCR REST endpoints if CCR disabled (elastic#33619) Lower version on full cluster restart settings test Upgrade remote cluster settings (elastic#33537) NETWORKING: http.publish_host Should Contain CNAME (elastic#32806) Add test coverage for global checkpoint listeners Reset replica engine to global checkpoint on promotion (elastic#33473) HLRC: ML Delete Forecast API (elastic#33526) Remove debug logging in full cluster restart tests (elastic#33612) Expose CCR to the transport client (elastic#33608) Mute testIndexDeletionWhenNodeRejoins SQL: Make Literal a NamedExpression (elastic#33583) [DOCS] Adds missing built-in user information (elastic#33585) ...
* master: (128 commits) [HLRC][ML] Add ML put datafeed API to HLRC (elastic#33603) Update AWS SDK to 1.11.406 in repository-s3 (elastic#30723) Expose CCR stats to monitoring (elastic#33617) [Docs] Update match-query.asciidoc (elastic#33610) TEST: Adjust rollback condition when shard is empty [CCR] Improve shard follow task's retryable error handling (elastic#33371) Forbid negative `weight` in Function Score Query (elastic#33390) Clarify context suggestions filtering and boosting (elastic#33601) Disable CCR REST endpoints if CCR disabled (elastic#33619) Lower version on full cluster restart settings test Upgrade remote cluster settings (elastic#33537) NETWORKING: http.publish_host Should Contain CNAME (elastic#32806) Add test coverage for global checkpoint listeners Reset replica engine to global checkpoint on promotion (elastic#33473) HLRC: ML Delete Forecast API (elastic#33526) Remove debug logging in full cluster restart tests (elastic#33612) Expose CCR to the transport client (elastic#33608) Mute testIndexDeletionWhenNodeRejoins SQL: Make Literal a NamedExpression (elastic#33583) [DOCS] Adds missing built-in user information (elastic#33585) ...
Literal now is a NamedExpression reducing the need for Aliases for
folded expressions leading to simpler optimization rules.
Fix #33523