Skip to content

Commit

Permalink
chore: remove unused methods in SchemaUtil (MINOR) (#3301)
Browse files Browse the repository at this point in the history
  • Loading branch information
agavra authored Sep 4, 2019
1 parent 6a3a2b9 commit b5bc9ff
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 105 deletions.
25 changes: 1 addition & 24 deletions ksql-common/src/main/java/io/confluent/ksql/util/SchemaUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -106,11 +106,6 @@ public static Class<?> getJavaType(final Schema schema) {
);
}

public static boolean matchFieldName(final Field field, final String fieldName) {
return field.name().equals(fieldName)
|| field.name().equals(getFieldNameWithNoAlias(fieldName));
}

/**
* Check if the supplied {@code actual} field name matches the supplied {@code required}.
*
Expand All @@ -125,10 +120,6 @@ public static boolean isFieldName(final String actual, final String required) {
|| required.equals(getFieldNameWithNoAlias(actual));
}

public static Field buildAliasedField(final String alias, final Field field) {
return new Field(buildAliasedFieldName(alias, field.name()), field.index(), field.schema());
}

public static String buildAliasedFieldName(final String alias, final String fieldName) {
final String prefix = alias + FIELD_NAME_DELIMITER;
if (fieldName.startsWith(prefix)) {
Expand All @@ -137,15 +128,6 @@ public static String buildAliasedFieldName(final String alias, final String fiel
return prefix + fieldName;
}

public static String getJavaCastString(final Schema schema) {
final String castString = SCHEMA_TYPE_TO_CAST_STRING.get(schema.type());
if (castString == null) {
return "";
}

return castString;
}

public static org.apache.avro.Schema buildAvroSchema(
final PersistenceSchema schema,
final String name
Expand Down Expand Up @@ -224,11 +206,6 @@ private static org.apache.avro.Schema unionWithNull(final org.apache.avro.Schema
return createUnion(org.apache.avro.Schema.create(org.apache.avro.Schema.Type.NULL), schema);
}

public static String getFieldNameWithNoAlias(final Field field) {
final String name = field.name();
return getFieldNameWithNoAlias(name);
}

public static String getFieldNameWithNoAlias(final String fieldName) {
final int idx = fieldName.indexOf(FIELD_NAME_DELIMITER);
if (idx < 0) {
Expand Down Expand Up @@ -311,7 +288,7 @@ private static Schema resolveDecimalOperatorResultType(
return DecimalUtil.builder(precision, scale).build();
}

public static boolean isNumber(final Schema.Type type) {
static boolean isNumber(final Schema.Type type) {
return ARITHMETIC_TYPES.contains(type);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -445,24 +445,6 @@ public void shouldFailForGetJavaTypeOnUnsuppportedConnectType() {
SchemaUtil.getJavaType(Schema.INT8_SCHEMA);
}

@Test
public void shouldMatchName() {
final Field field = new Field("foo", 0, Schema.INT32_SCHEMA);
assertThat(SchemaUtil.matchFieldName(field, "foo"), is(true));
}

@Test
public void shouldNotMatchDifferentName() {
final Field field = new Field("foo", 0, Schema.INT32_SCHEMA);
assertThat(SchemaUtil.matchFieldName(field, "bar"), is(false));
}

@Test
public void shouldMatchNameWithAlias() {
final Field field = new Field("foo", 0, Schema.INT32_SCHEMA);
assertThat(SchemaUtil.matchFieldName(field, "bar.foo"), is(true));
}

@Test
public void shouldMatchFieldNameOnExactMatch() {
assertThat(SchemaUtil.isFieldName("bob", "bob"), is(true));
Expand All @@ -485,44 +467,6 @@ public void shouldNotMatchFieldNamesIfRequiredIsAliased() {
assertThat(SchemaUtil.isFieldName("bob", "aliased.bob"), is(false));
}

@Test
public void shouldGetTheCorrectJavaCastClass() {
assertThat("Incorrect class.", SchemaUtil.getJavaCastString(Schema.OPTIONAL_BOOLEAN_SCHEMA),
equalTo("(Boolean)"));
assertThat("Incorrect class.", SchemaUtil.getJavaCastString(Schema.OPTIONAL_INT32_SCHEMA),
equalTo("(Integer)"));
assertThat("Incorrect class.", SchemaUtil.getJavaCastString(Schema.OPTIONAL_INT64_SCHEMA),
equalTo("(Long)"));
assertThat("Incorrect class.", SchemaUtil.getJavaCastString(Schema.OPTIONAL_FLOAT64_SCHEMA),
equalTo("(Double)"));
assertThat("Incorrect class.", SchemaUtil.getJavaCastString(Schema.OPTIONAL_STRING_SCHEMA),
equalTo("(String)"));
}

@Test
public void shouldStripAliasFromField() {
// Given:
final Field field = new Field("alias.some-field-name", 1, Schema.OPTIONAL_STRING_SCHEMA);

// When:
final String result = SchemaUtil.getFieldNameWithNoAlias(field);

// Then:
assertThat(result, is("some-field-name"));
}

@Test
public void shouldReturnFieldWithoutAliasAsIs() {
// Given:
final Field field = new Field("some-field-name", 1, Schema.OPTIONAL_STRING_SCHEMA);

// When:
final String result = SchemaUtil.getFieldNameWithNoAlias(field);

// Then:
assertThat(result, is("some-field-name"));
}

@Test
public void shouldStripAliasFromFieldName() {
// When:
Expand Down Expand Up @@ -861,31 +805,6 @@ public void shouldBuildAliasedFieldNameThatIsAlreadyAliased() {
assertThat(result, is("SomeAlias.SomeFieldName"));
}

@Test
public void shouldBuildAliasedField() {
// Given:
final Field field = new Field("col0", 1, Schema.INT64_SCHEMA);

// When:
final Field result = SchemaUtil
.buildAliasedField("TheAlias", field);

// Then:
assertThat(result, is(new Field("TheAlias.col0", 1, Schema.INT64_SCHEMA)));
}

@Test
public void shouldBuildAliasedFieldThatIsAlreadyAliased() {
// Given:
final Field field = new Field("TheAlias.col0", 1, Schema.INT64_SCHEMA);

// When:
final Field result = SchemaUtil.buildAliasedField("TheAlias", field);

// Then:
assertThat(result, is(field));
}

@Test
public void shouldEnsureDeepOptional() {
// Given:
Expand Down

0 comments on commit b5bc9ff

Please sign in to comment.