| 56 | } |
| 57 | |
| 58 | public void construct(){ |
| 59 | //Step 1 read the dataset from the tables |
| 60 | //Step 1.1 prepare the parameters |
| 61 | id = new String[record_num + 1]; |
| 62 | keyword = new String[record_num + 1][key_column]; |
| 63 | join_attr = new String[record_num + 1][join_column]; |
| 64 | Map<String, ArrayList<Integer>> reverse_id = new LinkedHashMap<>(); //the pairs of (attribute-value pair, record ids) |
| 65 | String path = "data/table" + table_id + "/table" + table_id + "_k" + key_column |
| 66 | + "_j" + join_column + "_" + record_num + condition +".csv"; |
| 67 | //Step 1.2 begin to read dataset |
| 68 | try (Reader reader = Files.newBufferedReader(Paths.get(path))) { |
| 69 | Iterable<CSVRecord> records = CSVFormat.DEFAULT.parse(reader); |
| 70 | int counter = 0; |
| 71 | for (CSVRecord record : records) { |
| 72 | id[counter] = record.get(0); |
| 73 | for (int j = 0; j < key_column; j++) { |
| 74 | keyword[counter][j] = record.get(j + 1); |
| 75 | if (counter != 0) { |
| 76 | String kword = keyword[0][j] + record.get(j + 1); //attribute-value pair |
| 77 | if (!reverse_id.containsKey(kword)) |
| 78 | reverse_id.put(kword, new ArrayList<>()); |
| 79 | reverse_id.get(kword).add(counter); |
| 80 | } |
| 81 | } |
| 82 | //note that join-attribute values pairs are also seen as the attribute-value pair |
| 83 | for (int j = 0; j < join_column; j++) { |
| 84 | join_attr[counter][j] = record.get(key_column + j + 1); |
| 85 | if (counter != 0){ |
| 86 | String kword = join_attr[0][j] + record.get(key_column + j + 1); |
| 87 | if (!reverse_id.containsKey(kword)) |
| 88 | reverse_id.put(kword, new ArrayList<>()); |
| 89 | reverse_id.get(kword).add(counter); |
| 90 | } |
| 91 | } |
| 92 | counter++; |
| 93 | } |
| 94 | } catch (IOException e) { |
| 95 | e.printStackTrace(); |
| 96 | } |
| 97 | |
| 98 | //Step 2 the process of setup |
| 99 | //Step 2.1 compute the XSet entries |
| 100 | long[] xy = new long[record_num * join_column]; //represents the xInd * yInd in the JXT paper |
| 101 | byte[][] x = new byte[record_num * join_column][]; // xInd |
| 102 | byte[][] y = new byte[record_num * join_column][]; // yInd |
| 103 | for (int i = 1; i <= record_num; i++) { |
| 104 | for (int j = 0; j < join_column; j++) { |
| 105 | x[(i - 1) * join_column + j] = Hash.Get_SHA_256((K_x + id[i] + join_attr[0][j]).getBytes(StandardCharsets.UTF_8)); |
| 106 | y[(i - 1) * join_column + j] = Hash.Get_SHA_256((K_y + join_attr[i][j]).getBytes(StandardCharsets.UTF_8)); |
| 107 | xy[(i - 1) * join_column + j] = tool.bytesToLong(tool.Xor(x[(i - 1) * join_column + j], y[(i - 1) * join_column + j])); |
| 108 | } |
| 109 | } |
| 110 | f = Bloom.construct(xy, 64);//XSet |
| 111 | //Step 2.2 compute the TSet entries |
| 112 | for(String kword : reverse_id.keySet()){//for each attribute-value pair |
| 113 | BigInteger token = new BigInteger(Hash.Get_SHA_256((K_token + kword + table_id).getBytes(StandardCharsets.UTF_8))); |
| 114 | ArrayList<Integer> reverse_tmp = reverse_id.get(kword); |
| 115 | byte[] h1_0 = Hash.Get_SHA_256((K_h1 + kword + 0).getBytes(StandardCharsets.UTF_8));//Z_0 = F(w||0) |