Skip to content

Commit

Permalink
style fix
Browse files Browse the repository at this point in the history
  • Loading branch information
ilicmarkodb committed Sep 24, 2024
1 parent 99ce5ae commit bd62e3d
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 63 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,8 @@ public static StructType deserializeStructType(String structTypeJson) {
DataType parsedType =
parseDataType(
OBJECT_MAPPER.reader().readTree(structTypeJson),
"" /* fieldPath */,
new FieldMetadata.Builder().build() /* collationsMetadata */);
"" /* fieldPath */,
new FieldMetadata.Builder().build() /* collationsMetadata */);
if (parsedType instanceof StructType) {
return (StructType) parsedType;
} else {
Expand Down Expand Up @@ -160,20 +160,18 @@ public static StructType deserializeStructType(String structTypeJson) {
* }
* </pre>
*
* @param fieldPath Path from the nearest ancestor that is of the {@link StructField} type.
* For example, "c1.key.element" represents a path starting from the {@link StructField} named "c1."
* The next element, "key," indicates that "c1" stores a {@link MapType} type. The final element, "element",
* shows that the key of the map is an {@link ArrayType} type.
* @param fieldPath Path from the nearest ancestor that is of the {@link StructField} type. For
* example, "c1.key.element" represents a path starting from the {@link StructField} named
* "c1." The next element, "key," indicates that "c1" stores a {@link MapType} type. The final
* element, "element", shows that the key of the map is an {@link ArrayType} type.
* @param collationsMetadata Metadata that maps the path of a {@link StringType} to its collation.
* Only maps non-UTF8_BINARY collated {@link StringType}.
* Collation metadata is stored in the nearest ancestor, which is the StructField.
* This is because StructField includes a metadata field, whereas Map and Array do not,
* making them unable to store this information.
* Paths are in same form as `fieldPath`.
* <a href="https://github.com/delta-io/delta/blob/master/protocol_rfcs/collated-string-type.md#collation-identifiers">Docs</a>
* Only maps non-UTF8_BINARY collated {@link StringType}. Collation metadata is stored in the
* nearest ancestor, which is the StructField. This is because StructField includes a metadata
* field, whereas Map and Array do not, making them unable to store this information. Paths
* are in same form as `fieldPath`. <a
* href="https://github.com/delta-io/delta/blob/master/protocol_rfcs/collated-string-type.md#collation-identifiers">Docs</a>
*/
static DataType parseDataType(
JsonNode json, String fieldPath, FieldMetadata collationsMetadata) {
static DataType parseDataType(JsonNode json, String fieldPath, FieldMetadata collationsMetadata) {
switch (json.getNodeType()) {
case STRING:
// simple types are stored as just a string
Expand Down Expand Up @@ -211,7 +209,8 @@ private static ArrayType parseArrayType(
String.format("Expected JSON object with 3 fields for array data type but got:\n%s", json));
boolean containsNull = getBooleanField(json, "containsNull");
DataType dataType =
parseDataType(getNonNullField(json, "elementType"), fieldPath + ".element", collationsMetadata);
parseDataType(
getNonNullField(json, "elementType"), fieldPath + ".element", collationsMetadata);
return new ArrayType(dataType, containsNull);
}

Expand Down Expand Up @@ -262,7 +261,8 @@ private static StructField parseStructField(JsonNode json) {
String name = getStringField(json, "name");
FieldMetadata metadata = parseFieldMetadata(json.get("metadata"), false);
DataType type =
parseDataType(getNonNullField(json, "type"), name, getCollationsMetadata(json.get("metadata")));
parseDataType(
getNonNullField(json, "type"), name, getCollationsMetadata(json.get("metadata")));
boolean nullable = getBooleanField(json, "nullable");
return new StructField(name, type, nullable, metadata);
}
Expand All @@ -276,7 +276,8 @@ private static FieldMetadata parseFieldMetadata(JsonNode json) {
* Parses a {@link FieldMetadata}, optionally including collation metadata, depending on
* `includecollationsMetadata`.
*/
private static FieldMetadata parseFieldMetadata(JsonNode json, boolean includecollationsMetadata) {
private static FieldMetadata parseFieldMetadata(
JsonNode json, boolean includecollationsMetadata) {
if (json == null || json.isNull()) {
return FieldMetadata.empty();
}
Expand Down Expand Up @@ -411,13 +412,12 @@ private static String getStringField(JsonNode rootNode, String fieldName) {
private static void assertValidTypeForCollations(
String fieldPath, String fieldType, FieldMetadata collationsMetadata) {
if (collationsMetadata.contains(fieldPath) && !fieldType.equals("string")) {
throw new IllegalArgumentException(String.format("Invalid data type for collations: \"%s\"", fieldType));
throw new IllegalArgumentException(
String.format("Invalid data type for collations: \"%s\"", fieldType));
}
}

/**
* Returns a metadata with a map of field path to collation name.
*/
/** Returns a metadata with a map of field path to collation name. */
private static FieldMetadata getCollationsMetadata(JsonNode fieldMetadata) {
if (fieldMetadata == null || !fieldMetadata.has(DataType.COLLATIONS_METADATA_KEY)) {
return new FieldMetadata.Builder().build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,16 @@
*/
package io.delta.kernel.types;

import io.delta.kernel.annotation.Evolving;
import static io.delta.kernel.internal.util.Preconditions.checkArgument;

import io.delta.kernel.annotation.Evolving;
import java.util.Objects;
import java.util.Optional;

import static io.delta.kernel.internal.util.Preconditions.checkArgument;

/**
* Identifies collation for string type.
* <a href="https://github.com/delta-io/delta/blob/master/protocol_rfcs/collated-string-type.md#collation-identifiers">
* Collation identifiers</a>
* Identifies collation for string type. <a
* href="https://github.com/delta-io/delta/blob/master/protocol_rfcs/collated-string-type.md#collation-identifiers">
* Collation identifiers</a>
*
* @since 3.3.0
*/
Expand Down Expand Up @@ -55,33 +54,24 @@ public CollationIdentifier(String provider, String collationName, Optional<Strin
this.version = version.map(String::toUpperCase);
}

/**
*
* @return collation provider.
*/
/** @return collation provider. */
public String getProvider() {
return provider;
}

/**
*
* @return collation name.
*/
/** @return collation name. */
public String getName() {
return name;
}

/**
*
* @return provider version.
*/
/** @return provider version. */
public Optional<String> getVersion() {
return version;
}

/**
*
* @param identifier collation identifier in string form of <br>{@code PROVIDER.COLLATION_NAME[.PROVIDER_VERSION]}.
* @param identifier collation identifier in string form of <br>
* {@code PROVIDER.COLLATION_NAME[.PROVIDER_VERSION]}.
* @return appropriate collation identifier object
*/
public static CollationIdentifier fromString(String identifier) {
Expand All @@ -96,9 +86,7 @@ public static CollationIdentifier fromString(String identifier) {
}
}

/**
* Collation identifiers are identical when the provider, name, and version are the same.
*/
/** Collation identifiers are identical when the provider, name, and version are the same. */
@Override
public boolean equals(Object o) {
if (!(o instanceof CollationIdentifier)) {
Expand All @@ -107,22 +95,16 @@ public boolean equals(Object o) {

CollationIdentifier other = (CollationIdentifier) o;
return this.provider.equals(other.provider)
&& this.name.equals(other.name)
&& this.version.equals(other.version);
&& this.name.equals(other.name)
&& this.version.equals(other.version);
}

/**
*
* @return collation identifier in form of {@code PROVIDER.COLLATION_NAME}.
*/
/** @return collation identifier in form of {@code PROVIDER.COLLATION_NAME}. */
public String toStringWithoutVersion() {
return String.format("%s.%s", provider, name);
}

/**
*
* @return collation identifier in form of {@code PROVIDER.COLLATION_NAME[.PROVIDER_VERSION]}
*/
/** @return collation identifier in form of {@code PROVIDER.COLLATION_NAME[.PROVIDER_VERSION]} */
@Override
public String toString() {
if (version.isPresent()) {
Expand All @@ -132,4 +114,3 @@ public String toString() {
}
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ public class StringType extends BasePrimitiveType {
private final CollationIdentifier collationIdentifier;

/**
*
* @param collationIdentifier identifier of collation in which this StringType will be observed
*/
public StringType(CollationIdentifier collationIdentifier) {
Expand All @@ -39,19 +38,15 @@ public StringType(CollationIdentifier collationIdentifier) {
}

/**
*
* @param collationName name of collation in which this StringType will be observed.
* In form of {@code PROVIDER.COLLATION_NAME[.VERSION]}
* @param collationName name of collation in which this StringType will be observed. In form of
* {@code PROVIDER.COLLATION_NAME[.VERSION]}
*/
public StringType(String collationName) {
super("string");
this.collationIdentifier = CollationIdentifier.fromString(collationName);
}

/**
*
* @return StringType's collation identifier
*/
/** @return StringType's collation identifier */
public CollationIdentifier getCollationIdentifier() {
return collationIdentifier;
}
Expand Down

0 comments on commit bd62e3d

Please sign in to comment.