@@ -18,9 +18,10 @@ const (
1818 MetadataConstraintName = "cq:extension:constraint_name"
1919 MetadataIncremental = "cq:extension:incremental"
2020
21- MetadataTrue = "true"
22- MetadataFalse = "false"
23- MetadataTableName = "cq:table_name"
21+ MetadataTrue = "true"
22+ MetadataFalse = "false"
23+ MetadataTableName = "cq:table_name"
24+ MetadataTableDescription = "cq:table_description"
2425)
2526
2627type FieldChange struct {
@@ -82,17 +83,19 @@ type MetadataFieldOptions struct {
8283}
8384
8485type MetadataSchemaOptions struct {
85- TableName string
86+ TableName string
87+ TableDescription string
8688}
8789
8890func NewSchemaMetadataFromOptions (opts MetadataSchemaOptions ) arrow.Metadata {
89- keys := make ([]string , 0 )
90- values := make ([]string , 0 )
91+ kv := map [string ]string {}
9192 if opts .TableName != "" {
92- keys = append (keys , MetadataTableName )
93- values = append (values , opts .TableName )
93+ kv [MetadataTableName ] = opts .TableName
9494 }
95- return arrow .NewMetadata (keys , values )
95+ if opts .TableDescription != "" {
96+ kv [MetadataTableDescription ] = opts .TableDescription
97+ }
98+ return arrow .MetadataFrom (kv )
9699}
97100
98101func NewFieldMetadataFromOptions (opts MetadataFieldOptions ) arrow.Metadata {
@@ -179,6 +182,14 @@ func TableName(sc *arrow.Schema) string {
179182 return name
180183}
181184
185+ func TableDescription (sc * arrow.Schema ) string {
186+ name , ok := sc .Metadata ().GetValue (MetadataTableDescription )
187+ if ! ok {
188+ return ""
189+ }
190+ return name
191+ }
192+
182193// GetSchemaChanges returns changes between two schemas
183194func GetSchemaChanges (target * arrow.Schema , source * arrow.Schema ) FieldChanges {
184195 var changes FieldChanges
@@ -283,7 +294,11 @@ func CQSchemaToArrow(table *Table) *arrow.Schema {
283294 for _ , col := range table .Columns {
284295 fields = append (fields , CQColumnToArrowField (& col ))
285296 }
286- metadata := arrow .NewMetadata ([]string {MetadataTableName }, []string {table .Name })
297+ opts := MetadataSchemaOptions {
298+ TableName : table .Name ,
299+ TableDescription : table .Description ,
300+ }
301+ metadata := NewSchemaMetadataFromOptions (opts )
287302 return arrow .NewSchema (fields , & metadata )
288303}
289304
0 commit comments