zhjwpku commented on code in PR #614:
URL: https://github.com/apache/iceberg-cpp/pull/614#discussion_r3141263763
##########
src/iceberg/catalog/rest/json_serde.cc:
##########
@@ -506,6 +523,114 @@ Result<OAuthTokenResponse>
OAuthTokenResponseFromJson(const nlohmann::json& json
return response;
}
+Result<nlohmann::json> ToJson(const PlanTableScanRequest& request) {
+ nlohmann::json json;
+ if (request.snapshot_id.has_value()) {
+ json[kSnapshotId] = request.snapshot_id.value();
+ }
+ if (!request.select.empty()) {
+ json[kSelect] = request.select;
+ }
+ if (request.filter) {
+ ICEBERG_ASSIGN_OR_RAISE(auto filter_json,
iceberg::ToJson(*request.filter));
+ json[kFilter] = std::move(filter_json);
+ }
+ json[kCaseSensitive] = request.case_sensitive;
+ json[kUseSnapshotSchema] = request.use_snapshot_schema;
+ if (request.start_snapshot_id.has_value()) {
+ json[kStartSnapshotId] = request.start_snapshot_id.value();
+ }
+ if (request.end_snapshot_id.has_value()) {
+ json[kEndSnapshotId] = request.end_snapshot_id.value();
+ }
+ if (!request.statsFields.empty()) {
+ json[kStatsFields] = request.statsFields;
+ }
+ if (request.min_rows_required.has_value()) {
+ json[kMinRowsRequired] = request.min_rows_required.value();
+ }
+ return json;
+}
+
+nlohmann::json ToJson(const FetchScanTasksRequest& request) {
+ nlohmann::json json;
+ json[kPlanTask] = request.planTask;
+ return json;
+}
+
+Status BaseScanTaskResponseFromJson(
Review Comment:
This looks like a helper function that isn's exposed in the header; perhaps
it should be placed in an anonymous namespace?
##########
src/iceberg/catalog/rest/resource_paths.cc:
##########
@@ -102,4 +102,26 @@ Result<std::string> ResourcePaths::CommitTransaction()
const {
return std::format("{}/v1/{}transactions/commit", base_uri_, prefix_);
}
+Result<std::string> ResourcePaths::ScanPlan(const TableIdentifier& ident)
const {
+ ICEBERG_ASSIGN_OR_RAISE(std::string encoded_namespace,
EncodeNamespace(ident.ns));
+ ICEBERG_ASSIGN_OR_RAISE(std::string encoded_table_name,
EncodeString(ident.name));
+ return std::format("{}/v1/{}namespaces/{}/tables/{}/plan", base_uri_,
prefix_,
+ encoded_namespace, encoded_table_name);
+}
+
+Result<std::string> ResourcePaths::ScanPlan(const TableIdentifier& ident,
+ const std::string& plan_id) const {
+ ICEBERG_ASSIGN_OR_RAISE(std::string encoded_namespace,
EncodeNamespace(ident.ns));
+ ICEBERG_ASSIGN_OR_RAISE(std::string encoded_table_name,
EncodeString(ident.name));
+ return std::format("{}/v1/{}namespaces/{}/tables/{}/plan/{}", base_uri_,
prefix_,
+ encoded_namespace, encoded_table_name, plan_id);
Review Comment:
Should we also encode plan_id?
##########
src/iceberg/catalog/rest/error_handlers.cc:
##########
@@ -183,4 +186,32 @@ Status ViewCommitErrorHandler::Accept(const ErrorResponse&
error) const {
return DefaultErrorHandler::Accept(error);
}
+const std::shared_ptr<ScanPlanErrorHandler>& ScanPlanErrorHandler::Instance() {
+ static const std::shared_ptr<ScanPlanErrorHandler> instance{new
ScanPlanErrorHandler()};
+ return instance;
+}
+
+Status ScanPlanErrorHandler::Accept(const ErrorResponse& error) const {
+ switch (error.code) {
+ case 404:
+ if (error.type == kNoSuchNamespaceException) {
+ return NoSuchNamespace(error.message);
+ }
+ if (error.type == kNoSuchTableException) {
+ return NoSuchTable(error.message);
+ }
+ if (error.type == kNoSuchPlanIdException) {
+ return NoSuchPlanId(error.message);
+ }
+ if (error.type == kNoSuchPlanTaskException) {
Review Comment:
Should we add a PlanTask level error handler like java implementation? see
https://github.com/apache/iceberg/blob/main/core/src/main/java/org/apache/iceberg/rest/ErrorHandlers.java#L197
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]