package com.dtstack.jlogstash.format.util;

import com.beust.jcommander.internal.Maps;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * @author: haisi
 * @date 2019-06-18 14:44
 */

public class HiveConverter {

    private static Logger logger = LoggerFactory.getLogger(HiveConverter.class);

    private static Pattern pat1 = Pattern.compile( "\\$\\{.*?\\}");

    /**
     *
     * @param path
     * @return
     */
    public static String regaxByRules(Map output, String path) {
        try {
            Matcher mat1 = pat1.matcher(path);
            while (mat1.find()) {
                String pkey =  mat1.group();
                String key = pkey.substring(2, pkey.length() - 1);
                Object value = output.get(key);
                if(value !=null){
                    path =  path.replace(pkey,value.toString());
                }
            }
        } catch (Exception e) {
            logger.error("parser path rules is fail", e);
        }
        return path;
    }


    public static void main(String[] args){

        String ss = "sss_${ysq}_${name}_${ysq}/ysq/ysq/yyy.txt";

        Map<String,String> evnets = Maps.newHashMap();
        evnets.put("ysq","bac");
        evnets.put("name","bbbb");
        System.out.println(regaxByRules(evnets,ss));
    }
}


@@ -41,51 +41,8 @@
 l;%0A%0A
-import com.beust.jcommander.internal.Maps;%0A
 impo
@@ -1055,301 +1055,7 @@
  %7D%0A%0A
-%0A    public static void main(String%5B%5D args)%7B%0A%0A        String ss = %22sss_$%7Bysq%7D_$%7Bname%7D_$%7Bysq%7D/ysq/ysq/yyy.txt%22;%0A%0A        Map%3CString,String%3E evnets = Maps.newHashMap();%0A        evnets.put(%22ysq%22,%22bac%22);%0A        evnets.put(%22name%22,%22bbbb%22);%0A        System.out.println(regaxByRules(evnets,ss));%0A    %7D%0A
 %7D%0A%0A

remove no nedd