Skip to content

Commit 14f9d6f

Browse files
authored
Move all of the code from the bigquery namespace to google::cloud::bigquery (googleapis/google-cloud-cpp-bigquery#2)
* Move the files from bigquery/ to google/cloud/bigquery/ * Change the bigquery namespace to google::cloud::bigquery
0 parents  commit 14f9d6f

16 files changed

Lines changed: 919 additions & 0 deletions

google/cloud/bigquery/BUILD

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# Copyright 2019 Google LLC
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
package(default_visibility = ["//visibility:public"])
16+
17+
cc_library(
18+
name = "bigquery_client",
19+
hdrs = [
20+
"client.h",
21+
"connection.h",
22+
"connection_options.h",
23+
"version.h",
24+
"version_info.h",
25+
],
26+
srcs = [
27+
"client.cc",
28+
"connection_options.cc",
29+
"internal/stream_reader.h",
30+
"internal/bigquerystorage_stub.cc",
31+
"internal/bigquerystorage_stub.h",
32+
"internal/connection_impl.cc",
33+
"internal/connection_impl.h",
34+
"version.cc",
35+
],
36+
deps = [
37+
"@com_github_googleapis_google_cloud_cpp//google/cloud:google_cloud_cpp_common",
38+
"@com_github_googleapis_google_cloud_cpp//google/cloud/grpc_utils:google_cloud_cpp_grpc_utils",
39+
"@com_google_googleapis//:bigquery_protos",
40+
],
41+
42+
)

google/cloud/bigquery/client.cc

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
// Copyright 2019 Google LLC
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
#include <memory>
16+
17+
#include "google/cloud/bigquery/client.h"
18+
#include "google/cloud/bigquery/connection.h"
19+
#include "google/cloud/bigquery/connection_options.h"
20+
#include "google/cloud/bigquery/internal/connection_impl.h"
21+
#include "google/cloud/bigquery/version.h"
22+
23+
namespace google {
24+
namespace cloud {
25+
namespace bigquery {
26+
inline namespace BIGQUERY_CLIENT_NS {
27+
using ::google::cloud::StatusOr;
28+
29+
StatusOr<std::string> Client::CreateSession(std::string parent_project_id,
30+
std::string table) {
31+
return conn_->CreateSession(parent_project_id, table);
32+
}
33+
34+
std::shared_ptr<Connection> MakeConnection(ConnectionOptions const& options) {
35+
std::shared_ptr<internal::BigQueryStorageStub> stub =
36+
internal::MakeDefaultBigQueryStorageStub(options);
37+
return internal::MakeConnection(std::move(stub));
38+
}
39+
40+
} // namespace BIGQUERY_CLIENT_NS
41+
} // namespace bigquery
42+
} // namespace cloud
43+
} // namespace google

google/cloud/bigquery/client.h

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
// Copyright 2019 Google LLC
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
#ifndef BIGQUERY_CLIENT_H_
16+
#define BIGQUERY_CLIENT_H_
17+
18+
#include <memory>
19+
20+
#include "google/cloud/bigquery/connection.h"
21+
#include "google/cloud/bigquery/connection_options.h"
22+
#include "google/cloud/bigquery/version.h"
23+
#include "google/cloud/status_or.h"
24+
25+
namespace google {
26+
namespace cloud {
27+
namespace bigquery {
28+
inline namespace BIGQUERY_CLIENT_NS {
29+
class Client {
30+
public:
31+
explicit Client(std::shared_ptr<Connection> conn) : conn_(std::move(conn)) {}
32+
33+
Client() = delete;
34+
35+
// Client is copyable and movable.
36+
Client(Client const&) = default;
37+
Client& operator=(Client const&) = default;
38+
Client(Client&&) = default;
39+
Client& operator=(Client&&) = default;
40+
41+
friend bool operator==(Client const& a, Client const& b) {
42+
return a.conn_ == b.conn_;
43+
}
44+
45+
friend bool operator!=(Client const& a, Client const& b) { return !(a == b); }
46+
47+
// Creates a new read session and returns its name if successful.
48+
//
49+
// This function is just a proof of concept to ensure we can send
50+
// requests to the server.
51+
google::cloud::StatusOr<std::string> CreateSession(
52+
std::string parent_project_id, std::string table);
53+
54+
private:
55+
std::shared_ptr<Connection> conn_;
56+
};
57+
58+
std::shared_ptr<Connection> MakeConnection(ConnectionOptions const& options);
59+
60+
} // namespace BIGQUERY_CLIENT_NS
61+
} // namespace bigquery
62+
} // namespace cloud
63+
} // namespace google
64+
65+
#endif // BIGQUERY_CLIENT_H_

google/cloud/bigquery/connection.h

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// Copyright 2019 Google LLC
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
#ifndef BIGQUERY_CONNECTION_H_
16+
#define BIGQUERY_CONNECTION_H_
17+
18+
#include "google/cloud/bigquery/version.h"
19+
#include "google/cloud/status_or.h"
20+
21+
namespace google {
22+
namespace cloud {
23+
namespace bigquery {
24+
inline namespace BIGQUERY_CLIENT_NS {
25+
class Connection {
26+
public:
27+
virtual ~Connection() = default;
28+
29+
virtual google::cloud::StatusOr<std::string> CreateSession(
30+
std::string parent_project_id, std::string table) = 0;
31+
};
32+
33+
} // namespace BIGQUERY_CLIENT_NS
34+
} // namespace bigquery
35+
} // namespace cloud
36+
} // namespace google
37+
38+
#endif // BIGQUERY_CONNECTION_H_
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
// Copyright 2019 Google LLC
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
#include <grpcpp/grpcpp.h>
16+
#include <memory>
17+
#include <string>
18+
19+
#include "google/cloud/bigquery/connection_options.h"
20+
#include "google/cloud/bigquery/version.h"
21+
22+
namespace google {
23+
namespace cloud {
24+
namespace bigquery {
25+
inline namespace BIGQUERY_CLIENT_NS {
26+
namespace internal {
27+
std::string BaseUserAgentPrefix() {
28+
// TODO(aryann): Add more info here.
29+
return "aryann-cpp-google/cloud/bigquery/" + VersionString();
30+
}
31+
} // namespace internal
32+
33+
ConnectionOptions::ConnectionOptions(
34+
std::shared_ptr<grpc::ChannelCredentials> credentials)
35+
: credentials_(std::move(credentials)),
36+
bigquerystorage_endpoint_("bigquerystorage.googleapis.com"),
37+
user_agent_prefix_(internal::BaseUserAgentPrefix()) {}
38+
39+
ConnectionOptions::ConnectionOptions()
40+
: ConnectionOptions(grpc::GoogleDefaultCredentials()) {}
41+
42+
grpc::ChannelArguments ConnectionOptions::CreateChannelArguments() const {
43+
grpc::ChannelArguments channel_arguments;
44+
45+
channel_arguments.SetUserAgentPrefix(user_agent_prefix());
46+
return channel_arguments;
47+
}
48+
49+
} // namespace BIGQUERY_CLIENT_NS
50+
} // namespace bigquery
51+
} // namespace cloud
52+
} // namespace google
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
// Copyright 2019 Google LLC
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
#ifndef BIGQUERY_CONNECTION_OPTIONS_H_
16+
#define BIGQUERY_CONNECTION_OPTIONS_H_
17+
18+
#include <grpcpp/grpcpp.h>
19+
#include <memory>
20+
#include <string>
21+
22+
#include "google/cloud/bigquery/version.h"
23+
24+
namespace google {
25+
namespace cloud {
26+
namespace bigquery {
27+
inline namespace BIGQUERY_CLIENT_NS {
28+
class ConnectionOptions {
29+
public:
30+
ConnectionOptions();
31+
32+
explicit ConnectionOptions(
33+
std::shared_ptr<grpc::ChannelCredentials> credentials);
34+
35+
ConnectionOptions& set_credentials(
36+
std::shared_ptr<grpc::ChannelCredentials> credentials) {
37+
credentials_ = std::move(credentials);
38+
return *this;
39+
}
40+
41+
std::shared_ptr<grpc::ChannelCredentials> credentials() const {
42+
return credentials_;
43+
}
44+
45+
ConnectionOptions& set_bigquerystorage_endpoint(std::string endpoint) {
46+
bigquerystorage_endpoint_ = std::move(endpoint);
47+
return *this;
48+
}
49+
50+
std::string const& bigquerystorage_endpoint() const {
51+
return bigquerystorage_endpoint_;
52+
}
53+
54+
ConnectionOptions& add_user_agent_prefix(std::string prefix) {
55+
prefix += " ";
56+
prefix += user_agent_prefix_;
57+
user_agent_prefix_ = std::move(prefix);
58+
return *this;
59+
}
60+
61+
std::string const& user_agent_prefix() const { return user_agent_prefix_; }
62+
63+
grpc::ChannelArguments CreateChannelArguments() const;
64+
65+
private:
66+
std::shared_ptr<grpc::ChannelCredentials> credentials_;
67+
std::string bigquerystorage_endpoint_;
68+
std::string user_agent_prefix_;
69+
};
70+
71+
} // namespace BIGQUERY_CLIENT_NS
72+
} // namespace bigquery
73+
} // namespace cloud
74+
} // namespace google
75+
76+
#endif // BIGQUERY_CONNECTION_OPTIONS_H_

0 commit comments

Comments
 (0)