From 6c88c90f9f854317a0a6fc4703cb315a07abf01f Mon Sep 17 00:00:00 2001 From: "jackdaw@loafle.com" Date: Tue, 25 Apr 2017 16:59:11 +0900 Subject: [PATCH] result set --- .../crawler/result/OFResultSetRow.java | 70 +++++++++++++++---- 1 file changed, 58 insertions(+), 12 deletions(-) diff --git a/src/main/java/com/loafle/overflow/crawler/result/OFResultSetRow.java b/src/main/java/com/loafle/overflow/crawler/result/OFResultSetRow.java index cd558ba..d4e944f 100644 --- a/src/main/java/com/loafle/overflow/crawler/result/OFResultSetRow.java +++ b/src/main/java/com/loafle/overflow/crawler/result/OFResultSetRow.java @@ -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; @@ -19,19 +20,19 @@ public class OFResultSetRow extends OFResultSet{ public void setMeta() { - List meta = new ArrayList<>(); + List meta = new ArrayList<>(); - List arrayColumns = (List) this.item.getQuery().getQueryInfo().get("arrayColumns"); - List keyColumns = (List) this.item.getQuery().getQueryInfo().get("keyColumns"); - String valueColumn = (String) this.item.getQuery().getQueryInfo().get("valueColumn"); + List arrayColumns = (List) this.item.getQuery().getQueryInfo().get("arrayColumns"); + List keyColumns = (List) this.item.getQuery().getQueryInfo().get("keyColumns"); + String valueColumn = (String) this.item.getQuery().getQueryInfo().get("valueColumn"); - for (String c : arrayColumns) { - meta.add(c); - } - for (String c: keyColumns) { - meta.add(c); - } - meta.add(valueColumn); + for (String c : arrayColumns) { + meta.add(c); + } + for (String c: keyColumns) { + meta.add(c); + } + meta.add(valueColumn); if(this.meta == null) { this.meta = new HashMap<>(); @@ -45,7 +46,52 @@ public class OFResultSetRow extends OFResultSet{ public Map parse() { - return null; + Map returnMap = new HashMap<>(); + + String valueColumn = (String) this.item.getQuery().getQueryInfo().get("valueColumn"); + + for (List row : this.rows) { + String key = makeKey(row); + returnMap.put(key,row.get(this.meta.get(valueColumn))); + } + + return returnMap; + } + + private String makeKey(List data) { + + Query query = this.item.getQuery(); + List arrayColumns = (List) this.item.getQuery().getQueryInfo().get("arrayColumns"); + List keyColumns = (List) this.item.getQuery().getQueryInfo().get("keyColumns"); + List keys = query.getKeys(); + List 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; } }