use of com.fasterxml.jackson.core.type.TypeReference in project pinot by linkedin.
the class Utils method convertToMetricExpressions.
public static List<MetricExpression> convertToMetricExpressions(String metricsJson, MetricAggFunction aggFunction, String collection) throws ExecutionException {
List<MetricExpression> metricExpressions = new ArrayList<>();
if (metricsJson == null) {
return metricExpressions;
}
ArrayList<String> metricExpressionNames;
try {
TypeReference<ArrayList<String>> valueTypeRef = new TypeReference<ArrayList<String>>() {
};
metricExpressionNames = OBJECT_MAPPER.readValue(metricsJson, valueTypeRef);
} catch (Exception e) {
LOG.warn("Expected json expression for metric [{}], adding as it is. Error in json parsing : [{}]", metricsJson, e.getMessage());
metricExpressionNames = new ArrayList<>();
String[] metrics = metricsJson.split(",");
for (String metric : metrics) {
metricExpressionNames.add(metric.trim());
}
}
for (String metricExpressionName : metricExpressionNames) {
String derivedMetricExpression = ThirdEyeUtils.getDerivedMetricExpression(metricExpressionName, collection);
MetricExpression metricExpression = new MetricExpression(metricExpressionName, derivedMetricExpression, aggFunction);
metricExpressions.add(metricExpression);
}
return metricExpressions;
}
use of com.fasterxml.jackson.core.type.TypeReference in project druid by druid-io.
the class SQLMetadataRuleManagerTest method testAuditEntryCreated.
@Test
public void testAuditEntryCreated() throws Exception {
List<Rule> rules = Arrays.<Rule>asList(new IntervalLoadRule(new Interval("2015-01-01/2015-02-01"), ImmutableMap.<String, Integer>of(DruidServer.DEFAULT_TIER, DruidServer.DEFAULT_NUM_REPLICANTS)));
AuditInfo auditInfo = new AuditInfo("test_author", "test_comment", "127.0.0.1");
ruleManager.overrideRule("test_dataSource", rules, auditInfo);
// fetch rules from metadata storage
ruleManager.poll();
Assert.assertEquals(rules, ruleManager.getRules("test_dataSource"));
// verify audit entry is created
List<AuditEntry> auditEntries = auditManager.fetchAuditHistory("test_dataSource", "rules", null);
Assert.assertEquals(1, auditEntries.size());
AuditEntry entry = auditEntries.get(0);
Assert.assertEquals(rules, mapper.readValue(entry.getPayload(), new TypeReference<List<Rule>>() {
}));
Assert.assertEquals(auditInfo, entry.getAuditInfo());
Assert.assertEquals("test_dataSource", entry.getKey());
}
use of com.fasterxml.jackson.core.type.TypeReference in project druid by druid-io.
the class SQLMetadataRuleManagerTest method testFetchAuditEntriesForAllDataSources.
@Test
public void testFetchAuditEntriesForAllDataSources() throws Exception {
List<Rule> rules = Arrays.<Rule>asList(new IntervalLoadRule(new Interval("2015-01-01/2015-02-01"), ImmutableMap.<String, Integer>of(DruidServer.DEFAULT_TIER, DruidServer.DEFAULT_NUM_REPLICANTS)));
AuditInfo auditInfo = new AuditInfo("test_author", "test_comment", "127.0.0.1");
ruleManager.overrideRule("test_dataSource", rules, auditInfo);
ruleManager.overrideRule("test_dataSource2", rules, auditInfo);
// fetch rules from metadata storage
ruleManager.poll();
Assert.assertEquals(rules, ruleManager.getRules("test_dataSource"));
Assert.assertEquals(rules, ruleManager.getRules("test_dataSource2"));
// test fetch audit entries
List<AuditEntry> auditEntries = auditManager.fetchAuditHistory("rules", null);
Assert.assertEquals(2, auditEntries.size());
for (AuditEntry entry : auditEntries) {
Assert.assertEquals(rules, mapper.readValue(entry.getPayload(), new TypeReference<List<Rule>>() {
}));
Assert.assertEquals(auditInfo, entry.getAuditInfo());
}
}
use of com.fasterxml.jackson.core.type.TypeReference in project druid by druid-io.
the class SqlResourceTest method doPost.
// Returns either an error or a result.
private Pair<QueryInterruptedException, List<Map<String, Object>>> doPost(final SqlQuery query) throws Exception {
final Response response = resource.doPost(query);
if (response.getStatus() == 200) {
final StreamingOutput output = (StreamingOutput) response.getEntity();
final ByteArrayOutputStream baos = new ByteArrayOutputStream();
output.write(baos);
return Pair.of(null, JSON_MAPPER.<List<Map<String, Object>>>readValue(baos.toByteArray(), new TypeReference<List<Map<String, Object>>>() {
}));
} else {
return Pair.of(JSON_MAPPER.readValue((byte[]) response.getEntity(), QueryInterruptedException.class), null);
}
}
use of com.fasterxml.jackson.core.type.TypeReference in project druid by druid-io.
the class WhiteListBasedConverter method readMap.
private ImmutableSortedMap<String, ImmutableSet<String>> readMap(final String mapPath) {
String fileContent;
String actualPath = mapPath;
try {
if (Strings.isNullOrEmpty(mapPath)) {
URL resource = this.getClass().getClassLoader().getResource("defaultWhiteListMap.json");
actualPath = resource.getFile();
LOGGER.info("using default whiteList map located at [%s]", actualPath);
fileContent = Resources.toString(resource, Charset.defaultCharset());
} else {
fileContent = Files.asCharSource(new File(mapPath), Charset.forName("UTF-8")).read();
}
return mapper.reader(new TypeReference<ImmutableSortedMap<String, ImmutableSet<String>>>() {
}).readValue(fileContent);
} catch (IOException e) {
throw new ISE(e, "Got an exception while parsing file [%s]", actualPath);
}
}
Aggregations