Skip to content

Commit 319a899

Browse files
authored
impl(bigquery): Dataset api response field name changes (#12155)
Fixes Issue #12110
1 parent 7c4bd27 commit 319a899

9 files changed

Lines changed: 191 additions & 288 deletions

File tree

google/cloud/bigquery/v2/minimal/internal/dataset.cc

Lines changed: 118 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -43,69 +43,63 @@ TargetType TargetType::Views() { return TargetType{"VIEWS"}; }
4343
TargetType TargetType::Routines() { return TargetType{"ROUTINES"}; }
4444

4545
void to_json(nlohmann::json& j, Dataset const& d) {
46-
j = nlohmann::json{
47-
{"kind", d.kind},
48-
{"etag", d.etag},
49-
{"id", d.id},
50-
{"self_link", d.self_link},
51-
{"friendly_name", d.friendly_name},
52-
{"description", d.description},
53-
{"type", d.type},
54-
{"location", d.location},
55-
{"default_collation", d.default_collation},
56-
{"published", d.published},
57-
{"is_case_insensitive", d.is_case_insensitive},
58-
{"labels", d.labels},
59-
{"access", d.access},
60-
{"tags", d.tags},
61-
{"dataset_reference", d.dataset_reference},
62-
63-
{"linked_dataset_source", d.linked_dataset_source},
64-
{"external_dataset_reference", d.external_dataset_reference},
65-
{"default_rounding_mode", d.default_rounding_mode},
66-
{"storage_billing_model", d.storage_billing_model}};
67-
68-
ToJson(d.default_table_expiration, j, "default_table_expiration");
69-
ToJson(d.default_partition_expiration, j, "default_partition_expiration");
70-
ToJson(d.creation_time, j, "creation_time");
71-
ToJson(d.last_modified_time, j, "last_modified_time");
72-
ToJson(d.max_time_travel, j, "max_time_travel");
46+
j = nlohmann::json{{"kind", d.kind},
47+
{"etag", d.etag},
48+
{"id", d.id},
49+
{"selfLink", d.self_link},
50+
{"friendlyName", d.friendly_name},
51+
{"description", d.description},
52+
{"type", d.type},
53+
{"location", d.location},
54+
{"defaultCollation", d.default_collation},
55+
{"published", d.published},
56+
{"isCaseInsensitive", d.is_case_insensitive},
57+
{"labels", d.labels},
58+
{"access", d.access},
59+
{"tags", d.tags},
60+
{"datasetReference", d.dataset_reference},
61+
{"linkedDatasetSource", d.linked_dataset_source},
62+
{"defaultRoundingMode", d.default_rounding_mode},
63+
{"storageBillingModel", d.storage_billing_model}};
64+
65+
ToJson(d.default_table_expiration, j, "defaultTableExpirationMs");
66+
ToJson(d.default_partition_expiration, j, "defaultPartitionExpirationMs");
67+
ToJson(d.creation_time, j, "creationTime");
68+
ToJson(d.last_modified_time, j, "lastModifiedTime");
69+
ToJson(d.max_time_travel, j, "maxTimeTravelHours");
7370
}
7471

7572
void from_json(nlohmann::json const& j, Dataset& d) {
7673
if (j.contains("kind")) j.at("kind").get_to(d.kind);
7774
if (j.contains("etag")) j.at("etag").get_to(d.etag);
7875
if (j.contains("id")) j.at("id").get_to(d.id);
79-
if (j.contains("self_link")) j.at("self_link").get_to(d.self_link);
80-
if (j.contains("friendly_name"))
81-
j.at("friendly_name").get_to(d.friendly_name);
76+
if (j.contains("selfLink")) j.at("selfLink").get_to(d.self_link);
77+
if (j.contains("friendlyName")) j.at("friendlyName").get_to(d.friendly_name);
8278
if (j.contains("description")) j.at("description").get_to(d.description);
8379
if (j.contains("type")) j.at("type").get_to(d.type);
8480
if (j.contains("location")) j.at("location").get_to(d.location);
85-
if (j.contains("default_collation"))
86-
j.at("default_collation").get_to(d.default_collation);
81+
if (j.contains("defaultCollation"))
82+
j.at("defaultCollation").get_to(d.default_collation);
8783
if (j.contains("published")) j.at("published").get_to(d.published);
88-
if (j.contains("is_case_insensitive"))
89-
j.at("is_case_insensitive").get_to(d.is_case_insensitive);
84+
if (j.contains("isCaseInsensitive"))
85+
j.at("isCaseInsensitive").get_to(d.is_case_insensitive);
9086
if (j.contains("labels")) j.at("labels").get_to(d.labels);
9187
if (j.contains("access")) j.at("access").get_to(d.access);
9288
if (j.contains("tags")) j.at("tags").get_to(d.tags);
93-
if (j.contains("dataset_reference"))
94-
j.at("dataset_reference").get_to(d.dataset_reference);
95-
if (j.contains("linked_dataset_source"))
96-
j.at("linked_dataset_source").get_to(d.linked_dataset_source);
97-
if (j.contains("external_dataset_reference"))
98-
j.at("external_dataset_reference").get_to(d.external_dataset_reference);
99-
if (j.contains("default_rounding_mode"))
100-
j.at("default_rounding_mode").get_to(d.default_rounding_mode);
101-
if (j.contains("storage_billing_model"))
102-
j.at("storage_billing_model").get_to(d.storage_billing_model);
103-
104-
FromJson(d.default_table_expiration, j, "default_table_expiration");
105-
FromJson(d.default_partition_expiration, j, "default_partition_expiration");
106-
FromJson(d.creation_time, j, "creation_time");
107-
FromJson(d.last_modified_time, j, "last_modified_time");
108-
FromJson(d.max_time_travel, j, "max_time_travel");
89+
if (j.contains("datasetReference"))
90+
j.at("datasetReference").get_to(d.dataset_reference);
91+
if (j.contains("linkedDatasetSource"))
92+
j.at("linkedDatasetSource").get_to(d.linked_dataset_source);
93+
if (j.contains("defaultRoundingMode"))
94+
j.at("defaultRoundingMode").get_to(d.default_rounding_mode);
95+
if (j.contains("storageBillingModel"))
96+
j.at("storageBillingModel").get_to(d.storage_billing_model);
97+
98+
FromJson(d.default_table_expiration, j, "defaultTableExpirationMs");
99+
FromJson(d.default_partition_expiration, j, "defaultPartitionExpirationMs");
100+
FromJson(d.creation_time, j, "creationTime");
101+
FromJson(d.last_modified_time, j, "lastModifiedTime");
102+
FromJson(d.max_time_travel, j, "maxTimeTravelHours");
109103
}
110104

111105
std::string LinkedDatasetSource::DebugString(absl::string_view name,
@@ -157,34 +151,6 @@ std::string Access::DebugString(absl::string_view name,
157151
.Build();
158152
}
159153

160-
std::string HiveMetastoreConnectivity::DebugString(
161-
absl::string_view name, TracingOptions const& options, int indent) const {
162-
return internal::DebugFormatter(name, options, indent)
163-
.StringField("access_uri_type", access_uri_type)
164-
.StringField("access_uri", access_uri)
165-
.StringField("metadata_connection", metadata_connection)
166-
.StringField("storage_connection", storage_connection)
167-
.Build();
168-
}
169-
170-
std::string HiveDatabaseReference::DebugString(absl::string_view name,
171-
TracingOptions const& options,
172-
int indent) const {
173-
return internal::DebugFormatter(name, options, indent)
174-
.StringField("catalog_id", catalog_id)
175-
.StringField("database", database)
176-
.SubMessage("metadata_connectivity", metadata_connectivity)
177-
.Build();
178-
}
179-
180-
std::string ExternalDatasetReference::DebugString(absl::string_view name,
181-
TracingOptions const& options,
182-
int indent) const {
183-
return internal::DebugFormatter(name, options, indent)
184-
.SubMessage("hive_database", hive_database)
185-
.Build();
186-
}
187-
188154
std::string GcpTag::DebugString(absl::string_view name,
189155
TracingOptions const& options,
190156
int indent) const {
@@ -219,7 +185,6 @@ std::string Dataset::DebugString(absl::string_view name,
219185
.Field("tags", tags)
220186
.SubMessage("dataset_reference", dataset_reference)
221187
.SubMessage("linked_dataset_source", linked_dataset_source)
222-
.SubMessage("external_dataset_reference", external_dataset_reference)
223188
.SubMessage("default_rounding_mode", default_rounding_mode)
224189
.SubMessage("storage_billing_model", storage_billing_model)
225190
.Build();
@@ -239,6 +204,80 @@ std::string ListFormatDataset::DebugString(absl::string_view name,
239204
.Build();
240205
}
241206

207+
void to_json(nlohmann::json& j, ListFormatDataset const& d) {
208+
j = nlohmann::json{{"kind", d.kind},
209+
{"id", d.id},
210+
{"friendlyName", d.friendly_name},
211+
{"location", d.location},
212+
{"type", d.type},
213+
{"datasetReference", d.dataset_reference},
214+
{"labels", d.labels}};
215+
}
216+
void from_json(nlohmann::json const& j, ListFormatDataset& d) {
217+
// TODO(#12188): Implement SafeGetTo(...) for potentially better performance.
218+
if (j.contains("kind")) j.at("kind").get_to(d.kind);
219+
if (j.contains("id")) j.at("id").get_to(d.id);
220+
if (j.contains("friendlyName")) j.at("friendlyName").get_to(d.friendly_name);
221+
if (j.contains("location")) j.at("location").get_to(d.location);
222+
if (j.contains("type")) j.at("type").get_to(d.type);
223+
if (j.contains("datasetReference")) {
224+
j.at("datasetReference").get_to(d.dataset_reference);
225+
}
226+
if (j.contains("labels")) j.at("labels").get_to(d.labels);
227+
}
228+
229+
void to_json(nlohmann::json& j, GcpTag const& t) {
230+
j = nlohmann::json{{"tagKey", t.tag_key}, {"tagValue", t.tag_value}};
231+
}
232+
void from_json(nlohmann::json const& j, GcpTag& t) {
233+
// TODO(#12188): Implement SafeGetTo(...) for potentially better performance.
234+
if (j.contains("tagKey")) j.at("tagKey").get_to(t.tag_key);
235+
if (j.contains("tagValue")) j.at("tagValue").get_to(t.tag_value);
236+
}
237+
238+
void to_json(nlohmann::json& j, Access const& a) {
239+
j = nlohmann::json{{"role", a.role},
240+
{"userByEmail", a.user_by_email},
241+
{"groupByEmail", a.group_by_email},
242+
{"domain", a.domain},
243+
{"specialGroup", a.special_group},
244+
{"iamMember", a.iam_member},
245+
{"view", a.view},
246+
{"routine", a.routine},
247+
{"dataset", a.dataset}};
248+
}
249+
void from_json(nlohmann::json const& j, Access& a) {
250+
// TODO(#12188): Implement SafeGetTo(...) for potentially better performance.
251+
if (j.contains("role")) j.at("role").get_to(a.role);
252+
if (j.contains("userByEmail")) j.at("userByEmail").get_to(a.user_by_email);
253+
if (j.contains("groupByEmail")) j.at("groupByEmail").get_to(a.group_by_email);
254+
if (j.contains("domain")) j.at("domain").get_to(a.domain);
255+
if (j.contains("specialGroup")) j.at("specialGroup").get_to(a.special_group);
256+
if (j.contains("iamMember")) j.at("iamMember").get_to(a.iam_member);
257+
if (j.contains("view")) j.at("view").get_to(a.view);
258+
if (j.contains("routine")) j.at("routine").get_to(a.routine);
259+
if (j.contains("dataset")) j.at("dataset").get_to(a.dataset);
260+
}
261+
262+
void to_json(nlohmann::json& j, DatasetAccessEntry const& d) {
263+
j = nlohmann::json{{"dataset", d.dataset}, {"targetTypes", d.target_types}};
264+
}
265+
void from_json(nlohmann::json const& j, DatasetAccessEntry& d) {
266+
// TODO(#12188): Implement SafeGetTo(...) for potentially better performance.
267+
if (j.contains("dataset")) j.at("dataset").get_to(d.dataset);
268+
if (j.contains("targetTypes")) j.at("targetTypes").get_to(d.target_types);
269+
}
270+
271+
void to_json(nlohmann::json& j, LinkedDatasetSource const& d) {
272+
j = nlohmann::json{{"sourceDataset", d.source_dataset}};
273+
}
274+
void from_json(nlohmann::json const& j, LinkedDatasetSource& d) {
275+
// TODO(#12188): Implement SafeGetTo(...) for potentially better performance.
276+
if (j.contains("sourceDataset")) {
277+
j.at("sourceDataset").get_to(d.source_dataset);
278+
}
279+
}
280+
242281
GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END
243282
} // namespace bigquery_v2_minimal_internal
244283
} // namespace cloud

google/cloud/bigquery/v2/minimal/internal/dataset.h

Lines changed: 12 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,8 @@ struct LinkedDatasetSource {
6767
TracingOptions const& options = {},
6868
int indent = 0) const;
6969
};
70-
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_WITH_DEFAULT(LinkedDatasetSource,
71-
source_dataset);
70+
void to_json(nlohmann::json& j, LinkedDatasetSource const& d);
71+
void from_json(nlohmann::json const& j, LinkedDatasetSource& d);
7272

7373
struct DatasetAccessEntry {
7474
DatasetReference dataset;
@@ -78,8 +78,8 @@ struct DatasetAccessEntry {
7878
TracingOptions const& options = {},
7979
int indent = 0) const;
8080
};
81-
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_WITH_DEFAULT(DatasetAccessEntry, dataset,
82-
target_types);
81+
void to_json(nlohmann::json& j, DatasetAccessEntry const& d);
82+
void from_json(nlohmann::json const& j, DatasetAccessEntry& d);
8383

8484
struct Access {
8585
std::string role;
@@ -97,49 +97,8 @@ struct Access {
9797
TracingOptions const& options = {},
9898
int indent = 0) const;
9999
};
100-
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_WITH_DEFAULT(Access, role, user_by_email,
101-
group_by_email, domain,
102-
special_group, iam_member, view,
103-
routine, dataset);
104-
105-
struct HiveMetastoreConnectivity {
106-
std::string access_uri_type;
107-
std::string access_uri;
108-
std::string metadata_connection;
109-
std::string storage_connection;
110-
111-
std::string DebugString(absl::string_view name,
112-
TracingOptions const& options = {},
113-
int indent = 0) const;
114-
};
115-
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_WITH_DEFAULT(HiveMetastoreConnectivity,
116-
access_uri_type, access_uri,
117-
metadata_connection,
118-
storage_connection);
119-
120-
struct HiveDatabaseReference {
121-
std::string catalog_id;
122-
std::string database;
123-
124-
HiveMetastoreConnectivity metadata_connectivity;
125-
126-
std::string DebugString(absl::string_view name,
127-
TracingOptions const& options = {},
128-
int indent = 0) const;
129-
};
130-
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_WITH_DEFAULT(HiveDatabaseReference,
131-
catalog_id, database,
132-
metadata_connectivity);
133-
134-
struct ExternalDatasetReference {
135-
HiveDatabaseReference hive_database;
136-
137-
std::string DebugString(absl::string_view name,
138-
TracingOptions const& options = {},
139-
int indent = 0) const;
140-
};
141-
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_WITH_DEFAULT(ExternalDatasetReference,
142-
hive_database);
100+
void to_json(nlohmann::json& j, Access const& a);
101+
void from_json(nlohmann::json const& j, Access& a);
143102

144103
struct GcpTag {
145104
std::string tag_key;
@@ -149,7 +108,8 @@ struct GcpTag {
149108
TracingOptions const& options = {},
150109
int indent = 0) const;
151110
};
152-
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_WITH_DEFAULT(GcpTag, tag_key, tag_value);
111+
void to_json(nlohmann::json& j, GcpTag const& t);
112+
void from_json(nlohmann::json const& j, GcpTag& t);
153113

154114
struct Dataset {
155115
std::string kind;
@@ -179,7 +139,6 @@ struct Dataset {
179139

180140
DatasetReference dataset_reference;
181141
LinkedDatasetSource linked_dataset_source;
182-
ExternalDatasetReference external_dataset_reference;
183142
RoundingMode default_rounding_mode;
184143

185144
StorageBillingModel storage_billing_model;
@@ -188,6 +147,8 @@ struct Dataset {
188147
TracingOptions const& options = {},
189148
int indent = 0) const;
190149
};
150+
void to_json(nlohmann::json& j, Dataset const& d);
151+
void from_json(nlohmann::json const& j, Dataset& d);
191152

192153
struct ListFormatDataset {
193154
std::string kind;
@@ -203,12 +164,8 @@ struct ListFormatDataset {
203164
TracingOptions const& options = {},
204165
int indent = 0) const;
205166
};
206-
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_WITH_DEFAULT(ListFormatDataset, kind, id,
207-
friendly_name, location, type,
208-
dataset_reference, labels);
209-
210-
void to_json(nlohmann::json& j, Dataset const& d);
211-
void from_json(nlohmann::json const& j, Dataset& d);
167+
void to_json(nlohmann::json& j, ListFormatDataset const& d);
168+
void from_json(nlohmann::json const& j, ListFormatDataset& d);
212169

213170
GOOGLE_CLOUD_CPP_INLINE_NAMESPACE_END
214171
} // namespace bigquery_v2_minimal_internal

google/cloud/bigquery/v2/minimal/internal/dataset_connection_test.cc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,9 @@ TEST(DatasetConnectionTest, GetDatasetSuccess) {
5959
R"({"kind": "d-kind",
6060
"etag": "d-tag",
6161
"id": "d-id",
62-
"self_link": "d-selfLink",
63-
"friendly_name": "d-friendly-name",
64-
"dataset_reference": {"projectId": "p-id", "datasetId": "d-id"}
62+
"selfLink": "d-selfLink",
63+
"friendlyName": "d-friendly-name",
64+
"datasetReference": {"projectId": "p-id", "datasetId": "d-id"}
6565
})";
6666

6767
EXPECT_CALL(*mock, GetDataset)

google/cloud/bigquery/v2/minimal/internal/dataset_logging_test.cc

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,9 @@ TEST(DatasetLoggingClientTest, GetDataset) {
4747
R"({"kind": "d-kind",
4848
"etag": "d-tag",
4949
"id": "d-id",
50-
"self_link": "d-selfLink",
51-
"friendly_name": "d-friendly-name",
52-
"dataset_reference": {"projectId": "p-id", "datasetId": "d-id"}
50+
"selfLink": "d-selfLink",
51+
"friendlyName": "d-friendly-name",
52+
"datasetReference": {"projectId": "p-id", "datasetId": "d-id"}
5353
})";
5454

5555
EXPECT_CALL(*mock_stub, GetDataset)
@@ -97,13 +97,13 @@ TEST(DatasetLoggingClientTest, ListDatasets) {
9797
auto constexpr kExpectedPayload =
9898
R"({"etag": "tag-1",
9999
"kind": "kind-1",
100-
"next_page_token": "npt-123",
100+
"nextPageToken": "npt-123",
101101
"datasets": [
102102
{
103103
"id": "1",
104104
"kind": "kind-1",
105-
"dataset_reference": {"projectId": "p123", "datasetId": "d123"},
106-
"friendly_name": "friendly-name",
105+
"datasetReference": {"projectId": "p123", "datasetId": "d123"},
106+
"friendlyName": "friendly-name",
107107
"location": "location",
108108
"type": "DEFAULT"
109109
}

0 commit comments

Comments
 (0)