Repository navigation
Expand file tree
/
Copy pathTest.java
More file actions
84 lines (75 loc) · 3.66 KB
/
Copy pathTest.java
File metadata and controls
84 lines (75 loc) · 3.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
package org.nlpcn.es4sql;
import org.elasticsearch.client.Client;
import org.elasticsearch.client.node.NodeClient;
import org.elasticsearch.common.settings.Settings;
import java.util.HashMap;
import java.util.Map;
/**
* Created by allwefantasy on 8/18/16.
*/
public class Test {
public static String sqlToEsQuery(String sql) throws Exception {
Map actions = new HashMap();
Settings settings = Settings.builder().build();
Client client = new NodeClient(settings, null, null, actions);
SearchDao searchDao = new org.nlpcn.es4sql.SearchDao(client);
try {
return searchDao.explain(sql).explain().explain();
} catch (Exception e) {
throw e;
}
}
public static void main(String[] args) throws Exception {
String sql = "SELECT u as u2,count(distinct(mid)) as count FROM panda_quality where ty='buffer' and day='20160816' and tm>1471312800.00 and tm<1471313100.00 and domain='http://pl10.live.panda.tv' group by u order by count desc limit 5000";
// sql = "SELECT sum(num) as num2,newtype as nt from twitter2 group by nt order by num2 ";
// System.out.println("sql" + sql + ":\n" + sqlToEsQuery(sql));
//
// sql = "SELECT sum(num_d) as num2,split(newtype,',') as nt from twitter2 group by nt order by num2 ";
//
// System.out.println("sql" + sql + ":\n" + sqlToEsQuery(sql));
//
// sql = "SELECT newtype as nt from twitter2 ";
//
// System.out.println("sql" + sql + ":\n----------\n" + sqlToEsQuery(sql));
//
// sql = "SELECT sum(num_d) as num2,floor(num) as nt from twitter2 group by floor(num),newtype order by num2 ";
//
// System.out.println("sql" + sql + ":\n----------\n" + sqlToEsQuery(sql));
//
// sql = "SELECT split('newtype','b')[1] as nt,sum(num_d) as num2 from twitter2 group by nt ";
//
// System.out.println("sql" + sql + ":\n----------\n" + sqlToEsQuery(sql));
//
// sql = "SELECT concat_ws('dd','newtype','num_d') as num2 from twitter2";
// System.out.println("sql" + sql + ":\n----------\n" + sqlToEsQuery(sql));
//
// sql = "SELECT split(split('newtype','c')[0],'b')[0] as num2 from twitter2";
// System.out.println("sql" + sql + ":\n----------\n" + sqlToEsQuery(sql));
//
// sql = "SELECT floor(split(substring('newtype',0,3),'c')[0]) as num2 from twitter2";
// System.out.println("sql" + sql + ":\n----------\n" + sqlToEsQuery(sql));
//
// sql = "SELECT split(substring('newtype',0,3),'c')[0] as nt,num_d from twitter2 group by nt";
// System.out.println("sql" + sql + ":\n----------\n" + sqlToEsQuery(sql));
//
// sql = "SELECT floor(num_d) as nt from twitter2 ";
// System.out.println("sql" + sql + ":\n----------\n" + sqlToEsQuery(sql));
//
// sql = "SELECT trim(newtype) as nt from twitter2 ";
// System.out.println("sql" + sql + ":\n----------\n" + sqlToEsQuery(sql));
//
// sql = "SELECT trim(concat_ws('dd',newtype,num_d)) as nt from twitter2 ";
// System.out.println("sql" + sql + ":\n----------\n" + sqlToEsQuery(sql));
//
//
// sql = "SELECT split(trim(concat_ws('dd',newtype,num_d)),'dd')[0] as nt from twitter2 ";
// System.out.println("sql" + sql + ":\n----------\n" + sqlToEsQuery(sql));
sql = "SELECT floor(" +
"floor(substring(newtype,0,14)/100)/5)*5 as key," +
"count(distinct(num)) cvalue FROM twitter2 " +
"group by key ";
String TEST_INDEX = "elasticsearch-sql_test_index";
sql = "select * from xxx/locs where 'a' = 'b' and a > 1";
System.out.println("sql" + sql + ":\n----------\n" + sqlToEsQuery(sql));
}
}