@cumulus/db 21.3.1-alpha.0 → 21.3.2-testlerna.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (55) hide show
  1. package/dist/index.d.ts +1 -0
  2. package/dist/index.js +3 -1
  3. package/dist/s3search/AsyncOperationS3Search.d.ts +20 -0
  4. package/dist/s3search/AsyncOperationS3Search.js +29 -0
  5. package/dist/s3search/CollectionS3Search.d.ts +39 -0
  6. package/dist/s3search/CollectionS3Search.js +113 -0
  7. package/dist/s3search/DuckDBSearchExecutor.d.ts +36 -0
  8. package/dist/s3search/DuckDBSearchExecutor.js +57 -0
  9. package/dist/s3search/ExecutionS3Search.d.ts +20 -0
  10. package/dist/s3search/ExecutionS3Search.js +29 -0
  11. package/dist/s3search/GranuleS3Search.d.ts +31 -0
  12. package/dist/s3search/GranuleS3Search.js +100 -0
  13. package/dist/s3search/PdrS3Search.d.ts +20 -0
  14. package/dist/s3search/PdrS3Search.js +29 -0
  15. package/dist/s3search/ProviderS3Search.d.ts +20 -0
  16. package/dist/s3search/ProviderS3Search.js +29 -0
  17. package/dist/s3search/ReconciliationReportS3Search.d.ts +20 -0
  18. package/dist/s3search/ReconciliationReportS3Search.js +29 -0
  19. package/dist/s3search/RuleS3Search.d.ts +20 -0
  20. package/dist/s3search/RuleS3Search.js +29 -0
  21. package/dist/s3search/StatsS3Search.d.ts +25 -0
  22. package/dist/s3search/StatsS3Search.js +51 -0
  23. package/dist/s3search/duckdbHelpers.d.ts +43 -0
  24. package/dist/s3search/duckdbHelpers.js +83 -0
  25. package/dist/s3search/s3TableSchemas.d.ts +11 -0
  26. package/dist/s3search/s3TableSchemas.js +272 -0
  27. package/dist/search/BaseSearch.d.ts +46 -2
  28. package/dist/search/BaseSearch.js +84 -22
  29. package/dist/search/CollectionSearch.d.ts +6 -4
  30. package/dist/search/CollectionSearch.js +2 -3
  31. package/dist/search/ExecutionSearch.d.ts +1 -1
  32. package/dist/search/ExecutionSearch.js +3 -3
  33. package/dist/search/GranuleSearch.d.ts +2 -3
  34. package/dist/search/GranuleSearch.js +3 -3
  35. package/dist/search/PdrSearch.js +1 -1
  36. package/dist/search/ReconciliationReportSearch.js +1 -1
  37. package/dist/search/RuleSearch.js +4 -4
  38. package/dist/search/StatsSearch.d.ts +15 -4
  39. package/dist/search/StatsSearch.js +12 -6
  40. package/dist/search/field-mapping.d.ts +1 -3
  41. package/dist/search/field-mapping.js +40 -19
  42. package/dist/test-duckdb-utils.d.ts +31 -0
  43. package/dist/test-duckdb-utils.js +125 -0
  44. package/dist/test-utils.js +6 -0
  45. package/dist/translate/async_operations.js +7 -3
  46. package/dist/translate/collections.js +6 -6
  47. package/dist/translate/executions.js +7 -7
  48. package/dist/translate/granules.js +16 -11
  49. package/dist/translate/pdr.js +4 -4
  50. package/dist/translate/providers.js +2 -2
  51. package/dist/translate/reconciliation_reports.js +5 -4
  52. package/dist/translate/rules.d.ts +1 -1
  53. package/dist/translate/rules.js +6 -6
  54. package/dist/types/file.d.ts +2 -0
  55. package/package.json +12 -11
package/dist/index.d.ts CHANGED
@@ -41,6 +41,7 @@ export { ProviderSearch, } from './search/ProviderSearch';
41
41
  export { RuleSearch, } from './search/RuleSearch';
42
42
  export { StatsSearch, } from './search/StatsSearch';
43
43
  export { ReconciliationReportSearch, } from './search/ReconciliationReportSearch';
44
+ export { CollectionS3Search, } from './s3search/CollectionS3Search';
44
45
  export { AsyncOperationPgModel } from './models/async_operation';
45
46
  export { BasePgModel } from './models/base';
46
47
  export { CollectionPgModel } from './models/collection';
package/dist/index.js CHANGED
@@ -24,7 +24,7 @@ var __importStar = (this && this.__importStar) || function (mod) {
24
24
  };
25
25
  Object.defineProperty(exports, "__esModule", { value: true });
26
26
  exports.getApiExecutionCumulusIds = exports.executionArnsFromGranuleIdsAndWorkflowNames = exports.batchDeleteExecutionFromDatabaseByCumulusCollectionId = exports.getUniqueCollectionsByGranuleFilter = exports.getCollectionsByGranuleIds = exports.translatePostgresReconReportToApiReconReport = exports.translateApiReconReportToPostgresReconReport = exports.translatePostgresPdrToApiPdr = exports.translateApiPdrToPostgresPdr = exports.translatePostgresGranuleResultToApiGranule = exports.translatePostgresGranuleToApiGranule = exports.translateApiGranuleToPostgresGranuleWithoutNilsRemoved = exports.translateApiGranuleToPostgresGranule = exports.translatePostgresExecutionToApiExecution = exports.translateApiExecutionToPostgresExecutionWithoutNilsRemoved = exports.translateApiExecutionToPostgresExecution = exports.translateApiRuleToPostgresRuleRaw = exports.translateApiRuleToPostgresRule = exports.translatePostgresRuleToApiRule = exports.translatePostgresProviderToApiProvider = exports.translateApiProviderToPostgresProvider = exports.translatePostgresCollectionToApiCollection = exports.translateApiCollectionToPostgresCollection = exports.translatePostgresFileToApiFile = exports.translateApiFiletoPostgresFile = exports.translatePostgresAsyncOperationToApiAsyncOperation = exports.translateApiAsyncOperationToPostgresAsyncOperation = exports.nullifyUndefinedProviderValues = exports.validateProviderHost = exports.migrationDir = exports.TableNames = exports.createRejectableTransaction = exports.localStackConnectionEnv = exports.getKnexConfig = exports.getKnexClient = exports.isCollisionError = exports.generateLocalTestDb = exports.fakeRuleRecordFactory = exports.fakeReconciliationReportRecordFactory = exports.fakeProviderRecordFactory = exports.fakePdrRecordFactory = exports.fakeGranuleRecordFactory = exports.fakeFileRecordFactory = exports.fakeExecutionRecordFactory = exports.fakeCollectionRecordFactory = exports.fakeAsyncOperationRecordFactory = exports.destroyLocalTestDb = exports.deleteTestDatabase = exports.createTestDatabase = exports.Knex = void 0;
27
- exports.RulePgModel = exports.ReconciliationReportPgModel = exports.ProviderPgModel = exports.PdrPgModel = exports.GranulesExecutionsPgModel = exports.GranulePgModel = exports.FilePgModel = exports.ExecutionPgModel = exports.CollectionPgModel = exports.BasePgModel = exports.AsyncOperationPgModel = exports.ReconciliationReportSearch = exports.StatsSearch = exports.RuleSearch = exports.ProviderSearch = exports.PdrSearch = exports.GranuleSearch = exports.ExecutionSearch = exports.CollectionSearch = exports.AsyncOperationSearch = exports.QuerySearchClient = exports.updateBatchGranulesCollection = exports.getGranuleAndCollection = exports.getGranulesByGranuleId = exports.getGranulesByApiPropertiesQuery = exports.upsertGranuleWithExecutionJoinRecord = exports.getGranuleCollectionId = exports.getApiGranuleExecutionCumulusIds = exports.getApiGranuleCumulusIds = exports.getGranuleIdAndCollectionIdFromFile = exports.getFilesAndGranuleInfoQuery = exports.newestExecutionArnFromGranuleIdWorkflowName = exports.getWorkflowNameIntersectFromGranuleIds = exports.getExecutionInfoByGranuleCumulusId = exports.getApiGranuleExecutionCumulusIdsByExecution = void 0;
27
+ exports.RulePgModel = exports.ReconciliationReportPgModel = exports.ProviderPgModel = exports.PdrPgModel = exports.GranulesExecutionsPgModel = exports.GranulePgModel = exports.FilePgModel = exports.ExecutionPgModel = exports.CollectionPgModel = exports.BasePgModel = exports.AsyncOperationPgModel = exports.CollectionS3Search = exports.ReconciliationReportSearch = exports.StatsSearch = exports.RuleSearch = exports.ProviderSearch = exports.PdrSearch = exports.GranuleSearch = exports.ExecutionSearch = exports.CollectionSearch = exports.AsyncOperationSearch = exports.QuerySearchClient = exports.updateBatchGranulesCollection = exports.getGranuleAndCollection = exports.getGranulesByGranuleId = exports.getGranulesByApiPropertiesQuery = exports.upsertGranuleWithExecutionJoinRecord = exports.getGranuleCollectionId = exports.getApiGranuleExecutionCumulusIds = exports.getApiGranuleCumulusIds = exports.getGranuleIdAndCollectionIdFromFile = exports.getFilesAndGranuleInfoQuery = exports.newestExecutionArnFromGranuleIdWorkflowName = exports.getWorkflowNameIntersectFromGranuleIds = exports.getExecutionInfoByGranuleCumulusId = exports.getApiGranuleExecutionCumulusIdsByExecution = void 0;
28
28
  const path = __importStar(require("path"));
29
29
  var knex_1 = require("knex");
30
30
  Object.defineProperty(exports, "Knex", { enumerable: true, get: function () { return knex_1.Knex; } });
@@ -131,6 +131,8 @@ var StatsSearch_1 = require("./search/StatsSearch");
131
131
  Object.defineProperty(exports, "StatsSearch", { enumerable: true, get: function () { return StatsSearch_1.StatsSearch; } });
132
132
  var ReconciliationReportSearch_1 = require("./search/ReconciliationReportSearch");
133
133
  Object.defineProperty(exports, "ReconciliationReportSearch", { enumerable: true, get: function () { return ReconciliationReportSearch_1.ReconciliationReportSearch; } });
134
+ var CollectionS3Search_1 = require("./s3search/CollectionS3Search");
135
+ Object.defineProperty(exports, "CollectionS3Search", { enumerable: true, get: function () { return CollectionS3Search_1.CollectionS3Search; } });
134
136
  var async_operation_1 = require("./models/async_operation");
135
137
  Object.defineProperty(exports, "AsyncOperationPgModel", { enumerable: true, get: function () { return async_operation_1.AsyncOperationPgModel; } });
136
138
  var base_1 = require("./models/base");
@@ -0,0 +1,20 @@
1
+ import { DuckDBConnection } from '@duckdb/node-api';
2
+ import { AsyncOperationSearch } from '../search/AsyncOperationSearch';
3
+ import { QueryEvent } from '../types/search';
4
+ /**
5
+ * Class to build and execute DuckDB search query for asyncOperation
6
+ */
7
+ export declare class AsyncOperationS3Search extends AsyncOperationSearch {
8
+ private duckDBSearchExecutor;
9
+ constructor(event: QueryEvent, dbConnection: DuckDBConnection);
10
+ /**
11
+ * Build and execute search query
12
+ *
13
+ * @returns search result
14
+ */
15
+ query(): Promise<{
16
+ meta: import("../search/BaseSearch").Meta;
17
+ results: any[];
18
+ }>;
19
+ }
20
+ //# sourceMappingURL=AsyncOperationS3Search.d.ts.map
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.AsyncOperationS3Search = void 0;
4
+ const DuckDBSearchExecutor_1 = require("./DuckDBSearchExecutor");
5
+ const AsyncOperationSearch_1 = require("../search/AsyncOperationSearch");
6
+ /**
7
+ * Class to build and execute DuckDB search query for asyncOperation
8
+ */
9
+ class AsyncOperationS3Search extends AsyncOperationSearch_1.AsyncOperationSearch {
10
+ constructor(event, dbConnection) {
11
+ super(event);
12
+ this.duckDBSearchExecutor = new DuckDBSearchExecutor_1.DuckDBSearchExecutor({
13
+ dbConnection,
14
+ dbQueryParameters: this.dbQueryParameters,
15
+ getMetaTemplate: this._metaTemplate.bind(this),
16
+ translateRecords: this.translatePostgresRecordsToApiRecords.bind(this),
17
+ });
18
+ }
19
+ /**
20
+ * Build and execute search query
21
+ *
22
+ * @returns search result
23
+ */
24
+ async query() {
25
+ return this.duckDBSearchExecutor.query((knexBuilder) => this.buildSearch(knexBuilder));
26
+ }
27
+ }
28
+ exports.AsyncOperationS3Search = AsyncOperationS3Search;
29
+ //# sourceMappingURL=AsyncOperationS3Search.js.map
@@ -0,0 +1,39 @@
1
+ import { Knex } from 'knex';
2
+ import { DuckDBConnection } from '@duckdb/node-api';
3
+ import { CollectionSearch, StatsRecords, CollectionRecordApi } from '../search/CollectionSearch';
4
+ import { PostgresCollectionRecord } from '../types/collection';
5
+ import { QueryEvent } from '../types/search';
6
+ /**
7
+ * Class to build and execute DuckDB search query for collections
8
+ */
9
+ export declare class CollectionS3Search extends CollectionSearch {
10
+ private dbConnection;
11
+ private duckDBSearchExecutor;
12
+ constructor(event: QueryEvent, dbConnection: DuckDBConnection);
13
+ /**
14
+ * Executes stats query to get granules' status aggregation
15
+ *
16
+ * @param collectionCumulusIds - array of cumulusIds of the collections
17
+ * @param knexClient - knex for the stats query
18
+ * @returns the collection's granules status' aggregation
19
+ */
20
+ protected retrieveGranuleStats(collectionCumulusIds: number[], knexClient: Knex): Promise<StatsRecords>;
21
+ /**
22
+ * Translate postgres records to api records
23
+ *
24
+ * @param pgRecords - postgres Collection records returned from query
25
+ * @param knexClient - knex for the stats query if incldueStats is true
26
+ * @returns translated api records
27
+ */
28
+ protected translatePostgresRecordsToApiRecords(pgRecords: PostgresCollectionRecord[], knexClient: Knex): Promise<Partial<CollectionRecordApi>[]>;
29
+ /**
30
+ * Build and execute search query
31
+ *
32
+ * @returns search result
33
+ */
34
+ query(): Promise<{
35
+ meta: import("../search/BaseSearch").Meta;
36
+ results: any[];
37
+ }>;
38
+ }
39
+ //# sourceMappingURL=CollectionS3Search.d.ts.map
@@ -0,0 +1,113 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.CollectionS3Search = void 0;
7
+ const pick_1 = __importDefault(require("lodash/pick"));
8
+ const logger_1 = __importDefault(require("@cumulus/logger"));
9
+ const CollectionSearch_1 = require("../search/CollectionSearch");
10
+ const tables_1 = require("../tables");
11
+ const collections_1 = require("../translate/collections");
12
+ const duckdbHelpers_1 = require("./duckdbHelpers");
13
+ const GranuleS3Search_1 = require("./GranuleS3Search");
14
+ const DuckDBSearchExecutor_1 = require("./DuckDBSearchExecutor");
15
+ const log = new logger_1.default({ sender: '@cumulus/db/CollectionS3Search' });
16
+ /**
17
+ * Class to build and execute DuckDB search query for collections
18
+ */
19
+ class CollectionS3Search extends CollectionSearch_1.CollectionSearch {
20
+ constructor(event, dbConnection) {
21
+ super(event);
22
+ this.dbConnection = dbConnection;
23
+ this.duckDBSearchExecutor = new DuckDBSearchExecutor_1.DuckDBSearchExecutor({
24
+ dbConnection,
25
+ dbQueryParameters: this.dbQueryParameters,
26
+ getMetaTemplate: this._metaTemplate.bind(this),
27
+ translateRecords: this.translatePostgresRecordsToApiRecords.bind(this),
28
+ });
29
+ }
30
+ /**
31
+ * Executes stats query to get granules' status aggregation
32
+ *
33
+ * @param collectionCumulusIds - array of cumulusIds of the collections
34
+ * @param knexClient - knex for the stats query
35
+ * @returns the collection's granules status' aggregation
36
+ */
37
+ async retrieveGranuleStats(collectionCumulusIds, knexClient) {
38
+ const granulesTable = tables_1.TableNames.granules;
39
+ let statsQuery = knexClient(granulesTable);
40
+ if (this.active) {
41
+ const granuleS3Search = new GranuleS3Search_1.GranuleS3Search({ queryStringParameters: this.queryStringParameters }, this.dbConnection);
42
+ const { countQuery } = granuleS3Search.buildSearchForActiveCollections(knexClient);
43
+ statsQuery = countQuery.clear('select');
44
+ }
45
+ statsQuery
46
+ .select(`${granulesTable}.collection_cumulus_id`, `${granulesTable}.status`)
47
+ .count('* as count')
48
+ .groupBy(`${granulesTable}.collection_cumulus_id`, `${granulesTable}.status`)
49
+ .whereIn(`${granulesTable}.collection_cumulus_id`, collectionCumulusIds);
50
+ log.debug(`retrieveGranuleStats statsQuery: ${statsQuery?.toSQL().sql}`);
51
+ const { sql, bindings } = statsQuery.toSQL().toNative();
52
+ const reader = await this.dbConnection.runAndReadAll(sql, (0, duckdbHelpers_1.prepareBindings)(bindings));
53
+ const results = reader.getRowObjectsJson();
54
+ const reduced = results.reduce((acc, record) => {
55
+ const cumulusId = Number(record.collection_cumulus_id);
56
+ if (!acc[cumulusId]) {
57
+ acc[cumulusId] = {
58
+ queued: 0,
59
+ completed: 0,
60
+ failed: 0,
61
+ running: 0,
62
+ total: 0,
63
+ };
64
+ }
65
+ acc[cumulusId][record.status] += Number(record.count);
66
+ acc[cumulusId]['total'] += Number(record.count);
67
+ return acc;
68
+ }, {});
69
+ return reduced;
70
+ }
71
+ /**
72
+ * Translate postgres records to api records
73
+ *
74
+ * @param pgRecords - postgres Collection records returned from query
75
+ * @param knexClient - knex for the stats query if incldueStats is true
76
+ * @returns translated api records
77
+ */
78
+ async translatePostgresRecordsToApiRecords(pgRecords, knexClient) {
79
+ log.debug(`translatePostgresRecordsToApiRecords number of records ${pgRecords.length} `);
80
+ const { fields } = this.dbQueryParameters;
81
+ let statsRecords;
82
+ const cumulusIds = pgRecords.map((record) => record.cumulus_id);
83
+ if (this.includeStats) {
84
+ statsRecords = await this.retrieveGranuleStats(cumulusIds, knexClient);
85
+ }
86
+ const apiRecords = pgRecords.map((record) => {
87
+ const apiRecord = (0, collections_1.translatePostgresCollectionToApiCollection)(record);
88
+ const apiRecordFinal = fields ? (0, pick_1.default)(apiRecord, fields) : apiRecord;
89
+ if (statsRecords) {
90
+ apiRecordFinal.stats = statsRecords[record.cumulus_id] ? statsRecords[record.cumulus_id]
91
+ : {
92
+ queued: 0,
93
+ completed: 0,
94
+ failed: 0,
95
+ running: 0,
96
+ total: 0,
97
+ };
98
+ }
99
+ return apiRecordFinal;
100
+ });
101
+ return apiRecords;
102
+ }
103
+ /**
104
+ * Build and execute search query
105
+ *
106
+ * @returns search result
107
+ */
108
+ async query() {
109
+ return this.duckDBSearchExecutor.query((knexBuilder) => this.buildSearch(knexBuilder));
110
+ }
111
+ }
112
+ exports.CollectionS3Search = CollectionS3Search;
113
+ //# sourceMappingURL=CollectionS3Search.js.map
@@ -0,0 +1,36 @@
1
+ import { Knex } from 'knex';
2
+ import { DuckDBConnection } from '@duckdb/node-api';
3
+ import { Meta } from '../search/BaseSearch';
4
+ import { DbQueryParameters } from '../types/search';
5
+ /**
6
+ * DuckDBSearchExecutor is a helper class for executing search queries on DuckDB.
7
+ * It wraps a DuckDB connection and provides a unified method to:
8
+ * - Build queries using Knex (Postgres dialect)
9
+ * - Execute them sequentially to avoid prepared statement conflicts
10
+ * - Transform raw database records into API-ready records
11
+ *
12
+ * This class is intended to be used by S3Search subclasses that inherit
13
+ * from BaseSearch, allowing them to reuse query logic while providing
14
+ * custom record translation.
15
+ */
16
+ export declare class DuckDBSearchExecutor {
17
+ private dbConnection;
18
+ private knexBuilder;
19
+ private dbQueryParameters;
20
+ private getMetaTemplate;
21
+ private translateRecords;
22
+ constructor(params: {
23
+ dbConnection: DuckDBConnection;
24
+ dbQueryParameters: DbQueryParameters;
25
+ getMetaTemplate: () => Meta;
26
+ translateRecords: (records: any[], knexClient: Knex) => any[] | Promise<any[]>;
27
+ });
28
+ query(buildSearch: (knex: Knex) => {
29
+ countQuery?: Knex.QueryBuilder;
30
+ searchQuery: Knex.QueryBuilder;
31
+ }): Promise<{
32
+ meta: Meta;
33
+ results: any[];
34
+ }>;
35
+ }
36
+ //# sourceMappingURL=DuckDBSearchExecutor.d.ts.map
@@ -0,0 +1,57 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.DuckDBSearchExecutor = void 0;
4
+ const knex_1 = require("knex");
5
+ const duckdbHelpers_1 = require("./duckdbHelpers");
6
+ /**
7
+ * DuckDBSearchExecutor is a helper class for executing search queries on DuckDB.
8
+ * It wraps a DuckDB connection and provides a unified method to:
9
+ * - Build queries using Knex (Postgres dialect)
10
+ * - Execute them sequentially to avoid prepared statement conflicts
11
+ * - Transform raw database records into API-ready records
12
+ *
13
+ * This class is intended to be used by S3Search subclasses that inherit
14
+ * from BaseSearch, allowing them to reuse query logic while providing
15
+ * custom record translation.
16
+ */
17
+ class DuckDBSearchExecutor {
18
+ constructor(params) {
19
+ this.dbConnection = params.dbConnection;
20
+ this.dbQueryParameters = params.dbQueryParameters;
21
+ this.getMetaTemplate = params.getMetaTemplate;
22
+ this.translateRecords = params.translateRecords;
23
+ // Use pg dialect to generate DuckDB-compatible SQL ($1, $2, etc.)
24
+ this.knexBuilder = (0, knex_1.knex)({ client: 'pg' });
25
+ }
26
+ async query(buildSearch) {
27
+ const { countQuery, searchQuery } = buildSearch(this.knexBuilder);
28
+ const shouldReturnCountOnly = this.dbQueryParameters.countOnly === true;
29
+ const queryConfigs = shouldReturnCountOnly
30
+ ? [{ key: 'count', query: countQuery }]
31
+ : [
32
+ { key: 'count', query: countQuery },
33
+ { key: 'records', query: searchQuery },
34
+ ];
35
+ let countResult = [];
36
+ let records = [];
37
+ // sequential execution (DuckDB cannot handle multiple prepared statements simultaneously)
38
+ for (const config of queryConfigs.filter((c) => c.query)) {
39
+ const { sql, bindings } = config.query.clone().toSQL().toNative();
40
+ // eslint-disable-next-line no-await-in-loop
41
+ const reader = await this.dbConnection.runAndReadAll(sql, (0, duckdbHelpers_1.prepareBindings)(bindings));
42
+ const result = reader.getRowObjectsJson();
43
+ if (config.key === 'count')
44
+ countResult = result;
45
+ else
46
+ records = result;
47
+ }
48
+ const meta = this.getMetaTemplate();
49
+ meta.limit = this.dbQueryParameters.limit;
50
+ meta.page = this.dbQueryParameters.page;
51
+ meta.count = Number(countResult[0]?.count ?? 0);
52
+ const apiRecords = await this.translateRecords(records, this.knexBuilder);
53
+ return { meta, results: apiRecords };
54
+ }
55
+ }
56
+ exports.DuckDBSearchExecutor = DuckDBSearchExecutor;
57
+ //# sourceMappingURL=DuckDBSearchExecutor.js.map
@@ -0,0 +1,20 @@
1
+ import { DuckDBConnection } from '@duckdb/node-api';
2
+ import { ExecutionSearch } from '../search/ExecutionSearch';
3
+ import { QueryEvent } from '../types/search';
4
+ /**
5
+ * Class to build and execute DuckDB search query for executions
6
+ */
7
+ export declare class ExecutionS3Search extends ExecutionSearch {
8
+ private duckDBSearchExecutor;
9
+ constructor(event: QueryEvent, dbConnection: DuckDBConnection);
10
+ /**
11
+ * Build and execute search query
12
+ *
13
+ * @returns search result
14
+ */
15
+ query(): Promise<{
16
+ meta: import("../search/BaseSearch").Meta;
17
+ results: any[];
18
+ }>;
19
+ }
20
+ //# sourceMappingURL=ExecutionS3Search.d.ts.map
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ExecutionS3Search = void 0;
4
+ const DuckDBSearchExecutor_1 = require("./DuckDBSearchExecutor");
5
+ const ExecutionSearch_1 = require("../search/ExecutionSearch");
6
+ /**
7
+ * Class to build and execute DuckDB search query for executions
8
+ */
9
+ class ExecutionS3Search extends ExecutionSearch_1.ExecutionSearch {
10
+ constructor(event, dbConnection) {
11
+ super(event, false); // disables estimateTableRowCount
12
+ this.duckDBSearchExecutor = new DuckDBSearchExecutor_1.DuckDBSearchExecutor({
13
+ dbConnection,
14
+ dbQueryParameters: this.dbQueryParameters,
15
+ getMetaTemplate: this._metaTemplate.bind(this),
16
+ translateRecords: this.translatePostgresRecordsToApiRecords.bind(this),
17
+ });
18
+ }
19
+ /**
20
+ * Build and execute search query
21
+ *
22
+ * @returns search result
23
+ */
24
+ async query() {
25
+ return this.duckDBSearchExecutor.query((knexBuilder) => this.buildSearch(knexBuilder));
26
+ }
27
+ }
28
+ exports.ExecutionS3Search = ExecutionS3Search;
29
+ //# sourceMappingURL=ExecutionS3Search.js.map
@@ -0,0 +1,31 @@
1
+ import { Knex } from 'knex';
2
+ import { DuckDBConnection } from '@duckdb/node-api';
3
+ import { ApiGranuleRecord } from '@cumulus/types/api/granules';
4
+ import { GranuleRecord, GranuleSearch } from '../search/GranuleSearch';
5
+ import { QueryEvent } from '../types/search';
6
+ /**
7
+ * Class to build and execute DuckDB search query for granules
8
+ */
9
+ export declare class GranuleS3Search extends GranuleSearch {
10
+ private dbConnection;
11
+ private duckDBSearchExecutor;
12
+ constructor(event: QueryEvent, dbConnection: DuckDBConnection);
13
+ /**
14
+ * Translate postgres records to api records
15
+ *
16
+ * @param pgRecords - postgres records returned from query
17
+ * @param knexClient - DB client
18
+ * @returns translated api records
19
+ */
20
+ protected translatePostgresRecordsToApiRecords(pgRecords: GranuleRecord[], knexClient: Knex): Promise<Partial<ApiGranuleRecord>[]>;
21
+ /**
22
+ * Build and execute search query
23
+ *
24
+ * @returns search result
25
+ */
26
+ query(): Promise<{
27
+ meta: import("../search/BaseSearch").Meta;
28
+ results: any[];
29
+ }>;
30
+ }
31
+ //# sourceMappingURL=GranuleS3Search.d.ts.map
@@ -0,0 +1,100 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.GranuleS3Search = void 0;
7
+ const pick_1 = __importDefault(require("lodash/pick"));
8
+ const logger_1 = __importDefault(require("@cumulus/logger"));
9
+ const duckdbHelpers_1 = require("./duckdbHelpers");
10
+ const DuckDBSearchExecutor_1 = require("./DuckDBSearchExecutor");
11
+ const GranuleSearch_1 = require("../search/GranuleSearch");
12
+ const granules_1 = require("../translate/granules");
13
+ const log = new logger_1.default({ sender: '@cumulus/db/GranuleS3Search' });
14
+ /**
15
+ * Class to build and execute DuckDB search query for granules
16
+ */
17
+ class GranuleS3Search extends GranuleSearch_1.GranuleSearch {
18
+ constructor(event, dbConnection) {
19
+ super(event, false); // disables estimateTableRowCount
20
+ this.dbConnection = dbConnection;
21
+ this.duckDBSearchExecutor = new DuckDBSearchExecutor_1.DuckDBSearchExecutor({
22
+ dbConnection,
23
+ dbQueryParameters: this.dbQueryParameters,
24
+ getMetaTemplate: this._metaTemplate.bind(this),
25
+ translateRecords: this.translatePostgresRecordsToApiRecords.bind(this),
26
+ });
27
+ }
28
+ /**
29
+ * Translate postgres records to api records
30
+ *
31
+ * @param pgRecords - postgres records returned from query
32
+ * @param knexClient - DB client
33
+ * @returns translated api records
34
+ */
35
+ async translatePostgresRecordsToApiRecords(pgRecords, knexClient) {
36
+ log.debug(`translatePostgresRecordsToApiRecords number of records ${pgRecords.length} `);
37
+ const { fields, includeFullRecord } = this.dbQueryParameters;
38
+ const fileMapping = {};
39
+ const executionMapping = {};
40
+ const cumulusIds = pgRecords.map((record) => record.cumulus_id);
41
+ if (includeFullRecord) {
42
+ //get files
43
+ const files = await (0, duckdbHelpers_1.getFilesByGranuleCumulusIds)({
44
+ connection: this.dbConnection,
45
+ granuleCumulusIds: cumulusIds,
46
+ knexBuilder: knexClient,
47
+ });
48
+ files.forEach((file) => {
49
+ if (!(file.granule_cumulus_id in fileMapping)) {
50
+ fileMapping[file.granule_cumulus_id] = [];
51
+ }
52
+ fileMapping[file.granule_cumulus_id].push(file);
53
+ });
54
+ //get Executions
55
+ const executions = await (0, duckdbHelpers_1.getExecutionInfoByGranuleCumulusIds)({
56
+ connection: this.dbConnection,
57
+ granuleCumulusIds: cumulusIds,
58
+ knexBuilder: knexClient,
59
+ });
60
+ executions.forEach((execution) => {
61
+ if (!(execution.granule_cumulus_id in executionMapping)) {
62
+ executionMapping[execution.granule_cumulus_id] = execution;
63
+ }
64
+ });
65
+ }
66
+ const apiRecords = pgRecords.map((item) => {
67
+ const collectionPgRecord = {
68
+ cumulus_id: item.collection_cumulus_id,
69
+ name: item.collectionName,
70
+ version: item.collectionVersion,
71
+ };
72
+ const executionUrls = executionMapping[item.cumulus_id]?.url
73
+ ? [{ url: executionMapping[item.cumulus_id].url }]
74
+ : [];
75
+ const pdr = item.pdrName ? { name: item.pdrName } : undefined;
76
+ const providerPgRecord = item.providerName ? { name: item.providerName } : undefined;
77
+ const fileRecords = fileMapping[item.cumulus_id] || [];
78
+ const apiRecord = (0, granules_1.translatePostgresGranuleToApiGranuleWithoutDbQuery)({
79
+ granulePgRecord: item,
80
+ collectionPgRecord,
81
+ pdr,
82
+ providerPgRecord,
83
+ files: fileRecords,
84
+ executionUrls,
85
+ });
86
+ return fields ? (0, pick_1.default)(apiRecord, fields) : apiRecord;
87
+ });
88
+ return apiRecords;
89
+ }
90
+ /**
91
+ * Build and execute search query
92
+ *
93
+ * @returns search result
94
+ */
95
+ async query() {
96
+ return this.duckDBSearchExecutor.query((knexBuilder) => this.buildSearch(knexBuilder));
97
+ }
98
+ }
99
+ exports.GranuleS3Search = GranuleS3Search;
100
+ //# sourceMappingURL=GranuleS3Search.js.map
@@ -0,0 +1,20 @@
1
+ import { DuckDBConnection } from '@duckdb/node-api';
2
+ import { PdrSearch } from '../search/PdrSearch';
3
+ import { QueryEvent } from '../types/search';
4
+ /**
5
+ * Class to build and execute DuckDB search query for PDRs
6
+ */
7
+ export declare class PdrS3Search extends PdrSearch {
8
+ private duckDBSearchExecutor;
9
+ constructor(event: QueryEvent, dbConnection: DuckDBConnection);
10
+ /**
11
+ * Build and execute search query
12
+ *
13
+ * @returns search result
14
+ */
15
+ query(): Promise<{
16
+ meta: import("../search/BaseSearch").Meta;
17
+ results: any[];
18
+ }>;
19
+ }
20
+ //# sourceMappingURL=PdrS3Search.d.ts.map
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.PdrS3Search = void 0;
4
+ const DuckDBSearchExecutor_1 = require("./DuckDBSearchExecutor");
5
+ const PdrSearch_1 = require("../search/PdrSearch");
6
+ /**
7
+ * Class to build and execute DuckDB search query for PDRs
8
+ */
9
+ class PdrS3Search extends PdrSearch_1.PdrSearch {
10
+ constructor(event, dbConnection) {
11
+ super(event);
12
+ this.duckDBSearchExecutor = new DuckDBSearchExecutor_1.DuckDBSearchExecutor({
13
+ dbConnection,
14
+ dbQueryParameters: this.dbQueryParameters,
15
+ getMetaTemplate: this._metaTemplate.bind(this),
16
+ translateRecords: this.translatePostgresRecordsToApiRecords.bind(this),
17
+ });
18
+ }
19
+ /**
20
+ * Build and execute search query
21
+ *
22
+ * @returns search result
23
+ */
24
+ async query() {
25
+ return this.duckDBSearchExecutor.query((knexBuilder) => this.buildSearch(knexBuilder));
26
+ }
27
+ }
28
+ exports.PdrS3Search = PdrS3Search;
29
+ //# sourceMappingURL=PdrS3Search.js.map
@@ -0,0 +1,20 @@
1
+ import { DuckDBConnection } from '@duckdb/node-api';
2
+ import { ProviderSearch } from '../search/ProviderSearch';
3
+ import { QueryEvent } from '../types/search';
4
+ /**
5
+ * Class to build and execute DuckDB search query for providers
6
+ */
7
+ export declare class ProviderS3Search extends ProviderSearch {
8
+ private duckDBSearchExecutor;
9
+ constructor(event: QueryEvent, dbConnection: DuckDBConnection);
10
+ /**
11
+ * Build and execute search query
12
+ *
13
+ * @returns search result
14
+ */
15
+ query(): Promise<{
16
+ meta: import("../search/BaseSearch").Meta;
17
+ results: any[];
18
+ }>;
19
+ }
20
+ //# sourceMappingURL=ProviderS3Search.d.ts.map
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.ProviderS3Search = void 0;
4
+ const DuckDBSearchExecutor_1 = require("./DuckDBSearchExecutor");
5
+ const ProviderSearch_1 = require("../search/ProviderSearch");
6
+ /**
7
+ * Class to build and execute DuckDB search query for providers
8
+ */
9
+ class ProviderS3Search extends ProviderSearch_1.ProviderSearch {
10
+ constructor(event, dbConnection) {
11
+ super(event);
12
+ this.duckDBSearchExecutor = new DuckDBSearchExecutor_1.DuckDBSearchExecutor({
13
+ dbConnection,
14
+ dbQueryParameters: this.dbQueryParameters,
15
+ getMetaTemplate: this._metaTemplate.bind(this),
16
+ translateRecords: this.translatePostgresRecordsToApiRecords.bind(this),
17
+ });
18
+ }
19
+ /**
20
+ * Build and execute search query
21
+ *
22
+ * @returns search result
23
+ */
24
+ async query() {
25
+ return this.duckDBSearchExecutor.query((knexBuilder) => this.buildSearch(knexBuilder));
26
+ }
27
+ }
28
+ exports.ProviderS3Search = ProviderS3Search;
29
+ //# sourceMappingURL=ProviderS3Search.js.map
@@ -0,0 +1,20 @@
1
+ import { DuckDBConnection } from '@duckdb/node-api';
2
+ import { ReconciliationReportSearch } from '../search/ReconciliationReportSearch';
3
+ import { QueryEvent } from '../types/search';
4
+ /**
5
+ * Class to build and execute DuckDB search query for Reconciliation Report
6
+ */
7
+ export declare class ReconciliationReportS3Search extends ReconciliationReportSearch {
8
+ private duckDBSearchExecutor;
9
+ constructor(event: QueryEvent, dbConnection: DuckDBConnection);
10
+ /**
11
+ * Build and execute search query
12
+ *
13
+ * @returns search result
14
+ */
15
+ query(): Promise<{
16
+ meta: import("../search/BaseSearch").Meta;
17
+ results: any[];
18
+ }>;
19
+ }
20
+ //# sourceMappingURL=ReconciliationReportS3Search.d.ts.map