<commit_before>import sqlalchemy as sq

from snakepit import hive, directory

def create_hive(hive_uri):
    """
    Create hive at C{hive_uri}

    @return: A metadata connected to the hive database. Caller is
    responsible for disposing of the engine with
    C{metadata.bind.dispose()}.

    @rtype: sqlaclhemy.MetaData
    """
    hive_metadata = sq.MetaData()
    hive_metadata.bind = sq.create_engine(
        hive_uri,
        strategy='threadlocal',
        )
    for table in hive.metadata.tables.values():
        table.tometadata(hive_metadata)
    hive_metadata.create_all()
    return hive_metadata


def create_primary_index(
    directory_uri,
    dimension_name,
    ):
    """
    Create a primary index for C{dimension_name} at C{directory_uri}.
    """
    directory_metadata = sq.MetaData()
    directory_metadata.bind = sq.create_engine(
        directory_uri,
        strategy='threadlocal',
        )
    table = directory.dynamic_table(
        table=directory.metadata.tables['hive_primary_DIMENSION'],
        metadata=directory_metadata,
        name='hive_primary_%s' % dimension_name,
        )
    directory_metadata.create_all()
    return directory_metadata


class DimensionExistsError(Exception):
    """Dimension exists already"""

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

def create_dimension(hive_metadata, dimension_name, directory_uri):
    """
    Create a dimension with C{dimension_name} at C{hive_metadata},
    where the directory index is stored at C{directory_uri}.

    Directory index must be set up before calling this function.

    @raise DimensionExistsError: a dimension with that name exists
    already in this hive<commit_msg>Document return value of create_dimension.<commit_after>import sqlalchemy as sq

from snakepit import hive, directory

def create_hive(hive_uri):
    """
    Create hive at C{hive_uri}

    @return: A metadata connected to the hive database. Caller is
    responsible for disposing of the engine with
    C{metadata.bind.dispose()}.

    @rtype: sqlaclhemy.MetaData
    """
    hive_metadata = sq.MetaData()
    hive_metadata.bind = sq.create_engine(
        hive_uri,
        strategy='threadlocal',
        )
    for table in hive.metadata.tables.values():
        table.tometadata(hive_metadata)
    hive_metadata.create_all()
    return hive_metadata


def create_primary_index(
    directory_uri,
    dimension_name,
    ):
    """
    Create a primary index for C{dimension_name} at C{directory_uri}.
    """
    directory_metadata = sq.MetaData()
    directory_metadata.bind = sq.create_engine(
        directory_uri,
        strategy='threadlocal',
        )
    table = directory.dynamic_table(
        table=directory.metadata.tables['hive_primary_DIMENSION'],
        metadata=directory_metadata,
        name='hive_primary_%s' % dimension_name,
        )
    directory_metadata.create_all()
    return directory_metadata


class DimensionExistsError(Exception):
    """Dimension exists already"""

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

def create_dimension(hive_metadata, dimension_name, directory_uri):
    """
    Create a dimension with C{dimension_name} at C{hive_metadata},
    where the directory index is stored at C{directory_uri}.

    Directory index must be set up before calling this function.

    @return: id of created dimension

    @rtype: int

    @raise DimensionExistsError: a dimension with that name exists
    already in this hive
{'fraction_non_alphanumeric': 0.08691959229898075, 'fraction_numerical': 0.0, 'mean_word_length': 3.3032886723507917, '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': '5242863', 'n_tokens_mistral': 1042, 'n_tokens_neox': 1024, 'n_words': 262}