Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 10 additions & 8 deletions src/meta/app/src/schema/table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -260,10 +260,12 @@ pub struct TableMeta {
pub storage_params: Option<StorageParams>,
pub part_prefix: String,
pub options: BTreeMap<String, String>,
// The default cluster key.
pub default_cluster_key: Option<String>,
// The sequence number of default_cluster_key.
pub default_cluster_key_id: u32,
pub cluster_key: Option<String>,
/// A sequential number that uniquely identifies changes to the cluster key.
/// This value increments by 1 each time the cluster key is created or modified,
/// ensuring a unique identifier for each version of the cluster key.
/// It remains unchanged when the cluster key is dropped.
pub cluster_key_seq: u32,
pub created_on: DateTime<Utc>,
pub updated_on: DateTime<Utc>,
pub comment: String,
Expand Down Expand Up @@ -408,9 +410,9 @@ impl TableInfo {

pub fn cluster_key(&self) -> Option<(u32, String)> {
self.meta
.default_cluster_key
.cluster_key
.clone()
.map(|k| (self.meta.default_cluster_key_id, k))
.map(|k| (self.meta.cluster_key_seq, k))
}
}

Expand All @@ -423,8 +425,8 @@ impl Default for TableMeta {
storage_params: None,
part_prefix: "".to_string(),
options: BTreeMap::new(),
default_cluster_key: None,
default_cluster_key_id: 0,
cluster_key: None,
cluster_key_seq: 0,
created_on: Utc::now(),
updated_on: Utc::now(),
comment: "".to_string(),
Expand Down
12 changes: 6 additions & 6 deletions src/meta/proto-conv/src/table_from_to_protobuf_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -192,8 +192,8 @@ impl FromToProto for mt::TableMeta {
indexes.insert(name, mt::TableIndex::from_pb(index)?);
}

let default_cluster_key_id = if let Some(cluster_key_id) = p.default_cluster_key_id {
cluster_key_id
let cluster_key_seq = if let Some(seq) = p.cluster_key_seq {
seq
} else if p.cluster_keys.is_empty() {
0
} else {
Expand All @@ -210,8 +210,8 @@ impl FromToProto for mt::TableMeta {
},
part_prefix: p.part_prefix.unwrap_or("".to_string()),
options: p.options,
default_cluster_key: p.default_cluster_key,
default_cluster_key_id,
cluster_key: p.cluster_key,
cluster_key_seq,
created_on: DateTime::<Utc>::from_pb(p.created_on)?,
updated_on: DateTime::<Utc>::from_pb(p.updated_on)?,
drop_on: match p.drop_on {
Expand Down Expand Up @@ -257,10 +257,10 @@ impl FromToProto for mt::TableMeta {
Some(self.part_prefix.clone())
},
options: self.options.clone(),
default_cluster_key: self.default_cluster_key.clone(),
cluster_key: self.cluster_key.clone(),
// cluster_keys is deprecated.
cluster_keys: vec![],
default_cluster_key_id: Some(self.default_cluster_key_id),
cluster_key_seq: Some(self.cluster_key_seq),
created_on: self.created_on.to_pb()?,
updated_on: self.updated_on.to_pb()?,
drop_on: match self.drop_on {
Expand Down
4 changes: 2 additions & 2 deletions src/meta/proto-conv/tests/it/proto_conv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -140,8 +140,8 @@ fn new_table_meta() -> mt::TableMeta {
part_prefix: "".to_string(),
engine_options: btreemap! {s("abc") => s("def")},
options: btreemap! {s("xyz") => s("foo")},
default_cluster_key: Some("(a + 2, b)".to_string()),
default_cluster_key_id: 0,
cluster_key: Some("(a + 2, b)".to_string()),
cluster_key_seq: 0,
created_on: Utc.with_ymd_and_hms(2014, 11, 28, 12, 0, 9).unwrap(),
updated_on: Utc.with_ymd_and_hms(2014, 11, 29, 12, 0, 10).unwrap(),
comment: s("table_comment"),
Expand Down
4 changes: 2 additions & 2 deletions src/meta/proto-conv/tests/it/v002_table_meta.rs
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,8 @@ fn test_decode_v2_table_meta() -> anyhow::Result<()> {
part_prefix: "".to_string(),
engine_options: btreemap! {s("abc") => s("def")},
options: btreemap! {s("xyz") => s("foo")},
default_cluster_key: Some("(a + 2, b)".to_string()),
default_cluster_key_id: 0,
cluster_key: Some("(a + 2, b)".to_string()),
cluster_key_seq: 0,
created_on: Utc.with_ymd_and_hms(2014, 11, 28, 12, 0, 9).unwrap(),
updated_on: Utc.with_ymd_and_hms(2014, 11, 29, 12, 0, 10).unwrap(),
comment: s("table_comment"),
Expand Down
4 changes: 2 additions & 2 deletions src/meta/proto-conv/tests/it/v010_table_meta.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,8 @@ fn test_decode_v10_table_meta() -> anyhow::Result<()> {
storage_params: None,
part_prefix: "".to_string(),
options: btreemap! {s("xyz") => s("foo")},
default_cluster_key: Some("(a + 2, b)".to_string()),
default_cluster_key_id: 0,
cluster_key: Some("(a + 2, b)".to_string()),
cluster_key_seq: 0,
created_on: Utc.with_ymd_and_hms(2014, 11, 28, 12, 0, 9).unwrap(),
updated_on: Utc.with_ymd_and_hms(2014, 11, 29, 12, 0, 10).unwrap(),
comment: s("table_comment"),
Expand Down
4 changes: 2 additions & 2 deletions src/meta/proto-conv/tests/it/v012_table_meta.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,8 @@ fn test_decode_v12_table_meta() -> anyhow::Result<()> {
storage_params: Some(StorageParams::default()),
part_prefix: "".to_string(),
options: btreemap! {s("xyz") => s("foo")},
default_cluster_key: Some("(a + 2, b)".to_string()),
default_cluster_key_id: 0,
cluster_key: Some("(a + 2, b)".to_string()),
cluster_key_seq: 0,
created_on: Utc.with_ymd_and_hms(2014, 11, 28, 12, 0, 9).unwrap(),
updated_on: Utc.with_ymd_and_hms(2014, 11, 29, 12, 0, 10).unwrap(),
comment: s("table_comment"),
Expand Down
4 changes: 2 additions & 2 deletions src/meta/proto-conv/tests/it/v023_table_meta.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,8 @@ fn test_decode_v23_table_meta() -> anyhow::Result<()> {
storage_params: Some(StorageParams::default()),
part_prefix: "lulu_".to_string(),
options: btreemap! {s("xyz") => s("foo")},
default_cluster_key: Some("(a + 2, b)".to_string()),
default_cluster_key_id: 0,
cluster_key: Some("(a + 2, b)".to_string()),
cluster_key_seq: 0,
created_on: Utc.with_ymd_and_hms(2014, 11, 28, 12, 0, 9).unwrap(),
updated_on: Utc.with_ymd_and_hms(2014, 11, 29, 12, 0, 10).unwrap(),
comment: s("table_comment"),
Expand Down
4 changes: 2 additions & 2 deletions src/meta/proto-conv/tests/it/v024_table_meta.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,8 @@ fn test_decode_v24_table_meta() -> anyhow::Result<()> {
storage_params: Some(StorageParams::default()),
part_prefix: "lulu_".to_string(),
options: btreemap! {s("xyz") => s("foo")},
default_cluster_key: Some("(a + 2, b)".to_string()),
default_cluster_key_id: 0,
cluster_key: Some("(a + 2, b)".to_string()),
cluster_key_seq: 0,
created_on: Utc.with_ymd_and_hms(2014, 11, 28, 12, 0, 9).unwrap(),
updated_on: Utc.with_ymd_and_hms(2014, 11, 29, 12, 0, 10).unwrap(),
comment: s("table_comment"),
Expand Down
4 changes: 2 additions & 2 deletions src/meta/proto-conv/tests/it/v033_table_meta.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,8 @@ fn test_decode_v33_table_meta() -> anyhow::Result<()> {
part_prefix: "".to_string(),
engine_options: btreemap! {s("abc") => s("def")},
options: btreemap! {s("xyz") => s("foo")},
default_cluster_key: Some("(a + 2, b)".to_string()),
default_cluster_key_id: 0,
cluster_key: Some("(a + 2, b)".to_string()),
cluster_key_seq: 0,
created_on: Utc.with_ymd_and_hms(2014, 11, 28, 12, 0, 9).unwrap(),
updated_on: Utc.with_ymd_and_hms(2014, 11, 29, 12, 0, 10).unwrap(),
comment: s("table_comment"),
Expand Down
4 changes: 2 additions & 2 deletions src/meta/proto-conv/tests/it/v040_table_meta.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,8 @@ fn test_decode_v40_table_meta() -> anyhow::Result<()> {
part_prefix: "".to_string(),
engine_options: btreemap! {s("abc") => s("def")},
options: btreemap! {s("xyz") => s("foo")},
default_cluster_key: Some("(a + 2, b)".to_string()),
default_cluster_key_id: 0,
cluster_key: Some("(a + 2, b)".to_string()),
cluster_key_seq: 0,
created_on: Utc.with_ymd_and_hms(2014, 11, 28, 12, 0, 9).unwrap(),
updated_on: Utc.with_ymd_and_hms(2014, 11, 29, 12, 0, 10).unwrap(),
comment: s("table_comment"),
Expand Down
4 changes: 2 additions & 2 deletions src/meta/proto-conv/tests/it/v044_table_meta.rs
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,8 @@ fn test_decode_v44_table_meta() -> anyhow::Result<()> {
part_prefix: "".to_string(),
engine_options: btreemap! {s("abc") => s("def")},
options: btreemap! {s("xyz") => s("foo")},
default_cluster_key: Some("(a + 2, b)".to_string()),
default_cluster_key_id: 0,
cluster_key: Some("(a + 2, b)".to_string()),
cluster_key_seq: 0,
created_on: Utc.with_ymd_and_hms(2014, 11, 28, 12, 0, 9).unwrap(),
updated_on: Utc.with_ymd_and_hms(2014, 11, 29, 12, 0, 10).unwrap(),
comment: s("table_comment"),
Expand Down
4 changes: 2 additions & 2 deletions src/meta/proto-conv/tests/it/v055_table_meta.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,8 @@ fn test_decode_v55_table_meta() -> anyhow::Result<()> {
part_prefix: "".to_string(),
engine_options: btreemap! {s("abc") => s("def")},
options: btreemap! {s("xyz") => s("foo")},
default_cluster_key: Some("(a + 2, b)".to_string()),
default_cluster_key_id: 0,
cluster_key: Some("(a + 2, b)".to_string()),
cluster_key_seq: 0,
created_on: Utc.with_ymd_and_hms(2014, 11, 28, 12, 0, 9).unwrap(),
updated_on: Utc.with_ymd_and_hms(2014, 11, 29, 12, 0, 10).unwrap(),
comment: s("table_comment"),
Expand Down
4 changes: 2 additions & 2 deletions src/meta/proto-conv/tests/it/v074_table_db_meta.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@ fn test_decode_v74_table_meta() -> anyhow::Result<()> {
part_prefix: "".to_string(),
engine_options: btreemap! {s("abc") => s("def")},
options: btreemap! {s("xyz") => s("foo")},
default_cluster_key: Some("(a + 2, b)".to_string()),
default_cluster_key_id: 0,
cluster_key: Some("(a + 2, b)".to_string()),
cluster_key_seq: 0,
created_on: Utc.with_ymd_and_hms(2014, 11, 28, 12, 0, 9).unwrap(),
updated_on: Utc.with_ymd_and_hms(2014, 11, 29, 12, 0, 10).unwrap(),
comment: s("table_comment"),
Expand Down
4 changes: 2 additions & 2 deletions src/meta/proto-conv/tests/it/v080_geometry_datatype.rs
Original file line number Diff line number Diff line change
Expand Up @@ -205,8 +205,8 @@ fn test_decode_v80_table_meta() -> anyhow::Result<()> {
part_prefix: "".to_string(),
engine_options: btreemap! {s("abc") => s("def")},
options: btreemap! {s("xyz") => s("foo")},
default_cluster_key: Some("(a + 2, b)".to_string()),
default_cluster_key_id: 0,
cluster_key: Some("(a + 2, b)".to_string()),
cluster_key_seq: 0,
created_on: Utc.with_ymd_and_hms(2014, 11, 28, 12, 0, 9).unwrap(),
updated_on: Utc.with_ymd_and_hms(2014, 11, 29, 12, 0, 10).unwrap(),
comment: s("table_comment"),
Expand Down
4 changes: 2 additions & 2 deletions src/meta/proto-conv/tests/it/v082_table_index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,8 @@ fn test_decode_v82_table_meta() -> anyhow::Result<()> {
part_prefix: "".to_string(),
engine_options: btreemap! {s("abc") => s("def")},
options: btreemap! {s("xyz") => s("foo")},
default_cluster_key: Some("(a + 2, b)".to_string()),
default_cluster_key_id: 0,
cluster_key: Some("(a + 2, b)".to_string()),
cluster_key_seq: 0,
created_on: Utc.with_ymd_and_hms(2014, 11, 28, 12, 0, 9).unwrap(),
updated_on: Utc.with_ymd_and_hms(2014, 11, 29, 12, 0, 10).unwrap(),
comment: s("table_comment"),
Expand Down
4 changes: 2 additions & 2 deletions src/meta/proto-conv/tests/it/v085_table_index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,8 @@ fn test_decode_v85_table_meta() -> anyhow::Result<()> {
part_prefix: "".to_string(),
engine_options: btreemap! {s("abc") => s("def")},
options: btreemap! {s("xyz") => s("foo")},
default_cluster_key: Some("(a + 2, b)".to_string()),
default_cluster_key_id: 0,
cluster_key: Some("(a + 2, b)".to_string()),
cluster_key_seq: 0,
created_on: Utc.with_ymd_and_hms(2014, 11, 28, 12, 0, 9).unwrap(),
updated_on: Utc.with_ymd_and_hms(2014, 11, 29, 12, 0, 10).unwrap(),
comment: s("table_comment"),
Expand Down
4 changes: 2 additions & 2 deletions src/meta/proto-conv/tests/it/v086_table_index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,8 @@ fn test_decode_v86_table_meta() -> anyhow::Result<()> {
part_prefix: "".to_string(),
engine_options: btreemap! {s("abc") => s("def")},
options: btreemap! {s("xyz") => s("foo")},
default_cluster_key: Some("(a + 2, b)".to_string()),
default_cluster_key_id: 0,
cluster_key: Some("(a + 2, b)".to_string()),
cluster_key_seq: 0,
created_on: Utc.with_ymd_and_hms(2014, 11, 28, 12, 0, 9).unwrap(),
updated_on: Utc.with_ymd_and_hms(2014, 11, 29, 12, 0, 10).unwrap(),
comment: s("table_comment"),
Expand Down
4 changes: 2 additions & 2 deletions src/meta/proto-conv/tests/it/v094_table_meta.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ fn test_decode_v94_table_meta() -> anyhow::Result<()> {
part_prefix: "".to_string(),
engine_options: btreemap! {s("abc") => s("def")},
options: btreemap! {s("xyz") => s("foo")},
default_cluster_key: Some("(a + 2, b)".to_string()),
default_cluster_key_id: 0,
cluster_key: Some("(a + 2, b)".to_string()),
cluster_key_seq: 0,
created_on: Utc.with_ymd_and_hms(2014, 11, 28, 12, 0, 9).unwrap(),
updated_on: Utc.with_ymd_and_hms(2014, 11, 29, 12, 0, 10).unwrap(),
comment: s("table_comment"),
Expand Down
4 changes: 2 additions & 2 deletions src/meta/proto-conv/tests/it/v107_geography_datatype.rs
Original file line number Diff line number Diff line change
Expand Up @@ -210,8 +210,8 @@ fn test_decode_v107_table_meta() -> anyhow::Result<()> {
part_prefix: "".to_string(),
engine_options: btreemap! {s("abc") => s("def")},
options: btreemap! {s("xyz") => s("foo")},
default_cluster_key: Some("(a + 2, b)".to_string()),
default_cluster_key_id: 0,
cluster_key: Some("(a + 2, b)".to_string()),
cluster_key_seq: 0,
created_on: Utc.with_ymd_and_hms(2014, 11, 28, 12, 0, 9).unwrap(),
updated_on: Utc.with_ymd_and_hms(2014, 11, 29, 12, 0, 10).unwrap(),
comment: s("table_comment"),
Expand Down
4 changes: 2 additions & 2 deletions src/meta/proto-conv/tests/it/v114_interval_datatype.rs
Original file line number Diff line number Diff line change
Expand Up @@ -201,8 +201,8 @@ fn test_decode_v114_table_meta() -> anyhow::Result<()> {
part_prefix: "".to_string(),
engine_options: btreemap! {s("abc") => s("def")},
options: btreemap! {s("xyz") => s("foo")},
default_cluster_key: Some("(a + 2, b)".to_string()),
default_cluster_key_id: 0,
cluster_key: Some("(a + 2, b)".to_string()),
cluster_key_seq: 0,
created_on: Utc.with_ymd_and_hms(2014, 11, 28, 12, 0, 9).unwrap(),
updated_on: Utc.with_ymd_and_hms(2014, 11, 29, 12, 0, 10).unwrap(),
comment: s("table_comment"),
Expand Down
6 changes: 3 additions & 3 deletions src/meta/protos/proto/table.proto
Original file line number Diff line number Diff line change
Expand Up @@ -82,13 +82,13 @@ message TableMeta {
map<string, string> options = 5;

// Keys to sort rows in table.
optional string default_cluster_key = 9;
optional string cluster_key = 9;

// The vector of cluster keys.
repeated string cluster_keys = 4;

// The default cluster keys id.
optional uint32 default_cluster_key_id = 8;
// A sequential number that uniquely identifies changes to the cluster key.
optional uint32 cluster_key_seq = 8;

// The time table created.
string created_on = 20;
Expand Down
2 changes: 1 addition & 1 deletion src/query/ee/src/attach_table/handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ impl AttachTableHandler for RealAttachTableHandler {
engine: plan.engine.to_string(),
storage_params: plan.storage_params.clone(),
options,
default_cluster_key: None,
cluster_key: None,
field_comments,
drop_on: None,
statistics: stat,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,8 @@ impl Interpreter for AlterTableClusterKeyInterpreter {
new_table_meta
.options
.insert(OPT_KEY_CLUSTER_TYPE.to_owned(), plan.cluster_type.clone());
new_table_meta.default_cluster_key = Some(cluster_key_str);
new_table_meta.default_cluster_key_id += 1;
new_table_meta.cluster_key = Some(cluster_key_str);
new_table_meta.cluster_key_seq += 1;

let req = UpdateTableMetaReq {
table_id: table_info.ident.table_id,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ impl Interpreter for DropTableClusterKeyInterpreter {
let fuse_table = FuseTable::try_from_table(table.as_ref())?;
let table_info = fuse_table.get_table_info();
let mut new_table_meta = table_info.meta.clone();
new_table_meta.default_cluster_key = None;
new_table_meta.cluster_key = None;
new_table_meta.options.remove(OPT_KEY_CLUSTER_TYPE);

let req = UpdateTableMetaReq {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,7 @@ impl CreateTableInterpreter {
storage_params: self.plan.storage_params.clone(),
options,
engine_options: self.plan.engine_options.clone(),
default_cluster_key: None,
cluster_key: None,
field_comments,
drop_on: None,
statistics: statistics.unwrap_or_default(),
Expand Down Expand Up @@ -411,8 +411,8 @@ impl CreateTableInterpreter {
}

if let Some(cluster_key) = &self.plan.cluster_key {
table_meta.default_cluster_key = Some(cluster_key.clone());
table_meta.default_cluster_key_id += 1;
table_meta.cluster_key = Some(cluster_key.clone());
table_meta.cluster_key_seq += 1;
}

let req = CreateTableReq {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ impl ShowCreateTableInterpreter {
let table_engine = format!(") ENGINE={}", engine);
table_create_sql.push_str(table_engine.as_str());

if let Some(cluster_keys_str) = &table_info.meta.default_cluster_key {
if let Some(cluster_keys_str) = &table_info.meta.cluster_key {
let cluster_type = table_info
.options()
.get(OPT_KEY_CLUSTER_TYPE)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ async fn test_fuse_alter_table_cluster_key() -> databend_common_exception::Resul

let table = fixture.latest_default_table().await?;
let table_info = table.get_table_info();
assert_eq!(table_info.meta.default_cluster_key_id, 1);
assert_eq!(table_info.meta.cluster_key_seq, 1);
assert_eq!(
table_info.meta.options.get(OPT_KEY_CLUSTER_TYPE).unwrap(),
LINEAR_CLUSTER_TYPE
Expand All @@ -93,8 +93,8 @@ async fn test_fuse_alter_table_cluster_key() -> databend_common_exception::Resul

let table = fixture.latest_default_table().await?;
let table_info = table.get_table_info();
assert_eq!(table_info.meta.default_cluster_key, None);
assert_eq!(table_info.meta.default_cluster_key_id, 1);
assert_eq!(table_info.meta.cluster_key, None);
assert_eq!(table_info.meta.cluster_key_seq, 1);

Ok(())
}
2 changes: 1 addition & 1 deletion src/query/storages/system/src/tables_table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -714,7 +714,7 @@ where TablesTable<WITH_HISTORY, WITHOUT_VIEW>: HistoryAware
.map(|v| {
v.get_table_info()
.meta
.default_cluster_key
.cluster_key
.clone()
.unwrap_or_else(|| "".to_owned())
})
Expand Down
Loading