-
Notifications
You must be signed in to change notification settings - Fork 350
[CDAP-21172] Implement Search functionality for Metadata Tables #15990
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Conversation
| return performSpannerSearch(request, cursor); | ||
| } | ||
|
|
||
| private io.cdap.cdap.spi.metadata.SearchResponse doSearch(SearchRequest request) throws IOException { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we import this SearchResponse class?
|
|
||
| LOG.info(sql); | ||
| LOG.info(statement.toString()); | ||
| LOG.info(resultSet.toString()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
log statements should be informative
|
|
||
| if (results.isEmpty()) { | ||
| nextCursor = null; | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add space
| throw new IOException("Spanner search failed", e); | ||
| } | ||
| } | ||
| private MetadataRecord mapSpannerResult(ResultSet resultSet) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
even though its privat function please add the comment about what this function is supposed to do
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
added javadocs
| Metadata metadata = parseMetadataFromJson(metadataString); | ||
| MetadataEntity entity = toMetadataEntity(documentId); | ||
|
|
||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why 9?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
removed the harcoded part
| } | ||
| } | ||
| private MetadataRecord mapSpannerResult(ResultSet resultSet) { | ||
| String documentId = resultSet.getString("metadata_id"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we have const for this
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
updated
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
rephrase the comment
| throw new IOException("NOT IMPLEMENTED"); | ||
| return request.getCursor() != null && !request.getCursor().isEmpty() | ||
| ? doScroll(request) : doSearch(request); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add space
| LOG.info("Found {} results.", results.size()); | ||
|
|
||
| return createSearchResponse(request, results, nextActualCursor); | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
namespace default value is default.
| @VisibleForTesting | ||
| static final boolean KEEP = true; | ||
| @VisibleForTesting | ||
| static final boolean DISCARD = false; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
okk
| 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
updated
| 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please combine the log statements.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
combined
|


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.