[transform_limit_by] well-sorted block for tests
async fn test_transform_limit_by() -> anyhow::Result<()> {
use std::sync::Arc;
+ use common_datavalues::DataSchemaRefExt;
use common_planners::*;
use futures::TryStreamExt;
use pretty_assertions::assert_eq;
@@ -18,13 +19,13 @@ async fn test_transform_limit_by() -> anyhow::Result<()> {
let mut pipeline = Pipeline::create(ctx.clone());
- let a = test_source.number_source_transform_for_test(8)?;
+ let a = test_source.number_source_transform_for_test(12)?;
pipeline.add_source(Arc::new(a))?;
pipeline.merge_processor()?;
if let PlanNode::Expression(plan) = PlanBuilder::create(test_source.number_schema_for_test()?)
- .expression(&[modular(col("number"), lit(3))], "")?
+ .expression(&[modular(col("number"), lit(3)), col("number")], "")?
.build()?
{
pipeline.add_simple_transform(|| {
@@ -34,7 +35,6 @@ async fn test_transform_limit_by() -> anyhow::Result<()> {
plan.exprs.clone(),
)?))
})?;
- }
pipeline.add_simple_transform(|| {
Ok(Box::new(LimitByTransform::create(2, vec![col(
@@ -42,22 +42,33 @@ async fn test_transform_limit_by() -> anyhow::Result<()> {
)])))
})?;
+ // make col("number % 3") be the first column, then we will have a well-sorted block to test
+ // col("number") is useless, and it may have unstable results so we don't need it any more
+ pipeline.add_simple_transform(|| {
+ Ok(Box::new(ProjectionTransform::try_create(
+ plan.schema(),
+ DataSchemaRefExt::create(vec![col("(number % 3)").to_data_field(&plan.schema())?]),
+ vec![col("(number % 3)"), col("number")],
+ )?))
+ })?;
+ }
+
let stream = pipeline.execute().await?;
let result = stream.try_collect::<Vec<_>>().await?;
let block = &result[0];
- assert_eq!(block.num_columns(), 2);
+ assert_eq!(block.num_columns(), 1);
let expected = vec![
- "+--------+--------------+",
- "| number | (number % 3) |",
- "+--------+--------------+",
- "| 2 | 2 |",
- "| 3 | 0 |",
- "| 4 | 1 |",
- "| 5 | 2 |",
- "| 6 | 0 |",
- "| 7 | 1 |",
- "+--------+--------------+",
+ "+--------------+",
+ "| (number % 3) |",
+ "+--------------+",
+ "| 0 |",
+ "| 0 |",
+ "| 1 |",
+ "| 1 |",
+ "| 2 |",
+ "| 2 |",
+ "+--------------+",
];
common_datablocks::assert_blocks_sorted_eq(expected, result.as_slice());
