Repository navigation
AI context: a metric concept carries its filters, granularity and unit - #37193
tomasmontielp wants to merge 1 commit into
Conversation
| private static List<String> filters(Metric metric) { | ||
| List<String> where = | ||
| listOrEmpty(metric.getFilters()).stream() | ||
| .map(filter -> filter.getWhere()) | ||
| .filter(condition -> !nullOrEmpty(condition)) | ||
| .toList(); | ||
| return where.isEmpty() ? null : where; | ||
| } |
There was a problem hiding this comment.
⚠️ Bug: Blank filter not dropped: nullOrEmpty(" ") is false, so new test fails
filters() uses !nullOrEmpty(condition) to drop empty conditions. CommonUtil.nullOrEmpty(String) is string == null || string.isEmpty(), so a whitespace-only where such as " " gets through. metricCarriesWhatDefinesItsNumber passes new MetricFilter().withWhere(" ") and asserts List.of("fee_category = 'ATM Fee'"), so the test will fail in CI. In production, a blank filter gets sent to the agent and rendered as an empty line inside the sql block. Check for blank strings as well (the Java rules call for nullOrEmpty(value) || value.isBlank()). Ideally, strip each condition before keeping it.
Drop null, empty and whitespace-only conditions:
private static List<String> filters(Metric metric) {
final List<String> where =
listOrEmpty(metric.getFilters()).stream()
.map(MetricFilter::getWhere)
.filter(condition -> !nullOrEmpty(condition) && !condition.isBlank())
.map(String::strip)
.toList();
return where.isEmpty() ? null : where;
}
- Apply fix
Check the box to apply the fix or reply for a change | Was this helpful? React with 👍 / 👎
| "filters": { | ||
| "description": "Metrics only: the SQL conditions the metric is defined under, each to be applied with the definition. The number is wrong without them.", | ||
| "type": "array", | ||
| "items": { "type": "string" } | ||
| }, | ||
| "granularity": { | ||
| "description": "Metrics only: the time grain the metric is reported at (DAY, MONTH, ...).", | ||
| "type": "string" | ||
| }, | ||
| "unit": { | ||
| "description": "Metrics only: the unit the value is measured in. The custom unit when unitOfMeasurement is OTHER, otherwise the unitOfMeasurement value.", | ||
| "type": "string" | ||
| }, |
There was a problem hiding this comment.
⚠️ Quality: New cross-repo conceptContext contract (filters/granularity/unit) has no ADR
This PR adds three JSON Schema fields to conceptContext (filters, granularity, unit). The description says open-metadata/ai-platform#2061 builds against them and that this PR has to merge first. That makes it a cross-repo contract, and nothing in docs/decisions/ covers the concept context shape. The rules exist only in the PR description and in schema prose. A record would need to say: "A metric's concept context carries the metric's non-blank filter conditions, its granularity enum value and its unit; the unit is customUnitOfMeasurement when unitOfMeasurement is OTHER and set, otherwise the enum value; each field is omitted when the metric does not declare it; type, dimensions, measures and the variant hierarchy are excluded because they do not change the number. OpenMetadata merges before ai-platform." These rules come from the description's lines "Type, dimensions, measures and the variant hierarchy stay out: they do not change the number" and "it builds against this one, so this merges first". Add a record under docs/decisions/ that states them.
Was this helpful? React with 👍 / 👎
Code Review
|
| Compact |
|
Was this helpful? React with 👍 / 👎 | Powered by Gitar — free for open source
Fixes open-metadata/openmetadata-collate#8310
Describe your changes:
A metric's concept context (
GET /metrics/name/{fqn}/context) carried only its expression and bindings, so the agent computing it never saw the rest of what defines the number:filters: the SQL conditions the metric is defined under (status = 'paid'). Without them the agent computes the metric unfiltered, and the number is wrong.granularity: the time grain it is reported at.unit: the unit it is measured in; the custom unit whenunitOfMeasurementisOTHER. QA found a DOLLARS metric whose$in the answer was only the model's guess.conceptContextgains the three optional fields;ConceptContextBuilderfills them for a metric (each omitted when the metric does not declare it), andConceptContextMarkdownrenders them under the definition. Type, dimensions, measures and the variant hierarchy stay out: they do not change the number.Companion: open-metadata/ai-platform renders the same fields in the SQL and worker concept text (open-metadata/ai-platform#2061); it builds against this one, so this merges first.
Type of change:
Verification
ConceptContextBuilderTest.metricCarriesWhatDefinesItsNumber,metricNamesItsCustomUnitAndOmitsWhatItDoesNotDeclare;ConceptContextMarkdownTest.rendersWhatDefinesAMetricsNumber.openmetadata-serviceneeds a fullmvn clean install(the shaded Elasticsearch module is only produced at install), which would overwrite the local snapshot used by another branch. CI runs them.mvn spotless:apply: clean.Checklist: