result set

This commit is contained in:
jackdaw@loafle.com 2017-04-25 16:59:11 +09:00
parent 4a9fca0bbd
commit 6c88c90f9f

View File

@ -1,6 +1,7 @@
package com.loafle.overflow.crawler.result;
import com.loafle.overflow.crawler.config.Item;
import com.loafle.overflow.crawler.config.Query;
import java.util.ArrayList;
import java.util.HashMap;
@ -45,7 +46,52 @@ public class OFResultSetRow extends OFResultSet{
public Map<String, String> parse() {
return null;
Map<String, String> returnMap = new HashMap<>();
String valueColumn = (String) this.item.getQuery().getQueryInfo().get("valueColumn");
for (List<String> row : this.rows) {
String key = makeKey(row);
returnMap.put(key,row.get(this.meta.get(valueColumn)));
}
return returnMap;
}
private String makeKey(List<String> data) {
Query query = this.item.getQuery();
List<String> arrayColumns = (List<String>) this.item.getQuery().getQueryInfo().get("arrayColumns");
List<String> keyColumns = (List<String>) this.item.getQuery().getQueryInfo().get("keyColumns");
List<String> keys = query.getKeys();
List<String> metrics = query.getKeys();
// 동적 키인지 일반 키들인지 체크해야함 // 일단은 동적 키적용
String metricsType = (String) query.getQueryInfo().get("metricsType");
boolean find = false;
int findIndex = -1;
for (String keyColumn: keyColumns) {
String row = data.get(this.meta.get(keyColumn));
for (int i =0 ; i < keys.size() ; ++i) {
if (row.equals(keys.get(i))) {
findIndex = i;
find = true;
break;
}
}
if (find == true) {break;}
}
String metric = metrics.get(findIndex);
for (int i =0 ; i< arrayColumns.size() ; ++i) {
// replace
String k = "$" + i;
metric = metric.replace(k,data.get(this.meta.get(arrayColumns.get(i))));
}
return metric;
}
}