Skip to content

Commit

Permalink
Fix route -> subtype
Browse files Browse the repository at this point in the history
  • Loading branch information
Abacn committed Aug 30, 2024
1 parent ac8adfb commit 0614c67
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -72,18 +72,18 @@ private static String wrapSegment(String value) {
*
* <ul>
* <li>{@code system:segment1.segment2}
* <li>{@code system:routine:segment1.segment2}
* <li>{@code system:subtype:segment1.segment2}
* <li>{@code system:`segment1.with.dots:clons`.segment2}
* </ul>
*
* <p>This helper method is for internal and testing usage only.
*/
@Internal
public static String getFqName(
String system, @Nullable String routine, Iterable<String> segments) {
String system, @Nullable String subtype, Iterable<String> segments) {
StringBuilder builder = new StringBuilder(system);
if (!Strings.isNullOrEmpty(routine)) {
builder.append(":").append(routine);
if (!Strings.isNullOrEmpty(subtype)) {
builder.append(":").append(subtype);
}
int idx = 0;
for (String segment : segments) {
Expand Down Expand Up @@ -111,8 +111,8 @@ public static String getFqName(String system, Iterable<String> segments) {
/**
* Add a FQN (fully-qualified name) to Lineage. Segments will be processed via {@link #getFqName}.
*/
public void add(String system, @Nullable String routine, Iterable<String> segments) {
metric.add(getFqName(system, routine, segments));
public void add(String system, @Nullable String subtype, Iterable<String> segments) {
metric.add(getFqName(system, subtype, segments));
}

/**
Expand Down
14 changes: 7 additions & 7 deletions sdks/python/apache_beam/metrics/metric.py
Original file line number Diff line number Diff line change
Expand Up @@ -352,25 +352,25 @@ def wrap_segment(segment: str) -> str:

@staticmethod
def get_fq_name(
system: str, *segments: str, route: Optional[str] = None) -> str:
system: str, *segments: str, subtype: Optional[str] = None) -> str:
"""Assemble fully qualified name
(`FQN <https://cloud.google.com/data-catalog/docs/fully-qualified-names>`_).
Format:
- `system:segment1.segment2`
- `system:routine:segment1.segment2`
- `system:`segment1.with.dots:clons`.segment2`
- `system:subtype:segment1.segment2`
- `system:`segment1.with.dots:colons`.segment2`
This helper method is for internal and testing usage only.
"""
segs = '.'.join(map(Lineage.wrap_segment, segments))
if route:
return ':'.join((system, route, segs))
if subtype:
return ':'.join((system, subtype, segs))
return ':'.join((system, segs))

def add(
self, system: str, *segments: str, route: Optional[str] = None) -> None:
self.metric.add(self.get_fq_name(system, *segments, route=route))
self, system: str, *segments: str, subtype: Optional[str] = None) -> None:
self.metric.add(self.get_fq_name(system, *segments, subtype=subtype))

@staticmethod
def query(results: MetricResults, label: str) -> Set[str]:
Expand Down
4 changes: 2 additions & 2 deletions sdks/python/apache_beam/metrics/metric_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -264,10 +264,10 @@ def test_fq_name(self):
for k, v in test_cases.items():
self.assertEqual("apache:" + v, Lineage.get_fq_name("apache", k))
self.assertEqual(
"apache:beam:" + v, Lineage.get_fq_name("apache", k, route="beam"))
"apache:beam:" + v, Lineage.get_fq_name("apache", k, subtype="beam"))
self.assertEqual(
"apache:beam:" + v + '.' + v,
Lineage.get_fq_name("apache", k, k, route="beam"))
Lineage.get_fq_name("apache", k, k, subtype="beam"))


if __name__ == '__main__':
Expand Down

0 comments on commit 0614c67

Please sign in to comment.