From b5bc9ffd690901edf69f40ab670819569e1eace9 Mon Sep 17 00:00:00 2001 From: Almog Gavra Date: Wed, 4 Sep 2019 10:10:48 -0700 Subject: [PATCH] chore: remove unused methods in SchemaUtil (MINOR) (#3301) --- .../io/confluent/ksql/util/SchemaUtil.java | 25 +----- .../confluent/ksql/util/SchemaUtilTest.java | 81 ------------------- 2 files changed, 1 insertion(+), 105 deletions(-) diff --git a/ksql-common/src/main/java/io/confluent/ksql/util/SchemaUtil.java b/ksql-common/src/main/java/io/confluent/ksql/util/SchemaUtil.java index 05a568cbd3df..8438e4ac509e 100644 --- a/ksql-common/src/main/java/io/confluent/ksql/util/SchemaUtil.java +++ b/ksql-common/src/main/java/io/confluent/ksql/util/SchemaUtil.java @@ -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}. * @@ -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)) { @@ -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 @@ -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) { @@ -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); } diff --git a/ksql-common/src/test/java/io/confluent/ksql/util/SchemaUtilTest.java b/ksql-common/src/test/java/io/confluent/ksql/util/SchemaUtilTest.java index 5ac50da7855f..b715aa7c6373 100644 --- a/ksql-common/src/test/java/io/confluent/ksql/util/SchemaUtilTest.java +++ b/ksql-common/src/test/java/io/confluent/ksql/util/SchemaUtilTest.java @@ -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)); @@ -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: @@ -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: