Skip to content

Commit 5bf12a7

Browse files
authored
fix: tests hanging (#30)
changed path to bigtable emulator and cbt in tests moved arguments' initializations to the body of the function in bigtable_ops.py fixed interleaveFromRange of column filters when using only one column
1 parent 16db041 commit 5bf12a7

File tree

4 files changed

+28
-17
lines changed

4 files changed

+28
-17
lines changed

tensorflow_io/core/kernels/bigtable/bigtable_dataset_kernel.cc

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,9 @@ class Iterator : public DatasetIterator<Dataset> {
225225
filters.push_back(std::move(f));
226226
}
227227

228-
return cbt::Filter::InterleaveFromRange(filters.begin(), filters.end());
228+
return filters.size() > 1 ? cbt::Filter::InterleaveFromRange(
229+
filters.begin(), filters.end())
230+
: filters[0];
229231
}
230232

231233
static std::pair<std::string, std::string> ColumnToFamilyAndQualifier(

tensorflow_io/python/ops/bigtable/bigtable_dataset_ops.py

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ def read_rows(
5757
self,
5858
columns: List[str],
5959
row_set: bigtable_row_set.RowSet,
60-
filter: filters.BigtableFilter = filters.latest(),
60+
filter: filters.BigtableFilter = None,
6161
output_type=tf.string,
6262
):
6363
"""Retrieves values from Google Bigtable sorted by RowKeys.
@@ -69,23 +69,24 @@ def read_rows(
6969
Returns:
7070
A `tf.data.Dataset` returning the cell contents.
7171
"""
72+
73+
# Python initializes the default arguments once at the start of the
74+
# program. If the fork happens after that (for instance when we run
75+
# tests using xdist) the program deadlocks and hangs. That is why we
76+
# have to make sure, all default arguments are initialized on each
77+
# invocation.
78+
if filter is None:
79+
filter = filters.latest()
7280
return _BigtableDataset(
73-
self._client_resource,
74-
self._table_id,
75-
columns,
76-
row_set,
77-
filter,
78-
output_type,
81+
self._client_resource, self._table_id, columns, row_set, filter, output_type
7982
)
8083

8184
def parallel_read_rows(
8285
self,
8386
columns: List[str],
8487
num_parallel_calls=tf.data.AUTOTUNE,
85-
row_set: bigtable_row_set.RowSet = bigtable_row_set.from_rows_or_ranges(
86-
bigtable_row_range.infinite()
87-
),
88-
filter: filters.BigtableFilter = filters.latest(),
88+
row_set: bigtable_row_set.RowSet = None,
89+
filter: filters.BigtableFilter = None,
8990
output_type=tf.string,
9091
):
9192
"""Retrieves values from Google Bigtable in parallel. The ammount of work
@@ -101,11 +102,17 @@ def parallel_read_rows(
101102
A `tf.data.Dataset` returning the cell contents.
102103
"""
103104

105+
# We have to make sure that all the default arguments are initialized
106+
# on each invocation. For more info see read_rows method.
107+
if row_set is None:
108+
row_set = bigtable_row_set.from_rows_or_ranges(
109+
bigtable_row_range.infinite()
110+
)
111+
if filter is None:
112+
filter = filters.latest()
113+
104114
samples = core_ops.bigtable_split_row_set_evenly(
105-
self._client_resource,
106-
row_set._impl,
107-
self._table_id,
108-
num_parallel_calls,
115+
self._client_resource, row_set._impl, self._table_id, num_parallel_calls
109116
)
110117

111118
def map_func(idx):

tests/test_bigtable/bigtable_emulator.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,14 @@
3030
CBT_EMULATOR_SEARCH_PATHS = [
3131
"/usr/lib/google-cloud-sdk/platform/bigtable-emulator/cbtemulator",
3232
"/usr/local/google-cloud-sdk/platform/bigtable-emulator/cbtemulator",
33+
"/v/google-cloud-sdk/platform/bigtable-emulator/cbtemulator",
3334
"cbtemulator",
3435
]
3536

3637
CBT_CLI_SEARCH_PATHS = [
3738
"/usr/local/google-cloud-sdk/bin/cbt",
3839
"/usr/bin/cbt",
40+
"/v/google-cloud-sdk/bin/cbt",
3941
"cbt",
4042
]
4143

tests/test_gcloud/test_pubsub_bigtable.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ fi
3434
curl -sSOL https://dl.google.com/dl/cloudsdk/channels/rapid/downloads/google-cloud-sdk-236.0.0-darwin-x86_64.tar.gz
3535
tar -xzf google-cloud-sdk-236.0.0-darwin-x86_64.tar.gz
3636
google-cloud-sdk/install.sh -q
37-
google-cloud-sdk/bin/gcloud -q components install beta
37+
google-cloud-sdk/bin/gcloud -q components install beta bigtable cbt
3838
google-cloud-sdk/bin/gcloud -q components install pubsub-emulator
3939
google-cloud-sdk/bin/gcloud -q components update beta
4040
google-cloud-sdk/bin/gcloud -q beta emulators pubsub start &

0 commit comments

Comments
 (0)