Skip to content

Commit

Permalink
moved fetchCollationMetadata to constructor
Browse files Browse the repository at this point in the history
  • Loading branch information
ilicmarkodb committed Sep 26, 2024
1 parent 555d49e commit d359ed4
Showing 1 changed file with 7 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public class StructField {
private final String name;
private final DataType dataType;
private final boolean nullable;
private FieldMetadata metadata;
private final FieldMetadata metadata;

public StructField(String name, DataType dataType, boolean nullable) {
this(name, dataType, nullable, FieldMetadata.empty());
Expand All @@ -67,7 +67,9 @@ public StructField(String name, DataType dataType, boolean nullable, FieldMetada
this.name = name;
this.dataType = dataType;
this.nullable = nullable;
this.metadata = metadata;

FieldMetadata collationMetadata = fetchCollationMetadata();
this.metadata = new FieldMetadata.Builder().fromMetadata(metadata).fromMetadata(collationMetadata).build();
}

/** @return the name of this field */
Expand All @@ -86,29 +88,19 @@ public FieldMetadata getMetadata() {
return metadata;
}

/** Indicated whether collation metadata is fetched and added to `metadata` */
private boolean isCollationMetadataFetched = false;

/** Fetches collation metadata from nested collated fields. */
private void fetchCollationMetadata() {
if (isCollationMetadataFetched) {
return;
}
isCollationMetadataFetched = true;

private FieldMetadata fetchCollationMetadata() {
List<Tuple2<String, String>> nestedCollatedFields = getNestedCollatedFields(dataType, name);
if (nestedCollatedFields.isEmpty()) {
return;
return FieldMetadata.empty();
}

FieldMetadata.Builder metadataBuilder = new FieldMetadata.Builder();
for (Tuple2<String, String> nestedField : nestedCollatedFields) {
metadataBuilder.putString(nestedField._1, nestedField._2);
}

metadata =
new FieldMetadata.Builder()
.fromMetadata(metadata)
return new FieldMetadata.Builder()
.putFieldMetadata(DataType.COLLATIONS_METADATA_KEY, metadataBuilder.build())
.build();
}
Expand Down Expand Up @@ -167,9 +159,6 @@ public boolean equals(Object o) {
return false;
}
StructField that = (StructField) o;
// Retrieve collation metadata if they haven't been fetched yet.
fetchCollationMetadata();
that.fetchCollationMetadata();
return nullable == that.nullable
&& name.equals(that.name)
&& dataType.equals(that.dataType)
Expand Down

0 comments on commit d359ed4

Please sign in to comment.