Skip to content

Commit

Permalink
Refactor QualifiedName. Removed fields that were not thread-safe.
Browse files Browse the repository at this point in the history
  • Loading branch information
ArtfulCoder committed Jun 28, 2021
1 parent ee14eb3 commit b26809f
Showing 1 changed file with 47 additions and 61 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,7 @@ public final class QualifiedName implements Serializable {
private final String partitionName;
private final String tableName;
private final String viewName;
private String qualifiedName;
private Map<String, String> qualifiedNameMap;
private Map<String, String> parts;
private Type type;
private final Type type;

private QualifiedName(
@NonNull final String catalogName,
Expand Down Expand Up @@ -471,31 +468,27 @@ private static String standardizeRequired(final String name, @Nullable final Str
*/
@JsonValue
public Map<String, String> toJson() {
if (qualifiedNameMap == null) {
final Map<String, String> map = new HashMap<>(5);
map.put("qualifiedName", toString());
map.put("catalogName", catalogName);
final Map<String, String> map = new HashMap<>(5);
map.put("qualifiedName", toString());
map.put("catalogName", catalogName);

if (!databaseName.isEmpty()) {
map.put("databaseName", databaseName);
}

if (!tableName.isEmpty()) {
map.put("tableName", tableName);
}
if (!databaseName.isEmpty()) {
map.put("databaseName", databaseName);
}

if (!partitionName.isEmpty()) {
map.put("partitionName", partitionName);
}
if (!tableName.isEmpty()) {
map.put("tableName", tableName);
}

if (!viewName.isEmpty()) {
map.put("viewName", viewName);
}
if (!partitionName.isEmpty()) {
map.put("partitionName", partitionName);
}

qualifiedNameMap = map;
if (!viewName.isEmpty()) {
map.put("viewName", viewName);
}

return qualifiedNameMap;
return map;
}

/**
Expand All @@ -504,30 +497,26 @@ public Map<String, String> toJson() {
* @return parts of the qualified name as a Map
*/
public Map<String, String> parts() {
if (parts == null) {
final Map<String, String> map = new HashMap<>(4);
map.put("catalogName", catalogName);

if (!databaseName.isEmpty()) {
map.put("databaseName", databaseName);
}
final Map<String, String> map = new HashMap<>(5);
map.put("catalogName", catalogName);

if (!tableName.isEmpty()) {
map.put("tableName", tableName);
}
if (!databaseName.isEmpty()) {
map.put("databaseName", databaseName);
}

if (!partitionName.isEmpty()) {
map.put("partitionName", partitionName);
}
if (!tableName.isEmpty()) {
map.put("tableName", tableName);
}

if (!viewName.isEmpty()) {
map.put("viewName", viewName);
}
if (!partitionName.isEmpty()) {
map.put("partitionName", partitionName);
}

parts = map;
if (!viewName.isEmpty()) {
map.put("viewName", viewName);
}

return parts;
return map;
}

public boolean isViewDefinition() {
Expand Down Expand Up @@ -568,32 +557,29 @@ public int hashCode() {
*/
@Override
public String toString() {
if (qualifiedName == null) {
final StringBuilder sb = new StringBuilder(catalogName);
final StringBuilder sb = new StringBuilder(catalogName);

if (!databaseName.isEmpty()) {
sb.append('/');
sb.append(databaseName);
}
if (!databaseName.isEmpty()) {
sb.append('/');
sb.append(databaseName);
}

if (!tableName.isEmpty()) {
sb.append('/');
sb.append(tableName);
}
if (!tableName.isEmpty()) {
sb.append('/');
sb.append(tableName);
}

if (!partitionName.isEmpty()) {
sb.append('/');
sb.append(partitionName);
}
if (!partitionName.isEmpty()) {
sb.append('/');
sb.append(partitionName);
}

if (!viewName.isEmpty()) {
sb.append('/');
sb.append(viewName);
}
qualifiedName = sb.toString();
if (!viewName.isEmpty()) {
sb.append('/');
sb.append(viewName);
}

return qualifiedName;
return sb.toString();
}


Expand Down

0 comments on commit b26809f

Please sign in to comment.