Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add comment on clause support #12849

Merged
merged 41 commits into from
Oct 25, 2023
Merged
Show file tree
Hide file tree
Changes from 19 commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
8ba0605
fix(over window): fix error in using aggregate function result as win…
jetjinser Sep 26, 2023
0d7caa6
test: add planner_test agg with window function
jetjinser Sep 29, 2023
fc9f48b
test: add e2e_test agg with window function
jetjinser Sep 29, 2023
593706c
test: add more complex agg with window e2e_test
jetjinser Oct 8, 2023
7cd9457
test: fix the agg planner_test query missed agg
jetjinser Oct 8, 2023
3b0645c
test: more complex agg with window planner_test
jetjinser Oct 8, 2023
5e18a8a
test: add "over_window with agg" streaming e2e_test
jetjinser Oct 8, 2023
4147b8c
test: add `group by` to every agg + window query
jetjinser Oct 9, 2023
a7f3dc2
feat: add `comment on` clause support
jetjinser Oct 15, 2023
1a217e3
fix: add license
jetjinser Oct 15, 2023
1e64388
fix(proto): revert tag order to avoid breaking change
jetjinser Oct 15, 2023
fc7e404
refactor: only support comment on `table` and `col`
jetjinser Oct 18, 2023
3772fe6
feat: new `description` field in `describe` result
jetjinser Oct 18, 2023
d32503c
test: update `describe` test
jetjinser Oct 18, 2023
c350d22
Merge branch 'main' into jinser/support-comment
jetjinser Oct 19, 2023
8b38fed
Merge remote-tracking branch 'upstream/main' into jinser/support-comment
jetjinser Oct 19, 2023
7999c4c
chore: add some comment
jetjinser Oct 19, 2023
d6b316a
refactor: use ok_or_else instead of unwrap
jetjinser Oct 19, 2023
6a0f9dd
feat: leave the `describe` description of pk and dk blank
jetjinser Oct 19, 2023
66c736e
Apply suggestions from code review
jetjinser Oct 19, 2023
a37fbde
Update src/frontend/src/catalog/system_catalog/rw_catalog/rw_descript…
jetjinser Oct 19, 2023
a9b64a9
chore: update comment
jetjinser Oct 19, 2023
effe791
refactor(frontend): remove unnecessary pub methods
jetjinser Oct 19, 2023
223f5fe
refactor(frontend): simplify the code
jetjinser Oct 19, 2023
e72854c
Update src/meta/src/manager/catalog/mod.rs
jetjinser Oct 23, 2023
7e151af
feat: resolve schema when `comment on`
jetjinser Oct 23, 2023
d61a60a
fix: add `PgFieldDescriptor` in `infer`
jetjinser Oct 23, 2023
d980bcd
refactor: better error in catalog comment_on
jetjinser Oct 23, 2023
9f9da21
feat: support `pg_description` upon `rw_description`
jetjinser Oct 23, 2023
3b1aeda
refactor: unify order of order `description`
jetjinser Oct 24, 2023
f4ad632
refactor: more specified function `concat`
jetjinser Oct 24, 2023
53ac310
feat: add table description in `describe`
jetjinser Oct 24, 2023
ccd8a91
feat: more consistent comment behavior with pgsql
jetjinser Oct 24, 2023
90ec94c
test: update `pg_description` e2e_test
jetjinser Oct 24, 2023
05fb23b
test: add more `comment on` & `describe` e2e_test
jetjinser Oct 24, 2023
2bf7dd9
refactor: avoid `type_complexity` clippy warning
jetjinser Oct 24, 2023
fd2fb36
Merge remote-tracking branch 'origin/main' into jinser/support-comment
jetjinser Oct 24, 2023
426bc1a
test: up to date `describe`
jetjinser Oct 25, 2023
7741106
Merge remote-tracking branch 'origin/main' into jinser/support-comment
jetjinser Oct 25, 2023
e2872ba
test: typo fix `NULL`
jetjinser Oct 25, 2023
b41c9c6
Merge remote-tracking branch 'origin/main' into jinser/support-comment
jetjinser Oct 25, 2023
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
39 changes: 24 additions & 15 deletions e2e_test/ddl/show.slt
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,21 @@ create materialized view mv3 as select sum(v1) as sum_v1 from t3;
statement ok
create view v3 as select sum(v2) as sum_v2 from t3;

query TTT
statement ok
comment on column t3.v2 is 'Lorem ipsum dolor sit amet';
yezizp2012 marked this conversation as resolved.
Show resolved Hide resolved

statement ok
comment on column t3._row_id is 'consectetur adipiscing elit';

query TTTT
describe t3;
----
v1 integer false
v2 integer false
v3 integer false
_row_id serial true
primary key _row_id NULL
distribution key _row_id NULL
v1 integer false NULL
v2 integer false Lorem ipsum dolor sit amet
v3 integer false NULL
_row_id serial true consectetur adipiscing elit
primary key _row_id NULL NULL
distribution key _row_id NULL NULL

query TTT
show columns from t3;
Expand All @@ -33,16 +39,19 @@ show indexes from t3;
----
idx1 t3 v1 ASC, v2 ASC v3 v1

query TTT
statement ok
comment on column t3.v2 is 'Nemo enim ipsam';

query TTTT
describe t3;
----
v1 integer false
v2 integer false
v3 integer false
_row_id serial true
primary key _row_id NULL
distribution key _row_id NULL
idx1 index(v1 ASC, v2 ASC) include(v3) distributed by(v1) NULL
v1 integer false NULL
v2 integer false Nemo enim ipsam
v3 integer false NULL
_row_id serial true consectetur adipiscing elit
primary key _row_id NULL NULL
distribution key _row_id NULL NULL
idx1 index(v1 ASC, v2 ASC) include(v3) distributed by(v1) NULL NULL

query TT
show create index idx1;
Expand Down
14 changes: 7 additions & 7 deletions e2e_test/extended_mode/basic.slt
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,15 @@ values(round(42.4382));
statement ok
create table t3 (v1 int, v2 int, v3 int);

query TTT
query TTTT
describe t3;
----
v1 integer false
v2 integer false
v3 integer false
_row_id serial true
primary key _row_id NULL
distribution key _row_id NULL
v1 integer false NULL
v2 integer false NULL
v3 integer false NULL
_row_id serial true NULL
primary key _row_id NULL NULL
distribution key _row_id NULL NULL

query TTT
show columns from t3;
Expand Down
8 changes: 8 additions & 0 deletions proto/catalog.proto
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,8 @@ message Table {

CreateType create_type = 32;

optional string description = 33;
stdrc marked this conversation as resolved.
Show resolved Hide resolved

// Per-table catalog version, used by schema change. `None` for internal tables and tests.
// Not to be confused with the global catalog version for notification service.
TableVersion version = 100;
Expand Down Expand Up @@ -317,3 +319,9 @@ message Database {
string name = 2;
uint32 owner = 3;
}

message Comment {
uint32 table_id = 1;
optional uint32 column_index = 2;
optional string description = 3;
}
12 changes: 12 additions & 0 deletions proto/ddl_service.proto
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,17 @@ message GetTablesResponse {
map<uint32, catalog.Table> tables = 1;
}

message CommentOnRequest {
uint32 table_id = 1;
optional uint32 column_index = 2;
optional string comment = 3;
}

message CommentOnResponse {
common.Status status = 1;
uint64 version = 2;
}

service DdlService {
rpc CreateDatabase(CreateDatabaseRequest) returns (CreateDatabaseResponse);
rpc DropDatabase(DropDatabaseRequest) returns (DropDatabaseResponse);
Expand Down Expand Up @@ -342,5 +353,6 @@ service DdlService {
rpc CreateConnection(CreateConnectionRequest) returns (CreateConnectionResponse);
rpc ListConnections(ListConnectionsRequest) returns (ListConnectionsResponse);
rpc DropConnection(DropConnectionRequest) returns (DropConnectionResponse);
rpc CommentOn(CommentOnRequest) returns (CommentOnResponse);
stdrc marked this conversation as resolved.
Show resolved Hide resolved
rpc GetTables(GetTablesRequest) returns (GetTablesResponse);
}
2 changes: 2 additions & 0 deletions proto/plan_common.proto
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ message ColumnDesc {
GeneratedColumnDesc generated_column = 6;
DefaultColumnDesc default_column = 7;
}

optional string description = 8;
stdrc marked this conversation as resolved.
Show resolved Hide resolved
}

message ColumnCatalog {
Expand Down
8 changes: 8 additions & 0 deletions src/common/src/catalog/column.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ pub struct ColumnDesc {
pub field_descs: Vec<ColumnDesc>,
pub type_name: String,
pub generated_or_default_column: Option<GeneratedOrDefaultColumn>,
pub description: Option<String>,
}

impl ColumnDesc {
Expand All @@ -112,6 +113,7 @@ impl ColumnDesc {
field_descs: vec![],
type_name: String::new(),
generated_or_default_column: None,
description: None,
}
}

Expand All @@ -128,6 +130,7 @@ impl ColumnDesc {
.map(|f| f.to_protobuf())
.collect_vec(),
type_name: self.type_name.clone(),
description: self.description.clone(),
generated_or_default_column: self.generated_or_default_column.clone(),
jetjinser marked this conversation as resolved.
Show resolved Hide resolved
}
}
Expand Down Expand Up @@ -171,6 +174,7 @@ impl ColumnDesc {
name: name.to_string(),
field_descs: vec![],
type_name: "".to_string(),
description: None,
generated_or_default_column: None,
}
}
Expand All @@ -191,6 +195,7 @@ impl ColumnDesc {
name: name.to_string(),
field_descs: fields,
type_name: type_name.to_string(),
description: None,
generated_or_default_column: None,
}
}
Expand All @@ -206,6 +211,7 @@ impl ColumnDesc {
.map(Self::from_field_without_column_id)
.collect_vec(),
type_name: field.type_name.clone(),
description: None,
generated_or_default_column: None,
}
}
Expand Down Expand Up @@ -242,6 +248,7 @@ impl From<PbColumnDesc> for ColumnDesc {
name: prost.name,
type_name: prost.type_name,
field_descs,
description: prost.description.clone(),
generated_or_default_column: prost.generated_or_default_column,
}
}
Expand All @@ -261,6 +268,7 @@ impl From<&ColumnDesc> for PbColumnDesc {
name: c.name.clone(),
field_descs: c.field_descs.iter().map(ColumnDesc::to_protobuf).collect(),
type_name: c.type_name.clone(),
description: c.description.clone(),
generated_or_default_column: c.generated_or_default_column.clone(),
}
}
Expand Down
2 changes: 2 additions & 0 deletions src/common/src/catalog/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ pub fn row_id_column_desc() -> ColumnDesc {
name: row_id_column_name(),
field_descs: vec![],
type_name: "".to_string(),
description: None,
generated_or_default_column: None,
}
}
Expand All @@ -130,6 +131,7 @@ pub fn offset_column_desc() -> ColumnDesc {
name: offset_column_name(),
field_descs: vec![],
type_name: "".to_string(),
description: None,
generated_or_default_column: None,
}
}
Expand Down
1 change: 1 addition & 0 deletions src/common/src/catalog/test_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ impl ColumnDescTestExt for ColumnDesc {
name: name.to_string(),
type_name: type_name.to_string(),
field_descs: fields,
description: None,
generated_or_default_column: None,
}
}
Expand Down
1 change: 1 addition & 0 deletions src/compute/tests/integration_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ async fn test_table_materialize() -> StreamResult<()> {
name: field.name,
field_descs: vec![],
type_name: "".to_string(),
description: None,
generated_or_default_column: None,
})
.collect_vec();
Expand Down
1 change: 1 addition & 0 deletions src/connector/src/parser/avro/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ fn avro_field_to_column_desc(
name: name.to_owned(),
field_descs: vec_column,
type_name: schema_name.to_string(),
description: None,
generated_or_default_column: None,
})
}
Expand Down
1 change: 1 addition & 0 deletions src/connector/src/parser/protobuf/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@ impl ProtobufParserConfig {
column_type: Some(field_type.to_protobuf()),
field_descs,
type_name: m.full_name().to_string(),
description: None,
generated_or_default_column: None,
})
} else {
Expand Down
1 change: 1 addition & 0 deletions src/connector/src/source/manager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ impl From<&SourceColumnDesc> for ColumnDesc {
name: s.name.clone(),
field_descs: s.fields.clone(),
type_name: "".to_string(),
description: None,
generated_or_default_column: None,
}
}
Expand Down
2 changes: 2 additions & 0 deletions src/frontend/src/binder/expr/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -575,6 +575,7 @@ pub fn bind_struct_field(column_def: &StructField) -> Result<ColumnDesc> {
name: f.name.real_value(),
field_descs: vec![],
type_name: "".to_string(),
description: None,
generated_or_default_column: None,
jetjinser marked this conversation as resolved.
Show resolved Hide resolved
})
})
Expand All @@ -588,6 +589,7 @@ pub fn bind_struct_field(column_def: &StructField) -> Result<ColumnDesc> {
name: column_def.name.real_value(),
field_descs,
type_name: "".to_string(),
description: None,
generated_or_default_column: None,
jetjinser marked this conversation as resolved.
Show resolved Hide resolved
})
}
Expand Down
20 changes: 20 additions & 0 deletions src/frontend/src/catalog/catalog_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,13 @@ pub trait CatalogWriter: Send + Sync {
connection: create_connection_request::Payload,
) -> Result<()>;

async fn comment_on(
&self,
table_id: TableId,
column_index: Option<u32>,
comment: Option<String>,
) -> Result<()>;

async fn drop_table(
&self,
source_id: Option<u32>,
Expand Down Expand Up @@ -282,6 +289,19 @@ impl CatalogWriter for CatalogWriterImpl {
self.wait_version(version).await
}

async fn comment_on(
&self,
TableId { table_id }: TableId,
column_index: Option<u32>,
comment: Option<String>,
) -> Result<()> {
let version = self
.meta_client
.comment_on(table_id, column_index, comment)
.await?;
self.wait_version(version).await
}

async fn drop_table(
&self,
source_id: Option<u32>,
Expand Down
8 changes: 8 additions & 0 deletions src/frontend/src/catalog/root_catalog.rs
Original file line number Diff line number Diff line change
Expand Up @@ -370,6 +370,14 @@ impl Catalog {
Ok(self.get_database_by_name(db_name)?.iter_schemas())
}

pub fn iter_schemas_except_rw_catalog(
&self,
db_name: &str,
) -> CatalogResult<impl Iterator<Item = &SchemaCatalog>> {
self.iter_schemas(db_name)
.map(|scs| scs.filter(|sc| !sc.is_rw_catalog()))
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this method expected to be used by other callers? It not, then it's just part of the logic of read_rw_description, rather than a public interface of Catalog. I guess it's OK to just filter the result at the caller side.


pub fn get_all_database_names(&self) -> Vec<String> {
self.database_by_name.keys().cloned().collect_vec()
}
Expand Down
4 changes: 4 additions & 0 deletions src/frontend/src/catalog/schema_catalog.rs
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,10 @@ impl SchemaCatalog {
self.system_table_by_name.values()
}

pub fn is_rw_catalog(&self) -> bool {
!self.system_table_by_name.is_empty()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not just comparing the schema name? Also, similar to iter_schemas_except_rw_catalog, it looks like unnecessary to add this method? Not sure though.

}

pub fn get_table_by_name(&self, table_name: &str) -> Option<&Arc<TableCatalog>> {
self.table_by_name.get(table_name)
}
Expand Down
4 changes: 4 additions & 0 deletions src/frontend/src/catalog/system_catalog/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ pub struct SystemTableCatalog {

// owner of table, should always be default super user, keep it for compatibility.
pub owner: u32,

pub description: Option<String>,
stdrc marked this conversation as resolved.
Show resolved Hide resolved
}

impl SystemTableCatalog {
Expand Down Expand Up @@ -165,6 +167,7 @@ impl From<&BuiltinTable> for SystemTableCatalog {
.collect(),
pk: val.pk.to_vec(),
owner: DEFAULT_SUPER_USER_ID,
description: None,
}
}
}
Expand Down Expand Up @@ -412,6 +415,7 @@ prepare_sys_catalog! {
{ BuiltinCatalog::Table(&RW_HUMMOCK_BRANCHED_OBJECTS), read_hummock_branched_objects await },
{ BuiltinCatalog::Table(&RW_HUMMOCK_COMPACTION_GROUP_CONFIGS), read_hummock_compaction_group_configs await },
{ BuiltinCatalog::Table(&RW_HUMMOCK_META_CONFIGS), read_hummock_meta_configs await},
{ BuiltinCatalog::Table(&RW_DESCRIPTION), read_rw_description },
}

#[cfg(test)]
Expand Down
2 changes: 2 additions & 0 deletions src/frontend/src/catalog/system_catalog/rw_catalog/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ mod rw_columns;
mod rw_connections;
mod rw_databases;
mod rw_ddl_progress;
mod rw_description;
mod rw_fragments;
mod rw_functions;
mod rw_hummock_branched_objects;
Expand Down Expand Up @@ -50,6 +51,7 @@ pub use rw_columns::*;
pub use rw_connections::*;
pub use rw_databases::*;
pub use rw_ddl_progress::*;
pub use rw_description::*;
pub use rw_fragments::*;
pub use rw_functions::*;
pub use rw_hummock_branched_objects::*;
Expand Down
Loading
Loading