fix: the inconsistent order of input/output in range select (#2229)

* fix: the inconsistent order of input/output in range select

* chore: apply CR
This commit is contained in:
WU Jingdi
2023-08-25 04:12:59 +00:00
committed by GitHub
parent dbe0e95f2f
commit 15912afd96
4 changed files with 259 additions and 194 deletions
+92 -17
View File
@@ -84,6 +84,14 @@ pub struct RangeSelect {
pub by: Vec<Expr>,
pub schema: DFSchemaRef,
pub by_schema: DFSchemaRef,
/// If the `schema` of the `RangeSelect` happens to be the same as the content of the upper-level Projection Plan,
/// the final output needs to be `project` through `schema_project`,
/// so that we can omit the upper-level Projection Plan.
pub schema_project: Option<Vec<usize>>,
/// The schema before run projection, follow the order of `range expr | time index | by columns`
/// `schema_before_project ---- schema_project ----> schema`
/// if `schema_project==None` then `schema_before_project==schema`
pub schema_before_project: DFSchemaRef,
}
impl RangeSelect {
@@ -93,6 +101,7 @@ impl RangeSelect {
align: Duration,
time_index: Expr,
by: Vec<Expr>,
projection_expr: &[Expr],
) -> Result<Self> {
let mut fields = range_expr
.iter()
@@ -118,18 +127,54 @@ impl RangeSelect {
let by_fields =
exprlist_to_fields(by.iter().collect::<Vec<_>>(), &input).context(DataFusionSnafu)?;
fields.extend(by_fields.clone());
let schema = DFSchema::new_with_metadata(fields, input.schema().metadata().clone())
.context(DataFusionSnafu)?;
let by_schema = DFSchema::new_with_metadata(by_fields, input.schema().metadata().clone())
.context(DataFusionSnafu)?;
let schema_before_project = Arc::new(
DFSchema::new_with_metadata(fields, input.schema().metadata().clone())
.context(DataFusionSnafu)?,
);
let by_schema = Arc::new(
DFSchema::new_with_metadata(by_fields, input.schema().metadata().clone())
.context(DataFusionSnafu)?,
);
// If the result of the project plan happens to be the schema of the range plan, no project plan is required
// that need project is identical to range plan schema.
// 1. all exprs in project must belong to range schema
// 2. range schema and project exprs must have same size
let schema_project = projection_expr
.iter()
.map(|project_expr| {
if let Expr::Column(column) = project_expr {
schema_before_project
.index_of_column_by_name(column.relation.as_ref(), &column.name)
.unwrap_or(None)
.ok_or(())
} else {
Err(())
}
})
.collect::<std::result::Result<Vec<usize>, ()>>()
.ok();
let schema = if let Some(project) = &schema_project {
let project_field = project
.iter()
.map(|i| schema_before_project.fields()[*i].clone())
.collect();
Arc::new(
DFSchema::new_with_metadata(project_field, input.schema().metadata().clone())
.context(DataFusionSnafu)?,
)
} else {
schema_before_project.clone()
};
Ok(Self {
input,
range_expr,
align,
time_index: time_index_name,
schema: Arc::new(schema),
by_schema: Arc::new(by_schema),
schema,
by_schema,
by,
schema_project,
schema_before_project,
})
}
}
@@ -179,6 +224,8 @@ impl UserDefinedLogicalNodeCore for RangeSelect {
schema: self.schema.clone(),
by: self.by.clone(),
by_schema: self.by_schema.clone(),
schema_project: self.schema_project.clone(),
schema_before_project: self.schema_before_project.clone(),
}
}
}
@@ -204,7 +251,7 @@ impl RangeSelect {
session_state: &SessionState,
) -> DfResult<Arc<dyn ExecutionPlan>> {
let fields: Vec<_> = self
.schema
.schema_before_project
.fields()
.iter()
.map(|field| Field::new(field.name(), field.data_type().clone(), field.is_nullable()))
@@ -270,6 +317,12 @@ impl RangeSelect {
})
})
.collect::<DfResult<Vec<_>>>()?;
let schema_before_project = Arc::new(Schema::new(fields));
let schema = if let Some(project) = &self.schema_project {
Arc::new(schema_before_project.project(project)?)
} else {
schema_before_project.clone()
};
Ok(Arc::new(RangeSelectExec {
input: exec_input,
range_exec,
@@ -281,9 +334,11 @@ impl RangeSelect {
session_state,
)?,
time_index: self.time_index.clone(),
schema: Arc::new(Schema::new(fields)),
schema,
by_schema: Arc::new(Schema::new(by_fields)),
metric: ExecutionPlanMetricsSet::new(),
schema_before_project,
schema_project: self.schema_project.clone(),
}))
}
}
@@ -305,6 +360,8 @@ pub struct RangeSelectExec {
schema: SchemaRef,
by_schema: SchemaRef,
metric: ExecutionPlanMetricsSet,
schema_project: Option<Vec<usize>>,
schema_before_project: SchemaRef,
}
impl DisplayAs for RangeSelectExec {
@@ -367,6 +424,8 @@ impl ExecutionPlan for RangeSelectExec {
schema: self.schema.clone(),
by_schema: self.by_schema.clone(),
metric: self.metric.clone(),
schema_before_project: self.schema_before_project.clone(),
schema_project: self.schema_project.clone(),
}))
}
@@ -405,6 +464,8 @@ impl ExecutionPlan for RangeSelectExec {
row_converter,
modify_map: HashMap::new(),
metric: baseline_metric,
schema_project: self.schema_project.clone(),
schema_before_project: self.schema_before_project.clone(),
}))
}
@@ -441,6 +502,8 @@ struct RangeSelectStream {
/// The number of rows of the final output
output_num_rows: usize,
metric: BaselineMetrics,
schema_project: Option<Vec<usize>>,
schema_before_project: SchemaRef,
}
struct SeriesState {
@@ -604,11 +667,20 @@ impl RangeSelectStream {
columns.push(ScalarValue::iter_to_array(column_scalar)?);
}
let ts_column = ts_builder.finish();
// output schema follow the order of range expr | time index | by columns
let ts_column = compute::cast(&ts_column, self.schema.field(columns.len()).data_type())?;
// output schema before project follow the order of range expr | time index | by columns
let ts_column = compute::cast(
&ts_column,
self.schema_before_project.field(columns.len()).data_type(),
)?;
columns.push(ts_column);
columns.extend(self.row_converter.convert_rows(by_rows)?);
Ok(RecordBatch::try_new(self.schema(), columns)?)
let output = RecordBatch::try_new(self.schema_before_project.clone(), columns)?;
let project_output = if let Some(project) = &self.schema_project {
output.project(project)?
} else {
output
};
Ok(project_output)
}
}
@@ -718,6 +790,12 @@ mod test {
expected: String,
) {
let memory_exec = Arc::new(prepare_test_data());
let schema = Arc::new(Schema::new(vec![
Field::new("MIN(value)", DataType::Int64, true),
Field::new("MAX(value)", DataType::Int64, true),
Field::new(TIME_INDEX_COLUMN, TimestampMillisecondType::DATA_TYPE, true),
Field::new("host", DataType::Utf8, true),
]));
let range_select_exec = Arc::new(RangeSelectExec {
input: memory_exec,
range_exec: vec![
@@ -743,12 +821,9 @@ mod test {
align,
by: vec![Arc::new(Column::new("host", 2))],
time_index: TIME_INDEX_COLUMN.to_string(),
schema: Arc::new(Schema::new(vec![
Field::new("MIN(value)", DataType::Int64, true),
Field::new("MAX(value)", DataType::Int64, true),
Field::new(TIME_INDEX_COLUMN, TimestampMillisecondType::DATA_TYPE, true),
Field::new("host", DataType::Utf8, true),
])),
schema: schema.clone(),
schema_before_project: schema.clone(),
schema_project: None,
by_schema: Arc::new(Schema::new(vec![Field::new("host", DataType::Utf8, true)])),
metric: ExecutionPlanMetricsSet::new(),
});
+11 -21
View File
@@ -205,28 +205,18 @@ impl RangePlanRewriter {
if range_rewriter.by.is_empty() {
range_rewriter.by = default_by;
}
let range_select = RangeSelect::try_new(
input.clone(),
range_rewriter.range_fn,
range_rewriter.align,
time_index,
range_rewriter.by,
&new_expr,
)?;
let no_additional_project = range_select.schema_project.is_some();
let range_plan = LogicalPlan::Extension(Extension {
node: Arc::new(RangeSelect::try_new(
input.clone(),
range_rewriter.range_fn,
range_rewriter.align,
time_index,
range_rewriter.by,
)?),
node: Arc::new(range_select),
});
// If the result of the project plan happens to be the schema of the range plan, no project plan is required
// that need project is identical to range plan schema.
// 1. all exprs in project must belong to range schema
// 2. range schema and project exprs must have same size
let all_in_range_schema = new_expr.iter().all(|expr| {
if let Expr::Column(column) = expr {
range_plan.schema().has_column(column)
} else {
false
}
});
let no_additional_project =
all_in_range_schema && new_expr.len() == range_plan.schema().fields().len();
if no_additional_project {
Ok(Some(range_plan))
} else {
@@ -417,7 +407,7 @@ mod test {
async fn range_no_project() {
let query = r#"SELECT timestamp, tag_0, tag_1, avg(field_0 + field_1) RANGE '5m' FROM test ALIGN '1h' by (tag_0,tag_1);"#;
let expected = String::from(
"RangeSelect: range_exprs=[RangeFn { expr:AVG(test.field_0 + test.field_1) range:300s fill: }], align=3600s time_index=timestamp [AVG(test.field_0 + test.field_1):Float64;N, timestamp:Timestamp(Millisecond, None), tag_0:Utf8, tag_1:Utf8]\
"RangeSelect: range_exprs=[RangeFn { expr:AVG(test.field_0 + test.field_1) range:300s fill: }], align=3600s time_index=timestamp [timestamp:Timestamp(Millisecond, None), tag_0:Utf8, tag_1:Utf8, AVG(test.field_0 + test.field_1):Float64;N]\
\n TableScan: test [tag_0:Utf8, tag_1:Utf8, tag_2:Utf8, tag_3:Utf8, tag_4:Utf8, timestamp:Timestamp(Millisecond, None), field_0:Float64;N, field_1:Float64;N, field_2:Float64;N, field_3:Float64;N, field_4:Float64;N]"
);
query_plan_compare(query, expected).await;
@@ -30,30 +30,30 @@ Affected Rows: 18
SELECT ts, host, min(val) RANGE '10s', max(val) RANGE '10s' FROM host ALIGN '5s' ORDER BY host, ts;
+---------------+---------------+---------------------+-------+
| MIN(host.val) | MAX(host.val) | ts | host |
+---------------+---------------+---------------------+-------+
| 0.0 | 0.0 | 1970-01-01T00:00:00 | host1 |
| 0.0 | 1.0 | 1970-01-01T00:00:05 | host1 |
| 1.0 | 2.0 | 1970-01-01T00:00:10 | host1 |
| 2.0 | 3.0 | 1970-01-01T00:00:15 | host1 |
| 3.0 | 4.0 | 1970-01-01T00:00:20 | host1 |
| 4.0 | 5.0 | 1970-01-01T00:00:25 | host1 |
| 5.0 | 6.0 | 1970-01-01T00:00:30 | host1 |
| 6.0 | 7.0 | 1970-01-01T00:00:35 | host1 |
| 7.0 | 8.0 | 1970-01-01T00:00:40 | host1 |
| 8.0 | 8.0 | 1970-01-01T00:00:45 | host1 |
| 9.0 | 9.0 | 1970-01-01T00:00:00 | host2 |
| 9.0 | 10.0 | 1970-01-01T00:00:05 | host2 |
| 10.0 | 11.0 | 1970-01-01T00:00:10 | host2 |
| 11.0 | 12.0 | 1970-01-01T00:00:15 | host2 |
| 12.0 | 13.0 | 1970-01-01T00:00:20 | host2 |
| 13.0 | 14.0 | 1970-01-01T00:00:25 | host2 |
| 14.0 | 15.0 | 1970-01-01T00:00:30 | host2 |
| 15.0 | 16.0 | 1970-01-01T00:00:35 | host2 |
| 16.0 | 17.0 | 1970-01-01T00:00:40 | host2 |
| 17.0 | 17.0 | 1970-01-01T00:00:45 | host2 |
+---------------+---------------+---------------------+-------+
+---------------------+-------+---------------+---------------+
| ts | host | MIN(host.val) | MAX(host.val) |
+---------------------+-------+---------------+---------------+
| 1970-01-01T00:00:00 | host1 | 0.0 | 0.0 |
| 1970-01-01T00:00:05 | host1 | 0.0 | 1.0 |
| 1970-01-01T00:00:10 | host1 | 1.0 | 2.0 |
| 1970-01-01T00:00:15 | host1 | 2.0 | 3.0 |
| 1970-01-01T00:00:20 | host1 | 3.0 | 4.0 |
| 1970-01-01T00:00:25 | host1 | 4.0 | 5.0 |
| 1970-01-01T00:00:30 | host1 | 5.0 | 6.0 |
| 1970-01-01T00:00:35 | host1 | 6.0 | 7.0 |
| 1970-01-01T00:00:40 | host1 | 7.0 | 8.0 |
| 1970-01-01T00:00:45 | host1 | 8.0 | 8.0 |
| 1970-01-01T00:00:00 | host2 | 9.0 | 9.0 |
| 1970-01-01T00:00:05 | host2 | 9.0 | 10.0 |
| 1970-01-01T00:00:10 | host2 | 10.0 | 11.0 |
| 1970-01-01T00:00:15 | host2 | 11.0 | 12.0 |
| 1970-01-01T00:00:20 | host2 | 12.0 | 13.0 |
| 1970-01-01T00:00:25 | host2 | 13.0 | 14.0 |
| 1970-01-01T00:00:30 | host2 | 14.0 | 15.0 |
| 1970-01-01T00:00:35 | host2 | 15.0 | 16.0 |
| 1970-01-01T00:00:40 | host2 | 16.0 | 17.0 |
| 1970-01-01T00:00:45 | host2 | 17.0 | 17.0 |
+---------------------+-------+---------------+---------------+
SELECT ts, host, min(val / 2.0)/2 RANGE '10s', max(val / 2.0)/2 RANGE '10s' FROM host ALIGN '5s' ORDER BY host, ts;
@@ -82,122 +82,122 @@ SELECT ts, host, min(val / 2.0)/2 RANGE '10s', max(val / 2.0)/2 RANGE '10s' FROM
| 1970-01-01T00:00:45 | host2 | 4.25 | 4.25 |
+---------------------+-------+---------------------------------------+---------------------------------------+
SELECT ts, host, covar(val, val) RANGE '10s' FROM host ALIGN '5s' ORDER BY host, ts;
SELECT ts, covar(val, val) RANGE '10s', host FROM host ALIGN '5s' ORDER BY host, ts;
+-------------------------------+---------------------+-------+
| COVARIANCE(host.val,host.val) | ts | host |
+-------------------------------+---------------------+-------+
| | 1970-01-01T00:00:00 | host1 |
| 0.5 | 1970-01-01T00:00:05 | host1 |
| 0.5 | 1970-01-01T00:00:10 | host1 |
| 0.5 | 1970-01-01T00:00:15 | host1 |
| 0.5 | 1970-01-01T00:00:20 | host1 |
| 0.5 | 1970-01-01T00:00:25 | host1 |
| 0.5 | 1970-01-01T00:00:30 | host1 |
| 0.5 | 1970-01-01T00:00:35 | host1 |
| 0.5 | 1970-01-01T00:00:40 | host1 |
| | 1970-01-01T00:00:45 | host1 |
| | 1970-01-01T00:00:00 | host2 |
| 0.5 | 1970-01-01T00:00:05 | host2 |
| 0.5 | 1970-01-01T00:00:10 | host2 |
| 0.5 | 1970-01-01T00:00:15 | host2 |
| 0.5 | 1970-01-01T00:00:20 | host2 |
| 0.5 | 1970-01-01T00:00:25 | host2 |
| 0.5 | 1970-01-01T00:00:30 | host2 |
| 0.5 | 1970-01-01T00:00:35 | host2 |
| 0.5 | 1970-01-01T00:00:40 | host2 |
| | 1970-01-01T00:00:45 | host2 |
+-------------------------------+---------------------+-------+
+---------------------+-------------------------------+-------+
| ts | COVARIANCE(host.val,host.val) | host |
+---------------------+-------------------------------+-------+
| 1970-01-01T00:00:00 | | host1 |
| 1970-01-01T00:00:05 | 0.5 | host1 |
| 1970-01-01T00:00:10 | 0.5 | host1 |
| 1970-01-01T00:00:15 | 0.5 | host1 |
| 1970-01-01T00:00:20 | 0.5 | host1 |
| 1970-01-01T00:00:25 | 0.5 | host1 |
| 1970-01-01T00:00:30 | 0.5 | host1 |
| 1970-01-01T00:00:35 | 0.5 | host1 |
| 1970-01-01T00:00:40 | 0.5 | host1 |
| 1970-01-01T00:00:45 | | host1 |
| 1970-01-01T00:00:00 | | host2 |
| 1970-01-01T00:00:05 | 0.5 | host2 |
| 1970-01-01T00:00:10 | 0.5 | host2 |
| 1970-01-01T00:00:15 | 0.5 | host2 |
| 1970-01-01T00:00:20 | 0.5 | host2 |
| 1970-01-01T00:00:25 | 0.5 | host2 |
| 1970-01-01T00:00:30 | 0.5 | host2 |
| 1970-01-01T00:00:35 | 0.5 | host2 |
| 1970-01-01T00:00:40 | 0.5 | host2 |
| 1970-01-01T00:00:45 | | host2 |
+---------------------+-------------------------------+-------+
SELECT ts, host, covar(sin(val), cos(val)) RANGE '10s' FROM host ALIGN '5s' ORDER BY host, ts;
SELECT covar(ceil(val), floor(val)) RANGE '10s', ts, host FROM host ALIGN '5s' ORDER BY host, ts;
+-----------------------------------------+---------------------+-------+
| COVARIANCE(sin(host.val),cos(host.val)) | ts | host |
+-----------------------------------------+---------------------+-------+
| | 1970-01-01T00:00:00 | host1 |
| -0.1934111356975278 | 1970-01-01T00:00:05 | host1 |
| -0.032436271150495265 | 1970-01-01T00:00:10 | host1 |
| 0.2204076389548557 | 1970-01-01T00:00:15 | host1 |
| -0.15100761225328058 | 1970-01-01T00:00:20 | host1 |
| -0.09472495868737531 | 1970-01-01T00:00:25 | host1 |
| 0.2298465960529006 | 1970-01-01T00:00:30 | host1 |
| -0.09657490898971162 | 1970-01-01T00:00:35 | host1 |
| -0.1494679103211072 | 1970-01-01T00:00:40 | host1 |
| | 1970-01-01T00:00:45 | host1 |
| | 1970-01-01T00:00:00 | host2 |
| -0.03444910384248826 | 1970-01-01T00:00:05 | host2 |
| -0.19230433390872206 | 1970-01-01T00:00:10 | host2 |
| 0.19450278426332843 | 1970-01-01T00:00:15 | host2 |
| 0.03042089716713121 | 1970-01-01T00:00:20 | host2 |
| -0.21982190450538358 | 1970-01-01T00:00:25 | host2 |
| 0.1525354831602356 | 1970-01-01T00:00:30 | host2 |
| 0.09286758694873963 | 1970-01-01T00:00:35 | host2 |
| -0.22982858821320498 | 1970-01-01T00:00:40 | host2 |
| | 1970-01-01T00:00:45 | host2 |
+-----------------------------------------+---------------------+-------+
+--------------------------------------------+---------------------+-------+
| COVARIANCE(ceil(host.val),floor(host.val)) | ts | host |
+--------------------------------------------+---------------------+-------+
| | 1970-01-01T00:00:00 | host1 |
| 0.5 | 1970-01-01T00:00:05 | host1 |
| 0.5 | 1970-01-01T00:00:10 | host1 |
| 0.5 | 1970-01-01T00:00:15 | host1 |
| 0.5 | 1970-01-01T00:00:20 | host1 |
| 0.5 | 1970-01-01T00:00:25 | host1 |
| 0.5 | 1970-01-01T00:00:30 | host1 |
| 0.5 | 1970-01-01T00:00:35 | host1 |
| 0.5 | 1970-01-01T00:00:40 | host1 |
| | 1970-01-01T00:00:45 | host1 |
| | 1970-01-01T00:00:00 | host2 |
| 0.5 | 1970-01-01T00:00:05 | host2 |
| 0.5 | 1970-01-01T00:00:10 | host2 |
| 0.5 | 1970-01-01T00:00:15 | host2 |
| 0.5 | 1970-01-01T00:00:20 | host2 |
| 0.5 | 1970-01-01T00:00:25 | host2 |
| 0.5 | 1970-01-01T00:00:30 | host2 |
| 0.5 | 1970-01-01T00:00:35 | host2 |
| 0.5 | 1970-01-01T00:00:40 | host2 |
| | 1970-01-01T00:00:45 | host2 |
+--------------------------------------------+---------------------+-------+
SELECT ts, host, covar((sin(val) + cos(val))/2.0 + 1.0, 2.0) RANGE '10s' FROM host ALIGN '5s' ORDER BY host, ts;
+--------------------------------------------------------------------------------+---------------------+-------+
| COVARIANCE(sin(host.val) + cos(host.val) / Float64(2) + Float64(1),Float64(2)) | ts | host |
+--------------------------------------------------------------------------------+---------------------+-------+
| | 1970-01-01T00:00:00 | host1 |
| 0.0 | 1970-01-01T00:00:05 | host1 |
| 0.0 | 1970-01-01T00:00:10 | host1 |
| 0.0 | 1970-01-01T00:00:15 | host1 |
| 0.0 | 1970-01-01T00:00:20 | host1 |
| 0.0 | 1970-01-01T00:00:25 | host1 |
| 0.0 | 1970-01-01T00:00:30 | host1 |
| 0.0 | 1970-01-01T00:00:35 | host1 |
| 0.0 | 1970-01-01T00:00:40 | host1 |
| | 1970-01-01T00:00:45 | host1 |
| | 1970-01-01T00:00:00 | host2 |
| 0.0 | 1970-01-01T00:00:05 | host2 |
| 0.0 | 1970-01-01T00:00:10 | host2 |
| 0.0 | 1970-01-01T00:00:15 | host2 |
| 0.0 | 1970-01-01T00:00:20 | host2 |
| 0.0 | 1970-01-01T00:00:25 | host2 |
| 0.0 | 1970-01-01T00:00:30 | host2 |
| 0.0 | 1970-01-01T00:00:35 | host2 |
| 0.0 | 1970-01-01T00:00:40 | host2 |
| | 1970-01-01T00:00:45 | host2 |
+--------------------------------------------------------------------------------+---------------------+-------+
+---------------------+-------+--------------------------------------------------------------------------------+
| ts | host | COVARIANCE(sin(host.val) + cos(host.val) / Float64(2) + Float64(1),Float64(2)) |
+---------------------+-------+--------------------------------------------------------------------------------+
| 1970-01-01T00:00:00 | host1 | |
| 1970-01-01T00:00:05 | host1 | 0.0 |
| 1970-01-01T00:00:10 | host1 | 0.0 |
| 1970-01-01T00:00:15 | host1 | 0.0 |
| 1970-01-01T00:00:20 | host1 | 0.0 |
| 1970-01-01T00:00:25 | host1 | 0.0 |
| 1970-01-01T00:00:30 | host1 | 0.0 |
| 1970-01-01T00:00:35 | host1 | 0.0 |
| 1970-01-01T00:00:40 | host1 | 0.0 |
| 1970-01-01T00:00:45 | host1 | |
| 1970-01-01T00:00:00 | host2 | |
| 1970-01-01T00:00:05 | host2 | 0.0 |
| 1970-01-01T00:00:10 | host2 | 0.0 |
| 1970-01-01T00:00:15 | host2 | 0.0 |
| 1970-01-01T00:00:20 | host2 | 0.0 |
| 1970-01-01T00:00:25 | host2 | 0.0 |
| 1970-01-01T00:00:30 | host2 | 0.0 |
| 1970-01-01T00:00:35 | host2 | 0.0 |
| 1970-01-01T00:00:40 | host2 | 0.0 |
| 1970-01-01T00:00:45 | host2 | |
+---------------------+-------+--------------------------------------------------------------------------------+
SELECT ts, host, min(val) RANGE '10s', max(val) RANGE '10s' FROM host ALIGN '1000s' ORDER BY host, ts;
SELECT ts, min(val) RANGE '10s', host, max(val) RANGE '10s' FROM host ALIGN '1000s' ORDER BY host, ts;
+---------------+---------------+---------------------+-------+
| MIN(host.val) | MAX(host.val) | ts | host |
+---------------+---------------+---------------------+-------+
| 0.0 | 0.0 | 1970-01-01T00:00:00 | host1 |
| 9.0 | 9.0 | 1970-01-01T00:00:00 | host2 |
+---------------+---------------+---------------------+-------+
+---------------------+---------------+-------+---------------+
| ts | MIN(host.val) | host | MAX(host.val) |
+---------------------+---------------+-------+---------------+
| 1970-01-01T00:00:00 | 0.0 | host1 | 0.0 |
| 1970-01-01T00:00:00 | 9.0 | host2 | 9.0 |
+---------------------+---------------+-------+---------------+
SELECT ts, host, min(val) RANGE '10s', max(val) RANGE '5s' FROM host ALIGN '5s' ORDER BY host, ts;
+---------------+---------------+---------------------+-------+
| MIN(host.val) | MAX(host.val) | ts | host |
+---------------+---------------+---------------------+-------+
| 0.0 | 0.0 | 1970-01-01T00:00:00 | host1 |
| 0.0 | 1.0 | 1970-01-01T00:00:05 | host1 |
| 1.0 | 2.0 | 1970-01-01T00:00:10 | host1 |
| 2.0 | 3.0 | 1970-01-01T00:00:15 | host1 |
| 3.0 | 4.0 | 1970-01-01T00:00:20 | host1 |
| 4.0 | 5.0 | 1970-01-01T00:00:25 | host1 |
| 5.0 | 6.0 | 1970-01-01T00:00:30 | host1 |
| 6.0 | 7.0 | 1970-01-01T00:00:35 | host1 |
| 7.0 | 8.0 | 1970-01-01T00:00:40 | host1 |
| 8.0 | | 1970-01-01T00:00:45 | host1 |
| 9.0 | 9.0 | 1970-01-01T00:00:00 | host2 |
| 9.0 | 10.0 | 1970-01-01T00:00:05 | host2 |
| 10.0 | 11.0 | 1970-01-01T00:00:10 | host2 |
| 11.0 | 12.0 | 1970-01-01T00:00:15 | host2 |
| 12.0 | 13.0 | 1970-01-01T00:00:20 | host2 |
| 13.0 | 14.0 | 1970-01-01T00:00:25 | host2 |
| 14.0 | 15.0 | 1970-01-01T00:00:30 | host2 |
| 15.0 | 16.0 | 1970-01-01T00:00:35 | host2 |
| 16.0 | 17.0 | 1970-01-01T00:00:40 | host2 |
| 17.0 | | 1970-01-01T00:00:45 | host2 |
+---------------+---------------+---------------------+-------+
+---------------------+-------+---------------+---------------+
| ts | host | MIN(host.val) | MAX(host.val) |
+---------------------+-------+---------------+---------------+
| 1970-01-01T00:00:00 | host1 | 0.0 | 0.0 |
| 1970-01-01T00:00:05 | host1 | 0.0 | 1.0 |
| 1970-01-01T00:00:10 | host1 | 1.0 | 2.0 |
| 1970-01-01T00:00:15 | host1 | 2.0 | 3.0 |
| 1970-01-01T00:00:20 | host1 | 3.0 | 4.0 |
| 1970-01-01T00:00:25 | host1 | 4.0 | 5.0 |
| 1970-01-01T00:00:30 | host1 | 5.0 | 6.0 |
| 1970-01-01T00:00:35 | host1 | 6.0 | 7.0 |
| 1970-01-01T00:00:40 | host1 | 7.0 | 8.0 |
| 1970-01-01T00:00:45 | host1 | 8.0 | |
| 1970-01-01T00:00:00 | host2 | 9.0 | 9.0 |
| 1970-01-01T00:00:05 | host2 | 9.0 | 10.0 |
| 1970-01-01T00:00:10 | host2 | 10.0 | 11.0 |
| 1970-01-01T00:00:15 | host2 | 11.0 | 12.0 |
| 1970-01-01T00:00:20 | host2 | 12.0 | 13.0 |
| 1970-01-01T00:00:25 | host2 | 13.0 | 14.0 |
| 1970-01-01T00:00:30 | host2 | 14.0 | 15.0 |
| 1970-01-01T00:00:35 | host2 | 15.0 | 16.0 |
| 1970-01-01T00:00:40 | host2 | 16.0 | 17.0 |
| 1970-01-01T00:00:45 | host2 | 17.0 | |
+---------------------+-------+---------------+---------------+
SELECT ts, host, (min(val)+max(val))/4 RANGE '10s' FROM host ALIGN '5s' ORDER BY host, ts;
@@ -318,30 +318,30 @@ Affected Rows: 18
SELECT ts, host, min(val) RANGE '10s', max(val) RANGE '10s' FROM host_sec ALIGN '5s' ORDER BY host, ts;
+-------------------+-------------------+---------------------+-------+
| MIN(host_sec.val) | MAX(host_sec.val) | ts | host |
+-------------------+-------------------+---------------------+-------+
| 0.0 | 0.0 | 1970-01-01T00:00:00 | host1 |
| 0.0 | 1.0 | 1970-01-01T00:00:05 | host1 |
| 1.0 | 2.0 | 1970-01-01T00:00:10 | host1 |
| 2.0 | 3.0 | 1970-01-01T00:00:15 | host1 |
| 3.0 | 4.0 | 1970-01-01T00:00:20 | host1 |
| 4.0 | 5.0 | 1970-01-01T00:00:25 | host1 |
| 5.0 | 6.0 | 1970-01-01T00:00:30 | host1 |
| 6.0 | 7.0 | 1970-01-01T00:00:35 | host1 |
| 7.0 | 8.0 | 1970-01-01T00:00:40 | host1 |
| 8.0 | 8.0 | 1970-01-01T00:00:45 | host1 |
| 9.0 | 9.0 | 1970-01-01T00:00:00 | host2 |
| 9.0 | 10.0 | 1970-01-01T00:00:05 | host2 |
| 10.0 | 11.0 | 1970-01-01T00:00:10 | host2 |
| 11.0 | 12.0 | 1970-01-01T00:00:15 | host2 |
| 12.0 | 13.0 | 1970-01-01T00:00:20 | host2 |
| 13.0 | 14.0 | 1970-01-01T00:00:25 | host2 |
| 14.0 | 15.0 | 1970-01-01T00:00:30 | host2 |
| 15.0 | 16.0 | 1970-01-01T00:00:35 | host2 |
| 16.0 | 17.0 | 1970-01-01T00:00:40 | host2 |
| 17.0 | 17.0 | 1970-01-01T00:00:45 | host2 |
+-------------------+-------------------+---------------------+-------+
+---------------------+-------+-------------------+-------------------+
| ts | host | MIN(host_sec.val) | MAX(host_sec.val) |
+---------------------+-------+-------------------+-------------------+
| 1970-01-01T00:00:00 | host1 | 0.0 | 0.0 |
| 1970-01-01T00:00:05 | host1 | 0.0 | 1.0 |
| 1970-01-01T00:00:10 | host1 | 1.0 | 2.0 |
| 1970-01-01T00:00:15 | host1 | 2.0 | 3.0 |
| 1970-01-01T00:00:20 | host1 | 3.0 | 4.0 |
| 1970-01-01T00:00:25 | host1 | 4.0 | 5.0 |
| 1970-01-01T00:00:30 | host1 | 5.0 | 6.0 |
| 1970-01-01T00:00:35 | host1 | 6.0 | 7.0 |
| 1970-01-01T00:00:40 | host1 | 7.0 | 8.0 |
| 1970-01-01T00:00:45 | host1 | 8.0 | 8.0 |
| 1970-01-01T00:00:00 | host2 | 9.0 | 9.0 |
| 1970-01-01T00:00:05 | host2 | 9.0 | 10.0 |
| 1970-01-01T00:00:10 | host2 | 10.0 | 11.0 |
| 1970-01-01T00:00:15 | host2 | 11.0 | 12.0 |
| 1970-01-01T00:00:20 | host2 | 12.0 | 13.0 |
| 1970-01-01T00:00:25 | host2 | 13.0 | 14.0 |
| 1970-01-01T00:00:30 | host2 | 14.0 | 15.0 |
| 1970-01-01T00:00:35 | host2 | 15.0 | 16.0 |
| 1970-01-01T00:00:40 | host2 | 16.0 | 17.0 |
| 1970-01-01T00:00:45 | host2 | 17.0 | 17.0 |
+---------------------+-------+-------------------+-------------------+
DROP TABLE host_sec;
@@ -28,13 +28,13 @@ SELECT ts, host, min(val) RANGE '10s', max(val) RANGE '10s' FROM host ALIGN '5s'
SELECT ts, host, min(val / 2.0)/2 RANGE '10s', max(val / 2.0)/2 RANGE '10s' FROM host ALIGN '5s' ORDER BY host, ts;
SELECT ts, host, covar(val, val) RANGE '10s' FROM host ALIGN '5s' ORDER BY host, ts;
SELECT ts, covar(val, val) RANGE '10s', host FROM host ALIGN '5s' ORDER BY host, ts;
SELECT ts, host, covar(sin(val), cos(val)) RANGE '10s' FROM host ALIGN '5s' ORDER BY host, ts;
SELECT covar(ceil(val), floor(val)) RANGE '10s', ts, host FROM host ALIGN '5s' ORDER BY host, ts;
SELECT ts, host, covar((sin(val) + cos(val))/2.0 + 1.0, 2.0) RANGE '10s' FROM host ALIGN '5s' ORDER BY host, ts;
SELECT ts, host, min(val) RANGE '10s', max(val) RANGE '10s' FROM host ALIGN '1000s' ORDER BY host, ts;
SELECT ts, min(val) RANGE '10s', host, max(val) RANGE '10s' FROM host ALIGN '1000s' ORDER BY host, ts;
SELECT ts, host, min(val) RANGE '10s', max(val) RANGE '5s' FROM host ALIGN '5s' ORDER BY host, ts;