package com.streever.hadoop.hive.money.honey;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.hadoop.hive.ql.exec.Description;
import org.apache.hadoop.hive.ql.exec.UDF;
import org.apache.hadoop.io.Text;

import java.text.DateFormat;
import java.text.ParseException;
import java.util.Date;

/**
 * Created by dstreev on 11/11/14.
 */

@Description(
        name = "remove_thousand_separator",
        value = "_FUNC_(text) - Returns converted $ by removing ',' from money",
        extended = "Examples:\n"
                + "  > SELECT _FUNC_('5,342,321.43') FROM src LIMIT 1;\n"
                + "  5342321.43\n"
)
public class RemoveThousandSeparator extends UDF {
    /**
     * Returns converted $ by removing ',' from money.
     *
     * @return Returns converted $ by removing ',' from money
     *
     */

    private Text result = new Text();
    static final Log LOG = LogFactory.getLog(RemoveThousandSeparator.class.getName());

    public Text evaluate(Text value) {
        String without = value.toString().replaceAll(",|'","");
        result.set(without);
        return result;
    }

}


@@ -1095,16 +1095,309 @@
 '%22,%22%22);%0A
+        if (without.startsWith(%22(%22)) %7B%0A            // This means it is surrounded by parentheses and is negative.%0A            StringBuilder sb = new StringBuilder(%22-%22);%0A            sb.append(without.substring(1,without.length()-1));%0A            result.set(sb.toString());%0A        %7D else %7B%0A    
         
@@ -1417,16 +1417,26 @@
 thout);%0A
+        %7D%0A
         

Add Check for Negative Value.