Skip to content

Commit

Permalink
feat: alter logical region in metric region (#2726)
Browse files Browse the repository at this point in the history
* add test for add and alter logical region

Signed-off-by: Ruihang Xia <[email protected]>

* remove table id

Signed-off-by: Ruihang Xia <[email protected]>

* Apply suggestions from code review

Co-authored-by: dennis zhuang <[email protected]>
Co-authored-by: JeremyHi <[email protected]>

* CR sugg.

Signed-off-by: Ruihang Xia <[email protected]>

* extract internal states into a struct

Signed-off-by: Ruihang Xia <[email protected]>

* remove unused deps

Signed-off-by: Ruihang Xia <[email protected]>

* Apply suggestions from code review

Co-authored-by: dennis zhuang <[email protected]>

* tweak fn name

Signed-off-by: Ruihang Xia <[email protected]>

---------

Signed-off-by: Ruihang Xia <[email protected]>
Co-authored-by: dennis zhuang <[email protected]>
Co-authored-by: JeremyHi <[email protected]>
  • Loading branch information
3 people authored Nov 15, 2023
1 parent f92b55c commit a691cff
Show file tree
Hide file tree
Showing 7 changed files with 469 additions and 223 deletions.
25 changes: 15 additions & 10 deletions src/metric-engine/src/data_region.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,18 +134,17 @@ mod test {

#[tokio::test]
async fn test_add_columns() {
common_telemetry::init_default_ut_logging();

let env = TestEnv::new().await;
env.init_metric_region().await;

let current_version = env
.mito()
.get_metadata(utils::to_data_region_id(env.default_region_id()))
.get_metadata(utils::to_data_region_id(env.default_physical_region_id()))
.await
.unwrap()
.schema_version;
assert_eq!(current_version, 0);
// TestEnv will create a logical region which changes the version to 1.
assert_eq!(current_version, 1);

let new_columns = vec![
ColumnMetadata {
Expand All @@ -168,29 +167,35 @@ mod test {
},
];
env.data_region()
.add_columns(env.default_region_id(), new_columns)
.add_columns(env.default_physical_region_id(), new_columns)
.await
.unwrap();

let new_metadata = env
.mito()
.get_metadata(utils::to_data_region_id(env.default_region_id()))
.get_metadata(utils::to_data_region_id(env.default_physical_region_id()))
.await
.unwrap();
let column_names = new_metadata
.column_metadatas
.iter()
.map(|c| &c.column_schema.name)
.collect::<Vec<_>>();
let expected = vec!["greptime_timestamp", "__metric", "__tsid", "tag2", "tag3"];
let expected = vec![
"greptime_timestamp",
"greptime_value",
"__metric",
"__tsid",
"job",
"tag2",
"tag3",
];
assert_eq!(column_names, expected);
}

// Only string is allowed for tag column
#[tokio::test]
async fn test_add_invalid_column() {
common_telemetry::init_default_ut_logging();

let env = TestEnv::new().await;
env.init_metric_region().await;

Expand All @@ -201,7 +206,7 @@ mod test {
}];
let result = env
.data_region()
.add_columns(env.default_region_id(), new_columns)
.add_columns(env.default_physical_region_id(), new_columns)
.await;
assert!(result.is_err());
}
Expand Down
Loading

0 comments on commit a691cff

Please sign in to comment.