[CDAP-21172] Implement Search functionality for Metadata Tables #15990
[CDAP-21172] Implement Search functionality for Metadata Tables #15990
Conversation
| return performSpannerSearch(request, cursor); | ||
| } | ||
|
|
||
| private io.cdap.cdap.spi.metadata.SearchResponse doSearch(SearchRequest request) throws IOException { |
There was a problem hiding this comment.
can we import this SearchResponse class?
|
|
||
| LOG.info(sql); | ||
| LOG.info(statement.toString()); | ||
| LOG.info(resultSet.toString()); |
There was a problem hiding this comment.
log statements should be informative
|
|
||
| if (results.isEmpty()) { | ||
| nextCursor = null; | ||
| } |
There was a problem hiding this comment.
this can be simplified I think can we use stream?
| return createSpannerSearchResponse(request, results, nextCursor); | ||
| } catch (SpannerException e) { | ||
| throw new IOException("Spanner search failed", e); | ||
| } |
There was a problem hiding this comment.
this is the internal function is it okay to let the function throw original exception and the caller should wrap it as needed?
| throw new IOException("Spanner search failed", e); | ||
| } | ||
| } | ||
| private MetadataRecord mapSpannerResult(ResultSet resultSet) { |
| throw new IOException("Spanner search failed", e); | ||
| } | ||
| } | ||
| private MetadataRecord mapSpannerResult(ResultSet resultSet) { |
There was a problem hiding this comment.
even though its privat function please add the comment about what this function is supposed to do
| Metadata metadata = parseMetadataFromJson(metadataString); | ||
| MetadataEntity entity = toMetadataEntity(documentId); | ||
|
|
||
|
|
There was a problem hiding this comment.
remove extra space
| String documentId = resultSet.getString("metadata_id"); | ||
| Struct row = resultSet.getCurrentRowAsStruct(); | ||
| LOG.info(row.toString()); | ||
| String metadataString = row.getJson(9); |
There was a problem hiding this comment.
removed the harcoded part
| } | ||
| } | ||
| private MetadataRecord mapSpannerResult(ResultSet resultSet) { | ||
| String documentId = resultSet.getString("metadata_id"); |
There was a problem hiding this comment.
can we have const for this
f4e1fa5 to
79d7f0b
Compare
| private DatabaseClient dbClient; | ||
| private DatabaseAdminClient adminClient; | ||
|
|
||
| // Define the wildcard characters you support for user input |
There was a problem hiding this comment.
rephrase the comment
| throw new IOException("NOT IMPLEMENTED"); | ||
| return request.getCursor() != null && !request.getCursor().isEmpty() | ||
| ? doScroll(request) : doSearch(request); | ||
| } |
| LOG.info("Found {} results.", results.size()); | ||
|
|
||
| return createSearchResponse(request, results, nextActualCursor); | ||
|
|
There was a problem hiding this comment.
remove extra space
a4409ff to
7f50de8
Compare
f0ff86a to
7f9ee57
Compare
449aea3 to
30020b0
Compare
ef0dd76 to
aa6d333
Compare
d6884fe to
de60c7c
Compare
f71c5d1 to
ca54c13
Compare
updated updated updated updated updated updated updated [CDAP-21172] Implement CRUD Operations for Metadata Tables updated updated updated updated updated updated updated formatted updated updated resolved checkstyle warnings updated updated updated updated updated updated updated formatted formatted updated updated updated formatted formatted updated updated [CDAP-21172] Implement the Search functionality updated updated updated updated updated updated updated updated updated updated updated updated updated updated updated updated updated updated
| private FormattedMetadata(MetadataEntity entity, Metadata metadata) throws IOException { | ||
| this.namespace = entity.getValue("namespace"); | ||
| this.namespace = Optional.ofNullable(entity.getValue("namespace")) | ||
| .orElse("default"); |
There was a problem hiding this comment.
Is namespace is null, is it ok to use default value default or could it be system as well?
There was a problem hiding this comment.
namespace default value is default.
| @VisibleForTesting | ||
| static final boolean KEEP = true; | ||
| @VisibleForTesting | ||
| static final boolean DISCARD = false; |
There was a problem hiding this comment.
No need to define const for these as they have single usage in source code. Use the boolean values in place.
For test code also use boolean values.
| public SearchResponse search(SearchRequest request) throws IOException { | ||
| throw new IOException("NOT IMPLEMENTED"); | ||
| public SearchResponse search(SearchRequest request) { | ||
| Cursor cursor = Optional.ofNullable(request.getCursor()) |
There was a problem hiding this comment.
Can be simplified as:
Cursor cursor = Strings.isNullOrEmpty(request.getCursor()) ? null : Cursor.fromString(request.getCursor());
return doSearch(request, cursor);
OR
Cursor cursor;
if !Strings.isNullOrEmpty(request.getCursor()) {
cursor = Cursor.fromString(request.getCursor());
}
return doSearch(request, cursor);
| params.forEach((key, value) -> statementBuilder.bind(key).to(value)); | ||
| Statement statement = statementBuilder.build(); | ||
|
|
||
| LOG.info("Executing Spanner SQL Template: {}", statement.getSql()); |
There was a problem hiding this comment.
Please combine the log statements.
|


Description:
This PR is the follow-up for #15986 and here we are temporarily building this module separately as a workaround for a dependency issue that breaks the unified build. Its key changes are listed below:
Testing:
MetadataStorageclasses are defined in theMetadataStorageTestclass.