Skip to content

Commit 00f80a7

Browse files
authored
Merge pull request #226 from czgdp1807/zetasql_dep
Deprecate `ZetaSQL`-based `filter_query` functionality for `v1.18.0` removal
2 parents 9357425 + 45ae7d2 commit 00f80a7

10 files changed

Lines changed: 119 additions & 37 deletions

RELEASE.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@
66

77
## Deprecations
88

9+
* Deprecate ZetaSQL-based filter_query functionality. The `filter_query`
10+
parameter in ListOperationOptions that relies on ZetaSQL for declarative
11+
filtering is deprecated and will be removed in version 1.18.0. ZetaSQL
12+
dependency is being removed from ML Metadata. Users should migrate to
13+
alternative filtering approaches before the 1.18.0 release.
14+
915
## Bug Fixed and Other Changes
1016

1117
# Version 1.17.0

docs/index.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,7 @@ artifacts = store.get_artifacts()
253253
# Plus, there are many ways to query the same Artifact
254254
[stored_data_artifact] = store.get_artifacts_by_id([data_artifact_id])
255255
artifacts_with_uri = store.get_artifacts_by_uri(data_artifact.uri)
256+
# Note: filter_query is deprecated and will be removed in version 1.18.0.
256257
artifacts_with_conditions = store.get_artifacts(
257258
list_options=mlmd.ListOptions(
258259
filter_query='uri LIKE "%/data" AND properties.day.int_value > 0'))
@@ -270,6 +271,7 @@ trainer_run.properties["state"].string_value = "RUNNING"
270271
# Query all registered Execution
271272
executions = store.get_executions_by_id([run_id])
272273
# Similarly, the same execution can be queried with conditions.
274+
# Note: filter_query is deprecated and will be removed in version 1.18.0.
273275
executions_with_conditions = store.get_executions(
274276
list_options = mlmd.ListOptions(
275277
filter_query='type = "Trainer" AND properties.state.string_value IS NOT NULL'))
@@ -355,6 +357,7 @@ experiment_executions = store.get_executions_by_context(experiment_id)
355357

356358
# You can also use neighborhood queries to fetch these artifacts and executions
357359
# with conditions.
360+
# Note: filter_query is deprecated and will be removed in version 1.18.0.
358361
experiment_artifacts_with_conditions = store.get_artifacts(
359362
list_options = mlmd.ListOptions(
360363
filter_query=('contexts_a.type = "Experiment" AND contexts_a.name = "exp1"')))

ml_metadata/metadata_store/metadata_store.py

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,13 @@ class ListOptions:
8181
is_asc: Specifies `order_by` is ascending or descending. If `order_by` is
8282
not given, the field is ignored. If `order_by` is set, then by default
8383
ascending order is used for performance benefit.
84-
filter_query: An optional boolean expression in SQL syntax to specify
85-
conditions on node attributes and directly connected assets. See
86-
https://github.com/google/ml-metadata/blob/master/ml_metadata/proto/metadata_store.proto#L705-L783 for the query capabilities and syntax.
84+
filter_query: DEPRECATED (will be removed in v1.18.0) - An optional boolean
85+
expression in SQL syntax to specify conditions on node attributes and
86+
directly connected assets. This feature depends on ZetaSQL which is being
87+
removed from ML Metadata. Please migrate to alternative filtering approaches
88+
before version 1.18.0. See
89+
https://github.com/google/ml-metadata/blob/master/ml_metadata/proto/metadata_store.proto#L705-L783
90+
for the query capabilities and syntax.
8791
"""
8892

8993
limit: Optional[int] = None
@@ -1478,6 +1482,16 @@ def _call_method_with_list_options(
14781482
if list_options.order_by:
14791483
request.options.order_by_field.field = list_options.order_by.value
14801484
if list_options.filter_query:
1485+
# DEPRECATED: ZetaSQL-based filter_query will be removed in v1.18.0
1486+
import warnings
1487+
warnings.warn(
1488+
'DEPRECATION WARNING: filter_query is deprecated and will be '
1489+
'removed in version 1.18.0. This feature depends on ZetaSQL '
1490+
'which is being removed from ML Metadata. Please migrate to '
1491+
'alternative filtering approaches before the 1.18.0 release.',
1492+
DeprecationWarning,
1493+
stacklevel=3
1494+
)
14811495
request.options.filter_query = list_options.filter_query
14821496

14831497
result = []

ml_metadata/metadata_store/metadata_store_test.py

Lines changed: 59 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import collections
1616
import os
1717
import uuid
18+
import warnings
1819

1920
import pytest
2021
from absl.testing import absltest, parameterized
@@ -1803,14 +1804,20 @@ def test_get_nodes_by_filter_query(self, create_type_fn, put_type_fn,
18031804
nodes[i].custom_properties["p"].int_value = i
18041805
node_ids = put_nodes_fn(store, nodes)
18051806

1806-
got_nodes = get_nodes_fn(
1807-
store,
1808-
list_options=mlmd.ListOptions(
1809-
order_by=mlmd.OrderByField.ID,
1810-
is_asc=True,
1811-
filter_query=("custom_properties.p.int_value < 21 AND "
1812-
"name LIKE 'node_2%'")
1813-
))
1807+
# Verify deprecation warning is raised when using filter_query
1808+
with self.assertWarns(DeprecationWarning) as warning_context:
1809+
got_nodes = get_nodes_fn(
1810+
store,
1811+
list_options=mlmd.ListOptions(
1812+
order_by=mlmd.OrderByField.ID,
1813+
is_asc=True,
1814+
filter_query=("custom_properties.p.int_value < 21 AND "
1815+
"name LIKE 'node_2%'")
1816+
))
1817+
# Verify the warning message mentions version 1.18.0
1818+
self.assertIn("1.18.0", str(warning_context.warning))
1819+
self.assertIn("filter_query", str(warning_context.warning))
1820+
18141821
self.assertLen(got_nodes, 2)
18151822
self.assertEqual(got_nodes[0].id, node_ids[2])
18161823
self.assertEqual(got_nodes[0].name, "node_2")
@@ -1822,9 +1829,15 @@ def test_get_nodes_by_filter_query(self, create_type_fn, put_type_fn,
18221829
(mlmd.MetadataStore.get_contexts))
18231830
def test_get_nodes_by_filter_query_syntax_errors(self, get_nodes_fn):
18241831
store = _get_metadata_store(self.cli_args)
1825-
with self.assertRaises(errors.InvalidArgumentError):
1832+
# Verify deprecation warning is raised even for syntax errors
1833+
with (
1834+
self.assertWarns(DeprecationWarning) as warning_context,
1835+
self.assertRaises(errors.InvalidArgumentError),
1836+
):
18261837
_ = get_nodes_fn(
18271838
store, list_options=mlmd.ListOptions(filter_query="invalid syntax"))
1839+
# Verify the warning message mentions version 1.18.0
1840+
self.assertIn("1.18.0", str(warning_context.warning))
18281841

18291842
def test_put_contexts_get_context_by_type_and_name(self):
18301843
# Prepare test data.
@@ -2112,12 +2125,15 @@ def test_put_lineage_subgraph_get_lineage_subgraph(self):
21122125
# Test get_lineage_subgraph() with max_num_hops = 10 and field mask paths =
21132126
# ["events", "associations", "attributions"], the whole lineage subgraph
21142127
# skeleton will be returned.
2115-
query_options = metadata_store_pb2.LineageSubgraphQueryOptions(
2116-
starting_artifacts=metadata_store_pb2.LineageSubgraphQueryOptions.StartingNodes(
2117-
filter_query="uri = 'output_artifact'"
2118-
),
2119-
max_num_hops=10,
2120-
)
2128+
# Note: filter_query is deprecated but tested here for backward compatibility.
2129+
with warnings.catch_warnings():
2130+
warnings.filterwarnings("ignore", category=DeprecationWarning)
2131+
query_options = metadata_store_pb2.LineageSubgraphQueryOptions(
2132+
starting_artifacts=metadata_store_pb2.LineageSubgraphQueryOptions.StartingNodes(
2133+
filter_query="uri = 'output_artifact'"
2134+
),
2135+
max_num_hops=10,
2136+
)
21212137

21222138
subgraph_skeleton = store.get_lineage_subgraph(
21232139
query_options, ["events", "associations", "attributions"]
@@ -2169,12 +2185,15 @@ def test_put_lineage_subgraph_get_lineage_subgraph(self):
21692185

21702186
# Test get_lineage_subgraph() with max_num_hops = 0 from starting executions
21712187
# filtered by context name. All the executions will be returned.
2172-
query_options = metadata_store_pb2.LineageSubgraphQueryOptions(
2173-
starting_executions=metadata_store_pb2.LineageSubgraphQueryOptions.StartingNodes(
2174-
filter_query="contexts_a.name='existing_context'"
2175-
),
2176-
max_num_hops=0,
2177-
)
2188+
# Note: filter_query is deprecated but tested here for backward compatibility.
2189+
with warnings.catch_warnings():
2190+
warnings.filterwarnings("ignore", category=DeprecationWarning)
2191+
query_options = metadata_store_pb2.LineageSubgraphQueryOptions(
2192+
starting_executions=metadata_store_pb2.LineageSubgraphQueryOptions.StartingNodes(
2193+
filter_query="contexts_a.name='existing_context'"
2194+
),
2195+
max_num_hops=0,
2196+
)
21782197
subgraph = store.get_lineage_subgraph(query_options)
21792198
self.assertEmpty(subgraph.artifacts)
21802199
self.assertLen(subgraph.executions, 2)
@@ -2195,12 +2214,15 @@ def test_put_lineage_subgraph_get_lineage_subgraph(self):
21952214
self.assertEmpty(subgraph.attributions)
21962215

21972216
# Test get_lineage_subgraph() with various field mask paths.
2198-
query_options = metadata_store_pb2.LineageSubgraphQueryOptions(
2199-
starting_artifacts=metadata_store_pb2.LineageSubgraphQueryOptions.StartingNodes(
2200-
filter_query="uri = 'output_artifact'"
2201-
),
2202-
max_num_hops=10,
2203-
)
2217+
# Note: filter_query is deprecated but tested here for backward compatibility.
2218+
with warnings.catch_warnings():
2219+
warnings.filterwarnings("ignore", category=DeprecationWarning)
2220+
query_options = metadata_store_pb2.LineageSubgraphQueryOptions(
2221+
starting_artifacts=metadata_store_pb2.LineageSubgraphQueryOptions.StartingNodes(
2222+
filter_query="uri = 'output_artifact'"
2223+
),
2224+
max_num_hops=10,
2225+
)
22042226

22052227
subgraph = store.get_lineage_subgraph(
22062228
query_options, ["artifact_types", "execution_types", "context_types"]
@@ -2291,13 +2313,16 @@ def test_put_lineage_subgraph_get_lineage_subgraph_with_direction(self):
22912313
)
22922314

22932315
# Test get_lineage_subgraph() with direction.
2294-
query_options = metadata_store_pb2.LineageSubgraphQueryOptions(
2295-
starting_executions=metadata_store_pb2.LineageSubgraphQueryOptions.StartingNodes(
2296-
filter_query="name = 'test_execution'"
2297-
),
2298-
max_num_hops=2,
2299-
direction=metadata_store_pb2.LineageSubgraphQueryOptions.Direction.DOWNSTREAM,
2300-
)
2316+
# Note: filter_query is deprecated but tested here for backward compatibility.
2317+
with warnings.catch_warnings():
2318+
warnings.filterwarnings("ignore", category=DeprecationWarning)
2319+
query_options = metadata_store_pb2.LineageSubgraphQueryOptions(
2320+
starting_executions=metadata_store_pb2.LineageSubgraphQueryOptions.StartingNodes(
2321+
filter_query="name = 'test_execution'"
2322+
),
2323+
max_num_hops=2,
2324+
direction=metadata_store_pb2.LineageSubgraphQueryOptions.Direction.DOWNSTREAM,
2325+
)
23012326
subgraph = store.get_lineage_subgraph(query_options)
23022327
self.assertLen(subgraph.artifacts, 1)
23032328
self.assertLen(subgraph.executions, 1)

ml_metadata/metadata_store/postgresql_query_executor.cc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -885,6 +885,12 @@ absl::Status PostgreSQLQueryExecutor::ListNodeIDsUsingOptions(
885885
}
886886

887887
if (options.has_filter_query() && !options.filter_query().empty()) {
888+
// DEPRECATED: ZetaSQL-based filter_query is deprecated and will be removed
889+
// in version 1.18.0. This feature depends on ZetaSQL which is being phased
890+
// out. Please migrate to alternative filtering approaches.
891+
LOG(WARNING) << "DEPRECATION WARNING: ZetaSQL-based filter_query is "
892+
<< "deprecated and will be removed in version 1.18.0. "
893+
<< "This feature depends on ZetaSQL which is being removed.";
888894
node_table_alias = ml_metadata::FilterQueryBuilder<Node>::kBaseTableAlias;
889895
ml_metadata::FilterQueryAstResolver<Node> ast_resolver(
890896
options.filter_query());

ml_metadata/metadata_store/query_config_executor.cc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -826,6 +826,12 @@ absl::Status QueryConfigExecutor::ListNodeIDsUsingOptions(
826826
}
827827

828828
if (options.has_filter_query() && !options.filter_query().empty()) {
829+
// DEPRECATED: ZetaSQL-based filter_query is deprecated and will be removed
830+
// in version 1.18.0. This feature depends on ZetaSQL which is being phased
831+
// out. Please migrate to alternative filtering approaches.
832+
LOG(WARNING) << "DEPRECATION WARNING: ZetaSQL-based filter_query is "
833+
<< "deprecated and will be removed in version 1.18.0. "
834+
<< "This feature depends on ZetaSQL which is being removed.";
829835
node_table_alias = ml_metadata::FilterQueryBuilder<Node>::kBaseTableAlias;
830836
ml_metadata::FilterQueryAstResolver<Node> ast_resolver(
831837
options.filter_query());

ml_metadata/query/filter_query_ast_resolver.cc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,12 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1212
See the License for the specific language governing permissions and
1313
limitations under the License.
1414
==============================================================================*/
15+
16+
// DEPRECATED: This file and its associated ZetaSQL-based filter_query
17+
// functionality is deprecated and will be removed in version 1.18.0.
18+
// ZetaSQL dependency is being phased out from ML Metadata.
19+
// Please migrate to alternative filtering approaches.
20+
1521
#include "ml_metadata/query/filter_query_ast_resolver.h"
1622
#include <vector>
1723

ml_metadata/query/filter_query_ast_resolver.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,11 @@ limitations under the License.
2222

2323
namespace ml_metadata {
2424

25+
// DEPRECATED: This class and its associated ZetaSQL-based filter_query
26+
// functionality is deprecated and will be removed in version 1.18.0.
27+
// ZetaSQL dependency is being phased out from ML Metadata.
28+
// Please migrate to alternative filtering approaches.
29+
//
2530
// FilterQueryAstResolver parses the MLMD filtering query string and generates
2631
// an AST via ZetaSQL analyzer. It can be instantiated with MLMD nodes types:
2732
// Artifact, Execution and Context.

ml_metadata/query/filter_query_builder.cc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,12 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1212
See the License for the specific language governing permissions and
1313
limitations under the License.
1414
==============================================================================*/
15+
16+
// DEPRECATED: This file and its associated ZetaSQL-based filter_query
17+
// functionality is deprecated and will be removed in version 1.18.0.
18+
// ZetaSQL dependency is being phased out from ML Metadata.
19+
// Please migrate to alternative filtering approaches.
20+
1521
#include "ml_metadata/query/filter_query_builder.h"
1622

1723
#include <glog/logging.h>

ml_metadata/query/filter_query_builder.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,11 @@ limitations under the License.
2121

2222
namespace ml_metadata {
2323

24+
// DEPRECATED: This class and its associated ZetaSQL-based filter_query
25+
// functionality is deprecated and will be removed in version 1.18.0.
26+
// ZetaSQL dependency is being phased out from ML Metadata.
27+
// Please migrate to alternative filtering approaches.
28+
//
2429
// FilterQueryBuilder is a ZetaSQL AST Visitor. It walks through a ZetaSQL
2530
// boolean expression AST parsed from a filtering query string and generates
2631
// FROM clauses and WHERE clauses which can be used by MLMD query executors. It

0 commit comments

Comments
 (0)