// Path: core/src/main/java/com/dnt/itl/ext/ExtensionFunction.java
// public class ExtensionFunction {
// 
//     public static final boolean getResumeRate(double age, String education, double income) {
// 
//         if (income * 0.75 > age) {
//             return true;
//         }
//         return false;
//     }
// 
// 
// }
// 
// Path: core/src/main/java/com/dnt/itl/parser/ITLExplainService.java
// public class ITLExplainService {
// 
//     Map<String, List<QlContextWithId>> ds2Ctx = new HashMap<>();
// 
//     static Gson gson = new Gson();
// 
//     ITLVisitor visitor;
// 
// 
//     public ITLExplainService() {
//         FunctionMgr functionMgr = new FunctionMgr();
// 
//         visitor = new ITLVisitor();
//         visitor.setFunctionMgr(functionMgr);
// 
//     }
// 
//     public void addFunction(String funcName, Method method, Object on) {
//         visitor.getFunctionMgr().addFunction(funcName, new Function(method, on));
//     }
// 
//     public synchronized void addITL(Object id, String ITL) {
//         ANTLRInputStream inputStream = null;
//         try {
//             inputStream = new ANTLRInputStream(new ByteArrayInputStream(ITL.getBytes()));
//         } catch (IOException e) {
//             e.printStackTrace();
//         }
//         ITLLexer lexer = new ITLLexer(inputStream);
//         CommonTokenStream tokenStream = new CommonTokenStream(lexer);
//         ITLParser ITLParse = new ITLParser(tokenStream);
// 
//         ITLParser.QlContext qlContext = ITLParse.ql();
// 
//         String fromSource = qlContext.from().fromSource.getText();
// 
//         List<QlContextWithId> ctxs = ds2Ctx.get(fromSource);
//         if (ctxs == null) {
//             ctxs = new ArrayList<>();
//             ds2Ctx.put(fromSource, ctxs);
//         }
// 
//         QlContextWithId qlContextWithId = new QlContextWithId(id, qlContext);
// 
//         ctxs.add(qlContextWithId);
//     }
// 
//     public synchronized boolean removeITL(Object id) {
//         for (List<QlContextWithId> qlContexts : ds2Ctx.values()) {
//             if (qlContexts.remove(id)) {
//                 return true;
//             }
//         }
//         return false;
//     }
// 
//     public Map<Object, Object> process(String datasource, String json) {
// 
//         Map data = gson.fromJson(json, Map.class);
// 
//         return this.process(datasource, data);
//     }
// 
//     public Map<Object, Object> process(String datasource, Object json) {
// 
//         List<QlContextWithId> qlContexts = ds2Ctx.get(datasource);
// 
//         if (qlContexts == null) {
//             return Collections.EMPTY_MAP;
//         }
// 
// 
//         Map<Object, Object> rets = new HashMap<>();
// 
//         for (QlContextWithId qlContextWithId : qlContexts) {
//             Object id = qlContextWithId.id;
//             ITLParser.QlContext qlContext = qlContextWithId.qlContext;
// 
//             visitor.setRawData(json);
//             Object var = visitor.visit(qlContext);
//             rets.put(id, var);
//         }
// 
//         return rets;
//     }
// 
// }


import com.dnt.itl.ext.ExtensionFunction;
import com.dnt.itl.parser.ITLExplainService;
import com.google.gson.Gson;
import java.io.IOException;
import java.io.InputStreamReader;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.Map;
        System.out.println(gson.toJson(ret));
    }


    static void runResume() throws NoSuchMethodException {
        // prepare data
        Map data = gson.fromJson(new InputStreamReader(DemoAppMain.class.getResourceAsStream("/person.json")), Map.class);

        String otl = "select\n" +
                "     person.name as name,\n" +
                "     upper(person.addr) as addr,\n" +
                "     person.workexp[0] as firstwork,\n" +
                "     getResumeRate(person.age, person.education, person.income) as resumeRate,\n" +
                "     (person.income-person.startIncome)/person.workyear as salaryIncreaseYearly,\n" +
                "     null as furtherData,\n" +
                "     nowStr() as datetime,\n" +
                "     \"Phase1\" as currStep,\n" +
                "     99 as status,\n" +
                "     'a' as grade,\n" +
                "     98.5 as mark,\n" +
                "     person.married as marriedStatus,\n" +
                "     map on person.workexp using upper (companyName) as mapCompanyName,\n" +
                "     reduce on person.workexp using maxOnFirst(workYear,companyName,position) as maxWorkExp\n" +
                "from PersonData as person\n" +
                "    where (person.age > 30 and person.workyear > 7) \n" +
                "    or person.location=\"Shanghai\"\n" +
                "    or person.education=\"doctor\"\n" +
                "    ";

        // ITLExplainService is used to run ITL
// Path: core/src/main/java/com/dnt/itl/ext/ExtensionFunction.java
// public class ExtensionFunction {
// 
//     public static final boolean getResumeRate(double age, String education, double income) {
// 
//         if (income * 0.75 > age) {
//             return true;
//         }
//         return false;
//     }
// 
// 
// }
// 
// Path: core/src/main/java/com/dnt/itl/parser/ITLExplainService.java
// public class ITLExplainService {
// 
//     Map<String, List<QlContextWithId>> ds2Ctx = new HashMap<>();
// 
//     static Gson gson = new Gson();
// 
//     ITLVisitor visitor;
// 
// 
//     public ITLExplainService() {
//         FunctionMgr functionMgr = new FunctionMgr();
// 
//         visitor = new ITLVisitor();
//         visitor.setFunctionMgr(functionMgr);
// 
//     }
// 
//     public void addFunction(String funcName, Method method, Object on) {
//         visitor.getFunctionMgr().addFunction(funcName, new Function(method, on));
//     }
// 
//     public synchronized void addITL(Object id, String ITL) {
//         ANTLRInputStream inputStream = null;
//         try {
//             inputStream = new ANTLRInputStream(new ByteArrayInputStream(ITL.getBytes()));
//         } catch (IOException e) {
//             e.printStackTrace();
//         }
//         ITLLexer lexer = new ITLLexer(inputStream);
//         CommonTokenStream tokenStream = new CommonTokenStream(lexer);
//         ITLParser ITLParse = new ITLParser(tokenStream);
// 
//         ITLParser.QlContext qlContext = ITLParse.ql();
// 
//         String fromSource = qlContext.from().fromSource.getText();
// 
//         List<QlContextWithId> ctxs = ds2Ctx.get(fromSource);
//         if (ctxs == null) {
//             ctxs = new ArrayList<>();
//             ds2Ctx.put(fromSource, ctxs);
//         }
// 
//         QlContextWithId qlContextWithId = new QlContextWithId(id, qlContext);
// 
//         ctxs.add(qlContextWithId);
//     }
// 
//     public synchronized boolean removeITL(Object id) {
//         for (List<QlContextWithId> qlContexts : ds2Ctx.values()) {
//             if (qlContexts.remove(id)) {
//                 return true;
//             }
//         }
//         return false;
//     }
// 
//     public Map<Object, Object> process(String datasource, String json) {
// 
//         Map data = gson.fromJson(json, Map.class);
// 
//         return this.process(datasource, data);
//     }
// 
//     public Map<Object, Object> process(String datasource, Object json) {
// 
//         List<QlContextWithId> qlContexts = ds2Ctx.get(datasource);
// 
//         if (qlContexts == null) {
//             return Collections.EMPTY_MAP;
//         }
// 
// 
//         Map<Object, Object> rets = new HashMap<>();
// 
//         for (QlContextWithId qlContextWithId : qlContexts) {
//             Object id = qlContextWithId.id;
//             ITLParser.QlContext qlContext = qlContextWithId.qlContext;
// 
//             visitor.setRawData(json);
//             Object var = visitor.visit(qlContext);
//             rets.put(id, var);
//         }
// 
//         return rets;
//     }
// 
// }


// Path: core/src/main/java/com/dnt/itl/DemoAppMain.java
import com.dnt.itl.ext.ExtensionFunction;
import com.dnt.itl.parser.ITLExplainService;
import com.google.gson.Gson;
import java.io.IOException;
import java.io.InputStreamReader;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.Map;

        System.out.println(gson.toJson(ret));
    }


    static void runResume() throws NoSuchMethodException {
        // prepare data
        Map data = gson.fromJson(new InputStreamReader(DemoAppMain.class.getResourceAsStream("/person.json")), Map.class);

        String otl = "select\n" +
                "     person.name as name,\n" +
                "     upper(person.addr) as addr,\n" +
                "     person.workexp[0] as firstwork,\n" +
                "     getResumeRate(person.age, person.education, person.income) as resumeRate,\n" +
                "     (person.income-person.startIncome)/person.workyear as salaryIncreaseYearly,\n" +
                "     null as furtherData,\n" +
                "     nowStr() as datetime,\n" +
                "     \"Phase1\" as currStep,\n" +
                "     99 as status,\n" +
                "     'a' as grade,\n" +
                "     98.5 as mark,\n" +
                "     person.married as marriedStatus,\n" +
                "     map on person.workexp using upper (companyName) as mapCompanyName,\n" +
                "     reduce on person.workexp using maxOnFirst(workYear,companyName,position) as maxWorkExp\n" +
                "from PersonData as person\n" +
                "    where (person.age > 30 and person.workyear > 7) \n" +
                "    or person.location=\"Shanghai\"\n" +
                "    or person.education=\"doctor\"\n" +
                "    ";

        // ITLExplainService is used to run ITL
        ITLExplainService ITLExplainService = new ITLExplainService();