Optional<TimestampTransformation> aggregationMethod = TimestampTransformation.fromPrettyName(dimension.get()); if (!aggregationMethod.isPresent()) { throw new RakamException(BAD_REQUEST);
public static Optional<TimestampTransformation> fromPrettyName(String name) { for (TimestampTransformation transformation : values()) { if (transformation.getPrettyName().equals(name)) { return Optional.of(transformation); } } return Optional.empty(); }
TimestampTransformation transformation = TimestampTransformation.fromString(d.type); return timestampMapping.get(transformation); }).collect(Collectors.joining(", "));
Optional<TimestampTransformation> aggregationMethod = fromPrettyName(dimension.get()); if (!aggregationMethod.isPresent()) { throw new RakamException(BAD_REQUEST);
protected String getColumnValue(Reference ref, boolean format) { switch (ref.type) { case COLUMN: return format ? checkTableColumn(ref.value, '`') : ref.value; case REFERENCE: return format(timestampMapping.get(fromString(ref.value.replace(" ", "_"))), "_time"); default: throw new IllegalArgumentException("Unknown reference type: " + ref.value); } }
@Override public Map<String, List<String>> getExtraDimensions(String project) { Map<String, List<String>> builder = new HashMap<>(); for (TimestampTransformation transformation : timestampMapping.keySet()) { builder.computeIfAbsent(transformation.getCategory(), k -> new ArrayList<>()) .add(transformation.getPrettyName()); } return builder; } }
public static void checkReference(String refValue, LocalDate startDate, LocalDate endDate, int size) { switch (fromString(refValue.replace(" ", "_"))) { case HOUR_OF_DAY: case DAY_OF_MONTH:
Optional<TimestampTransformation> trans = fromPrettyName(dimension); new EventExplorer.Reference(EventExplorer.ReferenceType.REFERENCE, trans.get().getPrettyName()), null, null, LocalDate.ofEpochDay(0), LocalDate.ofEpochDay(SCALE_FACTOR), ZoneOffset.UTC).getResult().join();
@Test public void testExtraDimensionsForStatistics() throws Exception { Collection<List<String>> dimensions = getEventExplorer().getExtraDimensions("test").values(); dimensions.stream().flatMap(e -> e.stream()).forEach(dimension -> { QueryResult test = getEventExplorer().getEventStatistics(new RequestContext(PROJECT_NAME, null), Optional.empty(), Optional.of(dimension), LocalDate.ofEpochDay(0), LocalDate.ofEpochDay(SCALE_FACTOR), ZoneOffset.UTC).join(); assertFalse(test.isFailed()); Optional<TimestampTransformation> transformation = fromPrettyName(dimension); if (transformation.isPresent()) { assertEquals(copyOf(test.getResult()), EVENT_STATISTICS_RESULTS.get(transformation.get())); } else { // TODO: test custom parameters } }); }
@Test public void testMultipleReferenceGrouping() throws Exception { QueryResult test = getEventExplorer().analyze(new RequestContext(PROJECT_NAME, null), of("test"), new EventExplorer.Measure("teststr", AggregationType.APPROXIMATE_UNIQUE), new EventExplorer.Reference(EventExplorer.ReferenceType.REFERENCE, DAY_OF_MONTH.getPrettyName()), new EventExplorer.Reference(EventExplorer.ReferenceType.REFERENCE, DAY_OF_MONTH.getPrettyName()), null, LocalDate.ofEpochDay(0), LocalDate.ofEpochDay(SCALE_FACTOR), ZoneOffset.UTC).getResult().join(); assertFalse(test.isFailed()); assertEquals(copyOf(test.getResult()), ImmutableSet.of(of("1th day", "1th day", 100L))); } }
public String getColumnValue(Map<TimestampTransformation, String> timestampMapping, Reference ref, boolean format) { switch (ref.type) { case COLUMN: return format ? checkTableColumn(ref.value) : ref.value; case REFERENCE: return format(timestampMapping.get(fromString(ref.value.replace(" ", "_"))), projectConfig.getTimeColumn()); default: throw new IllegalArgumentException("Unknown reference type: " + ref.value); } }
@JsonCreator public static TimestampTransformation fromString(String key) { try { return key == null ? null : valueOf(key.toUpperCase()); } catch (IllegalArgumentException e) { throw new RakamException("Invalid date range value: " + key, BAD_REQUEST); } }
@Override public Map<String, List<String>> getExtraDimensions(String project) { Map<String, List<String>> builder = new HashMap<>(); for (TimestampTransformation transformation : timestampMapping.keySet()) { builder.computeIfAbsent(transformation.getCategory(), k -> new ArrayList<>()) .add(transformation.getPrettyName()); } return builder; }