Skip to content

Commit

Permalink
fix: schema mismatch during write (apache#966)
Browse files Browse the repository at this point in the history
## Rationale
Close apache#308 

## Detailed Changes


## Test Plan
This is a corner case between write and alter schema, the testcase is
not easy to construct, so we plan to test this in test env first, then
add tests later.

---------

Co-authored-by: jiacai2050 <dev@liujiacai.net>
  • Loading branch information
2 people authored and dust1 committed Aug 9, 2023
1 parent 9f4a068 commit c04ad6c
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 8 deletions.
6 changes: 2 additions & 4 deletions analytic_engine/src/instance/write.rs
Original file line number Diff line number Diff line change
Expand Up @@ -281,9 +281,7 @@ impl<'a> MemTableWriter<'a> {
// inserting memtable? RocksDB checks memtable size in MemTableInserter
/// Write data into memtable.
///
/// The data in `encoded_rows` will be moved to memtable.
///
/// The len of `row_group` and `encoded_rows` must be equal.
/// index_in_writer must match the schema in table_data.
pub fn write(
&self,
sequence: SequenceNumber,
Expand All @@ -295,7 +293,7 @@ impl<'a> MemTableWriter<'a> {
return Ok(());
}

let schema = row_group.schema();
let schema = &self.table_data.schema();
// Store all memtables we wrote and update their last sequence later.
let mut wrote_memtables: SmallVec<[_; 4]> = SmallVec::new();
let mut last_mutable_mem: Option<MemTableForWrite> = None;
Expand Down
3 changes: 1 addition & 2 deletions analytic_engine/src/table/data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -368,12 +368,11 @@ impl TableData {
timestamp: Timestamp,
table_schema: &Schema,
) -> Result<MemTableForWrite> {
let schema_version = table_schema.version();
let last_sequence = self.last_sequence();

if let Some(mem) = self
.current_version
.memtable_for_write(timestamp, schema_version)
.memtable_for_write(timestamp, table_schema.version())
.context(FindMemTable)?
{
return Ok(mem);
Expand Down
2 changes: 0 additions & 2 deletions common_types/src/row/contiguous.rs
Original file line number Diff line number Diff line change
Expand Up @@ -286,8 +286,6 @@ impl<'a, T: RowBuffer + 'a> ContiguousRowWriter<'a, T> {
self.inner
.reset(datum_buffer_len, DatumKind::Null.into_u8());

assert_eq!(row.num_columns(), self.table_schema.num_columns());

// Offset to next string in string buffer.
let mut next_string_offset: OffsetSize = 0;
for index_in_table in 0..self.table_schema.num_columns() {
Expand Down

0 comments on commit c04ad6c

Please sign in to comment.