Skip to content

Commit c70d8b0

Browse files
committed
add tests
1 parent a2ce1e5 commit c70d8b0

File tree

1 file changed

+98
-0
lines changed
  • rust/cubestore/cubestore/src/metastore

1 file changed

+98
-0
lines changed

rust/cubestore/cubestore/src/metastore/mod.rs

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5649,6 +5649,104 @@ mod tests {
56495649
let _ = fs::remove_dir_all(remote_store_path.clone());
56505650
}
56515651

5652+
#[tokio::test]
5653+
async fn table_with_default_index_no_measures_test() {
5654+
init_test_logger().await;
5655+
5656+
let config = Config::test("table_with_default_index_no_measures_test");
5657+
let store_path = env::current_dir()
5658+
.unwrap()
5659+
.join("test-table-default-index-no-measure-local");
5660+
let remote_store_path = env::current_dir()
5661+
.unwrap()
5662+
.join("test-table-default-index-no-measure-remote");
5663+
let _ = fs::remove_dir_all(store_path.clone());
5664+
let _ = fs::remove_dir_all(remote_store_path.clone());
5665+
let remote_fs = LocalDirRemoteFs::new(Some(remote_store_path.clone()), store_path.clone());
5666+
{
5667+
let meta_store = RocksMetaStore::new(
5668+
store_path.clone().join("metastore").as_path(),
5669+
BaseRocksStoreFs::new_for_metastore(remote_fs.clone(), config.config_obj()),
5670+
config.config_obj(),
5671+
)
5672+
.unwrap();
5673+
5674+
meta_store
5675+
.create_schema("foo".to_string(), false)
5676+
.await
5677+
.unwrap();
5678+
let mut columns = Vec::new();
5679+
columns.push(Column::new("col1".to_string(), ColumnType::Int, 0));
5680+
columns.push(Column::new("col2".to_string(), ColumnType::String, 1));
5681+
columns.push(Column::new("col3".to_string(), ColumnType::Int, 2));
5682+
columns.push(Column::new("aggr_col1".to_string(), ColumnType::Int, 3));
5683+
columns.push(Column::new("aggr_col2".to_string(), ColumnType::String, 4));
5684+
columns.push(Column::new("aggr_col3".to_string(), ColumnType::Int, 5));
5685+
5686+
let table1 = meta_store
5687+
.create_table(
5688+
"foo".to_string(),
5689+
"boo".to_string(),
5690+
columns.clone(),
5691+
None,
5692+
None,
5693+
vec![],
5694+
true,
5695+
None,
5696+
None,
5697+
None,
5698+
None,
5699+
None,
5700+
None,
5701+
Some(vec![
5702+
("sum".to_string(), "aggr_col1".to_string()),
5703+
("max".to_string(), "aggr_col2".to_string()),
5704+
("min".to_string(), "aggr_col3".to_string()),
5705+
]),
5706+
None,
5707+
None,
5708+
false,
5709+
None,
5710+
)
5711+
.await
5712+
.unwrap();
5713+
5714+
let table_id = table1.get_id();
5715+
5716+
assert_eq!(
5717+
meta_store
5718+
.get_table("foo".to_string(), "boo".to_string())
5719+
.await
5720+
.unwrap(),
5721+
table1
5722+
);
5723+
5724+
let indexes = meta_store.get_table_indexes(table_id).await.unwrap();
5725+
assert_eq!(indexes.len(), 1);
5726+
let ind = &indexes[0];
5727+
5728+
let index = ind.get_row();
5729+
assert_eq!(index.get_name(), &"default".to_string());
5730+
assert!(match index.get_type() {
5731+
IndexType::Regular => true,
5732+
_ => false,
5733+
});
5734+
assert_eq!(index.sort_key_size(), 3); // The main test point is here, sort key should exclude all measures
5735+
5736+
let expected_columns = vec![
5737+
Column::new("col1".to_string(), ColumnType::Int, 0),
5738+
Column::new("col2".to_string(), ColumnType::String, 1),
5739+
Column::new("col3".to_string(), ColumnType::Int, 2),
5740+
Column::new("aggr_col1".to_string(), ColumnType::Int, 3),
5741+
Column::new("aggr_col2".to_string(), ColumnType::String, 4),
5742+
Column::new("aggr_col3".to_string(), ColumnType::Int, 5),
5743+
];
5744+
assert_eq!(index.get_columns(), &expected_columns);
5745+
}
5746+
let _ = fs::remove_dir_all(store_path.clone());
5747+
let _ = fs::remove_dir_all(remote_store_path.clone());
5748+
}
5749+
56525750
#[tokio::test]
56535751
async fn cold_start_test() {
56545752
init_test_logger().await;

0 commit comments

Comments
 (0)