<commit_before># (C) Datadog, Inc. 2019-present
# All rights reserved
# Licensed under Simplified BSD License (see LICENSE)
import re

import psycopg2
import semver
from semver import VersionInfo

V8_3 = VersionInfo(**semver.parse("8.3.0"))
V9 = VersionInfo(**semver.parse("9.0.0"))
V9_1 = VersionInfo(**semver.parse("9.1.0"))
V9_2 = VersionInfo(**semver.parse("9.2.0"))
V9_4 = VersionInfo(**semver.parse("9.4.0"))
V9_6 = VersionInfo(**semver.parse("9.6.0"))
V10 = VersionInfo(**semver.parse("10.0.0"))


def get_raw_version(db):
    cursor = db.cursor()
    cursor.execute('SHOW SERVER_VERSION;')
    raw_version = cursor.fetchone()[0]
    return raw_version


def is_aurora(db):
    cursor = db.cursor()
    try:
        cursor.execute('select AURORA_VERSION();')
        return True
    except psycopg2.errors.UndefinedFunction:
        db.rollback()
        return False


def parse_version(raw_version):
    try:
        # Only works for MAJOR.MINOR.PATCH(-PRE_RELEASE)
        return semver.parse_version_info(raw_version)
    except ValueError:
        pass
    try:
        # Version may be missing minor eg: 10.0
        version = raw_version.split(' ')[0].split('.')
        version = [int(part) for part in version]
        while len(version) < 3:
            version.append(0)
        return VersionInfo(*version)
    except ValueError:
        # Postgres might be in development, with format \d+[beta|rc]\d+
        match = re.match(r'(\d+)([a-zA-Z]+)(\d+)', raw_version)
        if match:
            version = list(match.groups())
            return semver.parse_version_info('{}.0.0-{}.{}'.format(*version))
    raise Exception("Cannot determine which version is {}".format(raw_version))


def transform_version(raw_version, options=None):
    """
    :param raw_version: raw version in str format
    :param options: keyword arguments to pass to any defined transformer<commit_msg>When postgres is not an aurora it is giving error in the execution of agent (#7542)<commit_after># (C) Datadog, Inc. 2019-present
# All rights reserved
# Licensed under Simplified BSD License (see LICENSE)
import re

import semver
from semver import VersionInfo

V8_3 = VersionInfo(**semver.parse("8.3.0"))
V9 = VersionInfo(**semver.parse("9.0.0"))
V9_1 = VersionInfo(**semver.parse("9.1.0"))
V9_2 = VersionInfo(**semver.parse("9.2.0"))
V9_4 = VersionInfo(**semver.parse("9.4.0"))
V9_6 = VersionInfo(**semver.parse("9.6.0"))
V10 = VersionInfo(**semver.parse("10.0.0"))


def get_raw_version(db):
    cursor = db.cursor()
    cursor.execute('SHOW SERVER_VERSION;')
    raw_version = cursor.fetchone()[0]
    return raw_version


def is_aurora(db):
    cursor = db.cursor()
    try:
        cursor.execute("select exists(select 1 from pg_proc where proname = 'aurora_version');")
        return cursor.fetchone()[0]
    except Exception:
        db.rollback()
        return False


def parse_version(raw_version):
    try:
        # Only works for MAJOR.MINOR.PATCH(-PRE_RELEASE)
        return semver.parse_version_info(raw_version)
    except ValueError:
        pass
    try:
        # Version may be missing minor eg: 10.0
        version = raw_version.split(' ')[0].split('.')
        version = [int(part) for part in version]
        while len(version) < 3:
            version.append(0)
        return VersionInfo(*version)
    except ValueError:
        # Postgres might be in development, with format \d+[beta|rc]\d+
        match = re.match(r'(\d+)([a-zA-Z]+)(\d+)', raw_version)
        if match:
            version = list(match.groups())
            return semver.parse_version_info('{}.0.0-{}.{}'.format(*version))
    raise Exception("Cannot determine which version is {}".format(raw_version))


def transform_version(raw_version, options=None):
    """
    :param raw_version: raw version in str format
    :param options: keyword arguments to pass to any defined transformer
{'fraction_non_alphanumeric': 0.1381172839506173, 'fraction_numerical': 0.026748971193415638, 'mean_word_length': 3.2736263736263735, 'pattern_counts': {'":': 0, '<': 5, '<?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': '5556858', 'n_tokens_mistral': 1291, 'n_tokens_neox': 1241, 'n_words': 306}