private Row getTestRow(Object dimensionValue) { return new MapBasedRow(0, ImmutableMap.of("dimension", dimensionValue)); }
@Test public void testGetLongMetricFromString() { MapBasedRow row = new MapBasedRow( DateTimes.nowUtc(), ImmutableMap.<String, Object>builder() .put("k0", "-1.2") .put("k1", "1.23") .put("k2", "1.8") .put("k3", "1e5") .put("k4", "9223372036854775806") .put("k5", "-9223372036854775807") .put("k6", "+9223372036854775802") .build() ); Assert.assertEquals(-1.2, row.getMetric("k0")); Assert.assertEquals(1.23, row.getMetric("k1")); Assert.assertEquals(1.8, row.getMetric("k2")); Assert.assertEquals(100000.0, row.getMetric("k3")); Assert.assertEquals(9223372036854775806L, row.getMetric("k4")); Assert.assertEquals(-9223372036854775807L, row.getMetric("k5")); Assert.assertEquals(9223372036854775802L, row.getMetric("k6")); } }
@Nullable @Override public Row apply(Row input) { Row preRow = preCompute.apply(input); if (preRow instanceof MapBasedRow) { MapBasedRow preMapRow = (MapBasedRow) preRow; Map<String, Object> event = new HashMap<>(preMapRow.getEvent()); for (String dim : optimizedDims) { final Object eventVal = event.get(dim); event.put(dim, extractionFnMap.get(dim).apply(eventVal)); } return new MapBasedRow(preMapRow.getTimestamp(), event); } else { return preRow; } } };
@Override public Row apply(Row input) { final MapBasedRow row = (MapBasedRow) input; return new MapBasedRow( query.getGranularity() .toDateTime(row.getTimestampFromEpoch()), row.getEvent() ); } }
@Override public IncrementalIndex accumulate(IncrementalIndex accumulated, T in) { if (in instanceof MapBasedRow) { try { MapBasedRow row = (MapBasedRow) in; accumulated.add( new MapBasedInputRow( row.getTimestamp(), dimensions, row.getEvent() ) ); } catch (IndexSizeExceededException e) { throw new ResourceLimitExceededException(e.getMessage()); } } else { throw new ISE("Unable to accumulate something of type [%s]", in.getClass()); } return accumulated; } };
@Test public void testIngestWithNullsIgnoredAndQuery() throws Exception { MapBasedRow row = ingestAndQuery(true); Assert.assertEquals(92.782760, row.getMetric("index_min").floatValue(), 0.0001); Assert.assertEquals(135.109191, row.getMetric("index_max").floatValue(), 0.0001); Assert.assertEquals(133.69340, row.getMetric("index_quantile").floatValue(), 0.0001); }
@Override public Row apply(Row input) { final MapBasedRow row = (MapBasedRow) input; return new MapBasedRow( query.getGranularity() .toDateTime(row.getTimestampFromEpoch()), row.getEvent() ); } }
@Test public void testIngestWithNullsIgnoredAndQuery() throws Exception { MapBasedRow row = ingestAndQuery(); if (!NullHandling.replaceWithDefault()) { Assert.assertEquals(92.782760, row.getMetric("index_min").floatValue(), 0.0001); Assert.assertEquals(135.109191, row.getMetric("index_max").floatValue(), 0.0001); Assert.assertEquals(135.9499969482422, row.getMetric("index_quantile").floatValue(), 0.0001); } else { Assert.assertEquals(0.0, row.getMetric("index_min")); Assert.assertEquals(135.109191, row.getMetric("index_max").floatValue(), 0.0001); Assert.assertEquals(135.8699951171875, row.getMetric("index_quantile").floatValue(), 0.0001); } }
@Override public IncrementalIndex accumulate(IncrementalIndex accumulated, T in) { if (in instanceof MapBasedRow) { try { MapBasedRow row = (MapBasedRow) in; accumulated.add( new MapBasedInputRow( row.getTimestamp(), dimensions, row.getEvent() ) ); } catch (IndexSizeExceededException e) { throw new ResourceLimitExceededException(e.getMessage()); } } else { throw new ISE("Unable to accumulate something of type [%s]", in.getClass()); } return accumulated; } };
private Iterable<Row> makeGroupByResults(Object... objects) { List<Row> retVal = new ArrayList<>(); int index = 0; while (index < objects.length) { DateTime timestamp = (DateTime) objects[index++]; retVal.add(new MapBasedRow(timestamp, (Map<String, Object>) objects[index++])); } return retVal; }
@Override public Row apply(Row input) { if (input instanceof MapBasedRow) { final MapBasedRow inputRow = (MapBasedRow) input; final Map<String, Object> values = new HashMap<>(inputRow.getEvent()); for (AggregatorFactory agg : query.getAggregatorSpecs()) { values.put(agg.getName(), fn.manipulate(agg, inputRow.getEvent().get(agg.getName()))); } return new MapBasedRow(inputRow.getTimestamp(), values); } return input; } };
@Test public void testIngestWithNullsToZeroAndQuery() throws Exception { // Nulls are ignored and not replaced with default for SQL compatible null handling. // This is already tested in testIngestWithNullsIgnoredAndQuery() if (NullHandling.replaceWithDefault()) { MapBasedRow row = ingestAndQuery(false); Assert.assertEquals(0.0F, row.getMetric("index_min")); Assert.assertEquals(135.109191, row.getMetric("index_max").floatValue(), 0.0001); Assert.assertEquals(131.428176, row.getMetric("index_quantile").floatValue(), 0.0001); } }
Assert.assertEquals(ImmutableMap.of("billy", "hi", "cnt", 1L), row.getEvent());
public static Row createExpectedRow(final DateTime timestamp, Object... vals) { Preconditions.checkArgument(vals.length % 2 == 0); Map<String, Object> theVals = new HashMap<>(); for (int i = 0; i < vals.length; i += 2) { theVals.put(vals[i].toString(), vals[i + 1]); } return new MapBasedRow(timestamp, theVals); }
@Nullable @Override public Row apply(Row input) { Row preRow = preCompute.apply(input); if (preRow instanceof MapBasedRow) { MapBasedRow preMapRow = (MapBasedRow) preRow; Map<String, Object> event = Maps.newHashMap(preMapRow.getEvent()); for (String dim : optimizedDims) { final Object eventVal = event.get(dim); event.put(dim, extractionFnMap.get(dim).apply(eventVal)); } return new MapBasedRow(preMapRow.getTimestamp(), event); } else { return preRow; } } };
private Row createRow(String timestamp, Object... vals) { Preconditions.checkArgument(vals.length % 2 == 0); Map<String, Object> theVals = new HashMap<>(); for (int i = 0; i < vals.length; i += 2) { theVals.put(vals[i].toString(), vals[i + 1]); } return new MapBasedRow(DateTimes.of(timestamp), theVals); } }