<commit_before><?php
namespace ntentan\atiaa\descriptors;

class PostgresqlDescriptor extends InformationSchemaDescriptor
{
    /**
     * 
     * @note Query sourced from http://stackoverflow.com/questions/2204058/show-which-columns-an-index-is-on-in-postgresql
     * @param type $table
     * @return type
     */
    protected function getIndices(&$table)
    {
        return $this->driver->query(
            sprintf("select
                        t.relname as table_name,
                        i.relname as name,
                        a.attname as column
                    from
                        pg_class t,
                        pg_class i,
                        pg_index ix,
                        pg_attribute a,
                        pg_namespace n
                    where
                        t.oid = ix.indrelid
                        and i.oid = ix.indexrelid
                        and a.attrelid = t.oid
                        and a.attnum = ANY(ix.indkey)<commit_msg>Experimenting with cleaning postgresql default values [skip ci]<commit_after><?php
namespace ntentan\atiaa\descriptors;

class PostgresqlDescriptor extends InformationSchemaDescriptor
{
    protected function getColumns(&$table)
    {
        $columns = parent::getColumns($table);
        foreach($columns as $i => $column) {
            if(preg_match("/(?<value>.*)(::)(?<type>[a-zA-Z0-9\s]*)/", $column['default'], $matches)) {
                $columns[$i]['default'] = $this->cleanDefaultValue($matches['value']);
            }
        }
        return $columns;
    }
    
    private function cleanDefaultValue($defaultValue) 
    {
        if(is_numeric($defaultValue)) {
            return $defaultValue;
        } else if (preg_match("/'(?<string>.*)'/", $defaultValue, $matches)) {
            return $matches['string'];
        } else {
            return null;
        }
    }

    /**
     * 
     * @note Query sourced from http://stackoverflow.com/questions/2204058/show-which-columns-an-index-is-on-in-postgresql
     * @param type $table
     * @return type
     */
    protected function getIndices(&$table)
    {
        return $this->driver->query(
            sprintf("select
                        t.relname as table_name,
                        i.relname as name,
                        a.attname as column
                    from
                        pg_class t,
                        pg_class i,
                        pg_index ix,
                        pg_attribute a,
                        pg_namespace n
                    where
                        t.oid = ix.indrelid
                        and i.oid = ix.indexrelid
                        and a.attrelid = t.oid
                        and a.attnum = ANY(ix.indkey)
{'fraction_non_alphanumeric': 0.1007919366450684, 'fraction_numerical': 0.005759539236861051, 'mean_word_length': 1.3024026512013256, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 12, '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': '1355565', 'n_tokens_mistral': 762, 'n_tokens_neox': 711, 'n_words': 148}