|
24 | 24 | * table1.column1 |
25 | 25 | */ |
26 | 26 | public class TableCollector implements GPatternTokenCollector { |
| 27 | + private final int dotHash; |
| 28 | + private final LongObjectHashMap<TableInfo> map; |
27 | 29 | private final TableInfo[] tables = new TableInfo[32]; |
28 | | - private final GPatternIdRecorder recorder; |
29 | | - private final Map<String, Map<String, TableInfo>> schemaInfos = new HashMap<>(); |
30 | | - private final LongObjectHashMap<TableInfo> map = new LongObjectHashMap<>(); |
31 | | - State state = State.EXCPECT_ID; |
32 | | - long currentSchemaLeftShift32; |
33 | | - int first; |
34 | | - int second; |
35 | | - private int dotHash; |
| 30 | + private final TableCollectorBuilder builder; |
36 | 31 | private int tableIndex; |
37 | | - |
38 | | - |
39 | | - public TableCollector(GPatternIdRecorder recorder, Map<String, Collection<String>> schemaInfos) { |
40 | | - this.recorder = recorder; |
41 | | - this.dotHash = recorder.createConstToken(".").hashCode(); |
42 | | - for (Map.Entry<String, Collection<String>> stringSetEntry : schemaInfos.entrySet()) { |
43 | | - String schemaName = stringSetEntry.getKey(); |
44 | | - List<Integer> schemaHashList = record(recorder, schemaName); |
45 | | - Map<String, TableInfo> tableInfoMap = this.schemaInfos.computeIfAbsent(schemaName, (s) -> new HashMap<>()); |
46 | | - Collection<String> tableNames = stringSetEntry.getValue(); |
47 | | - for (String tableName : tableNames) { |
48 | | - List<Integer> tableNameHashList = record(recorder, tableName); |
49 | | - for (Integer schemaNameHash : schemaHashList) { |
50 | | - for (Integer tableNameHash : tableNameHashList) { |
51 | | - long hash = schemaNameHash; |
52 | | - hash = hash << 32; |
53 | | - hash = hash | tableNameHash; |
54 | | - TableInfo tableInfo = new TableInfo(schemaName, tableName, schemaNameHash, tableNameHash, hash); |
55 | | - tableInfoMap.put(tableName, tableInfo); |
56 | | - map.put(hash, tableInfo); |
57 | | - } |
58 | | - } |
59 | | - } |
60 | | - } |
| 32 | + private State state = State.EXCPECT_ID; |
| 33 | + private long currentSchemaLeftShift32; |
| 34 | + private int first; |
| 35 | + private int second; |
| 36 | + |
| 37 | + public TableCollector(TableCollectorBuilder builder) { |
| 38 | + this.builder = builder; |
| 39 | + this.dotHash = builder.dotHash; |
| 40 | + this.map = builder.map; |
61 | 41 | } |
62 | 42 |
|
63 | 43 | public void useSchema(String schema) { |
64 | | - Map<String, TableInfo> stringTableInfoMap = schemaInfos.get(schema); |
65 | | - if (stringTableInfoMap == null) throw new UnsupportedOperationException(); |
66 | | - long hash = stringTableInfoMap.values().iterator().next().getSchema(); |
| 44 | + Integer intHash = builder.schemaHash.get(schema); |
| 45 | + if (intHash == null) throw new UnsupportedOperationException(); |
| 46 | + long hash = intHash; |
67 | 47 | hash = hash << 32; |
68 | 48 | currentSchemaLeftShift32 = hash; |
69 | 49 | } |
70 | 50 |
|
71 | | - private List<Integer> record(GPatternIdRecorder recorder, String text) { |
72 | | - String lowerCase = text.toLowerCase(); |
73 | | - String upperCase = text.toUpperCase(); |
74 | | - |
75 | | - ArrayList<Integer> list = new ArrayList<>(); |
76 | | - list.add(recorder.createConstToken(lowerCase).hashCode()); |
77 | | - list.add(recorder.createConstToken(upperCase).hashCode()); |
78 | | - list.add(recorder.createConstToken("`" + lowerCase + "`").hashCode()); |
79 | | - list.add(recorder.createConstToken("`" + upperCase + "`").hashCode()); |
80 | | - return list; |
81 | | - } |
82 | | - |
83 | 51 |
|
84 | 52 | @Override |
85 | 53 | public void onCollectStart() { |
@@ -155,12 +123,11 @@ public TableInfo[] getTableArray() { |
155 | 123 | } |
156 | 124 |
|
157 | 125 | public Map<String, Collection<String>> geTableMap(Map<String, Collection<String>> map) { |
158 | | - Map<String, Collection<String>> collectionMap = new HashMap<>(); |
159 | 126 | for (int i = 0; i < this.tableIndex; i++) { |
160 | 127 | TableInfo table = tables[i]; |
161 | | - collectionMap.computeIfAbsent(table.getSchemaName(), s -> new HashSet<>()).add(table.getTableName()); |
| 128 | + map.computeIfAbsent(table.getSchemaName(), s -> new HashSet<>()).add(table.getTableName()); |
162 | 129 | } |
163 | | - return collectionMap; |
| 130 | + return map; |
164 | 131 | } |
165 | 132 |
|
166 | 133 | public Map<String, Collection<String>> geTableMap() { |
|
0 commit comments