|
7 | 7 |
|
8 | 8 | "github.com/apache/arrow/go/v13/arrow" |
9 | 9 | "github.com/cloudquery/plugin-sdk/v3/internal/glob" |
| 10 | + "golang.org/x/exp/slices" |
10 | 11 | ) |
11 | 12 |
|
12 | 13 | // TableResolver is the main entry point when a table is sync is called. |
@@ -173,9 +174,10 @@ func (tt Tables) FilterDfsFunc(include, exclude func(*Table) bool, skipDependent |
173 | 174 | } |
174 | 175 |
|
175 | 176 | func (tt Tables) ToArrowSchemas() Schemas { |
176 | | - schemas := make(Schemas, 0, len(tt.FlattenTables())) |
177 | | - for _, t := range tt.FlattenTables() { |
178 | | - schemas = append(schemas, t.ToArrowSchema()) |
| 177 | + flattened := tt.FlattenTables() |
| 178 | + schemas := make(Schemas, len(flattened)) |
| 179 | + for i, t := range flattened { |
| 180 | + schemas[i] = t.ToArrowSchema() |
179 | 181 | } |
180 | 182 | return schemas |
181 | 183 | } |
@@ -228,19 +230,22 @@ func (tt Tables) FilterDfs(tables, skipTables []string, skipDependentTables bool |
228 | 230 | func (tt Tables) FlattenTables() Tables { |
229 | 231 | tables := make(Tables, 0, len(tt)) |
230 | 232 | for _, t := range tt { |
231 | | - tables = append(tables, t) |
| 233 | + table := *t |
| 234 | + table.Relations = nil |
| 235 | + tables = append(tables, &table) |
232 | 236 | tables = append(tables, t.Relations.FlattenTables()...) |
233 | 237 | } |
234 | | - tableNames := make(map[string]bool) |
235 | | - dedupedTables := make(Tables, 0, len(tables)) |
| 238 | + |
| 239 | + seen := make(map[string]struct{}) |
| 240 | + deduped := make(Tables, 0, len(tables)) |
236 | 241 | for _, t := range tables { |
237 | | - if _, found := tableNames[t.Name]; !found { |
238 | | - dedupedTables = append(dedupedTables, t) |
239 | | - tableNames[t.Name] = true |
| 242 | + if _, found := seen[t.Name]; !found { |
| 243 | + deduped = append(deduped, t) |
| 244 | + seen[t.Name] = struct{}{} |
240 | 245 | } |
241 | 246 | } |
242 | 247 |
|
243 | | - return dedupedTables |
| 248 | + return slices.Clip(deduped) |
244 | 249 | } |
245 | 250 |
|
246 | 251 | func (tt Tables) TableNames() []string { |
|
0 commit comments