@@ -25,7 +25,9 @@ use databend_common_expression::TableDataType;
2525use databend_common_expression:: TableField ;
2626use databend_common_expression:: TableSchemaRefExt ;
2727use databend_common_expression:: infer_table_schema;
28+ use databend_common_expression:: types:: NumberDataType ;
2829use databend_common_expression:: types:: StringType ;
30+ use databend_common_expression:: types:: UInt64Type ;
2931use databend_common_expression:: utils:: FromData ;
3032use databend_common_functions:: BUILTIN_FUNCTIONS ;
3133use databend_common_meta_app:: schema:: CatalogInfo ;
@@ -84,10 +86,12 @@ impl AsyncSystemTable for ColumnsTable {
8486 let mut default_exprs: Vec < String > = Vec :: with_capacity ( rows. len ( ) ) ;
8587 let mut is_nullables: Vec < String > = Vec :: with_capacity ( rows. len ( ) ) ;
8688 let mut comments: Vec < String > = Vec :: with_capacity ( rows. len ( ) ) ;
89+ let mut column_ids: Vec < Option < u64 > > = Vec :: with_capacity ( rows. len ( ) ) ;
8790 for column_info in rows. into_iter ( ) {
8891 names. push ( column_info. column . name ( ) . clone ( ) ) ;
8992 tables. push ( column_info. table_name ) ;
9093 databases. push ( column_info. database_name ) ;
94+ column_ids. push ( column_info. column_id ) ;
9195 types. push ( column_info. column . data_type ( ) . wrapped_display ( ) ) ;
9296 let data_type = column_info
9397 . column
@@ -123,6 +127,7 @@ impl AsyncSystemTable for ColumnsTable {
123127 StringType :: from_data( default_exprs) ,
124128 StringType :: from_data( is_nullables) ,
125129 StringType :: from_data( comments) ,
130+ UInt64Type :: from_opt_data( column_ids) ,
126131 ] ) )
127132 }
128133}
@@ -133,6 +138,7 @@ struct TableColumnInfo {
133138
134139 column : TableField ,
135140 column_comment : String ,
141+ column_id : Option < u64 > ,
136142}
137143
138144impl ColumnsTable {
@@ -149,6 +155,10 @@ impl ColumnsTable {
149155 TableField :: new( "default_expression" , TableDataType :: String ) ,
150156 TableField :: new( "is_nullable" , TableDataType :: String ) ,
151157 TableField :: new( "comment" , TableDataType :: String ) ,
158+ TableField :: new(
159+ "column_id" ,
160+ TableDataType :: Nullable ( Box :: new( TableDataType :: Number ( NumberDataType :: UInt64 ) ) ) ,
161+ ) ,
152162 ] ) ;
153163
154164 let table_info = TableInfo {
@@ -210,6 +220,9 @@ impl ColumnsTable {
210220 table_name : table. name ( ) . into ( ) ,
211221 column : field. clone ( ) ,
212222 column_comment : "" . to_string ( ) ,
223+ // View output columns are inferred from the query plan here; their
224+ // ids are not stable table column ids.
225+ column_id : None ,
213226 } )
214227 }
215228 }
@@ -223,6 +236,7 @@ impl ColumnsTable {
223236 table_name : table. name ( ) . into ( ) ,
224237 column : field. clone ( ) ,
225238 column_comment : "" . to_string ( ) ,
239+ column_id : Some ( field. column_id ( ) as u64 ) ,
226240 } )
227241 }
228242 }
@@ -253,6 +267,7 @@ impl ColumnsTable {
253267 table_name : table. name ( ) . into ( ) ,
254268 column : field. clone ( ) ,
255269 column_comment : comment,
270+ column_id : Some ( field. column_id ( ) as u64 ) ,
256271 } )
257272 }
258273 }
0 commit comments