Skip to content

Commit 0c9556a

Browse files
authored
Add support for mongoDB (#1207)
* [mongo] build libmongoc * [tests] setup container for tests * add platform based genrule conditions * expose handler python api * lint fixes * disable sasl build for linux * modify build opts for libmongoc add unistd.h for windows build add missing include os based bson build bson os fix * expose MongoDBIODataset * expose MongoDBWriter python api * modify build options add missing header modify ssl build opts modify ssl opts disable aws auth opt ssl secure channel for windows ssl opts for linux and mac disable ssl for linux modify bson opts openssl based build disable ssl for mac and linux enable dnsapi for windows use mongo-c-driver-1.16.2 enable sasl support add linkopts for boringssl build update boringssl version add openssl deps for centos add libssl-dev dep become sudo update README.md instructions modify build options * build separate .so for mongo_ops * install make for centos builds * build libtensorflow_io_mongodb.so in windows * handle scopes for centos 7 * use boringssl for windows * lint fixes * disable libcrypto for windows * patch boringssl dependency
1 parent 778ceac commit 0c9556a

File tree

14 files changed

+1048
-3
lines changed

14 files changed

+1048
-3
lines changed

.github/workflows/build.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,7 @@ jobs:
302302
bash -x -e tests/test_pubsub/pubsub_test.sh
303303
bash -x -e tests/test_prometheus/prometheus_test.sh start
304304
bash -x -e tests/test_elasticsearch/elasticsearch_test.sh start
305+
bash -x -e tests/test_mongodb/mongodb_test.sh start
305306
bash -x -e tests/test_azure/start_azure.sh
306307
bash -x -e tests/test_sql/sql_test.sh
307308
bash -x -e tests/test_gcloud/test_gcs.sh gcs-emulator

.kokorun/io_cpu.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ bash -x -e tests/test_prometheus/prometheus_test.sh start
8080
bash -x -e tests/test_azure/start_azure.sh
8181
bash -x -e tests/test_sql/sql_test.sh sql
8282
bash -x -e tests/test_elasticsearch/elasticsearch_test.sh start
83+
bash -x -e tests/test_mongodb/mongodb_test.sh start
8384

8485
docker run -i --rm -v $PWD:/v -w /v --net=host \
8586
buildpack-deps:20.04 bash -x -e .github/workflows/build.wheel.sh python${PYTHON_VERSION}

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ the shared libraries on CentOS 8:
282282
#!/usr/bin/env bash
283283

284284
# Install gcc/g++, git, unzip/which (for bazel), and python3
285-
sudo yum install -y python3 python3-devel gcc gcc-c++ git unzip which
285+
sudo yum install -y python3 python3-devel gcc gcc-c++ git unzip which make
286286

287287
# Install Bazel version specified in .bazelversion
288288
curl -sSOL https://github.com/bazelbuild/bazel/releases/download/$(cat .bazelversion)/bazel-$(cat .bazelversion)-installer-linux-x86_64.sh
@@ -321,7 +321,7 @@ The following will install bazel, devtoolset-9, rh-python36, and build the share
321321

322322
# Install centos-release-scl, then install gcc/g++ (devtoolset), git, and python 3
323323
sudo yum install -y centos-release-scl
324-
sudo yum install -y devtoolset-9 git rh-python36
324+
sudo yum install -y devtoolset-9 git rh-python36 make
325325

326326
# Install Bazel version specified in .bazelversion
327327
curl -sSOL https://github.com/bazelbuild/bazel/releases/download/$(cat .bazelversion)/bazel-$(cat .bazelversion)-installer-linux-x86_64.sh

WORKSPACE

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ http_archive(
281281
patch_cmds = [
282282
"rm -f src/win32_config.h",
283283
# TODO: Remove the fowllowing once librdkafka issue is resolved.
284-
"""sed -i.bak '\|rd_kafka_log(rk,|,/ exceeded);/ s/^/\/\//' src/rdkafka_cgrp.c""",
284+
"""sed -i.bak '\\|rd_kafka_log(rk,|,/ exceeded);/ s/^/\\/\\//' src/rdkafka_cgrp.c""",
285285
],
286286
sha256 = "f7fee59fdbf1286ec23ef0b35b2dfb41031c8727c90ced6435b8cf576f23a656",
287287
strip_prefix = "librdkafka-1.5.0",
@@ -1092,3 +1092,16 @@ http_archive(
10921092
"https://github.com/apache/pulsar/archive/v2.6.1.tar.gz",
10931093
],
10941094
)
1095+
1096+
http_archive(
1097+
name = "libmongoc",
1098+
build_file = "//third_party:libmongoc.BUILD",
1099+
patch_cmds = [
1100+
"sed -i.bak 's/undef MONGOC_LOG_DOMAIN/undef MONGOC_LOG_DOMAIN\\'$'\\n''# define BIO_get_ssl(b,sslp) BIO_ctrl(b,BIO_C_GET_SSL,0,(char *)(sslp))\\'$'\\n''# define BIO_do_handshake(b) BIO_ctrl(b,BIO_C_DO_STATE_MACHINE,0,NULL)/g' src/libmongoc/src/mongoc/mongoc-stream-tls-openssl.c",
1101+
],
1102+
sha256 = "0a722180e5b5c86c415b9256d753b2d5552901dc5d95c9f022072c3cd336887e",
1103+
strip_prefix = "mongo-c-driver-1.16.2",
1104+
urls = [
1105+
"https://github.com/mongodb/mongo-c-driver/releases/download/1.16.2/mongo-c-driver-1.16.2.tar.gz",
1106+
],
1107+
)

tensorflow_io/core/BUILD

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -679,6 +679,22 @@ cc_library(
679679
alwayslink = 1,
680680
)
681681

682+
cc_library(
683+
name = "mongodb_ops",
684+
srcs = [
685+
"kernels/mongodb_kernels.cc",
686+
"ops/mongodb_ops.cc",
687+
],
688+
copts = tf_io_copts(),
689+
linkstatic = True,
690+
deps = [
691+
"@libmongoc",
692+
"@local_config_tf//:libtensorflow_framework",
693+
"@local_config_tf//:tf_header_lib",
694+
],
695+
alwayslink = 1,
696+
)
697+
682698
cc_binary(
683699
name = "python/ops/libtensorflow_io.so",
684700
copts = tf_io_copts(),
@@ -707,6 +723,7 @@ cc_binary(
707723
"//tensorflow_io/core:sql_ops",
708724
"//tensorflow_io/core:text_ops",
709725
"//tensorflow_io/core:ignite_ops",
726+
"//tensorflow_io/core:mongodb_ops",
710727
"@local_config_tf//:libtensorflow_framework",
711728
"@local_config_tf//:tf_header_lib",
712729
] + select({

0 commit comments

Comments
 (0)