Skip to content

Commit

Permalink
Use switch expressions
Browse files Browse the repository at this point in the history
  • Loading branch information
martint committed Aug 27, 2023
1 parent 39af728 commit 4490238
Show file tree
Hide file tree
Showing 44 changed files with 645 additions and 1,260 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,47 +52,27 @@ protected QueryRunner createQueryRunner()
return createAccumuloQueryRunner(ImmutableMap.of());
}

@SuppressWarnings("DuplicateBranchesInSwitch")
@Override
protected boolean hasBehavior(TestingConnectorBehavior connectorBehavior)
{
switch (connectorBehavior) {
case SUPPORTS_DELETE:
case SUPPORTS_UPDATE:
case SUPPORTS_MERGE:
return false;

case SUPPORTS_TOPN_PUSHDOWN:
return false;

case SUPPORTS_RENAME_SCHEMA:
case SUPPORTS_DROP_SCHEMA_CASCADE:
return false;

case SUPPORTS_CREATE_TABLE_WITH_TABLE_COMMENT:
case SUPPORTS_RENAME_TABLE_ACROSS_SCHEMAS:
return false;

case SUPPORTS_ADD_COLUMN:
case SUPPORTS_SET_COLUMN_TYPE:
return false;

case SUPPORTS_COMMENT_ON_TABLE:
case SUPPORTS_COMMENT_ON_COLUMN:
return false;

case SUPPORTS_CREATE_MATERIALIZED_VIEW:
return false;

case SUPPORTS_NOT_NULL_CONSTRAINT:
return false;

case SUPPORTS_ROW_TYPE:
return false;

default:
return super.hasBehavior(connectorBehavior);
}
return switch (connectorBehavior) {
case SUPPORTS_ADD_COLUMN,
SUPPORTS_COMMENT_ON_COLUMN,
SUPPORTS_COMMENT_ON_TABLE,
SUPPORTS_CREATE_MATERIALIZED_VIEW,
SUPPORTS_CREATE_TABLE_WITH_TABLE_COMMENT,
SUPPORTS_DELETE,
SUPPORTS_DROP_SCHEMA_CASCADE,
SUPPORTS_MERGE,
SUPPORTS_NOT_NULL_CONSTRAINT,
SUPPORTS_RENAME_SCHEMA,
SUPPORTS_RENAME_TABLE_ACROSS_SCHEMAS,
SUPPORTS_ROW_TYPE,
SUPPORTS_SET_COLUMN_TYPE,
SUPPORTS_TOPN_PUSHDOWN,
SUPPORTS_UPDATE -> false;
default -> super.hasBehavior(connectorBehavior);
};
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,28 +134,18 @@ public void afterClass()
@Override
protected boolean hasBehavior(TestingConnectorBehavior connectorBehavior)
{
switch (connectorBehavior) {
case SUPPORTS_UPDATE: // not supported by any JDBC connector
case SUPPORTS_MERGE: // not supported by any JDBC connector
return false;

case SUPPORTS_CREATE_VIEW: // not supported by DefaultJdbcMetadata
case SUPPORTS_CREATE_MATERIALIZED_VIEW: // not supported by DefaultJdbcMetadata
return false;

case SUPPORTS_PREDICATE_EXPRESSION_PUSHDOWN:
// TODO support pushdown of complex expressions in predicates
return false;

case SUPPORTS_DYNAMIC_FILTER_PUSHDOWN:
// Dynamic filters can be pushed down only if predicate push down is supported.
// It is possible for a connector to have predicate push down support but not push down dynamic filters.
// TODO default SUPPORTS_DYNAMIC_FILTER_PUSHDOWN to SUPPORTS_PREDICATE_PUSHDOWN
return super.hasBehavior(SUPPORTS_PREDICATE_PUSHDOWN);

default:
return super.hasBehavior(connectorBehavior);
}
return switch (connectorBehavior) {
case SUPPORTS_CREATE_MATERIALIZED_VIEW,
SUPPORTS_CREATE_VIEW,
SUPPORTS_MERGE,
SUPPORTS_PREDICATE_EXPRESSION_PUSHDOWN,
SUPPORTS_UPDATE -> false;
// Dynamic filters can be pushed down only if predicate push down is supported.
// It is possible for a connector to have predicate push down support but not push down dynamic filters.
// TODO default SUPPORTS_DYNAMIC_FILTER_PUSHDOWN to SUPPORTS_PREDICATE_PUSHDOWN
case SUPPORTS_DYNAMIC_FILTER_PUSHDOWN -> super.hasBehavior(SUPPORTS_PREDICATE_PUSHDOWN);
default -> super.hasBehavior(connectorBehavior);
};
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,35 +56,23 @@ protected QueryRunner createQueryRunner()
return createH2QueryRunner(REQUIRED_TPCH_TABLES, properties);
}

@SuppressWarnings("DuplicateBranchesInSwitch")
@Override
protected boolean hasBehavior(TestingConnectorBehavior connectorBehavior)
{
switch (connectorBehavior) {
case SUPPORTS_LIMIT_PUSHDOWN:
case SUPPORTS_TOPN_PUSHDOWN:
case SUPPORTS_AGGREGATION_PUSHDOWN:
return false;

case SUPPORTS_CREATE_TABLE_WITH_TABLE_COMMENT:
case SUPPORTS_CREATE_TABLE_WITH_COLUMN_COMMENT:
case SUPPORTS_RENAME_TABLE_ACROSS_SCHEMAS:
return false;

case SUPPORTS_ADD_COLUMN_WITH_COMMENT:
return false;

case SUPPORTS_COMMENT_ON_TABLE:
case SUPPORTS_COMMENT_ON_COLUMN:
return false;

case SUPPORTS_ARRAY:
case SUPPORTS_ROW_TYPE:
return false;

default:
return super.hasBehavior(connectorBehavior);
}
return switch (connectorBehavior) {
case SUPPORTS_ADD_COLUMN_WITH_COMMENT,
SUPPORTS_AGGREGATION_PUSHDOWN,
SUPPORTS_ARRAY,
SUPPORTS_COMMENT_ON_COLUMN,
SUPPORTS_COMMENT_ON_TABLE,
SUPPORTS_CREATE_TABLE_WITH_COLUMN_COMMENT,
SUPPORTS_CREATE_TABLE_WITH_TABLE_COMMENT,
SUPPORTS_LIMIT_PUSHDOWN,
SUPPORTS_RENAME_TABLE_ACROSS_SCHEMAS,
SUPPORTS_ROW_TYPE,
SUPPORTS_TOPN_PUSHDOWN -> false;
default -> super.hasBehavior(connectorBehavior);
};
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,28 +19,19 @@
public abstract class BaseBigQueryConnectorSmokeTest
extends BaseConnectorSmokeTest
{
@SuppressWarnings("DuplicateBranchesInSwitch")
@Override
protected boolean hasBehavior(TestingConnectorBehavior connectorBehavior)
{
switch (connectorBehavior) {
case SUPPORTS_DELETE:
case SUPPORTS_UPDATE:
case SUPPORTS_MERGE:
return false;
case SUPPORTS_TRUNCATE:
return true;

case SUPPORTS_RENAME_TABLE:
case SUPPORTS_RENAME_SCHEMA:
return false;

case SUPPORTS_CREATE_VIEW:
case SUPPORTS_CREATE_MATERIALIZED_VIEW:
return false;

default:
return super.hasBehavior(connectorBehavior);
}
return switch (connectorBehavior) {
case SUPPORTS_TRUNCATE -> true;
case SUPPORTS_CREATE_MATERIALIZED_VIEW,
SUPPORTS_CREATE_VIEW,
SUPPORTS_DELETE,
SUPPORTS_MERGE,
SUPPORTS_RENAME_SCHEMA,
SUPPORTS_RENAME_TABLE,
SUPPORTS_UPDATE -> false;
default -> super.hasBehavior(connectorBehavior);
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -63,46 +63,27 @@ public void initBigQueryExecutor(String gcpStorageBucket)
this.gcpStorageBucket = gcpStorageBucket;
}

@SuppressWarnings("DuplicateBranchesInSwitch")
@Override
protected boolean hasBehavior(TestingConnectorBehavior connectorBehavior)
{
switch (connectorBehavior) {
case SUPPORTS_DELETE:
case SUPPORTS_UPDATE:
case SUPPORTS_MERGE:
return false;
case SUPPORTS_TRUNCATE:
return true;

case SUPPORTS_TOPN_PUSHDOWN:
case SUPPORTS_DEREFERENCE_PUSHDOWN:
return false;

case SUPPORTS_RENAME_SCHEMA:
return false;

case SUPPORTS_RENAME_TABLE:
return false;

case SUPPORTS_ADD_COLUMN:
case SUPPORTS_RENAME_COLUMN:
case SUPPORTS_SET_COLUMN_TYPE:
return false;

case SUPPORTS_CREATE_VIEW:
case SUPPORTS_CREATE_MATERIALIZED_VIEW:
return false;

case SUPPORTS_NOT_NULL_CONSTRAINT:
return false;

case SUPPORTS_NEGATIVE_DATE:
return false;

default:
return super.hasBehavior(connectorBehavior);
}
return switch (connectorBehavior) {
case SUPPORTS_TRUNCATE -> true;
case SUPPORTS_ADD_COLUMN,
SUPPORTS_CREATE_MATERIALIZED_VIEW,
SUPPORTS_CREATE_VIEW,
SUPPORTS_DELETE,
SUPPORTS_DEREFERENCE_PUSHDOWN,
SUPPORTS_MERGE,
SUPPORTS_NEGATIVE_DATE,
SUPPORTS_NOT_NULL_CONSTRAINT,
SUPPORTS_RENAME_COLUMN,
SUPPORTS_RENAME_SCHEMA,
SUPPORTS_RENAME_TABLE,
SUPPORTS_SET_COLUMN_TYPE,
SUPPORTS_TOPN_PUSHDOWN,
SUPPORTS_UPDATE -> false;
default -> super.hasBehavior(connectorBehavior);
};
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,41 +32,23 @@ public abstract class BaseCassandraConnectorSmokeTest
public static final String KEYSPACE = "smoke_test";
public static final ZonedDateTime TIMESTAMP_VALUE = ZonedDateTime.of(1970, 1, 1, 3, 4, 5, 0, ZoneId.of("UTC"));

@SuppressWarnings("DuplicateBranchesInSwitch")
@Override
protected boolean hasBehavior(TestingConnectorBehavior connectorBehavior)
{
switch (connectorBehavior) {
case SUPPORTS_TOPN_PUSHDOWN:
return false;

case SUPPORTS_CREATE_SCHEMA:
return false;

case SUPPORTS_RENAME_TABLE:
return false;

case SUPPORTS_COMMENT_ON_TABLE:
case SUPPORTS_COMMENT_ON_COLUMN:
return false;

case SUPPORTS_CREATE_VIEW:
case SUPPORTS_CREATE_MATERIALIZED_VIEW:
return false;

case SUPPORTS_UPDATE:
return false;
case SUPPORTS_DELETE:
return true;
case SUPPORTS_MERGE:
return false;

case SUPPORTS_ARRAY:
return false;

default:
return super.hasBehavior(connectorBehavior);
}
return switch (connectorBehavior) {
case SUPPORTS_DELETE -> true;
case SUPPORTS_ARRAY,
SUPPORTS_COMMENT_ON_COLUMN,
SUPPORTS_COMMENT_ON_TABLE,
SUPPORTS_CREATE_MATERIALIZED_VIEW,
SUPPORTS_CREATE_SCHEMA,
SUPPORTS_CREATE_VIEW,
SUPPORTS_MERGE,
SUPPORTS_RENAME_TABLE,
SUPPORTS_TOPN_PUSHDOWN,
SUPPORTS_UPDATE -> false;
default -> super.hasBehavior(connectorBehavior);
};
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,53 +86,31 @@ public class TestCassandraConnectorTest
private CassandraServer server;
private CassandraSession session;

@SuppressWarnings("DuplicateBranchesInSwitch")
@Override
protected boolean hasBehavior(TestingConnectorBehavior connectorBehavior)
{
switch (connectorBehavior) {
case SUPPORTS_UPDATE:
case SUPPORTS_MERGE:
return false;

case SUPPORTS_DELETE:
case SUPPORTS_TRUNCATE:
return true;

case SUPPORTS_TOPN_PUSHDOWN:
return false;

case SUPPORTS_CREATE_SCHEMA:
return false;

case SUPPORTS_CREATE_TABLE_WITH_TABLE_COMMENT:
case SUPPORTS_CREATE_TABLE_WITH_COLUMN_COMMENT:
case SUPPORTS_RENAME_TABLE:
return false;

case SUPPORTS_ADD_COLUMN:
case SUPPORTS_RENAME_COLUMN:
case SUPPORTS_SET_COLUMN_TYPE:
return false;

case SUPPORTS_COMMENT_ON_TABLE:
case SUPPORTS_COMMENT_ON_COLUMN:
return false;

case SUPPORTS_CREATE_VIEW:
case SUPPORTS_CREATE_MATERIALIZED_VIEW:
return false;

case SUPPORTS_NOT_NULL_CONSTRAINT:
return false;

case SUPPORTS_ARRAY:
case SUPPORTS_ROW_TYPE:
return false;

default:
return super.hasBehavior(connectorBehavior);
}
return switch (connectorBehavior) {
case SUPPORTS_DELETE,
SUPPORTS_TRUNCATE -> true;
case SUPPORTS_ADD_COLUMN,
SUPPORTS_ARRAY,
SUPPORTS_COMMENT_ON_COLUMN,
SUPPORTS_COMMENT_ON_TABLE,
SUPPORTS_CREATE_MATERIALIZED_VIEW,
SUPPORTS_CREATE_SCHEMA,
SUPPORTS_CREATE_TABLE_WITH_COLUMN_COMMENT,
SUPPORTS_CREATE_TABLE_WITH_TABLE_COMMENT,
SUPPORTS_CREATE_VIEW,
SUPPORTS_MERGE,
SUPPORTS_NOT_NULL_CONSTRAINT,
SUPPORTS_RENAME_COLUMN,
SUPPORTS_RENAME_TABLE,
SUPPORTS_ROW_TYPE,
SUPPORTS_SET_COLUMN_TYPE,
SUPPORTS_TOPN_PUSHDOWN,
SUPPORTS_UPDATE -> false;
default -> super.hasBehavior(connectorBehavior);
};
}

@Override
Expand Down
Loading

0 comments on commit 4490238

Please sign in to comment.