Skip to content

Commit

Permalink
Introduce InvalidCastTestCase to verify failure cast test case
Browse files Browse the repository at this point in the history
  • Loading branch information
krvikash committed Oct 10, 2024
1 parent aeec1bd commit 50ec6fb
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 47 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@

import static java.util.Objects.requireNonNull;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;

public abstract class BaseJdbcCastPushdownTest
extends AbstractTestQueryFramework
Expand All @@ -38,7 +37,7 @@ public abstract class BaseJdbcCastPushdownTest

protected abstract List<CastTestCase> unsupportedCastTypePushdown();

protected abstract List<CastTestCase> failCast();
protected abstract List<InvalidCastTestCase> invalidCast();

@Test
public void testProjectionPushdownWithCast()
Expand Down Expand Up @@ -69,26 +68,37 @@ public void testJoinPushdownWithCast()
}

@Test
public void testCastFails()
public void testInvalidCast()
{
for (CastTestCase testCase : failCast()) {
assertThatThrownBy(() -> getQueryRunner().execute("SELECT CAST(%s AS %s) FROM %s".formatted(testCase.sourceColumn(), testCase.castType(), leftTable())))
.hasMessageMatching("(.*)Cannot cast (.*) to (.*)");
for (InvalidCastTestCase testCase : invalidCast()) {
assertThat(query("SELECT CAST(%s AS %s) FROM %s".formatted(testCase.sourceColumn(), testCase.castType(), leftTable())))
.failure()
.hasMessageMatching(testCase.errorMessage());
}
}

public record CastTestCase(String sourceColumn, String castType, Optional<String> targetColumn)
{
public CastTestCase(String sourceColumn, String castType)
public CastTestCase
{
requireNonNull(sourceColumn, "sourceColumn is null");
requireNonNull(castType, "castType is null");
requireNonNull(targetColumn, "targetColumn is null");
}
}

public record InvalidCastTestCase(String sourceColumn, String castType, String errorMessage)
{
public InvalidCastTestCase(String sourceColumn, String castType)
{
this(sourceColumn, castType, Optional.empty());
this(sourceColumn, castType, "(.*)Cannot cast (.*) to (.*)");
}

public CastTestCase
public InvalidCastTestCase
{
requireNonNull(sourceColumn, "sourceColumn is null");
requireNonNull(castType, "castType is null");
requireNonNull(targetColumn, "targetColumn is null");
requireNonNull(errorMessage, "errorMessage is null");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -474,45 +474,45 @@ protected List<CastTestCase> unsupportedCastTypePushdown()
}

@Override
protected List<CastTestCase> failCast()
protected List<InvalidCastTestCase> invalidCast()
{
return ImmutableList.of(
new CastTestCase("c_number_3", "char(50)"),
new CastTestCase("c_number_5", "char(50)"),
new CastTestCase("c_number_10", "char(50)"),
new CastTestCase("c_number_19", "char(50)"),
new CastTestCase("c_float", "char(50)"),
new CastTestCase("c_float_5", "char(50)"),
new CastTestCase("c_binary_float", "char(50)"),
new CastTestCase("c_binary_double", "char(50)"),
new CastTestCase("c_number_15", "char(50)"),
new CastTestCase("c_number_10_2", "char(50)"),
new CastTestCase("c_number_30_2", "char(50)"),
new CastTestCase("c_date", "char(50)"),
new CastTestCase("c_timestamp", "char(50)"),
new CastTestCase("c_timestamptz", "char(50)"),
new CastTestCase("c_blob", "char(50)"),
new CastTestCase("c_raw_200", "char(50)"),

new CastTestCase("c_number_3", "char(501)"),
new CastTestCase("c_number_5", "char(501)"),
new CastTestCase("c_number_10", "char(501)"),
new CastTestCase("c_number_19", "char(501)"),
new CastTestCase("c_float", "char(501)"),
new CastTestCase("c_float_5", "char(501)"),
new CastTestCase("c_binary_float", "char(501)"),
new CastTestCase("c_binary_double", "char(501)"),
new CastTestCase("c_number_15", "char(501)"),
new CastTestCase("c_number_10_2", "char(501)"),
new CastTestCase("c_number_30_2", "char(501)"),
new CastTestCase("c_date", "char(501)"),
new CastTestCase("c_timestamp", "char(501)"),
new CastTestCase("c_timestamptz", "char(501)"),
new CastTestCase("c_blob", "char(501)"),
new CastTestCase("c_raw_200", "char(501)"),

new CastTestCase("c_blob", "varchar(50)"),
new CastTestCase("c_raw_200", "varchar(50)"));
new InvalidCastTestCase("c_number_3", "char(50)"),
new InvalidCastTestCase("c_number_5", "char(50)"),
new InvalidCastTestCase("c_number_10", "char(50)"),
new InvalidCastTestCase("c_number_19", "char(50)"),
new InvalidCastTestCase("c_float", "char(50)"),
new InvalidCastTestCase("c_float_5", "char(50)"),
new InvalidCastTestCase("c_binary_float", "char(50)"),
new InvalidCastTestCase("c_binary_double", "char(50)"),
new InvalidCastTestCase("c_number_15", "char(50)"),
new InvalidCastTestCase("c_number_10_2", "char(50)"),
new InvalidCastTestCase("c_number_30_2", "char(50)"),
new InvalidCastTestCase("c_date", "char(50)"),
new InvalidCastTestCase("c_timestamp", "char(50)"),
new InvalidCastTestCase("c_timestamptz", "char(50)"),
new InvalidCastTestCase("c_blob", "char(50)"),
new InvalidCastTestCase("c_raw_200", "char(50)"),

new InvalidCastTestCase("c_number_3", "char(501)"),
new InvalidCastTestCase("c_number_5", "char(501)"),
new InvalidCastTestCase("c_number_10", "char(501)"),
new InvalidCastTestCase("c_number_19", "char(501)"),
new InvalidCastTestCase("c_float", "char(501)"),
new InvalidCastTestCase("c_float_5", "char(501)"),
new InvalidCastTestCase("c_binary_float", "char(501)"),
new InvalidCastTestCase("c_binary_double", "char(501)"),
new InvalidCastTestCase("c_number_15", "char(501)"),
new InvalidCastTestCase("c_number_10_2", "char(501)"),
new InvalidCastTestCase("c_number_30_2", "char(501)"),
new InvalidCastTestCase("c_date", "char(501)"),
new InvalidCastTestCase("c_timestamp", "char(501)"),
new InvalidCastTestCase("c_timestamptz", "char(501)"),
new InvalidCastTestCase("c_blob", "char(501)"),
new InvalidCastTestCase("c_raw_200", "char(501)"),

new InvalidCastTestCase("c_blob", "varchar(50)"),
new InvalidCastTestCase("c_raw_200", "varchar(50)"));
}

private static List<CastTestCase> specialCaseNClob()
Expand Down

0 comments on commit 50ec6fb

Please sign in to comment.