(writeClient safeWriteClient, destinationSpec specs.Destination, destinationsClient *managedplugin.Client, destinationTransformer *transformer.RecordTransformer, summary *syncSummary, noMigrate bool)
| 148 | } |
| 149 | |
| 150 | func sendSummary(writeClient safeWriteClient, destinationSpec specs.Destination, destinationsClient *managedplugin.Client, destinationTransformer *transformer.RecordTransformer, summary *syncSummary, noMigrate bool) error { |
| 151 | summaryTable, err := generateSummaryTable() |
| 152 | if err != nil { |
| 153 | return err |
| 154 | } |
| 155 | |
| 156 | csr := caser.New(caser.WithCustomInitialisms(map[string]bool{"CLI": true}), caser.WithCustomExceptions(map[string]string{"cli": "CLI"})) |
| 157 | |
| 158 | // Respect the noMigrate flag |
| 159 | if !noMigrate { |
| 160 | if err := migrateSummaryTable(writeClient, destinationTransformer, destinationSpec); err != nil { |
| 161 | return fmt.Errorf("failed to migrate sync summary table: %w", err) |
| 162 | } |
| 163 | } |
| 164 | |
| 165 | // Get Information about the DestinationPlugin |
| 166 | m := destinationsClient.Metrics() |
| 167 | summary.DestinationErrors = m.Errors |
| 168 | summary.DestinationWarnings = m.Warnings |
| 169 | |
| 170 | summary.DestinationName = destinationSpec.Name |
| 171 | summary.DestinationVersion = destinationSpec.Version |
| 172 | summary.DestinationPath = destinationSpec.Path |
| 173 | |
| 174 | resource := schema.NewResourceData(summaryTable, nil, nil) |
| 175 | for _, col := range summaryTable.Columns { |
| 176 | // Use funk.Get to get the value from the summary struct using the column name converted to PascalCase |
| 177 | err := resource.Set(col.Name, funk.Get(summary, csr.ToPascal(col.Name), funk.WithAllowZero())) |
| 178 | if err != nil { |
| 179 | return fmt.Errorf("failed to set %s: %w", col.Name, err) |
| 180 | } |
| 181 | } |
| 182 | |
| 183 | vector := resource.GetValues() |
| 184 | arrowRecord := vector.ToArrowRecord(resource.Table.ToArrowSchema()) |
| 185 | |
| 186 | transformedRecord := destinationTransformer.Transform(arrowRecord) |
| 187 | transformedRecordBytes, err := plugin.RecordToBytes(transformedRecord) |
| 188 | if err != nil { |
| 189 | return fmt.Errorf("failed to transform sync summary bytes: %w", err) |
| 190 | } |
| 191 | |
| 192 | wr := &plugin.Write_Request{} |
| 193 | wr.Message = &plugin.Write_Request_Insert{ |
| 194 | Insert: &plugin.Write_MessageInsert{ |
| 195 | Record: transformedRecordBytes, |
| 196 | }, |
| 197 | } |
| 198 | if err := writeClient.Send(wr); err != nil { |
| 199 | return handleSendError(err, writeClient, "insert sync summary") |
| 200 | } |
| 201 | |
| 202 | return nil |
| 203 | } |
no test coverage detected