Skip to content
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: Internal refactoring of operators as functions #34097

Merged
merged 2 commits into from
Sep 27, 2018

Conversation

costin
Copy link
Member

@costin costin commented Sep 26, 2018

Sorry for the largish PR, the renaming and moving of some files had a broad effect (the PR actually adds only ~300 loc).

The main goal of this PR is to centralize and simplify the script generation between operators and functions which are currently decoupled. As part of this process most predicates (<, <=, etc...) were made ScalarFunction as their purpose and functionality is quite similar (see % and MOD functions).

In a similar vein, the script generation and processing was moved onto Expression itself as a general concern - it the future it might be tweaked a bit andwas moved to the NamedExpression.
ProcessDefinition was renamed to Pipe to make the name shorter and a bit more clearer (a Pipe of processes) though it doesn't fully convey its purpose.
The advantage of moving this into the expression itself is that OO-ify the generation.
The script customization which was scattered across the code is now centralized into ScriptWeaver .
In the process, applied de-duplication over some function definitions, in particular String ones.

Lastly, this work started as part of the NULL support as every scripted operation, including operators (like -) need to be made null-safe. This essentially means having the same infrastructure across all pushed-down expressions.

Close #33975

Rename ProcessDefinition to Pipe
Add asScript / asPipe onto Expression (might be pushed further down)
Add ScriptWeaver as a mixin-in interface for script customization
Add logic for equals/lte/lt
Improve BinaryOperator/expression toString
Minimize duplication across string functions

Close elastic#33975
@elasticmachine
Copy link
Collaborator

Pinging @elastic/es-search-aggs

Copy link
Contributor

@matriv matriv left a comment

Choose a reason for hiding this comment

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

LGTM. Nice stuff! Left two really minor comments.

@@ -59,4 +61,15 @@ public boolean equals(Object obj) {
public int hashCode() {
return location().hashCode();
}

Copy link
Contributor

Choose a reason for hiding this comment

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

extra new line :-)

dataType());
}

default String formatScript(String template) {
Copy link
Contributor

Choose a reason for hiding this comment

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

maybe rename template -> script ?

/**
* Binary operator. Operators act as _special_ functions in that they have a symbol
* instead of a name and do not use parathensis.
* Further more they are don't registered as the rest of the functions as are implicit
Copy link
Contributor

Choose a reason for hiding this comment

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

Probably you meant "they are not registered".

import java.util.Objects;

/**
* Processor definition for math operations requiring two arguments.
Copy link
Contributor

Choose a reason for hiding this comment

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

Not a processor definition anymore

import java.util.Objects;

/**
* Processor definition for String operations requiring one string and one numeric argument.
Copy link
Contributor

Choose a reason for hiding this comment

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

Not a processor definition anymore

import java.util.Objects;

/**
* Processor definition for String operations requiring two string arguments.
Copy link
Contributor

Choose a reason for hiding this comment

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

Not a processor definition anymore

Copy link
Contributor

@astefan astefan 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 minor comments. LGTM

@costin costin merged commit 15515a6 into elastic:master Sep 27, 2018
costin added a commit that referenced this pull request Sep 27, 2018
Centralize and simplify the script generation between operators and functions which are currently decoupled. As part of this process most predicates (<, <=, etc...) were made ScalarFunction as their purpose and functionality is quite similar (see % and MOD functions).
Renamed ProcessDefinition to Pipe
Add ScriptWeaver as a mixin-in interface for script customization
Add logic for equals/lte/lt
Improve BinaryOperator/expression toString
Minimize duplication across string functions

Close #33975

(cherry picked from commit 15515a6)
@costin
Copy link
Member Author

costin commented Sep 27, 2018

Merged - thanks for the quick reviews!

@costin costin deleted the fix-33975 branch September 27, 2018 20:49
jasontedor added a commit to jasontedor/elasticsearch that referenced this pull request Sep 28, 2018
* master:
  Use more precise does S3 bucket exist method (elastic#34123)
  LLREST: Introduce a strict mode (elastic#33708)
  [CCR] Adjust list retryable errors (elastic#33985)
  Fix AggregationFactories.Builder equality and hash regarding order (elastic#34005)
  MINOR: Remove some deadcode in NodeEnv and Related (elastic#34133)
  Rest-Api-Spec: Correct spelling in filter_path description (elastic#33154)
  Core: Don't rely on java time for epoch seconds formatting (elastic#34086)
  Retry errors when fetching follower global checkpoint. (elastic#34019)
  Watcher: Reenable watcher stats REST tests (elastic#34107)
  Remove special-casing of Synonym filters in AnalysisRegistry (elastic#34034)
  Rename CCR APIs (elastic#34027)
  Fixed CCR stats api serialization issues and (elastic#33983)
  Support 'string'-style queries on metadata fields when reasonable. (elastic#34089)
  Logging: Drop Settings from security logger get calls (elastic#33940)
  SQL: Internal refactoring of operators as functions (elastic#34097)
kcm pushed a commit that referenced this pull request Oct 30, 2018
Centralize and simplify the script generation between operators and functions which are currently decoupled. As part of this process most predicates (<, <=, etc...) were made ScalarFunction as their purpose and functionality is quite similar (see % and MOD functions).
Renamed ProcessDefinition to Pipe
Add ScriptWeaver as a mixin-in interface for script customization
Add logic for equals/lte/lt
Improve BinaryOperator/expression toString
Minimize duplication across string functions

Close #33975
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants