@@ -14,17 +14,6 @@ type ColumnList []Column
1414// resource holds the current row we are resolving the column for.
1515type ColumnResolver func (ctx context.Context , meta ClientMeta , resource * Resource , c Column ) error
1616
17- // ColumnCreationOptions allow modification of how column is defined when table is created
18- type ColumnCreationOptions struct {
19- PrimaryKey bool
20- NotNull bool
21- // IncrementalKey is a flag that indicates if the column is used as part of an incremental key.
22- // It is mainly used for documentation purposes, but may also be used as part of ensuring that
23- // migrations are done correctly.
24- IncrementalKey bool
25- Unique bool
26- }
27-
2817// Column definition for Table
2918type Column struct {
3019 // Name of column
@@ -35,62 +24,68 @@ type Column struct {
3524 Description string
3625 // Column Resolver allows to set your own data for a column; this can be an API call, setting multiple embedded values, etc
3726 Resolver ColumnResolver
38- // Creation options allow modifying how column is defined when table is created
39- CreationOptions ColumnCreationOptions
27+
4028 // IgnoreInTests is used to skip verifying the column is non-nil in integration tests.
4129 // By default, integration tests perform a fetch for all resources in cloudquery's test account, and
4230 // verify all columns are non-nil.
4331 // If IgnoreInTests is true, verification is skipped for this column.
4432 // Used when it is hard to create a reproducible environment with this column being non-nil (e.g. various error columns).
4533 IgnoreInTests bool
34+
35+ // PrimaryKey requires the destinations supporting this to include this column into the primary key
36+ PrimaryKey bool
37+ // NotNull requires the destinations supporting this to mark this column as non-nullable
38+ NotNull bool
39+ // IncrementalKey is a flag that indicates if the column is used as part of an incremental key.
40+ // It is mainly used for documentation purposes, but may also be used as part of ensuring that
41+ // migrations are done correctly.
42+ IncrementalKey bool
43+ // Unique requires the destinations supporting this to mark this column as unique
44+ Unique bool
4645}
4746
4847// NewColumnFromArrowField creates a new Column from an arrow.Field
4948// arrow.Field is a low-level representation of a CloudQuery column
5049// that can be sent over the wire in a cross-language way.
5150func NewColumnFromArrowField (f arrow.Field ) Column {
52- creationOptions := ColumnCreationOptions {
51+ column := Column {
52+ Name : f .Name ,
53+ Type : f .Type ,
5354 NotNull : ! f .Nullable ,
5455 }
55- if v , ok := f .Metadata .GetValue (MetadataPrimaryKey ); ok {
56- if v == MetadataTrue {
57- creationOptions .PrimaryKey = true
58- } else {
59- creationOptions .PrimaryKey = false
60- }
61- }
6256
63- if v , ok := f .Metadata .GetValue (MetadataUnique ); ok {
64- if v == MetadataTrue {
65- creationOptions .Unique = true
66- } else {
67- creationOptions .Unique = false
68- }
69- }
70- return Column {
71- Name : f .Name ,
72- Type : f .Type ,
73- CreationOptions : creationOptions ,
74- }
57+ v , ok := f .Metadata .GetValue (MetadataPrimaryKey )
58+ column .PrimaryKey = ok && v == MetadataTrue
59+
60+ v , ok = f .Metadata .GetValue (MetadataUnique )
61+ column .Unique = ok && v == MetadataTrue
62+
63+ v , ok = f .Metadata .GetValue (MetadataIncremental )
64+ column .IncrementalKey = ok && v == MetadataTrue
65+
66+ return column
7567}
7668
7769func (c Column ) ToArrowField () arrow.Field {
78- mdKV := map [string ]string {}
79- if c .CreationOptions .PrimaryKey {
70+ mdKV := map [string ]string {
71+ MetadataPrimaryKey : MetadataFalse ,
72+ MetadataUnique : MetadataFalse ,
73+ MetadataIncremental : MetadataFalse ,
74+ }
75+ if c .PrimaryKey {
8076 mdKV [MetadataPrimaryKey ] = MetadataTrue
81- } else {
82- mdKV [MetadataPrimaryKey ] = MetadataFalse
8377 }
84- if c .CreationOptions . Unique {
78+ if c .Unique {
8579 mdKV [MetadataUnique ] = MetadataTrue
86- } else {
87- mdKV [MetadataUnique ] = MetadataFalse
80+ }
81+ if c .IncrementalKey {
82+ mdKV [MetadataIncremental ] = MetadataTrue
8883 }
8984
9085 return arrow.Field {
9186 Name : c .Name ,
9287 Type : c .Type ,
93- Nullable : ! c .CreationOptions . NotNull ,
88+ Nullable : ! c .NotNull ,
9489 Metadata : arrow .MetadataFrom (mdKV ),
9590 }
9691}
@@ -100,12 +95,18 @@ func (c Column) String() string {
10095 sb .WriteString (c .Name )
10196 sb .WriteString (":" )
10297 sb .WriteString (c .Type .String ())
103- if c .CreationOptions . PrimaryKey {
98+ if c .PrimaryKey {
10499 sb .WriteString (":PK" )
105100 }
106- if c .CreationOptions . NotNull {
101+ if c .NotNull {
107102 sb .WriteString (":NotNull" )
108103 }
104+ if c .Unique {
105+ sb .WriteString (":Unique" )
106+ }
107+ if c .IncrementalKey {
108+ sb .WriteString (":IncrementalKey" )
109+ }
109110 return sb .String ()
110111}
111112
0 commit comments