<commit_before>/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package ca.nrc.cadc.tap.parser;

import ca.nrc.cadc.tap.parser.region.pgsphere.function.Spoint;
import ca.nrc.cadc.tap.parser.region.pgsphere.function.Spoly;
import java.util.List;
import net.sf.jsqlparser.expression.Expression;
import net.sf.jsqlparser.expression.Function;
import net.sf.jsqlparser.expression.StringValue;
import net.sf.jsqlparser.statement.select.SelectVisitor;
import org.apache.log4j.Logger;

/**
 * De-parser for PostgreSQL PGSphere functions.
 * 
 * @author jburke
 */
public class PgsphereDeParser extends BaseExpressionDeParser
{
    private static Logger log = Logger.getLogger(PgsphereDeParser.class);

    public PgsphereDeParser(SelectVisitor selectVisitor, StringBuffer buffer)
    {
        super(selectVisitor, buffer);
    }

    /**
     * De-parses PGSphere functions, else passes the function
     * to the super class for de-parsing.
     *
     * @param function
     */<commit_msg>added hack to strip quotes from quoted identifiers (column names) since it generally breaks in postgresql<commit_after>/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package ca.nrc.cadc.tap.parser;

import ca.nrc.cadc.tap.parser.region.pgsphere.function.Spoint;
import ca.nrc.cadc.tap.parser.region.pgsphere.function.Spoly;
import java.util.List;
import net.sf.jsqlparser.expression.Expression;
import net.sf.jsqlparser.expression.Function;
import net.sf.jsqlparser.expression.StringValue;
import net.sf.jsqlparser.schema.Column;
import net.sf.jsqlparser.statement.select.SelectVisitor;
import org.apache.log4j.Logger;

/**
 * De-parser for PostgreSQL PGSphere functions.
 * 
 * @author jburke
 */
public class PgsphereDeParser extends BaseExpressionDeParser
{
    private static Logger log = Logger.getLogger(PgsphereDeParser.class);

    public PgsphereDeParser(SelectVisitor selectVisitor, StringBuffer buffer)
    {
        super(selectVisitor, buffer);
    }
    
    @Override
    public void visit(Column column)
    {
        log.debug("visit(" +  column.getClass().getSimpleName() + ") " + column);
        
        // postgresql: quoted identifiers avoid case foling so mixed-case columns
        // will not be found, so HACK: just strip the quotes because no sane person 
        // would actually rely on quoted identifers :-)
        // TODO: this should really go into a super class PostresqlQueryDeparser
        // but we don't have that right now... or be na option on BaseExpressionDeParser
        String wcn = column.getWholeColumnName();
        if (wcn.indexOf('"') >= 0)
        {
            wcn = wcn.replace("\"", "");
            column.setColumnName(wcn);
        }
        
        super.visit(column);
    }

    /**
     * De-parses PGSphere functions, else passes the function
     * to the super class for de-parsing.
     *
     * @param function
     */
{'fraction_non_alphanumeric': 0.10003356831151393, 'fraction_numerical': 0.0010070493454179255, 'mean_word_length': 3.1853932584269664, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 4, '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': '3315564', 'n_tokens_mistral': 903, 'n_tokens_neox': 873, 'n_words': 231}