@Override protected Result map(Result result, ResultSetSchema schema) { if (columnName == null) { throw new IllegalStateException("Cannot map results without a column name"); } MetricColumn metricColumn = schema.getColumn(columnName, MetricColumn.class).orElseThrow( () -> new IllegalStateException("Unexpected missing column: " + columnName) ); BigDecimal value = result.getMetricValueAsNumber(metricColumn); if (value == null) { return result; } BigDecimal newValue = value.setScale(0, RoundingMode.CEILING); return result.withMetricValue(metricColumn, newValue); }
@Override public ResultSet map(ResultSet resultSet) { ResultSetSchema schema = map(resultSet.getSchema()); MetricColumn column = schema.getColumn(ROW_NUM_COLUMN_NAME, MetricColumn.class).get(); int resultSetSize = resultSet.size(); List<Result> newResults = new ArrayList<>(resultSetSize); for (int i = 0; i < resultSetSize; i++) { newResults.add(rowNumMap(resultSet.get(i), column, i)); } ResultSet newResultSet = new ResultSet(schema, newResults); LOG.trace("Mapped resultSet: {} to new resultSet {}", resultSet, newResultSet); return newResultSet; }
@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_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 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_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 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); }