<commit_before>import sqlalchemy as sq

from snakepit import directory

class NoSuchDimensionError(Exception):
    """No such dimension"""

    def __str__(self):
        return ': '.join([self.__doc__]+list(self.args))

class NoSuchNodeError(Exception):
    """No such node"""

    def __str__(self):
        return ': '.join([self.__doc__]+list(self.args))

def get_engine(metadata, dimension, id_):
    """
    Get node ID of hive node that stores C{id_} for C{dimension}.

    @param metadata: metadata for the hive db, bound to an engine

    @type metadata: sqlalchemy.MetaData

    @param dimension: name of the dimension

    @type dimension: str

    @param id_: the primary id of the row in question

    @type id_: int
    """

    t = metadata.tables['partition_dimension_metadata']
    q = sq.select(
        [
            t.c.id,
            t.c.index_uri,
            ],
        t.c.name==dimension,
        limit=1,
        )
    res = q.execute().fetchone()
    if res is None:
        raise NoSuchDimensionError(repr(dimension))
    partition_id = res[t.c.id]
    index_uri = res[t.c.index_uri]

    directory_metadata = sq.MetaData()
    directory_metadata.bind = sq.create_engine(
        index_uri,<commit_msg>Document get_engine return value.<commit_after>import sqlalchemy as sq

from snakepit import directory

class NoSuchDimensionError(Exception):
    """No such dimension"""

    def __str__(self):
        return ': '.join([self.__doc__]+list(self.args))

class NoSuchNodeError(Exception):
    """No such node"""

    def __str__(self):
        return ': '.join([self.__doc__]+list(self.args))

def get_engine(metadata, dimension, id_):
    """
    Get node ID of hive node that stores C{id_} for C{dimension}.

    @param metadata: metadata for the hive db, bound to an engine

    @type metadata: sqlalchemy.MetaData

    @param dimension: name of the dimension

    @type dimension: str

    @param id_: the primary id of the row in question

    @type id_: int

    @return: engine connected the the node

    @rtype: sqlalchemy.engine.Engine
    """

    t = metadata.tables['partition_dimension_metadata']
    q = sq.select(
        [
            t.c.id,
            t.c.index_uri,
            ],
        t.c.name==dimension,
        limit=1,
        )
    res = q.execute().fetchone()
    if res is None:
        raise NoSuchDimensionError(repr(dimension))
    partition_id = res[t.c.id]
    index_uri = res[t.c.index_uri]

    directory_metadata = sq.MetaData()
    directory_metadata.bind = sq.create_engine(
        index_uri,
{'fraction_non_alphanumeric': 0.11193447737909516, 'fraction_numerical': 0.00078003120124805, 'mean_word_length': 2.659058487874465, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, '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': '468288', 'n_tokens_mistral': 812, 'n_tokens_neox': 776, 'n_words': 214}