* [ML][Data Frame] improve pivot nested field validations * addressing pr comments
This commit is contained in:
parent
c00e305d79
commit
52e26bbc42
|
@ -33,6 +33,8 @@ import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Objects;
|
import java.util.Objects;
|
||||||
|
|
||||||
|
import static org.elasticsearch.action.ValidateActions.addValidationError;
|
||||||
|
|
||||||
public class PreviewDataFrameTransformAction extends Action<PreviewDataFrameTransformAction.Response> {
|
public class PreviewDataFrameTransformAction extends Action<PreviewDataFrameTransformAction.Response> {
|
||||||
|
|
||||||
public static final PreviewDataFrameTransformAction INSTANCE = new PreviewDataFrameTransformAction();
|
public static final PreviewDataFrameTransformAction INSTANCE = new PreviewDataFrameTransformAction();
|
||||||
|
@ -94,8 +96,15 @@ public class PreviewDataFrameTransformAction extends Action<PreviewDataFrameTran
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ActionRequestValidationException validate() {
|
public ActionRequestValidationException validate() {
|
||||||
return null;
|
ActionRequestValidationException validationException = null;
|
||||||
|
if(config.getPivotConfig() != null) {
|
||||||
|
for(String failure : config.getPivotConfig().aggFieldValidation()) {
|
||||||
|
validationException = addValidationError(failure, validationException);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
return validationException;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
|
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
|
||||||
|
|
|
@ -75,7 +75,7 @@ setup:
|
||||||
"pivot": {
|
"pivot": {
|
||||||
"group_by": {
|
"group_by": {
|
||||||
"airline": {"terms": {"field": "airline"}},
|
"airline": {"terms": {"field": "airline"}},
|
||||||
"by-hour": {"date_histogram": {"fixed_interval": "1h", "field": "time", "format": "yyyy-MM-dd HH"}}},
|
"by-hour": {"date_histogram": {"fixed_interval": "1h", "field": "time"}}},
|
||||||
"aggs": {
|
"aggs": {
|
||||||
"avg_response": {"avg": {"field": "responsetime"}},
|
"avg_response": {"avg": {"field": "responsetime"}},
|
||||||
"time.max": {"max": {"field": "time"}},
|
"time.max": {"max": {"field": "time"}},
|
||||||
|
@ -84,17 +84,17 @@ setup:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
- match: { preview.0.airline: foo }
|
- match: { preview.0.airline: foo }
|
||||||
- match: { preview.0.by-hour: "2017-02-18 00" }
|
- match: { preview.0.by-hour: 1487376000000 }
|
||||||
- match: { preview.0.avg_response: 1.0 }
|
- match: { preview.0.avg_response: 1.0 }
|
||||||
- match: { preview.0.time.max: "2017-02-18T00:30:00.000Z" }
|
- match: { preview.0.time.max: "2017-02-18T00:30:00.000Z" }
|
||||||
- match: { preview.0.time.min: "2017-02-18T00:00:00.000Z" }
|
- match: { preview.0.time.min: "2017-02-18T00:00:00.000Z" }
|
||||||
- match: { preview.1.airline: bar }
|
- match: { preview.1.airline: bar }
|
||||||
- match: { preview.1.by-hour: "2017-02-18 01" }
|
- match: { preview.1.by-hour: 1487379600000 }
|
||||||
- match: { preview.1.avg_response: 42.0 }
|
- match: { preview.1.avg_response: 42.0 }
|
||||||
- match: { preview.1.time.max: "2017-02-18T01:00:00.000Z" }
|
- match: { preview.1.time.max: "2017-02-18T01:00:00.000Z" }
|
||||||
- match: { preview.1.time.min: "2017-02-18T01:00:00.000Z" }
|
- match: { preview.1.time.min: "2017-02-18T01:00:00.000Z" }
|
||||||
- match: { preview.2.airline: foo }
|
- match: { preview.2.airline: foo }
|
||||||
- match: { preview.2.by-hour: "2017-02-18 01" }
|
- match: { preview.2.by-hour: 1487379600000 }
|
||||||
- match: { preview.2.avg_response: 42.0 }
|
- match: { preview.2.avg_response: 42.0 }
|
||||||
- match: { preview.2.time.max: "2017-02-18T01:01:00.000Z" }
|
- match: { preview.2.time.max: "2017-02-18T01:01:00.000Z" }
|
||||||
- match: { preview.2.time.min: "2017-02-18T01:01:00.000Z" }
|
- match: { preview.2.time.min: "2017-02-18T01:01:00.000Z" }
|
||||||
|
@ -123,22 +123,22 @@ setup:
|
||||||
"pivot": {
|
"pivot": {
|
||||||
"group_by": {
|
"group_by": {
|
||||||
"airline": {"terms": {"field": "airline"}},
|
"airline": {"terms": {"field": "airline"}},
|
||||||
"by-hour": {"date_histogram": {"fixed_interval": "1h", "field": "time", "format": "yyyy-MM-dd HH"}}},
|
"by-hour": {"date_histogram": {"fixed_interval": "1h", "field": "time"}}},
|
||||||
"aggs": {
|
"aggs": {
|
||||||
"avg_response": {"avg": {"field": "responsetime"}}
|
"avg_response": {"avg": {"field": "responsetime"}}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
- match: { preview.0.airline: foo }
|
- match: { preview.0.airline: foo }
|
||||||
- match: { preview.0.by-hour: "2017-02-18 00" }
|
- match: { preview.0.by-hour: 1487376000000 }
|
||||||
- match: { preview.0.avg_response: 1.0 }
|
- match: { preview.0.avg_response: 1.0 }
|
||||||
- match: { preview.0.my_field: 42 }
|
- match: { preview.0.my_field: 42 }
|
||||||
- match: { preview.1.airline: bar }
|
- match: { preview.1.airline: bar }
|
||||||
- match: { preview.1.by-hour: "2017-02-18 01" }
|
- match: { preview.1.by-hour: 1487379600000 }
|
||||||
- match: { preview.1.avg_response: 42.0 }
|
- match: { preview.1.avg_response: 42.0 }
|
||||||
- match: { preview.1.my_field: 42 }
|
- match: { preview.1.my_field: 42 }
|
||||||
- match: { preview.2.airline: foo }
|
- match: { preview.2.airline: foo }
|
||||||
- match: { preview.2.by-hour: "2017-02-18 01" }
|
- match: { preview.2.by-hour: 1487379600000 }
|
||||||
- match: { preview.2.avg_response: 42.0 }
|
- match: { preview.2.avg_response: 42.0 }
|
||||||
- match: { preview.2.my_field: 42 }
|
- match: { preview.2.my_field: 42 }
|
||||||
|
|
||||||
|
@ -166,7 +166,7 @@ setup:
|
||||||
"pivot": {
|
"pivot": {
|
||||||
"group_by": {
|
"group_by": {
|
||||||
"airline": {"terms": {"field": "airline"}},
|
"airline": {"terms": {"field": "airline"}},
|
||||||
"by-hour": {"date_histogram": {"fixed_interval": "1h", "field": "time", "format": "yyyy-MM-dd HH"}}},
|
"by-hour": {"date_histogram": {"fixed_interval": "1h", "field": "time"}}},
|
||||||
"aggs": {"avg_response": {"avg": {"field": "responsetime"}}}
|
"aggs": {"avg_response": {"avg": {"field": "responsetime"}}}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -180,7 +180,7 @@ setup:
|
||||||
"source": { "index": "airline-data" },
|
"source": { "index": "airline-data" },
|
||||||
"pivot": {
|
"pivot": {
|
||||||
"group_by": {
|
"group_by": {
|
||||||
"time": {"date_histogram": {"fixed_interval": "1h", "field": "time", "format": "yyyy-MM-DD HH"}}},
|
"time": {"date_histogram": {"fixed_interval": "1h", "field": "time"}}},
|
||||||
"aggs": {
|
"aggs": {
|
||||||
"avg_response": {"avg": {"field": "responsetime"}},
|
"avg_response": {"avg": {"field": "responsetime"}},
|
||||||
"time.min": {"min": {"field": "time"}}
|
"time.min": {"min": {"field": "time"}}
|
||||||
|
@ -189,20 +189,43 @@ setup:
|
||||||
}
|
}
|
||||||
|
|
||||||
- do:
|
- do:
|
||||||
catch: /mixed object types of nested and non-nested fields \[time.min\]/
|
catch: /field \[time\] cannot be both an object and a field/
|
||||||
data_frame.preview_data_frame_transform:
|
data_frame.preview_data_frame_transform:
|
||||||
body: >
|
body: >
|
||||||
{
|
{
|
||||||
"source": { "index": "airline-data" },
|
"source": { "index": "airline-data" },
|
||||||
"pivot": {
|
"pivot": {
|
||||||
"group_by": {
|
"group_by": {
|
||||||
"time": {"date_histogram": {"fixed_interval": "1h", "field": "time", "format": "yyyy-MM-DD HH"}}},
|
"time": {"date_histogram": {"fixed_interval": "1h", "field": "time"}}},
|
||||||
"aggs": {
|
"aggs": {
|
||||||
"avg_response": {"avg": {"field": "responsetime"}},
|
"avg_response": {"avg": {"field": "responsetime"}},
|
||||||
"time.min": {"min": {"field": "time"}}
|
"time.min": {"min": {"field": "time"}}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
- do:
|
||||||
|
catch: /field \[super_metric\] cannot be both an object and a field/
|
||||||
|
data_frame.preview_data_frame_transform:
|
||||||
|
body: >
|
||||||
|
{
|
||||||
|
"source": { "index": "airline-data" },
|
||||||
|
"pivot": {
|
||||||
|
"group_by": {
|
||||||
|
"time": {"date_histogram": {"fixed_interval": "1h", "field": "time"}}},
|
||||||
|
"aggs": {
|
||||||
|
"avg_response": {"avg": {"field": "responsetime"}},
|
||||||
|
"super_metric.time": {"min": {"field": "time"}},
|
||||||
|
"super_metric": {
|
||||||
|
"scripted_metric": {
|
||||||
|
"init_script": "",
|
||||||
|
"map_script": "",
|
||||||
|
"combine_script": "",
|
||||||
|
"reduce_script": "return ['value1': 1, 'value2':2]"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
---
|
---
|
||||||
"Test preview with missing pipeline":
|
"Test preview with missing pipeline":
|
||||||
- do:
|
- do:
|
||||||
|
@ -214,7 +237,7 @@ setup:
|
||||||
"dest": { "pipeline": "missing-pipeline" },
|
"dest": { "pipeline": "missing-pipeline" },
|
||||||
"pivot": {
|
"pivot": {
|
||||||
"group_by": {
|
"group_by": {
|
||||||
"time": {"date_histogram": {"fixed_interval": "1h", "field": "time", "format": "yyyy-MM-DD HH"}}},
|
"time": {"date_histogram": {"fixed_interval": "1h", "field": "time"}}},
|
||||||
"aggs": {
|
"aggs": {
|
||||||
"avg_response": {"avg": {"field": "responsetime"}},
|
"avg_response": {"avg": {"field": "responsetime"}},
|
||||||
"time.min": {"min": {"field": "time"}}
|
"time.min": {"min": {"field": "time"}}
|
||||||
|
|
Loading…
Reference in New Issue