Skip to content

Commit 722e673

Browse files
committed
注解完成部分语法和测试用例,sql和catlet语法还需完善
1 parent 074f5d8 commit 722e673

File tree

8 files changed

+884
-604
lines changed

8 files changed

+884
-604
lines changed

minimal_sql_tokens.txt

+37-6
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
AS
2+
ID
23
IF
34
ON
45
FOR
@@ -11,39 +12,69 @@ DESC
1112
FROM
1213
INTO
1314
JOIN
15+
KILL
1416
LOCK
1517
LEFT
18+
NAME
1619
SHOW
20+
SLOW
21+
TIME
22+
USER
1723
ALTER
24+
CLEAR
25+
CACHE
1826
GROUP
1927
GRANT
28+
INDEX
2029
LIMIT
2130
MYCAT
2231
ORDER
2332
RIGHT
33+
ROUTE
2434
TABLE
2535
UNION
2636
WHERE
2737
CATLET
38+
CONFIG
2839
CREATE
29-
EXISTS
30-
UPDATE
40+
DETAIL
3141
DELETE
32-
SELECT
42+
EXISTS
3343
INSERT
3444
IGNORE
35-
SCHEMA
45+
ONLINE
46+
RELOAD
3647
RENAME
3748
REVOKE
49+
ROUTER
50+
SELECT
51+
SERVER
52+
SCHEMA
53+
SWITCH
54+
UPDATE
55+
BACKEND
56+
BALANCE
57+
CURRENT
3858
DB_TYPE
59+
DELAYED
60+
EXECUTE
3961
EXPLAIN
40-
BALANCE
62+
OFFLINE
4163
REPLACE
42-
DELAYED
64+
SESSION
65+
STARTUP
66+
VERSION
67+
DATABASE
4368
DATANODE
4469
DESCRIBE
70+
ROLLBACK
4571
TRUNCATE
72+
HEARTBEAT
4673
PROCEDURE
74+
PROCESSOR
75+
CONNECTION
76+
DATASOURCE
77+
THREADPOOL
4778
LOW_PRIORITY
4879
HIGH_PRIORITY
4980

sql_tokens.txt

+18-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@ AUTOEXTEND_SIZE
2424
AUTO_INCREMENT
2525
AVG_ROW_LENGTH
2626
AVG
27+
BACKEND
2728
BACKUP
29+
BALANCE
2830
BEFORE
2931
BEGIN
3032
BETWEEN
@@ -51,6 +53,7 @@ CASCADED
5153
CASE
5254
CAST
5355
CATALOG_NAME
56+
CATLET
5457
CHAIN
5558
CHANGE
5659
CHANGED
@@ -62,6 +65,7 @@ CHECKSUM
6265
CHECK
6366
CIPHER
6467
CLASS_ORIGIN
68+
CLEAR
6569
CLIENT
6670
CLOSE
6771
COALESCE
@@ -81,6 +85,7 @@ COMPRESSED
8185
COMPRESSION
8286
CONCURRENT
8387
CONDITION
88+
CONFIG
8489
CONNECTION
8590
CONSISTENT
8691
CONSTRAINT
@@ -110,6 +115,8 @@ DATABASE
110115
DATABASES
111116
DATAFILE
112117
DATA
118+
DATANODE
119+
DATASOURCE
113120
DATETIME
114121
DATE_ADD
115122
DATE_ADD_INTERVAL
@@ -122,6 +129,7 @@ DAY_MICROSECOND
122129
DAY_MINUTE
123130
DAY_SECOND
124131
DAY
132+
DB_TYPE
125133
DEALLOCATE
126134
DEC
127135
DECIMAL_NUM
@@ -136,6 +144,7 @@ DELETE
136144
DESC
137145
DESCRIBE
138146
DES_KEY_FILE
147+
DETAIL
139148
DETERMINISTIC
140149
DIAGNOSTICS
141150
DIRECTORY
@@ -196,9 +205,9 @@ FLOAT8
196205
FLOAT
197206
FLUSH
198207
FOLLOWS
208+
FOR
199209
FORCE
200210
FOREIGN
201-
FOR
202211
FORMAT
203212
FOUND
204213
FRAC_SECOND
@@ -221,6 +230,7 @@ GROUP_CONCAT
221230
HANDLER
222231
HASH
223232
HAVING
233+
HEARTBEAT
224234
HELP
225235
HIGH_PRIORITY
226236
HOST
@@ -229,6 +239,7 @@ HOUR_MICROSECOND
229239
HOUR_MINUTE
230240
HOUR_SECOND
231241
HOUR
242+
ID
232243
IDENTIFIED
233244
IF
234245
IGNORE
@@ -353,6 +364,7 @@ MULTILINESTRING
353364
MULTIPOINT
354365
MULTIPOLYGON
355366
MUTEX
367+
MYCAT
356368
MYSQL_ERRNO
357369
NAMES
358370
NAME
@@ -423,6 +435,7 @@ PRIMARY
423435
PRIVILEGES
424436
PROCEDURE
425437
PROCESS
438+
PROCESSOR
426439
PROCESSLIST
427440
PROFILE
428441
PROFILES
@@ -481,6 +494,8 @@ RIGHT
481494
RLIKE
482495
ROLLBACK
483496
ROLLUP
497+
ROUTE
498+
ROUTER
484499
ROUTINE
485500
ROWS
486501
ROW_COUNT
@@ -542,6 +557,7 @@ STACKED
542557
STARTING
543558
STARTS
544559
START
560+
STARTUP
545561
STATS_AUTO_RECALC
546562
STATS_PERSISTENT
547563
STATS_SAMPLE_PAGES
@@ -581,6 +597,7 @@ TERMINATED
581597
TEXT
582598
THAN
583599
THEN
600+
THREADPOOL
584601
TIMESTAMP
585602
TIMESTAMP_ADD
586603
TIMESTAMP_DIFF

src/main/java/io/mycat/IntTokenHash.java

+48-15
Original file line numberDiff line numberDiff line change
@@ -4,55 +4,88 @@
44
* Created by Kaiz on 2017/3/4.
55
*/
66
public class IntTokenHash {
7+
public static final int ANNOTATION_BALANCE= 0x00140001;
8+
public static final int ANNOTATION_START = 0x00150002;
9+
public static final int ANNOTATION_END = 0x00160002;
10+
11+
//generate by MatchMethodGenerator.GenerateSqlTokenHash
712
public static final int AS = 0x46580002;
13+
public static final int ID = 0x47670002;
814
public static final int IF = 0x47650002;
915
public static final int ON = 0x409e0002;
10-
1116
public static final int FOR = 0x576e0003;
1217
public static final int NOT = 0x68b00003;
1318
public static final int SQL = 0x53820003;
1419
public static final int USE = 0x0f840003;
15-
20+
public static final int CALL = 0x25d00004;
1621
public static final int DROP = 0xba5d0004;
22+
public static final int DESC = 0xc08f0004;
1723
public static final int FROM = 0x992e0004;
1824
public static final int INTO = 0xb2e70004;
1925
public static final int JOIN = 0xf9700004;
26+
public static final int KILL = 0x5f7f0004;
2027
public static final int LOCK = 0xed330004;
2128
public static final int LEFT = 0xf4e50004;
29+
public static final int NAME = 0x33200004;
2230
public static final int SHOW = 0xb0300004;
23-
31+
public static final int SLOW = 0xa3340004;
32+
public static final int TIME = 0x5f050004;
33+
public static final int USER = 0x7bfa0004;
2434
public static final int ALTER = 0xb2db0005;
35+
public static final int CLEAR = 0x19bf0005;
36+
public static final int CACHE = 0xf61c0005;
2537
public static final int GROUP = 0x43f50005;
38+
public static final int GRANT = 0x29c20005;
39+
public static final int INDEX = 0xfcff0005;
2640
public static final int LIMIT = 0x450a0005;
2741
public static final int MYCAT = 0xdce50005;
2842
public static final int ORDER = 0x88da0005;
2943
public static final int RIGHT = 0xec610005;
44+
public static final int ROUTE = 0x82ef0005;
3045
public static final int TABLE = 0x03780005;
3146
public static final int UNION = 0xcf9d0005;
3247
public static final int WHERE = 0x75950005;
33-
3448
public static final int CATLET = 0xda600006;
49+
public static final int CONFIG = 0xebd60006;
3550
public static final int CREATE = 0xdde00006;
36-
public static final int EXISTS = 0x2ed70006;
37-
public static final int UPDATE = 0x62840006;
51+
public static final int DETAIL = 0x47690006;
3852
public static final int DELETE = 0x33e50006;
39-
public static final int SELECT = 0x02a10006;
53+
public static final int EXISTS = 0x2ed70006;
4054
public static final int INSERT = 0xa3b10006;
4155
public static final int IGNORE = 0x6c360006;
56+
public static final int ONLINE = 0x05bc0006;
57+
public static final int RELOAD = 0xd7200006;
58+
public static final int RENAME = 0xe6c60006;
59+
public static final int REVOKE = 0x5cc20006;
60+
public static final int ROUTER = 0x3c570006;
61+
public static final int SELECT = 0x02a10006;
62+
public static final int SERVER = 0x31fa0006;
4263
public static final int SCHEMA = 0x0c490006;
43-
44-
public static final int DB_TYPE = 0xac610007;
64+
public static final int SWITCH = 0xe0500006;
65+
public static final int UPDATE = 0x62840006;
66+
public static final int BACKEND = 0x9c0b0007;
4567
public static final int BALANCE = 0x8d070007;
46-
public static final int REPLACE = 0xa88c0007;
68+
public static final int CURRENT = 0x6af60007;
69+
public static final int DB_TYPE = 0xac610007;
4770
public static final int DELAYED = 0x56380007;
48-
71+
public static final int EXECUTE = 0x304b0007;
72+
public static final int EXPLAIN = 0xe41f0007;
73+
public static final int OFFLINE = 0x9ead0007;
74+
public static final int REPLACE = 0xa88c0007;
75+
public static final int SESSION = 0xf2080007;
76+
public static final int STARTUP = 0x16770007;
77+
public static final int VERSION = 0x66380007;
78+
public static final int DATABASE = 0xbbcc0008;
4979
public static final int DATANODE = 0x045d0008;
80+
public static final int DESCRIBE = 0x8ad30008;
81+
public static final int ROLLBACK = 0xe7390008;
5082
public static final int TRUNCATE = 0xcb5d0008;
51-
83+
public static final int HEARTBEAT = 0xabb70009;
5284
public static final int PROCEDURE = 0x11600009;
53-
85+
public static final int PROCESSOR = 0xfdbc0009;
86+
public static final int CONNECTION = 0x307d000a;
87+
public static final int DATASOURCE = 0x0b35000a;
88+
public static final int THREADPOOL = 0x5a7a000a;
5489
public static final int LOW_PRIORITY = 0xb805000c;
55-
5690
public static final int HIGH_PRIORITY = 0x7c6f000d;
57-
5891
}

src/main/java/io/mycat/MatchMethodGenerator.java

+25-4
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ static void initShrinkCharTbl () {
131131
shrinkCharTbl[0] = 1;//从 $ 开始计算
132132
IntStream.rangeClosed('0', '9').forEach(c -> shrinkCharTbl[c-'$'] = (byte)(c-'0'+2));
133133
IntStream.rangeClosed('A', 'Z').forEach(c -> shrinkCharTbl[c-'$'] = (byte)(c-'A'+12));
134+
IntStream.rangeClosed('a', 'z').forEach(c -> shrinkCharTbl[c-'$'] = (byte)(c-'a'+12));
134135
shrinkCharTbl['_'-'$'] = (byte)38;
135136
}
136137

@@ -327,21 +328,36 @@ static void skipXXXTokenGenerator() {
327328
System.out.format("final void skip%sToken() {\npos+=%d;\n}%n", keyword, keyword.length());
328329
});
329330
}
330-
static void GenerateSqlTokenHash(String fileName) {
331+
static void GenerateLongTokenHash(String fileName) {
331332
initShrinkCharTbl();
332333
try {
333334
Files.lines(Paths.get(fileName))
334335
.filter(x -> x.length()>0)
335336
.forEach(x -> {
336-
System.out.format(" public static final int %-16s = 0x%04x%04x;%n", x, genHash2(x.toCharArray()) & 0xFFFF, x.length());
337-
// System.out.format(" public static final int %s = 0x%x;%n", x, genHash2(x.toCharArray()));
337+
// System.out.format(" public static final int %-16s = 0x%04x%04x;%n", x, genHash2(x.toCharArray()) & 0xFFFF, x.length());
338+
System.out.format(" public static final long %-12s = 0x%xL;%n", x, genHash(x.toCharArray()));
338339
});
339340
// System.out.println("conflict count : "+count);
340341
} catch (IOException e) {
341342
e.printStackTrace();
342343
}
343344
}
344345

346+
static void GenerateIntTokenHash(String fileName) {
347+
initShrinkCharTbl();
348+
try {
349+
Files.lines(Paths.get(fileName))
350+
.filter(x -> x.length()>0)
351+
.forEach(x -> {
352+
System.out.format(" public static final int %-16s = 0x%04x%04x;%n", x, genHash2(x.toCharArray()) & 0xFFFF, x.length());
353+
// System.out.format(" public static final long %-12s = 0x%x;%n", x, genHash(x.toCharArray()));
354+
});
355+
// System.out.println("conflict count : "+count);
356+
} catch (IOException e) {
357+
e.printStackTrace();
358+
}
359+
}
360+
345361
public static void main(String[] args) {
346362
//isXXXTokenGenerator();
347363
//skipXXXTokenGenerator();
@@ -350,6 +366,11 @@ public static void main(String[] args) {
350366
// sqlKeyHastTest("minimal_sql_tokens.txt", s -> genHash(s.toCharArray()), 0x3FL);
351367
// run();
352368
// test1();
353-
GenerateSqlTokenHash("minimal_sql_tokens.txt");
369+
// GenerateIntTokenHash("minimal_sql_tokens.txt");
370+
// GenerateLongTokenHash("sql_tokens.txt");
371+
initShrinkCharTbl();
372+
System.out.format("0x%xL;%n", genHash("dn1".toCharArray()));
373+
374+
354375
}
355376
}

0 commit comments

Comments
 (0)