99import java .sql .SQLException ;
1010import java .util .Collections ;
1111import java .util .List ;
12+ import java .util .Objects ;
1213import java .util .Properties ;
1314import org .junit .jupiter .api .Test ;
1415import org .junit .jupiter .api .condition .DisabledIf ;
@@ -72,6 +73,11 @@ private boolean isOracle() {
7273 return JdbcEnv .isOracle ();
7374 }
7475
76+ @ SuppressWarnings ("unused" )
77+ private boolean isSqlServer () {
78+ return JdbcEnv .isSqlServer ();
79+ }
80+
7581 @ SuppressWarnings ("unused" )
7682 private boolean isDb2 () {
7783 return JdbcEnv .isDb2 ();
@@ -84,7 +90,7 @@ private boolean isSqlite() {
8490
8591 @ SuppressWarnings ("unused" )
8692 private boolean isColumnTypeConversionToTextNotFullySupported () {
87- return JdbcEnv .isDb2 () || JdbcEnv .isOracle () || JdbcEnv .isSqlite ();
93+ return JdbcEnv .isDb2 () || JdbcEnv .isSqlServer () || JdbcEnv . isOracle () || JdbcEnv .isSqlite ();
8894 }
8995
9096 @ SuppressWarnings ("unused" )
@@ -117,6 +123,54 @@ public void importTable_ForUnsupportedDatabase_ShouldThrowUnsupportedOperationEx
117123 .alterColumnType_AlterColumnTypeFromEachExistingDataTypeToText_ForImportedTable_ShouldAlterColumnTypesCorrectly ();
118124 }
119125
126+ @ Test
127+ @ EnabledIf ("isSqlServer" )
128+ public void
129+ alterColumnType_SqlServer_AlterColumnTypeFromEachExistingDataTypeToText_ForImportedTable_ShouldAlterColumnTypesCorrectly ()
130+ throws Exception {
131+ // Arrange
132+ testDataList .addAll (createExistingDatabaseWithAllDataTypes ());
133+ for (TestData testData : testDataList ) {
134+ if (testData .isImportableTable ()) {
135+ admin .importTable (
136+ getNamespace (),
137+ testData .getTableName (),
138+ Collections .emptyMap (),
139+ testData .getOverrideColumnsType ());
140+ }
141+ }
142+
143+ for (TestData testData : testDataList ) {
144+ if (testData .isImportableTable ()) {
145+ // Act
146+ TableMetadata metadata = testData .getTableMetadata ();
147+ for (String column : metadata .getColumnNames ()) {
148+ if (!metadata .getPartitionKeyNames ().contains (column )
149+ && !metadata .getClusteringKeyNames ().contains (column )) {
150+ if (Objects .equals (column , "col16" )) {
151+ // Conversion from IMAGE to VARCHAR(8000) is not supported in SQL Server engine
152+ continue ;
153+ }
154+ admin .alterColumnType (getNamespace (), testData .getTableName (), column , DataType .TEXT );
155+ }
156+ }
157+
158+ // Assert
159+ TableMetadata newMetadata = admin .getTableMetadata (getNamespace (), testData .getTableName ());
160+ assertThat (newMetadata ).isNotNull ();
161+ for (String column : metadata .getColumnNames ()) {
162+ if (!metadata .getPartitionKeyNames ().contains (column )
163+ && !metadata .getClusteringKeyNames ().contains (column )) {
164+ if (metadata .getColumnDataType (column ).equals (DataType .BLOB )) {
165+ continue ;
166+ }
167+ assertThat (newMetadata .getColumnDataType (column )).isEqualTo (DataType .TEXT );
168+ }
169+ }
170+ }
171+ }
172+ }
173+
120174 @ Test
121175 @ EnabledIf ("isDb2" )
122176 public void
@@ -142,7 +196,7 @@ public void importTable_ForUnsupportedDatabase_ShouldThrowUnsupportedOperationEx
142196 if (!metadata .getPartitionKeyNames ().contains (column )
143197 && !metadata .getClusteringKeyNames ().contains (column )) {
144198 if (metadata .getColumnDataType (column ).equals (DataType .BLOB )) {
145- // Conversion from BLOB TO TEXT is not supported in Oracle engine
199+ // Conversion from BLOB to TEXT is not supported in Db2 engine
146200 continue ;
147201 }
148202 admin .alterColumnType (getNamespace (), testData .getTableName (), column , DataType .TEXT );
0 commit comments