-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
[Feature] Add a second version implementation of get table schema and partition API. #41938
[Feature] Add a second version implementation of get table schema and partition API. #41938
Conversation
5fcb372
to
204eea9
Compare
3ecf130
to
cccd226
Compare
cccd226
to
e91bd5b
Compare
@@ -197,4 +219,42 @@ public boolean redirectToLeader(BaseRequest request, BaseResponse response) thro | |||
new TNetworkAddress(leaderIpAndPort.first, leaderIpAndPort.second)); | |||
return true; | |||
} | |||
|
|||
protected static String getParameter(BaseRequest request, String paramName) { |
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.
while these getParameters
are good help functions, thinking about a few improvements,
getParameter()
return null if the paremter doesn't exist, it is up to the caller to determine what to do.getParameterRequired()
throws BAD_REQUEST http exception if the parameter is not there.getParameterOrDefault()
returns default value if the parameter is not there.- generic programming, getParameter for int/boolean/string/double/...,
org.apache.hadoop.conf.Configuration might be a good reference for these interfaces.
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.
@kevincai Good suggestions.
fe/fe-core/src/main/java/com/starrocks/http/rest/v2/vo/TablePartitionView.java
Outdated
Show resolved
Hide resolved
e91bd5b
to
26e5330
Compare
.orElse(DEFAULT_INTERNAL_CATALOG_NAME).equalsIgnoreCase(catalogName)) { | ||
throw new StarRocksHttpException( | ||
HttpResponseStatus.NOT_FOUND, | ||
String.format("Database[%s] does not exist in catalog %s", dbName, catalogName) |
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.
Will this message be shown to users?
If yes, put it into ErrorCode.java
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.
Yeah, and I found that I can reuse some existing ErrorCode.
if (null == table) { | ||
throw new StarRocksHttpException( | ||
HttpResponseStatus.NOT_FOUND, | ||
String.format("Table[%s.%s] does not exist in catalog %s", dbName, tableName, catalogName) |
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.
Same as above.
|
||
OlapTable olapTable = getOlapTable(catalogName, dbName, tableName); | ||
Collection<Partition> partitions = | ||
temporary ? olapTable.getTempPartitions() : olapTable.getPartitions(); |
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.
Do we need to lock the table to get a partition snapshot?
Or will the olapTable be modified when geting partitions.
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.
Yeah, It is a problem, and i encapsulated the processing logic of OlapTable into the db read lock.
Collection<Partition> partitions = | ||
temporary ? olapTable.getTempPartitions() : olapTable.getPartitions(); | ||
if (CollectionUtils.isNotEmpty(partitions)) { | ||
int pages = partitions.size() / pageSize; | ||
pagedResult.setPages(partitions.size() % pageSize == 0 ? pages : (pages + 1)); | ||
pagedResult.setTotal(partitions.size()); | ||
pagedResult.setItems(partitions.stream() | ||
.sorted(Comparator.comparingLong(Partition::getId)) | ||
.skip((long) pageNum * pageSize) | ||
.limit(pageSize) | ||
.map(partition -> | ||
TablePartitionView.createFrom(olapTable.getPartitionInfo(), partition)) | ||
.collect(Collectors.toList()) | ||
); | ||
} |
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.
need read lock
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.
Yeah, It is a problem, and i encapsulated the processing logic of OlapTable into the db read lock.
String tableName = getSingleParameterRequired(request, TABLE_KEY, Function.identity()); | ||
|
||
OlapTable olapTable = getOlapTable(catalogName, dbName, tableName); | ||
sendResult(request, response, new RestBaseResultV2<>(TableSchemaView.createFrom(olapTable))); |
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.
need read lock
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.
Yeah, It is a problem, and i encapsulated the processing logic of OlapTable into the db read lock.
f5acdcd
f5acdcd
to
6271a96
Compare
@@ -110,7 +122,7 @@ public String getErrorRespWhenUnauthorized(AccessDeniedException accessDeniedExc | |||
List<String> activatedRoles = authorizationMgr.getRoleNamesByRoleIds(context.getCurrentRoleIds()); | |||
List<String> inactivatedRoles = | |||
authorizationMgr.getInactivatedRoleNamesByUser(userIdentity, activatedRoles); | |||
return "Access denied for user " + userIdentity + ". " + | |||
return "Access denied for user " + userIdentity + ". " + |
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.
You can use ErrorCode.ERR_AUTHENTICATION_FAIL
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 change is caused by code formatting, and have nothing to do with the business logic of this PR. I have rolled it back to make this PR more focused.
@@ -110,7 +122,7 @@ public String getErrorRespWhenUnauthorized(AccessDeniedException accessDeniedExc | |||
List<String> activatedRoles = authorizationMgr.getRoleNamesByRoleIds(context.getCurrentRoleIds()); | |||
List<String> inactivatedRoles = | |||
authorizationMgr.getInactivatedRoleNamesByUser(userIdentity, activatedRoles); | |||
return "Access denied for user " + userIdentity + ". " + | |||
return "Access denied for user " + userIdentity + ". " + | |||
String.format(ErrorCode.ERR_ACCESS_DENIED_HINT_MSG_FORMAT, activatedRoles, inactivatedRoles); | |||
} | |||
return "Access denied."; |
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.
Will it be too simple to let user know the error reason?
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 intended to do so, because we cannot get any more specific info.
} else if (dateLiteral.getType().isDatetime()) { | ||
return dateLiteral.getLongValue(); | ||
} else { | ||
throw new StarRocksPlannerException("Invalid date type: " + dateLiteral.getType(), ErrorType.INTERNAL_ERROR); |
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 put into ErrorCode?
import java.util.Optional; | ||
import java.util.stream.Collectors; | ||
|
||
public class TablePartitionView { |
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 this class be merged with PartitionInfoView
?
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.
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.
LGTM
6271a96
to
9085e31
Compare
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.
The error msgs LGTM
@mergify rebase |
… partition API. Signed-off-by: plotor <[email protected]>
✅ Branch has been successfully rebased |
9085e31
to
58f48d0
Compare
|
[FE Incremental Coverage Report]✅ pass : 526 / 559 (94.10%) file detail
|
[BE Incremental Coverage Report]✅ pass : 0 / 0 (0%) |
Why I'm doing:
You can learn about the background from PR #38466.
What I'm doing:
This is a relatively big feature, and we will split it into multiple PRs. Related PRs include:
This PR is one of them, which mainly add a second version implementation of get table schema and partition API. This version of the API is designed to be as neutral as possible, and not tied to specific scenarios. Howeaver, there are still some usage restrictions to note:
OlapTable
.The API of Get Table Schema and Partition are defined as follows:
Get Table Schema API Definition
/api/v2/catalogs/{catalog}/databases/{db}/tables/{table}/schema
GET
default_catalog
Response Example:
Get Table Partition API Definition
/api/v2/catalogs/{catalog}/databases/{db}/tables/{table}/partition
GET
default_catalog
true
, If set to true, it means get temporary partition infoThe response template is as follows:
Parameter description:
pageNum
: the page number in request.pageSize
: the page size in request.pages
: total page size.total
: total item size.items
: data items.Response Example:
Fixes #issue
What type of PR is this:
Does this PR entail a change in behavior?
If yes, please specify the type of change:
Checklist:
Bugfix cherry-pick branch check: