Skip to content

Commit 11a830b

Browse files
committed
Searching columns globally by labels filters only by labels assigned to the column.
1 parent c24793b commit 11a830b

File tree

4 files changed

+48
-1
lines changed

4 files changed

+48
-1
lines changed

dqops/src/main/java/com/dqops/metadata/search/ColumnSearchFilters.java

+40
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,10 @@ public class ColumnSearchFilters {
5555
"The labels are assigned on the labels screen and stored in the *labels* node in the *.dqotable.yaml* file.")
5656
private String[] labels;
5757

58+
@JsonPropertyDescription("An array of labels assigned only to a column. All labels must be present on a column to match. The labels can use patterns: 'prefix\\*', '\\*suffix', 'prefix\\*suffix'. " +
59+
"The labels are assigned on the labels screen and stored in the *labels* node in the *.dqotable.yaml* file.")
60+
private String[] columnLabels;
61+
5862
@JsonPropertyDescription("Optional limit for the maximum number of results to return.")
5963
private Integer maxResults;
6064

@@ -68,6 +72,9 @@ public class ColumnSearchFilters {
6872
private SearchPattern[] tagsSearchPatterns;
6973
@JsonIgnore
7074
private SearchPattern[] labelsSearchPatterns;
75+
@JsonIgnore
76+
private SearchPattern[] columnLabelSearchPatterns;
77+
7178

7279
/**
7380
* Create a hierarchy tree node traversal visitor that will search for nodes matching the current filter.
@@ -207,6 +214,22 @@ public void setLabels(String[] labels) {
207214
this.labels = labels;
208215
}
209216

217+
/**
218+
* Returns a list of labels that must be present only on a column.
219+
* @return Column level labels.
220+
*/
221+
public String[] getColumnLabels() {
222+
return columnLabels;
223+
}
224+
225+
/**
226+
* Sets a filter with a list of labels that must be present on a column (not a table).
227+
* @param columnLabels Column level label filters.
228+
*/
229+
public void setColumnLabels(String[] columnLabels) {
230+
this.columnLabels = columnLabels;
231+
}
232+
210233
/**
211234
* Sets the limit for the maximum number of results to return.
212235
* @return Limit or null.
@@ -298,4 +321,21 @@ public SearchPattern getLabelSearchPatternAt(int i) {
298321

299322
return labelsSearchPatterns[i];
300323
}
324+
325+
/**
326+
* Returns the {@link SearchPattern} related to a specific column label in <code>labels</code>.
327+
* Lazy getter, parses each <code>label</code> as a search pattern when requested and returns parsed object.
328+
* @param i Index of requested label search pattern. Corresponds to <code>labels[i]</code>.
329+
* @return {@link SearchPattern} related to <code>i</code>'th <code>label</code>.
330+
*/
331+
public SearchPattern getColumnLabelSearchPatternAt(int i) {
332+
if (columnLabelSearchPatterns == null) {
333+
columnLabelSearchPatterns = new SearchPattern[columnLabels.length];
334+
}
335+
if (columnLabelSearchPatterns[i] == null && columnLabels[i] != null) {
336+
columnLabelSearchPatterns[i] = SearchPattern.create(false, columnLabels[i]);
337+
}
338+
339+
return columnLabelSearchPatterns[i];
340+
}
301341
}

dqops/src/main/java/com/dqops/metadata/search/ColumnSearchFiltersVisitor.java

+4
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,10 @@ public TreeNodeTraversalResult accept(ColumnSpec columnSpec, SearchParameterObje
264264
return TreeNodeTraversalResult.SKIP_CHILDREN;
265265
}
266266

267+
if (this.filters.getColumnLabels() != null && !LabelsSearchMatcher.hasAllLabels(this.filters.getColumnLabels(), columnSpec.getLabels())) {
268+
return TreeNodeTraversalResult.SKIP_CHILDREN;
269+
}
270+
267271
String columnNameFilter = this.filters.getColumnName();
268272
if (Strings.isNullOrEmpty(columnNameFilter)) {
269273
parameter.getNodes().add(columnSpec);

dqops/src/main/java/com/dqops/metadata/search/LabelsSearchMatcher.java

+3
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,9 @@ public static boolean hasAllLabels(String[] requiredLabels, LabelSetSpec labels)
134134
if (requiredLabels == null) {
135135
return true;
136136
}
137+
if (labels == null && requiredLabels.length > 0) {
138+
return false;
139+
}
137140
for (String label : requiredLabels) {
138141
if (!containsPattern(label, labels)) {
139142
return false;

dqops/src/main/java/com/dqops/rest/controllers/SearchController.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ public ResponseEntity<Flux<ColumnListModel>> findColumns(
272272
columnSearchFilters.setSchemaTableName(tableNameFilter + "." + schemaNameFilter);
273273

274274
if (label.isPresent() && label.get().size() > 0) {
275-
columnSearchFilters.setLabels(label.get().toArray(String[]::new));
275+
columnSearchFilters.setColumnLabels(label.get().toArray(String[]::new));
276276
}
277277

278278
columnSearchFilters.setColumnName(column.orElse(null));

0 commit comments

Comments
 (0)