15
15
*/
16
16
package com .dqops .core .jobqueue .jobs .table ;
17
17
18
- import com .dqops .connectors .ConnectionProvider ;
19
- import com .dqops .connectors .ConnectionProviderRegistry ;
20
- import com .dqops .connectors .ProviderType ;
21
- import com .dqops .connectors .SourceConnection ;
18
+ import com .dqops .connectors .*;
22
19
import com .dqops .core .configuration .DqoMetadataImportConfigurationProperties ;
23
20
import com .dqops .core .jobqueue .DqoJobExecutionContext ;
24
21
import com .dqops .core .jobqueue .DqoJobType ;
32
29
import com .dqops .core .principal .UserDomainIdentity ;
33
30
import com .dqops .core .secrets .SecretValueLookupContext ;
34
31
import com .dqops .core .secrets .SecretValueProvider ;
32
+ import com .dqops .metadata .search .pattern .SearchPattern ;
35
33
import com .dqops .metadata .sources .*;
36
34
import com .dqops .metadata .storage .localfiles .userhome .UserHomeContext ;
37
35
import com .dqops .metadata .storage .localfiles .userhome .UserHomeContextFactory ;
38
36
import com .dqops .metadata .userhome .UserHome ;
37
+ import org .apache .parquet .Strings ;
39
38
import org .springframework .beans .factory .annotation .Autowired ;
40
39
import org .springframework .beans .factory .config .ConfigurableBeanFactory ;
41
40
import org .springframework .context .annotation .Scope ;
45
44
import tech .tablesaw .api .Table ;
46
45
import tech .tablesaw .api .TextColumn ;
47
46
47
+ import java .util .ArrayList ;
48
48
import java .util .List ;
49
49
import java .util .stream .Collectors ;
50
50
@@ -94,10 +94,7 @@ public void setImportParameters(ImportTablesQueueJobParameters importParameters)
94
94
*/
95
95
public Table createDatasetTableFromTableSpecs (List <TableSpec > sourceTableSpecs ) {
96
96
// TODO: move method to tablesaw utils (repeated in ImportSchemaQueueJob).
97
- Table resultTable = Table .create ().addColumns (
98
- TextColumn .create ("Schema name" ),
99
- TextColumn .create ("Table name" ),
100
- IntColumn .create ("Column count" ));
97
+ Table resultTable = createEmptyOutputResult ();
101
98
102
99
for (TableSpec sourceTableSpec : sourceTableSpecs ) {
103
100
Row row = resultTable .appendRow ();
@@ -108,6 +105,17 @@ public Table createDatasetTableFromTableSpecs(List<TableSpec> sourceTableSpecs)
108
105
return resultTable ;
109
106
}
110
107
108
+ /**
109
+ * Creates an empty result table
110
+ * @return Empty result table.
111
+ */
112
+ private Table createEmptyOutputResult () {
113
+ return Table .create ().addColumns (
114
+ TextColumn .create ("Schema name" ),
115
+ TextColumn .create ("Table name" ),
116
+ IntColumn .create ("Column count" ));
117
+ }
118
+
111
119
/**
112
120
* Job internal implementation method that should be implemented by derived jobs.
113
121
*
@@ -134,27 +142,71 @@ public ImportTablesResult onExecute(DqoJobExecutionContext jobExecutionContext)
134
142
135
143
ProviderType providerType = expandedConnectionSpec .getProviderType ();
136
144
ConnectionProvider connectionProvider = this .connectionProviderRegistry .getConnectionProvider (providerType );
145
+
146
+ String schemaNameFilter = Strings .isNullOrEmpty (this .importParameters .getSchemaName ()) ? "*" : this .importParameters .getSchemaName ();
147
+ SearchPattern schemaSearchPattern = SearchPattern .create (false , schemaNameFilter );
148
+
137
149
try (SourceConnection sourceConnection = connectionProvider .createConnection (expandedConnectionSpec , true , secretValueLookupContext )) {
138
- List <TableSpec > sourceTableSpecs = sourceConnection .retrieveTableMetadata (
139
- this .importParameters .getSchemaName (),
140
- this .importParameters .getTableNameContains (),
141
- this .metadataImportConfigurationProperties .getTablesImportLimit (),
142
- this .importParameters .getTableNames (),
143
- connectionWrapper ,
144
- secretValueLookupContext );
145
-
146
- List <TableSpec > importedTablesSpecs = sourceTableSpecs
147
- .stream ()
148
- .map (tableSpec -> tableSpec .deepClone ())
149
- .collect (Collectors .toList ());
150
-
151
- TableList currentTablesColl = connectionWrapper .getTables ();
152
- currentTablesColl .importTables (importedTablesSpecs , connectionSpec .getDefaultGroupingConfiguration ());
153
- userHomeContext .flush ();
154
-
155
- Table resultTable = createDatasetTableFromTableSpecs (importedTablesSpecs );
156
-
157
- return new ImportTablesResult (resultTable , sourceTableSpecs );
150
+ if (schemaSearchPattern .isWildcardSearchPattern ()) {
151
+ // must iterate over schemas
152
+ List <SourceSchemaModel > sourceSchemaModels = sourceConnection .listSchemas ();
153
+ jobExecutionContext .getCancellationToken ().throwIfCancelled ();
154
+ List <TableSpec > fullTableList = new ArrayList <>();
155
+ Table fullTableResult = createEmptyOutputResult ();
156
+
157
+ for (SourceSchemaModel sourceSchemaModel : sourceSchemaModels ) {
158
+ jobExecutionContext .getCancellationToken ().throwIfCancelled ();
159
+
160
+ if (!schemaSearchPattern .match (sourceSchemaModel .getSchemaName ())) {
161
+ continue ;
162
+ }
163
+
164
+ List <TableSpec > sourceTableSpecs = sourceConnection .retrieveTableMetadata (
165
+ sourceSchemaModel .getSchemaName (),
166
+ this .importParameters .getTableNameContains (),
167
+ this .metadataImportConfigurationProperties .getTablesImportLimit (),
168
+ this .importParameters .getTableNames (),
169
+ connectionWrapper ,
170
+ secretValueLookupContext );
171
+
172
+ List <TableSpec > importedTablesSpecs = sourceTableSpecs
173
+ .stream ()
174
+ .map (tableSpec -> tableSpec .deepClone ())
175
+ .collect (Collectors .toList ());
176
+
177
+ TableList currentTablesColl = connectionWrapper .getTables ();
178
+ currentTablesColl .importTables (importedTablesSpecs , connectionSpec .getDefaultGroupingConfiguration ());
179
+ fullTableList .addAll (importedTablesSpecs );
180
+
181
+ Table resultTable = createDatasetTableFromTableSpecs (importedTablesSpecs );
182
+ fullTableResult .append (resultTable );
183
+ }
184
+
185
+ userHomeContext .flush ();
186
+ return new ImportTablesResult (fullTableResult , fullTableList );
187
+ } else {
188
+ // only one schema
189
+ List <TableSpec > sourceTableSpecs = sourceConnection .retrieveTableMetadata (
190
+ this .importParameters .getSchemaName (),
191
+ this .importParameters .getTableNameContains (),
192
+ this .metadataImportConfigurationProperties .getTablesImportLimit (),
193
+ this .importParameters .getTableNames (),
194
+ connectionWrapper ,
195
+ secretValueLookupContext );
196
+
197
+ List <TableSpec > importedTablesSpecs = sourceTableSpecs
198
+ .stream ()
199
+ .map (tableSpec -> tableSpec .deepClone ())
200
+ .collect (Collectors .toList ());
201
+
202
+ TableList currentTablesColl = connectionWrapper .getTables ();
203
+ currentTablesColl .importTables (importedTablesSpecs , connectionSpec .getDefaultGroupingConfiguration ());
204
+ userHomeContext .flush ();
205
+
206
+ Table resultTable = createDatasetTableFromTableSpecs (importedTablesSpecs );
207
+
208
+ return new ImportTablesResult (resultTable , sourceTableSpecs );
209
+ }
158
210
}
159
211
}
160
212
0 commit comments