I extends scalarfunction like this,and I invoke tableEnv.createTemporarySystemFunction("tree_map", new TreeMapFunction()); public class TreeMapFunction extends ScalarFunction { private static Logger profileLog = Logger.getLogger("zhangying480");
@Override public boolean isDeterministic() { return false; } public Map<String, String> eval() { Map<String, String> result = new TreeMap<>(new Comparator<String>() { @Override public int compare(String o1, String o2) { return o1.compareTo(o2); } }); result.put("a", "zhangying480"); result.put("as", "azhangying480"); result.put("abs", "aabzhangying480"); result.put("dv", "dzhangying480"); result.put("dd", "dczhangying480"); result.put("de", "eazhangying480"); result.put("e", "efzhangying480"); result.put("1", "eezhangying480"); result.put("#", "12zhangying480"); result.put("i", "#zhangying480"); return result; } } also,I extends scalarfunction like this,and I invoke tableEnv.createTemporarySystemFunction("map_unfold", new MapUnfoldFunction()) public class MapUnfoldFunction extends ScalarFunction { public static Logger log = LoggerFactory.getLogger(MapUnfoldFunction.class); public String eval(Map<String, String> string2StringMap) { StringBuilder result = new StringBuilder(); if(null != string2StringMap) { Set<Map.Entry<String, String>> entrySet = string2StringMap.entrySet(); for (Map.Entry<String, String> entry : entrySet) { result.append(entry.getKey()).append(","); } } return result.toString(); } } I run a sql like this: Table tableTreeMap = tableEnv.sqlQuery("select pvid,tree_map() as group_name from db1.`search_realtime_table_dump_p13`"); TableResult tableResult = tableEnv.executeSql("select map_unfold(group_name) as map_unfold from " + tableTreeMap) I think the result like this: #,1,a,abs,as,dd,de,dv,e,i, but I get the result like this,it is out-of-order | dd,1,a,de,as,dv,#,abs,e,i, | +--------------------------------+