<commit_before># Copyright 2019 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""A python API to the metadata store.

Provides access to a SQLite3 or a MySQL backend. Artifact types and execution
types can be created on the fly.
"""

from __future__ import absolute_import
from __future__ import division

from __future__ import print_function

from absl import logging
import grpc
from typing import List, Optional, Sequence, Text, Tuple, Union

from ml_metadata.metadata_store import pywrap_tf_metadata_store_serialized as metadata_store_serialized
from ml_metadata.proto import metadata_store_pb2
from ml_metadata.proto import metadata_store_service_pb2
from ml_metadata.proto import metadata_store_service_pb2_grpc
from tensorflow.python.framework import errors


class MetadataStore(object):
  """A store for the artifact metadata."""

  def __init__(self,
               config: Union[metadata_store_pb2.ConnectionConfig,
                             metadata_store_pb2.MetadataStoreClientConfig],
               enable_upgrade_migration: bool = False):
    """Initialize the MetadataStore.

    MetadataStore can directly connect to either the metadata database or
    the metadata store server.

    Args:
      config: metadata_store_pb2.ConnectionConfig or
        metadata_store_pb2.MetadataStoreClientConfig. Configuration to
        connect to the database or the metadata store server.
      enable_upgrade_migration: if set to True, the library upgrades the db
        schema and migrates all data if it connects to an old version backend.
        It is ignored when using GRPC client connection config.
    """
    if isinstance(config, metadata_store_pb2.ConnectionConfig):
      self._using_db_connection = True
      migration_options = metadata_store_pb2.MigrationOptions()
      migration_options.enable_upgrade_migration = enable_upgrade_migration
      self._metadata_store = metadata_store_serialized.CreateMetadataStore(
          config.SerializeToString(), migration_options.SerializeToString())
      logging.log(logging.INFO, 'MetadataStore with DB connection initialized')
      return
    if not isinstance(config, metadata_store_pb2.MetadataStoreClientConfig):
      raise ValueError('MetadataStore is expecting either'
                       'metadata_store_pb2.ConnectionConfig or'
                       'metadata_store_pb2.MetadataStoreClientConfig')
    self._using_db_connection = False
    if enable_upgrade_migration:<commit_msg>Fix a typo in Exception message<commit_after># Copyright 2019 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
"""A python API to the metadata store.

Provides access to a SQLite3 or a MySQL backend. Artifact types and execution
types can be created on the fly.
"""

from __future__ import absolute_import
from __future__ import division

from __future__ import print_function

from absl import logging
import grpc
from typing import List, Optional, Sequence, Text, Tuple, Union

from ml_metadata.metadata_store import pywrap_tf_metadata_store_serialized as metadata_store_serialized
from ml_metadata.proto import metadata_store_pb2
from ml_metadata.proto import metadata_store_service_pb2
from ml_metadata.proto import metadata_store_service_pb2_grpc
from tensorflow.python.framework import errors


class MetadataStore(object):
  """A store for the artifact metadata."""

  def __init__(self,
               config: Union[metadata_store_pb2.ConnectionConfig,
                             metadata_store_pb2.MetadataStoreClientConfig],
               enable_upgrade_migration: bool = False):
    """Initialize the MetadataStore.

    MetadataStore can directly connect to either the metadata database or
    the metadata store server.

    Args:
      config: metadata_store_pb2.ConnectionConfig or
        metadata_store_pb2.MetadataStoreClientConfig. Configuration to
        connect to the database or the metadata store server.
      enable_upgrade_migration: if set to True, the library upgrades the db
        schema and migrates all data if it connects to an old version backend.
        It is ignored when using GRPC client connection config.
    """
    if isinstance(config, metadata_store_pb2.ConnectionConfig):
      self._using_db_connection = True
      migration_options = metadata_store_pb2.MigrationOptions()
      migration_options.enable_upgrade_migration = enable_upgrade_migration
      self._metadata_store = metadata_store_serialized.CreateMetadataStore(
          config.SerializeToString(), migration_options.SerializeToString())
      logging.log(logging.INFO, 'MetadataStore with DB connection initialized')
      return
    if not isinstance(config, metadata_store_pb2.MetadataStoreClientConfig):
      raise ValueError('MetadataStore is expecting either '
                       'metadata_store_pb2.ConnectionConfig or '
                       'metadata_store_pb2.MetadataStoreClientConfig')
    self._using_db_connection = False
    if enable_upgrade_migration:
{'fraction_non_alphanumeric': 0.0504847876964226, 'fraction_numerical': 0.007021063189568706, 'mean_word_length': 3.9775374376039934, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4032643', 'n_tokens_mistral': 1495, 'n_tokens_neox': 1470, 'n_words': 556}