Skip to content

Commit 617b166

Browse files
authored
refactor: remove unused min/max timestamp in the RowGroup (#1297)
## Rationale The min/max timestamp in `RowGroup` is not used any more. ## Detailed Changes - Remove the min/max timestamp from the `RowGroup` - Remove the `RowGroupBuilder` because it's too simple without min/max timestamp updating ## Test Plan All the tests in the CI should pass.
1 parent 2cb70f7 commit 617b166

File tree

13 files changed

+114
-242
lines changed

13 files changed

+114
-242
lines changed

analytic_engine/src/instance/write.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -712,7 +712,7 @@ mod tests {
712712
use common_types::{
713713
column_schema::Builder as ColumnSchemaBuilder,
714714
datum::{Datum, DatumKind},
715-
row::{Row, RowGroupBuilder},
715+
row::Row,
716716
schema::Builder as SchemaBuilder,
717717
time::Timestamp,
718718
};
@@ -738,7 +738,7 @@ mod tests {
738738
.primary_key_indexes(vec![0])
739739
.build()
740740
.unwrap();
741-
let row_group = RowGroupBuilder::with_rows(schema, rows).unwrap().build();
741+
let row_group = RowGroup::try_new(schema, rows).unwrap();
742742

743743
(encoded_rows, row_group)
744744
}

analytic_engine/src/payload.rs

+6-5
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ use codec::{
2222
Decoder,
2323
};
2424
use common_types::{
25-
row::{RowGroup, RowGroupBuilder, RowGroupBuilderFromColumn},
25+
row::{RowGroup, RowGroupBuilderFromColumn},
2626
schema::Schema,
2727
table::TableId,
2828
};
@@ -202,18 +202,19 @@ impl ReadPayload {
202202

203203
// Consume and convert rows in pb
204204
let encoded_rows = write_req_pb.rows;
205-
let mut builder = RowGroupBuilder::with_capacity(schema.clone(), encoded_rows.len());
205+
let mut rows = Vec::with_capacity(encoded_rows.len());
206206
let row_decoder = WalRowDecoder::new(&schema);
207207
for row_bytes in &encoded_rows {
208208
let row = row_decoder
209209
.decode(&mut row_bytes.as_slice())
210210
.context(DecodeRow)?;
211211
// We skip schema check here
212-
builder.push_checked_row(row);
212+
rows.push(row);
213213
}
214214

215-
let row_group = builder.build();
216-
215+
// The `rows` are decoded according to the schema, so there is no need to do one
216+
// more check here.
217+
let row_group = RowGroup::new_unchecked(schema, rows);
217218
Ok(Self::Write { row_group })
218219
}
219220

analytic_engine/src/table/mod.rs

+14-15
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ use std::{
2222

2323
use async_trait::async_trait;
2424
use common_types::{
25-
row::{Row, RowGroupBuilder},
25+
row::{Row, RowGroup},
2626
schema::Schema,
2727
time::TimeRange,
2828
};
@@ -251,20 +251,19 @@ fn merge_pending_write_requests(
251251
assert!(!pending_writes.is_empty());
252252

253253
let mut last_req = pending_writes.pop().unwrap();
254-
let last_rows = last_req.row_group.take_rows();
255-
let schema = last_req.row_group.into_schema();
256-
let mut row_group_builder = RowGroupBuilder::with_capacity(schema, num_pending_rows);
257-
258-
for mut pending_req in pending_writes {
259-
let rows = pending_req.row_group.take_rows();
260-
for row in rows {
261-
row_group_builder.push_checked_row(row)
254+
let total_rows = {
255+
let mut rows = Vec::with_capacity(num_pending_rows);
256+
for mut pending_req in pending_writes {
257+
let mut pending_rows = pending_req.row_group.take_rows();
258+
rows.append(&mut pending_rows);
262259
}
263-
}
264-
for row in last_rows {
265-
row_group_builder.push_checked_row(row);
266-
}
267-
let row_group = row_group_builder.build();
260+
let mut last_rows = last_req.row_group.take_rows();
261+
rows.append(&mut last_rows);
262+
rows
263+
};
264+
265+
let schema = last_req.row_group.into_schema();
266+
let row_group = RowGroup::new_unchecked(schema, total_rows);
268267
WriteRequest { row_group }
269268
}
270269

@@ -653,7 +652,7 @@ mod tests {
653652
schema_rows.push(row);
654653
}
655654
let rows = row_util::new_rows_6(&schema_rows);
656-
let row_group = RowGroupBuilder::with_rows(schema, rows).unwrap().build();
655+
let row_group = RowGroup::try_new(schema, rows).unwrap();
657656
WriteRequest { row_group }
658657
}
659658

analytic_engine/src/tests/alter_test.rs

+4-10
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ use std::collections::{BTreeMap, HashMap};
1919
use common_types::{
2020
column_schema,
2121
datum::DatumKind,
22-
row::{RowGroup, RowGroupBuilder},
22+
row::RowGroup,
2323
schema::{self, Schema},
2424
time::Timestamp,
2525
};
@@ -232,9 +232,7 @@ async fn alter_schema_add_column_case<T: WalsOpener>(
232232
),
233233
];
234234
let rows_vec = row_util::new_rows_8(&rows);
235-
let row_group = RowGroupBuilder::with_rows(new_schema.clone(), rows_vec)
236-
.unwrap()
237-
.build();
235+
let row_group = RowGroup::try_new(new_schema.clone(), rows_vec).unwrap();
238236

239237
// Write data with new schema.
240238
test_ctx.write_to_table(table_name, row_group).await;
@@ -288,9 +286,7 @@ async fn alter_schema_add_column_case<T: WalsOpener>(
288286
)),
289287
];
290288
let new_schema_row_group =
291-
RowGroupBuilder::with_rows(new_schema.clone(), new_schema_rows.to_vec())
292-
.unwrap()
293-
.build();
289+
RowGroup::try_new(new_schema.clone(), new_schema_rows.to_vec()).unwrap();
294290

295291
// Read data using new schema.
296292
check_read_row_group(
@@ -337,9 +333,7 @@ async fn alter_schema_add_column_case<T: WalsOpener>(
337333
),
338334
];
339335
let old_schema_rows_vec = row_util::new_rows_6(&old_schema_rows);
340-
let old_schema_row_group = RowGroupBuilder::with_rows(old_schema.clone(), old_schema_rows_vec)
341-
.unwrap()
342-
.build();
336+
let old_schema_row_group = RowGroup::try_new(old_schema.clone(), old_schema_rows_vec).unwrap();
343337

344338
// Read data using old schema.
345339
check_read_row_group(

analytic_engine/src/tests/table.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ use common_types::{
2222
projected_schema::ProjectedSchema,
2323
record_batch::RecordBatch,
2424
request_id::RequestId,
25-
row::{Row, RowGroup, RowGroupBuilder},
25+
row::{Row, RowGroup},
2626
schema::{self, Schema},
2727
table::DEFAULT_SHARD_ID,
2828
time::Timestamp,
@@ -122,9 +122,7 @@ impl FixedSchemaTable {
122122
}
123123

124124
fn new_row_group(&self, rows: Vec<Row>) -> RowGroup {
125-
RowGroupBuilder::with_rows(self.create_request.params.table_schema.clone(), rows)
126-
.unwrap()
127-
.build()
125+
RowGroup::try_new(self.create_request.params.table_schema.clone(), rows).unwrap()
128126
}
129127

130128
fn new_row_opt(data: RowTupleOpt) -> Row {

0 commit comments

Comments
 (0)