Skip to content

Commit

Permalink
fix(uri): marks uri field as deprecated, removes problem code, and ad…
Browse files Browse the repository at this point in the history
…ds coercer for usages of URI typeref (datahub-project#7093)
  • Loading branch information
RyanHolstien authored and Eric Yomi committed Feb 8, 2023
1 parent 6de7507 commit 3c31c6b
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -136,9 +136,6 @@ private void mapDatasetProperties(@Nonnull Dataset dataset, @Nonnull DataMap dat
properties.setQualifiedName(gmsProperties.getQualifiedName());
dataset.setProperties(properties);
dataset.setDescription(properties.getDescription());
if (gmsProperties.getUri() != null) {
dataset.setUri(gmsProperties.getUri().toString());
}
}

private void mapEditableDatasetProperties(@Nonnull Dataset dataset, @Nonnull DataMap dataMap) {
Expand Down
38 changes: 38 additions & 0 deletions li-utils/src/main/javaPegasus/com/linkedin/common/uri/Uri.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package com.linkedin.common.uri;

import java.net.URI;
import java.net.URISyntaxException;

public class Uri {
private final String _uri;

public Uri(String url) {
if (url == null) {
throw new NullPointerException("URL must be non-null");
}
_uri = url;
}

@Override
public String toString() {
return _uri;
}

@Override
public boolean equals(Object obj) {
if (!(obj instanceof Uri)) {
return false;
} else {
return _uri.equals(((Uri) obj)._uri);
}
}

@Override
public int hashCode() {
return _uri.hashCode();
}

public URI toURI() throws URISyntaxException {
return new URI(_uri);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.linkedin.common.uri;

import com.linkedin.data.template.Custom;
import com.linkedin.data.template.DirectCoercer;
import com.linkedin.data.template.TemplateOutputCastException;

public class UriCoercer implements DirectCoercer<Uri> {
private static final boolean REGISTER_COERCER = Custom.registerCoercer(new UriCoercer(), Uri.class);

@Override
public Object coerceInput(Uri object) throws ClassCastException {
return object.toString();
}

@Override
public Uri coerceOutput(Object object) throws TemplateOutputCastException {
return new Uri((String) object);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ record DatasetProperties includes CustomProperties, ExternalReference {
/**
* The abstracted URI such as hdfs:///data/tracking/PageViewEvent, file:///dir/file_name. Uri should not include any environment specific properties. Some datasets might not have a standardized uri, which makes this field optional (i.e. kafka topic).
*/
@deprecated = "Use ExternalReference.externalUrl field instead."
uri: optional Uri

/**
Expand Down

0 comments on commit 3c31c6b

Please sign in to comment.