Skip to content

Commit

Permalink
feat: remove equalsIgnoreCase from all Name classes (MINOR) (#3411)
Browse files Browse the repository at this point in the history
  • Loading branch information
agavra authored Sep 26, 2019
1 parent 295314e commit b78619c
Show file tree
Hide file tree
Showing 13 changed files with 56 additions and 64 deletions.
14 changes: 0 additions & 14 deletions ksql-common/src/main/java/io/confluent/ksql/name/Name.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,20 +42,6 @@ public String name() {
return name;
}

/**
* @see String#equalsIgnoreCase(String)
*/
public boolean equalsIgnoreCase(final T o) {
if (this == o) {
return true;
}
if (o == null || getClass() != o.getClass()) {
return false;
}

return name.equalsIgnoreCase(o.name());
}

public boolean startsWith(final T o) {
if (this == o) {
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,12 @@ public static FormatOptions none() {
return new FormatOptions(word -> true);
}

/**
* @return options that escape nothing
* @apiNote this is <i>dangerous</i> and could cause reserved identifiers
* to be mangled. Use this API sparingly (e.g. in logging error
* messages)
*/
public static FormatOptions noEscape() {
return new FormatOptions(word -> false);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ public Optional<Column> findColumn(final ColumnName columnName) {
}

@VisibleForTesting
public Optional<Column> findColumn(final String columnName) {
private Optional<Column> findColumn(final String columnName) {
Optional<Column> found = doFindColumn(columnName, metadata);
if (found.isPresent()) {
return found;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ public void shouldGetKeyFieldFromValueIfAdded() {

@Test
public void shouldGetMetaFields() {
assertThat(SOME_SCHEMA.findColumn("ROWTIME"), is(Optional.of(
assertThat(SOME_SCHEMA.findColumn(ROWTIME_NAME), is(Optional.of(
Column.of(ROWTIME_NAME, SqlTypes.BIGINT)
)));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -268,8 +268,8 @@ private List<ColumnName> getNoneMetaOrKeySelectAliases() {
}

final ColumnName columnName = select.getName();
if (columnName.equalsIgnoreCase(SchemaUtil.ROWTIME_NAME)
|| columnName.equalsIgnoreCase(SchemaUtil.ROWKEY_NAME)) {
if (columnName.equals(SchemaUtil.ROWTIME_NAME)
|| columnName.equals(SchemaUtil.ROWKEY_NAME)) {
columnNames.remove(idx);
}
}
Expand Down Expand Up @@ -473,7 +473,7 @@ private Optional<ColumnName> getJoinFieldNameFromExpr(
final SourceName sourceAlias
) {
if (nameRef.getReference().qualifier().isPresent()
&& !nameRef.getReference().qualifier().get().equalsIgnoreCase(sourceAlias)) {
&& !nameRef.getReference().qualifier().get().equals(sourceAlias)) {
return Optional.empty();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ Set<SourceName> sourcesWithField(final ColumnName columnName) {
return ImmutableSet.of();
}

return sourceSchema.findColumn(baseColumnName).isPresent()
return sourceSchema.findColumn(ColumnName.of(baseColumnName)).isPresent()
? ImmutableSet.of(sourceName)
: ImmutableSet.of();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -271,11 +271,11 @@ private static LogicalSchema buildSchema(final TableElements tableElements) {
}

tableElements.forEach(e -> {
if (e.getName().equalsIgnoreCase(SchemaUtil.ROWTIME_NAME)) {
if (e.getName().equals(SchemaUtil.ROWTIME_NAME)) {
throw new KsqlException("'" + e.getName().name() + "' is a reserved column name.");
}

final boolean isRowKey = e.getName().equalsIgnoreCase(SchemaUtil.ROWKEY_NAME);
final boolean isRowKey = e.getName().equals(SchemaUtil.ROWKEY_NAME);

if (e.getNamespace() == Namespace.KEY) {
if (!isRowKey) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -478,7 +478,7 @@ private static void enforceKeyEquivalence(

if (sinkKeyCol.isPresent()
&& resultKeyCol.isPresent()
&& sinkKeyCol.get().name().equalsIgnoreCase(resultKeyCol.get().name())
&& sinkKeyCol.get().name().equals(resultKeyCol.get().name())
&& Objects.equals(sinkKeyCol.get().type(), resultKeyCol.get().type())) {
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import static org.hamcrest.Matchers.hasSize;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.not;
import static org.junit.Assert.assertEquals;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.verify;
Expand Down Expand Up @@ -134,9 +135,9 @@ public void init() {
public void testSimpleQueryAnalysis() {
final String simpleQuery = "SELECT col0, col2, col3 FROM test1 WHERE col0 > 100 EMIT CHANGES;";
final Analysis analysis = analyzeQuery(simpleQuery, jsonMetaStore);
Assert.assertTrue("FROM was not analyzed correctly.",
analysis.getFromDataSources().get(0).getDataSource().getName()
.equalsIgnoreCase(SourceName.of("test1")));
assertEquals("FROM was not analyzed correctly.",
analysis.getFromDataSources().get(0).getDataSource().getName(),
SourceName.of("TEST1"));
assertThat(analysis.getWhereExpression().get().toString(), is("(TEST1.COL0 > 100)"));

final List<SelectExpression> selects = analysis.getSelectExpressions();
Expand Down Expand Up @@ -201,9 +202,8 @@ public void testBooleanExpressionAnalysis() {
final String queryStr = "SELECT col0 = 10, col2, col3 > col1 FROM test1 EMIT CHANGES;";
final Analysis analysis = analyzeQuery(queryStr, jsonMetaStore);

Assert.assertTrue("FROM was not analyzed correctly.",
analysis.getFromDataSources().get(0).getDataSource().getName()
.equalsIgnoreCase(SourceName.of("test1")));
assertEquals("FROM was not analyzed correctly.",
analysis.getFromDataSources().get(0).getDataSource().getName(), SourceName.of("TEST1"));

final List<SelectExpression> selects = analysis.getSelectExpressions();
assertThat(selects.get(0).getExpression().toString(), is("(TEST1.COL0 = 10)"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -397,7 +397,7 @@ public void shouldGetCorrectSchemaForSearchedCaseWhenStruct() {
final SqlType result = expressionTypeManager.getExpressionSqlType(expression);

// Then:
final SqlType sqlType = SCHEMA.findColumn(ADDRESS.toString()).get().type();
final SqlType sqlType = SCHEMA.findColumn(ColumnName.of(ADDRESS.toString())).get().type();
assertThat(result, is(sqlType));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1037,14 +1037,14 @@ public Node visitColumnReference(final SqlBaseParser.ColumnReferenceContext cont

private boolean isValidNameOrAlias(final SourceName name) {
if (dataSourceExtractor.isJoin()) {
final boolean sameAsLeft = name.equalsIgnoreCase(dataSourceExtractor.getLeftAlias())
|| name.equalsIgnoreCase(dataSourceExtractor.getLeftName());
final boolean sameAsRight = name.equalsIgnoreCase(dataSourceExtractor.getRightAlias())
|| name.equalsIgnoreCase(dataSourceExtractor.getRightName());
final boolean sameAsLeft = name.equals(dataSourceExtractor.getLeftAlias())
|| name.equals(dataSourceExtractor.getLeftName());
final boolean sameAsRight = name.equals(dataSourceExtractor.getRightAlias())
|| name.equals(dataSourceExtractor.getRightName());
return sameAsLeft || sameAsRight;
}
return ((name.equalsIgnoreCase(dataSourceExtractor.getFromAlias())
|| name.equalsIgnoreCase(dataSourceExtractor.getFromName())));
return ((name.equals(dataSourceExtractor.getFromAlias())
|| name.equals(dataSourceExtractor.getFromName())));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -212,8 +212,8 @@ public void testProjection() {
Assert.assertTrue(query.getSelect().getSelectItems().size() == 3);
Assert.assertTrue(query.getSelect().getSelectItems().get(0) instanceof SingleColumn);
final SingleColumn column0 = (SingleColumn)query.getSelect().getSelectItems().get(0);
Assert.assertTrue(column0.getAlias().equalsIgnoreCase(ColumnName.of("COL0")));
Assert.assertTrue(column0.getExpression().toString().equalsIgnoreCase("TEST1.COL0"));
Assert.assertTrue(column0.getAlias().equals(ColumnName.of("COL0")));
Assert.assertTrue(column0.getExpression().toString().equals("TEST1.COL0"));
}

@Test
Expand All @@ -227,15 +227,15 @@ public void testProjectionWithArrayMap() {
Assert.assertTrue(query.getSelect().getSelectItems().get(0) instanceof SingleColumn);
final SingleColumn column0 = (SingleColumn)query.getSelect().getSelectItems().get(0);
Assert.assertTrue("testProjectionWithArrayMap fails",
column0.getAlias().equalsIgnoreCase(ColumnName.of("COL0")));
Assert.assertTrue(column0.getExpression().toString().equalsIgnoreCase("TEST1.COL0"));
column0.getAlias().equals(ColumnName.of("COL0")));
Assert.assertTrue(column0.getExpression().toString().equals("TEST1.COL0"));

final SingleColumn column3 = (SingleColumn)query.getSelect().getSelectItems().get(3);
final SingleColumn column4 = (SingleColumn)query.getSelect().getSelectItems().get(4);
Assert.assertTrue(column3.getExpression().toString()
.equalsIgnoreCase("TEST1.COL4[0]"));
.equals("TEST1.COL4[0]"));
Assert.assertTrue(column4.getExpression().toString()
.equalsIgnoreCase("TEST1.COL5['key1']"));
.equals("TEST1.COL5['key1']"));
}

@Test
Expand All @@ -259,7 +259,7 @@ public void testBinaryExpression() {
Assert.assertTrue(statement instanceof Query);
final Query query = (Query) statement;
final SingleColumn column0 = (SingleColumn)query.getSelect().getSelectItems().get(0);
Assert.assertTrue(column0.getAlias().equalsIgnoreCase(ColumnName.of("KSQL_COL_0")));
Assert.assertTrue(column0.getAlias().equals(ColumnName.of("KSQL_COL_0")));
Assert.assertTrue(column0.getExpression().toString().equalsIgnoreCase("(TEST1.COL0 + 10)"));
}

Expand All @@ -270,7 +270,7 @@ public void testBooleanExpression() {
Assert.assertTrue(statement instanceof Query);
final Query query = (Query) statement;
final SingleColumn column0 = (SingleColumn)query.getSelect().getSelectItems().get(0);
Assert.assertTrue(column0.getAlias().equalsIgnoreCase(ColumnName.of("KSQL_COL_0")));
Assert.assertTrue(column0.getAlias().equals(ColumnName.of("KSQL_COL_0")));
Assert.assertTrue(column0.getExpression().toString().equalsIgnoreCase("(TEST1.COL0 = 10)"));
}

Expand All @@ -281,27 +281,27 @@ public void testLiterals() {
Assert.assertTrue(statement instanceof Query);
final Query query = (Query) statement;
final SingleColumn column0 = (SingleColumn)query.getSelect().getSelectItems().get(0);
Assert.assertTrue(column0.getAlias().equalsIgnoreCase(ColumnName.of("KSQL_COL_0")));
Assert.assertTrue(column0.getAlias().equals(ColumnName.of("KSQL_COL_0")));
Assert.assertTrue(column0.getExpression().toString().equalsIgnoreCase("10"));

final SingleColumn column1 = (SingleColumn)query.getSelect().getSelectItems().get(1);
Assert.assertTrue(column1.getAlias().equalsIgnoreCase(ColumnName.of("COL2")));
Assert.assertTrue(column1.getAlias().equals(ColumnName.of("COL2")));
Assert.assertTrue(column1.getExpression().toString().equalsIgnoreCase("TEST1.COL2"));

final SingleColumn column2 = (SingleColumn)query.getSelect().getSelectItems().get(2);
Assert.assertTrue(column2.getAlias().equalsIgnoreCase(ColumnName.of("KSQL_COL_2")));
Assert.assertTrue(column2.getAlias().equals(ColumnName.of("KSQL_COL_2")));
Assert.assertTrue(column2.getExpression().toString().equalsIgnoreCase("'test'"));

final SingleColumn column3 = (SingleColumn)query.getSelect().getSelectItems().get(3);
Assert.assertTrue(column3.getAlias().equalsIgnoreCase(ColumnName.of("KSQL_COL_3")));
Assert.assertTrue(column3.getAlias().equals(ColumnName.of("KSQL_COL_3")));
Assert.assertTrue(column3.getExpression().toString().equalsIgnoreCase("2.5"));

final SingleColumn column4 = (SingleColumn)query.getSelect().getSelectItems().get(4);
Assert.assertTrue(column4.getAlias().equalsIgnoreCase(ColumnName.of("KSQL_COL_4")));
Assert.assertTrue(column4.getAlias().equals(ColumnName.of("KSQL_COL_4")));
Assert.assertTrue(column4.getExpression().toString().equalsIgnoreCase("true"));

final SingleColumn column5 = (SingleColumn)query.getSelect().getSelectItems().get(5);
Assert.assertTrue(column5.getAlias().equalsIgnoreCase(ColumnName.of("KSQL_COL_5")));
Assert.assertTrue(column5.getAlias().equals(ColumnName.of("KSQL_COL_5")));
Assert.assertTrue(column5.getExpression().toString().equalsIgnoreCase("-5"));
}

Expand Down Expand Up @@ -355,15 +355,15 @@ public void testBooleanLogicalExpression() {
Assert.assertTrue(statement instanceof Query);
final Query query = (Query) statement;
final SingleColumn column0 = (SingleColumn)query.getSelect().getSelectItems().get(0);
Assert.assertTrue(column0.getAlias().equalsIgnoreCase(ColumnName.of("KSQL_COL_0")));
Assert.assertTrue(column0.getAlias().equals(ColumnName.of("KSQL_COL_0")));
Assert.assertTrue(column0.getExpression().toString().equalsIgnoreCase("10"));

final SingleColumn column1 = (SingleColumn)query.getSelect().getSelectItems().get(1);
Assert.assertTrue(column1.getAlias().equalsIgnoreCase(ColumnName.of("COL2")));
Assert.assertTrue(column1.getAlias().equals(ColumnName.of("COL2")));
Assert.assertTrue(column1.getExpression().toString().equalsIgnoreCase("TEST1.COL2"));

final SingleColumn column2 = (SingleColumn)query.getSelect().getSelectItems().get(2);
Assert.assertTrue(column2.getAlias().equalsIgnoreCase(ColumnName.of("KSQL_COL_2")));
Assert.assertTrue(column2.getAlias().equals(ColumnName.of("KSQL_COL_2")));
Assert.assertTrue(column2.getExpression().toString().equalsIgnoreCase("'test'"));

}
Expand Down Expand Up @@ -397,8 +397,8 @@ public void testSimpleLeftJoin() {
final Join join = (Join) query.getFrom();
Assert.assertTrue("testSimpleLeftJoin fails", join.getType().toString().equalsIgnoreCase("LEFT"));

Assert.assertTrue("testSimpleLeftJoin fails", ((AliasedRelation)join.getLeft()).getAlias().equalsIgnoreCase(SourceName.of("T1")));
Assert.assertTrue("testSimpleLeftJoin fails", ((AliasedRelation)join.getRight()).getAlias().equalsIgnoreCase(SourceName.of("T2")));
Assert.assertTrue("testSimpleLeftJoin fails", ((AliasedRelation)join.getLeft()).getAlias().equals(SourceName.of("T1")));
Assert.assertTrue("testSimpleLeftJoin fails", ((AliasedRelation)join.getRight()).getAlias().equals(SourceName.of("T2")));

}

Expand All @@ -415,8 +415,8 @@ public void testLeftJoinWithFilter() {
final Join join = (Join) query.getFrom();
Assert.assertTrue(join.getType().toString().equalsIgnoreCase("LEFT"));

Assert.assertTrue(((AliasedRelation)join.getLeft()).getAlias().equalsIgnoreCase(SourceName.of("T1")));
Assert.assertTrue(((AliasedRelation)join.getRight()).getAlias().equalsIgnoreCase(SourceName.of("T2")));
Assert.assertTrue(((AliasedRelation)join.getLeft()).getAlias().equals(SourceName.of("T1")));
Assert.assertTrue(((AliasedRelation)join.getRight()).getAlias().equals(SourceName.of("T2")));

Assert.assertTrue(query.getWhere().get().toString().equalsIgnoreCase("(T2.COL2 = 'test')"));
}
Expand Down Expand Up @@ -480,15 +480,15 @@ public void testUDF() {
final Query query = (Query) statement;

final SingleColumn column0 = (SingleColumn)query.getSelect().getSelectItems().get(0);
Assert.assertTrue(column0.getAlias().equalsIgnoreCase(ColumnName.of("KSQL_COL_0")));
Assert.assertTrue(column0.getAlias().equals(ColumnName.of("KSQL_COL_0")));
Assert.assertTrue(column0.getExpression().toString().equalsIgnoreCase("LCASE(T1.COL1)"));

final SingleColumn column1 = (SingleColumn)query.getSelect().getSelectItems().get(1);
Assert.assertTrue(column1.getAlias().equalsIgnoreCase(ColumnName.of("KSQL_COL_1")));
Assert.assertTrue(column1.getAlias().equals(ColumnName.of("KSQL_COL_1")));
Assert.assertTrue(column1.getExpression().toString().equalsIgnoreCase("CONCAT(T1.COL2, 'hello')"));

final SingleColumn column2 = (SingleColumn)query.getSelect().getSelectItems().get(2);
Assert.assertTrue(column2.getAlias().equalsIgnoreCase(ColumnName.of("KSQL_COL_2")));
Assert.assertTrue(column2.getAlias().equals(ColumnName.of("KSQL_COL_2")));
Assert.assertTrue(column2.getExpression().toString().equalsIgnoreCase("FLOOR(ABS(T1.COL3))"));
}

Expand Down Expand Up @@ -601,7 +601,7 @@ public void testSelectTumblingWindow() {
Assert.assertTrue(query.getSelect().getSelectItems
().size() == 2);
Assert.assertTrue(query.getWhere().get().toString().equalsIgnoreCase("(ORDERS.ORDERUNITS > 5)"));
Assert.assertTrue(((AliasedRelation)query.getFrom()).getAlias().equalsIgnoreCase(SourceName.of("ORDERS")));
Assert.assertTrue(((AliasedRelation)query.getFrom()).getAlias().equals(SourceName.of("ORDERS")));
Assert.assertTrue(query.getWindow().isPresent());
Assert.assertTrue(query.getWindow().get().toString().equalsIgnoreCase(" WINDOW STREAMWINDOW TUMBLING ( SIZE 30 SECONDS ) "));
}
Expand Down Expand Up @@ -641,7 +641,7 @@ public void testSelectSessionWindow() {
Assert.assertTrue(query.getSelect().getSelectItems
().size() == 2);
Assert.assertTrue(query.getWhere().get().toString().equalsIgnoreCase("(ORDERS.ORDERUNITS > 5)"));
Assert.assertTrue(((AliasedRelation)query.getFrom()).getAlias().equalsIgnoreCase(SourceName.of("ORDERS")));
Assert.assertTrue(((AliasedRelation)query.getFrom()).getAlias().equals(SourceName.of("ORDERS")));
Assert.assertTrue(query
.getWindow().isPresent());
Assert.assertTrue(query
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ private static List<KsqlTable<?>> getSpecificTables(
) {
return executionContext.getMetaStore().getAllDataSources().values().stream()
.filter(KsqlTable.class::isInstance)
.filter(structuredDataSource -> !structuredDataSource.getName().equalsIgnoreCase(
.filter(structuredDataSource -> !structuredDataSource.getName().equals(
KsqlRestApplication.getCommandsStreamName()))
.map(table -> (KsqlTable<?>) table)
.collect(Collectors.toList());
Expand All @@ -165,7 +165,7 @@ private static List<KsqlStream<?>> getSpecificStreams(
) {
return executionContext.getMetaStore().getAllDataSources().values().stream()
.filter(KsqlStream.class::isInstance)
.filter(structuredDataSource -> !structuredDataSource.getName().equalsIgnoreCase(
.filter(structuredDataSource -> !structuredDataSource.getName().equals(
KsqlRestApplication.getCommandsStreamName()))
.map(table -> (KsqlStream<?>) table)
.collect(Collectors.toList());
Expand Down

0 comments on commit b78619c

Please sign in to comment.