在这里,代码正在寻找删除以前可能已加载的行。二重集合数据使用两个表:用于参数数据的dieudocollection,以及用于查找表以获取收集表的uuid的dieudocomponentid。
该代码检查两个表上的计数(每个计数都会超时)。看来这是使用此计数的唯一位置。
但是这是删除逻辑。
在表ddl下面:
CREATE TABLE eaa.dieudocomponentid (
componentname text,
datapoints int,
apexcollectionid uuid,
PRIMARY KEY ((componentname, datapoints), apexcollectionid)
) WITH CLUSTERING ORDER BY (apexcollectionid ASC)
CREATE TABLE eaa.dieudocollection (
apexcollectionid uuid PRIMARY KEY,
afx double,
afy double,
apexsec double,
avg double,
blocknumber bigint,
channelname text,
collectionid bigint,
componentname text,
datapoints int,
datatype text,
dc double,
dpflag text,
elapsedtime double,
engineserialnumber text,
eo double,
fftphase double,
filename text,
fitness double,
freqfitness double,
frequency double,
ieo bigint,
isnoise text,
magfitness double,
magnitude double,
magratio double,
method text,
modeid bigint,
model text,
modename text,
noise double,
partname text,
percentlimit double,
phasefitness double,
ratioedeu double,
reading bigint,
scopelimit double,
testid text,
testnumber bigint,
testtype text,
timehalfp2p double,
timeirig text,
timep2p double,
timepeak double,
timerms double,
unitofmeasure text,
xnhct1 double,
xnlct1 double,
xsecx double,
xsecy double
)
应用代码:
但这是删除逻辑:
/**
* Deletes existing matched records prior to start for storing. Also,
calculates elapsed time for deleting mechanism.
* Deleting mechanism makes a reverse lookup by using eaa.Dieudocomponentid.
The mechanism is needed since Cassandra
* does not accept delete query without using keys.
*
* @param file CSV file to parse
* @param headerMap Header that maps indices so columnar data can be
retrieved
* @param session Session to Cassandra, to execute the query made
* @return Elapsed Time for deleting mechanism
* @throws DieudoGeneralException
*/
private Double deleteExisting(File file, Map<String, Integer> headerMap,
Session session) throws DieudoGeneralException {
System.out.println("Deleting existing rows");
LOGGER.info("CSV to statement deleting existing rows");
Long startDeleteTime = System.nanoTime();
boolean hasTableRow = (hasTablesRow(session, CassandraModel.DIEUDO_COLLECTION) && hasTablesRow(session,
CassandraModel.DIEUDO_COMPONENT_ID)) ? true : false;
try (BufferedReader reader = new BufferedReader(new FileReader(file))) {
if (hasTableRow) {
String line = reader.readLine();
while ((line = reader.readLine()) != null) {
DieudoCsv DieudoCsv = parseLine(line, headerMap);
getExistingRecords(DieudoCsv, session);
// deleteExisting(DieudoCsv, session);
}
这是“ hasTablesRow”计数代码:
/**
* Checks table row counts.
*
* @param session Session to Cassandra, to execute the query made
* @param tableName To check count
* @return Table has row or not
*/
private boolean hasTablesRow(Session session, String tableName) {
long count = -1;
ResultSet rs = session.execute("SELECT COUNT(*) as coun FROM " + CassandraModel.LOCATION_KEYSPACE + "." + tableName);
Row row = rs.one();
if (row != null) {
count = row.getLong("coun");
}
if (count != -1 && count > 0) {
return true;
} else {
return false;
}
}
感谢您的建议。