-
Notifications
You must be signed in to change notification settings - Fork 181
Support eval returns decimal division result instead of integer #4440
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -90,68 +90,80 @@ public void executeWithCalcite( | |
| UnresolvedPlan plan, | ||
| QueryType queryType, | ||
| ResponseListener<ExecutionEngine.QueryResponse> listener) { | ||
| try { | ||
| AccessController.doPrivileged( | ||
| (PrivilegedAction<Void>) | ||
| () -> { | ||
| CalcitePlanContext context = | ||
| CalcitePlanContext.create( | ||
| buildFrameworkConfig(), getQuerySizeLimit(), queryType); | ||
| RelNode relNode = analyze(plan, context); | ||
| RelNode optimized = optimize(relNode, context); | ||
| RelNode calcitePlan = convertToCalcitePlan(optimized); | ||
| executionEngine.execute(calcitePlan, context, listener); | ||
| return null; | ||
| }); | ||
| } catch (Throwable t) { | ||
| if (isCalciteFallbackAllowed(t) && !(t instanceof NonFallbackCalciteException)) { | ||
| log.warn("Fallback to V2 query engine since got exception", t); | ||
| executeWithLegacy(plan, queryType, listener, Optional.of(t)); | ||
| } else { | ||
| if (t instanceof Exception) { | ||
| listener.onFailure((Exception) t); | ||
| } else if (t instanceof VirtualMachineError) { | ||
| // throw and fast fail the VM errors such as OOM (same with v2). | ||
| throw t; | ||
| } else { | ||
| // Calcite may throw AssertError during query execution. | ||
| listener.onFailure(new CalciteUnsupportedException(t.getMessage(), t)); | ||
| } | ||
| } | ||
| } | ||
| CalcitePlanContext.run( | ||
| () -> { | ||
| try { | ||
| AccessController.doPrivileged( | ||
| (PrivilegedAction<Void>) | ||
| () -> { | ||
| CalcitePlanContext context = | ||
| CalcitePlanContext.create( | ||
| buildFrameworkConfig(), getQuerySizeLimit(), queryType); | ||
| RelNode relNode = analyze(plan, context); | ||
| RelNode optimized = optimize(relNode, context); | ||
| RelNode calcitePlan = convertToCalcitePlan(optimized); | ||
| executionEngine.execute(calcitePlan, context, listener); | ||
| return null; | ||
| }); | ||
| } catch (Throwable t) { | ||
| if (isCalciteFallbackAllowed(t) && !(t instanceof NonFallbackCalciteException)) { | ||
| log.warn("Fallback to V2 query engine since got exception", t); | ||
| executeWithLegacy(plan, queryType, listener, Optional.of(t)); | ||
| } else { | ||
| if (t instanceof Exception) { | ||
| listener.onFailure((Exception) t); | ||
| } else if (t instanceof VirtualMachineError) { | ||
| // throw and fast fail the VM errors such as OOM (same with v2). | ||
| throw t; | ||
| } else { | ||
| // Calcite may throw AssertError during query execution. | ||
| listener.onFailure(new CalciteUnsupportedException(t.getMessage(), t)); | ||
| } | ||
| } | ||
| } | ||
| }, | ||
| settings); | ||
| } | ||
|
|
||
| public void explainWithCalcite( | ||
| UnresolvedPlan plan, | ||
| QueryType queryType, | ||
| ResponseListener<ExecutionEngine.ExplainResponse> listener, | ||
| Explain.ExplainFormat format) { | ||
| try { | ||
| AccessController.doPrivileged( | ||
| (PrivilegedAction<Void>) | ||
| () -> { | ||
| CalcitePlanContext context = | ||
| CalcitePlanContext.create( | ||
| buildFrameworkConfig(), getQuerySizeLimit(), queryType); | ||
| RelNode relNode = analyze(plan, context); | ||
| RelNode optimized = optimize(relNode, context); | ||
| RelNode calcitePlan = convertToCalcitePlan(optimized); | ||
| executionEngine.explain(calcitePlan, format, context, listener); | ||
| return null; | ||
| }); | ||
| } catch (Throwable t) { | ||
| if (isCalciteFallbackAllowed(t)) { | ||
| log.warn("Fallback to V2 query engine since got exception", t); | ||
| explainWithLegacy(plan, queryType, listener, format, Optional.of(t)); | ||
| } else { | ||
| if (t instanceof Error) { | ||
| // Calcite may throw AssertError during query execution. | ||
| listener.onFailure(new CalciteUnsupportedException(t.getMessage())); | ||
| } else { | ||
| listener.onFailure((Exception) t); | ||
| } | ||
| } | ||
| } | ||
| CalcitePlanContext.run( | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Wrap with CalcitePlanContext.run, No code logic change. |
||
| () -> { | ||
| try { | ||
| AccessController.doPrivileged( | ||
| (PrivilegedAction<Void>) | ||
| () -> { | ||
| CalcitePlanContext context = | ||
| CalcitePlanContext.create( | ||
| buildFrameworkConfig(), getQuerySizeLimit(), queryType); | ||
| context.run( | ||
| () -> { | ||
| RelNode relNode = analyze(plan, context); | ||
| RelNode optimized = optimize(relNode, context); | ||
| RelNode calcitePlan = convertToCalcitePlan(optimized); | ||
| executionEngine.explain(calcitePlan, format, context, listener); | ||
| }, | ||
| settings); | ||
| return null; | ||
| }); | ||
| } catch (Throwable t) { | ||
| if (isCalciteFallbackAllowed(t)) { | ||
| log.warn("Fallback to V2 query engine since got exception", t); | ||
| explainWithLegacy(plan, queryType, listener, format, Optional.of(t)); | ||
| } else { | ||
| if (t instanceof Error) { | ||
| // Calcite may throw AssertError during query execution. | ||
| listener.onFailure(new CalciteUnsupportedException(t.getMessage())); | ||
| } else { | ||
| listener.onFailure((Exception) t); | ||
| } | ||
| } | ||
| } | ||
| }, | ||
| settings); | ||
| } | ||
|
|
||
| public void executeWithLegacy( | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -200,8 +200,9 @@ This configuration is introduced since 3.3.0 which is used to switch some behavi | |
| The behaviours it controlled includes: | ||
|
|
||
| - The default value of argument ``bucket_nullable`` in ``stats`` command. Check `stats command <../cmd/stats.rst>`_ for details. | ||
| - The return value of ``divide`` and ``/`` operator. Check `expressions <../functions/expressions.rst>`_ for details. | ||
|
|
||
| Example | ||
| Example 1 | ||
| ------- | ||
|
|
||
| You can update the setting with a new value like this. | ||
|
|
@@ -227,6 +228,22 @@ PPL query:: | |
| } | ||
| } | ||
|
|
||
| Example 2 | ||
|
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To be removed. #4441
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. PR #4449 |
||
| --------- | ||
|
|
||
| Reset to default (true) by setting to null: | ||
|
|
||
| PPL query:: | ||
|
|
||
| sh$ curl -sS -H 'Content-Type: application/json' \ | ||
| ... -X PUT localhost:9200/_plugins/_query/settings \ | ||
| ... -d '{"transient" : {"plugins.ppl.syntax.legacy.preferred" : null}}' | ||
| { | ||
| "acknowledged": true, | ||
| "persistent": {}, | ||
| "transient": {} | ||
| } | ||
|
|
||
| plugins.ppl.values.max.limit | ||
| ============================ | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,70 @@ | ||
| setup: | ||
| - do: | ||
| query.settings: | ||
| body: | ||
| transient: | ||
| plugins.calcite.enabled: true | ||
| plugins.ppl.syntax.legacy.preferred: true | ||
| - do: | ||
| indices.create: | ||
| index: test_divide_settings | ||
| body: | ||
| settings: | ||
| number_of_shards: 1 | ||
| number_of_replicas: 0 | ||
| - do: | ||
| bulk: | ||
| index: test_divide_settings | ||
| refresh: true | ||
| body: | ||
| - '{"index": {}}' | ||
| - '{"id": 1}' | ||
|
|
||
| --- | ||
| teardown: | ||
| - do: | ||
| query.settings: | ||
| body: | ||
| transient: | ||
| plugins.calcite.enabled: false | ||
| plugins.ppl.syntax.legacy.preferred: true | ||
| - do: | ||
| indices.delete: | ||
| index: test_divide_settings | ||
|
|
||
| --- | ||
| "legacy division retains integer truncation": | ||
| - skip: | ||
| features: | ||
| - headers | ||
| - allowed_warnings | ||
| - do: | ||
| allowed_warnings: [] | ||
| headers: | ||
| Content-Type: 'application/json' | ||
| ppl: | ||
| body: | ||
| query: source=test_divide_settings | eval a=4/2 | eval b=2/4 | eval c=2/40 | fields a,b,c | ||
| - match: { total: 1 } | ||
| - match: { datarows: [[2,0,0]] } | ||
|
|
||
| --- | ||
| "non-legacy division returns floating values": | ||
| - skip: | ||
| features: | ||
| - headers | ||
| - allowed_warnings | ||
| - do: | ||
| query.settings: | ||
| body: | ||
| transient: | ||
| plugins.ppl.syntax.legacy.preferred: false | ||
| - do: | ||
| allowed_warnings: [] | ||
| headers: | ||
| Content-Type: 'application/json' | ||
| ppl: | ||
| body: | ||
| query: source=test_divide_settings | eval a=4/2 | eval b=2/4 | eval c=2/40 | fields a,b,c | ||
| - match: { total: 1 } | ||
| - match: { datarows: [[2.0,0.5,0.05]] } |
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.
Wrap with CalcitePlanContext.run, No code logic change.