( columnDescriptions: dataform.IColumnDescriptor[], metadataArray: TableField[] )
| 586 | } |
| 587 | |
| 588 | function addDescriptionToMetadata( |
| 589 | columnDescriptions: dataform.IColumnDescriptor[], |
| 590 | metadataArray: TableField[] |
| 591 | ): TableField[] { |
| 592 | if (!columnDescriptions) { |
| 593 | return metadataArray; |
| 594 | } |
| 595 | const findDescription = (path: string[]) => |
| 596 | columnDescriptions.find(column => column.path.join("") === path.join("")); |
| 597 | |
| 598 | const mapDescriptionToMetadata = (metadata: TableField, path: string[]) => { |
| 599 | const description = findDescription(path); |
| 600 | if (description) { |
| 601 | metadata.description = description.description; |
| 602 | if (description.bigqueryPolicyTags?.length > 0) { |
| 603 | metadata.policyTags = { |
| 604 | names: description.bigqueryPolicyTags |
| 605 | }; |
| 606 | } |
| 607 | } |
| 608 | |
| 609 | if (metadata.fields) { |
| 610 | metadata.fields = metadata.fields.map(nestedMetadata => |
| 611 | mapDescriptionToMetadata(nestedMetadata, [...path, nestedMetadata.name]) |
| 612 | ); |
| 613 | } |
| 614 | |
| 615 | return metadata; |
| 616 | }; |
| 617 | |
| 618 | const newMetadata = metadataArray.map(metaItem => |
| 619 | mapDescriptionToMetadata(metaItem, [metaItem.name]) |
| 620 | ); |
| 621 | return newMetadata; |
| 622 | } |
| 623 | |
| 624 | function createBigQueryError(jobMetadata: any): IBigQueryError { |
| 625 | const error: IBigQueryError = new Error(jobMetadata.status.errorResult.message); |
no test coverage detected