@Override protected Result map(Result result, ResultSetSchema schema) { MetricColumn column = schema.getColumn(A_BOOLEAN_METRIC.asName(), MetricColumn.class).orElseThrow( () -> new IllegalStateException(UNEXPECTED_MISSING_COLUMN + A_BOOLEAN_METRIC.asName()) ); return result.getMetricValueAsBoolean(column) ? result : null; }
@Override protected Result map(Result result, ResultSetSchema schema) { MetricColumn column = schema.getColumn(A_JSON_NODE_METRIC.asName(), MetricColumn.class).orElseThrow( () -> new IllegalStateException(UNEXPECTED_MISSING_COLUMN + A_JSON_NODE_METRIC.asName()) ); ObjectNode node = (ObjectNode) result.getMetricValueAsJsonNode(column); node.put("length", node.get("clarification").textValue().length()); return result; }
@Override protected Result map(Result result, ResultSetSchema schema) { MetricColumn column = schema.getColumn(A_BOOLEAN_METRIC.asName(), MetricColumn.class).orElseThrow( () -> new IllegalStateException(UNEXPECTED_MISSING_COLUMN + A_BOOLEAN_METRIC.asName()) ); return result.getMetricValueAsBoolean(column) ? result : null; }
@Override protected Result map(Result result, ResultSetSchema schema) { MetricColumn column = schema.getColumn(A_JSON_NODE_METRIC.asName(), MetricColumn.class).orElseThrow( () -> new IllegalStateException(UNEXPECTED_MISSING_COLUMN + A_JSON_NODE_METRIC.asName()) ); ObjectNode node = (ObjectNode) result.getMetricValueAsJsonNode(column); node.put("length", node.get("clarification").textValue().length()); return result; }
@Override protected Result map(Result result, ResultSetSchema schema) { MetricColumn column = schema.getColumn(A_NULL_METRIC.asName(), MetricColumn.class).orElseThrow( () -> new IllegalStateException(UNEXPECTED_MISSING_COLUMN + A_NULL_METRIC.asName()) ); Object nullMetric = result.getMetricValue(column); if (nullMetric != null) { throw new IllegalStateException( String.format("Metric 'nullMetric' should be null but is: %s", nullMetric) ); } return result; }
@Override protected Result map(Result result, ResultSetSchema schema) { MetricColumn column = schema.getColumn(A_NULL_METRIC.asName(), MetricColumn.class).orElseThrow( () -> new IllegalStateException(UNEXPECTED_MISSING_COLUMN + A_NULL_METRIC.asName()) ); Object nullMetric = result.getMetricValue(column); if (nullMetric != null) { throw new IllegalStateException( String.format("Metric 'nullMetric' should be null but is: %s", nullMetric) ); } return result; }
@Override protected Result map(Result result, ResultSetSchema schema) { MetricColumn stringColumn = schema.getColumn(A_STRING_METRIC.asName(), MetricColumn.class) .orElseThrow( () -> new IllegalStateException(UNEXPECTED_MISSING_COLUMN + A_STRING_METRIC.asName()) ); String stringValue = result.getMetricValueAsString(stringColumn); return result.withMetricValue(stringColumn, stringValue + stringValue); }
@Override protected Result map(Result result, ResultSetSchema schema) { MetricColumn stringColumn = schema.getColumn(A_STRING_METRIC.asName(), MetricColumn.class) .orElseThrow( () -> new IllegalStateException(UNEXPECTED_MISSING_COLUMN + A_STRING_METRIC.asName()) ); String stringValue = result.getMetricValueAsString(stringColumn); return result.withMetricValue(stringColumn, stringValue + stringValue); }
@Override public void loadMetricDictionary(MetricDictionary metricDictionary, DimensionDictionary dimensionDictionary) { buildMetricMakers(metricDictionary); // Metrics that directly aggregate druid fields List<MetricInstance> metrics = Arrays.asList( new MetricInstance((ApiMetricName) A_HEIGHT, longSumMaker, HEIGHT), new MetricInstance(A_WIDTH, longSumMaker, WIDTH), new MetricInstance(A_DEPTH, longSumMaker, DEPTH), new MetricInstance(A_LIMBS, longSumMaker, LIMBS), new MetricInstance(A_USERS, sketchMaker, USERS), new MetricInstance(A_OTHER_USERS, sketchMaker, USERS), new MetricInstance(A_ROW_NUM, rowNumMaker, new FieldName[] {}), new MetricInstance(A_AREA, productMaker, A_HEIGHT, A_WIDTH), new MetricInstance(A_VOLUME, productMaker, A_HEIGHT, A_WIDTH, A_DEPTH), new MetricInstance(A_DAY_AVG_USERS, simpleDailyAverageMaker, A_USERS), new MetricInstance(A_DAY_AVG_OTHER_USERS, simpleDailyAverageMaker, A_OTHER_USERS), new MetricInstance(A_DAY_AVG_LIMBS, simpleDailyAverageMaker, A_LIMBS) ); metrics.stream().map(MetricInstance::make).forEach(metricDictionary::add); metricDictionary.getScope("shapes").add( new MetricInstance(new LogicalMetricInfo(A_SCOPED_WIDTH.asName()), longSumMaker, WIDTH.asName()).make() ); //Allows us to add some non-numeric LogicalMetrics without having to write a Maker for them. Makers should //be written if using complex metrics in production code. NonNumericMetrics.getLogicalMetrics().forEach(metricDictionary::add); } }
@Override public void loadMetricDictionary(MetricDictionary metricDictionary, DimensionDictionary dimensionDictionary) { buildMetricMakers(metricDictionary); // Metrics that directly aggregate druid fields List<MetricInstance> metrics = Arrays.asList( new MetricInstance((ApiMetricName) A_HEIGHT, longSumMaker, HEIGHT), new MetricInstance(A_WIDTH, longSumMaker, WIDTH), new MetricInstance(A_DEPTH, longSumMaker, DEPTH), new MetricInstance(A_LIMBS, longSumMaker, LIMBS), new MetricInstance(A_USERS, sketchMaker, USERS), new MetricInstance(A_OTHER_USERS, sketchMaker, USERS), new MetricInstance(A_ROW_NUM, rowNumMaker, new FieldName[] {}), new MetricInstance(A_AREA, productMaker, A_HEIGHT, A_WIDTH), new MetricInstance(A_VOLUME, productMaker, A_HEIGHT, A_WIDTH, A_DEPTH), new MetricInstance(A_DAY_AVG_USERS, simpleDailyAverageMaker, A_USERS), new MetricInstance(A_DAY_AVG_OTHER_USERS, simpleDailyAverageMaker, A_OTHER_USERS), new MetricInstance(A_DAY_AVG_LIMBS, simpleDailyAverageMaker, A_LIMBS) ); metrics.stream().map(MetricInstance::make).forEach(metricDictionary::add); metricDictionary.getScope("shapes").add( new MetricInstance(new LogicalMetricInfo(A_SCOPED_WIDTH.asName()), longSumMaker, WIDTH.asName()).make() ); //Allows us to add some non-numeric LogicalMetrics without having to write a Maker for them. Makers should //be written if using complex metrics in production code. NonNumericMetrics.getLogicalMetrics().forEach(metricDictionary::add); } }
A_STRING_METRIC.asName(), A_HEIGHT.getApiName() )), new TemplateDruidQuery( Collections.singleton(new LongMinAggregation( A_BOOLEAN_METRIC.asName(), A_HEIGHT.getApiName() )), new TemplateDruidQuery( Collections.singleton( new LongMinAggregation(A_JSON_NODE_METRIC.asName(), A_HEIGHT.getApiName()) ), Collections.emptySet() new TemplateDruidQuery( Collections.singleton(new LongMinAggregation( A_NULL_METRIC.asName(), A_HEIGHT.getApiName() )),
A_STRING_METRIC.asName(), A_HEIGHT.getApiName() )), new TemplateDruidQuery( Collections.singleton(new LongMinAggregation( A_BOOLEAN_METRIC.asName(), A_HEIGHT.getApiName() )), new TemplateDruidQuery( Collections.singleton( new LongMinAggregation(A_JSON_NODE_METRIC.asName(), A_HEIGHT.getApiName()) ), Collections.emptySet() new TemplateDruidQuery( Collections.singleton(new LongMinAggregation( A_NULL_METRIC.asName(), A_HEIGHT.getApiName() )),