我正在尝试在具有匹配哈希数的文件之间创建差异计数。匹配的节点标签是QueryBlock和RegisterBlock。
我想建立这个QueryBlock和RegisterBlock节点的哈希总数以及匹配哈希的数量。然后从Total Register Hashes中减去匹配哈希的数量以得出差值
import java.util.*;
public class Menu
{
public static void main(String[] args){
new Menu().use();
}
public void use() {
int choice;
while ((choice = readChoice()) != 0){
switch (choice){
case 1: ; break;
case 2: ; break;
case 3: ; break;
case 4: ; break;
}
}
}
private int readChoice(){
Scanner scanner = new Scanner(System.in);
System.out.println("Main Menu:");
System.out.println("1. Setting.");
System.out.println("2. View hardware detail.");
System.out.println("3. View Log.");
System.out.println("4. Access Admin Mode.");
System.out.println("0. Exit the system.");
System.out.print("Enter a choice: ");
return scanner.nextInt();
}
}
我正在运行此查询:
TotalRegisterHashes TotalQueryHashes TotalMatchingHashes Difference
1400 400 400 1000
回复:
//Match QueryFiles to RegisterFiles using Block Hash Matches
MATCH (m:QueryBlock),(p:RegisterBlock)
WHERE m.qBlockHash = p.rBlockHash
RETURN
COUNT(p) AS TotalRegisterHashes,
COUNT(m) AS TotalQueryHashes,
COUNT(*) AS TotalMatchingHashes,
abs((COUNT(p) - COUNT(*))) AS Difference
TotalRegisterHashes TotalQueryHashes TotalMatchingHashes Difference
793 793 793 0
是正确的,但其他人则没有。请你告诉我我哪里出错了。
答案 0 :(得分:0)
运行count()
函数时,在过滤完成后运行它们,所以在过滤之前无法为您提供节点的总数。你应该先计算总数。获取标签的所有节点的计数是优化的操作,使用预先计算的总数而不是实际必须计算db中的节点。获得给定标签的总计后,然后对查询的其余部分进行匹配哈希和差异。
//Match QueryFiles to RegisterFiles using Block Hash Matches
MATCH (m:QueryBlock)
WITH COUNT(m) AS TotalQueryHashes
MATCH (p:RegisterBlock)
WITH TotalQueryHashes, COUNT(p) AS TotalRegisterHashes
MATCH (m:QueryBlock),(p:RegisterBlock)
WHERE m.qBlockHash = p.rBlockHash
WITH TotalRegisterHashes, TotalQueryHashes, COUNT(*) AS TotalMatchingHashes
RETURN TotalRegisterHashes,
TotalQueryHashes,
abs(TotalRegisterHashes - TotalMatchingHashes) AS Difference