Skip to content

Commit 8179fe0

Browse files
authored
Merge branch 'master' into fix-bug-in-rename-table
2 parents 6441ab0 + 4a4d176 commit 8179fe0

File tree

6 files changed

+419
-10
lines changed

6 files changed

+419
-10
lines changed

.github/workflows/ci.yaml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1789,16 +1789,16 @@ jobs:
17891789
group_commit_enabled: true
17901790

17911791
steps:
1792-
- uses: actions/checkout@v4
1792+
- uses: actions/checkout@v5
17931793

17941794
- name: Set up JDK ${{ env.JAVA_VERSION }} (${{ env.JAVA_VENDOR }})
1795-
uses: actions/setup-java@v4
1795+
uses: actions/setup-java@v5
17961796
with:
17971797
java-version: ${{ env.JAVA_VERSION }}
17981798
distribution: ${{ env.JAVA_VENDOR }}
17991799

18001800
- name: Set up JDK ${{ env.INT_TEST_JAVA_RUNTIME_VERSION }} (${{ env.INT_TEST_JAVA_RUNTIME_VENDOR }}) to run integration test
1801-
uses: actions/setup-java@v4
1801+
uses: actions/setup-java@v5
18021802
if: ${{ env.SET_UP_INT_TEST_RUNTIME_NON_ORACLE_JDK == 'true'}}
18031803
with:
18041804
java-version: ${{ env.INT_TEST_JAVA_RUNTIME_VERSION }}
@@ -1819,7 +1819,7 @@ jobs:
18191819
docker cp -L "$container_id:/usr/java/default" /usr/lib/jvm/oracle-jdk && docker rm "$container_id"
18201820
18211821
- name: Setup Gradle
1822-
uses: gradle/actions/setup-gradle@v4
1822+
uses: gradle/actions/setup-gradle@v5
18231823

18241824
- name: Execute Gradle 'integrationTestJdbc' task
18251825
run: ./gradlew integrationTestJdbc -Dscalardb.jdbc.url=jdbc:postgresql://localhost:5432/ -Dscalardb.jdbc.username=postgres -Dscalardb.jdbc.password=postgres ${{ matrix.mode.group_commit_enabled && env.INT_TEST_GRADLE_OPTIONS_FOR_GROUP_COMMIT || '' }}
@@ -1855,16 +1855,16 @@ jobs:
18551855
group_commit_enabled: true
18561856

18571857
steps:
1858-
- uses: actions/checkout@v4
1858+
- uses: actions/checkout@v5
18591859

18601860
- name: Set up JDK ${{ env.JAVA_VERSION }} (${{ env.JAVA_VENDOR }})
1861-
uses: actions/setup-java@v4
1861+
uses: actions/setup-java@v5
18621862
with:
18631863
java-version: ${{ env.JAVA_VERSION }}
18641864
distribution: ${{ env.JAVA_VENDOR }}
18651865

18661866
- name: Set up JDK ${{ env.INT_TEST_JAVA_RUNTIME_VERSION }} (${{ env.INT_TEST_JAVA_RUNTIME_VENDOR }}) to run integration test
1867-
uses: actions/setup-java@v4
1867+
uses: actions/setup-java@v5
18681868
if: ${{ env.SET_UP_INT_TEST_RUNTIME_NON_ORACLE_JDK == 'true'}}
18691869
with:
18701870
java-version: ${{ env.INT_TEST_JAVA_RUNTIME_VERSION }}
@@ -1885,7 +1885,7 @@ jobs:
18851885
docker cp -L "$container_id:/usr/java/default" /usr/lib/jvm/oracle-jdk && docker rm "$container_id"
18861886
18871887
- name: Setup Gradle
1888-
uses: gradle/actions/setup-gradle@v4
1888+
uses: gradle/actions/setup-gradle@v5
18891889

18901890
- name: Execute Gradle 'integrationTestJdbc' task
18911891
run: ./gradlew integrationTestJdbc -Dscalardb.jdbc.url=jdbc:postgresql://localhost:5432/ -Dscalardb.jdbc.username=postgres -Dscalardb.jdbc.password=postgres ${{ matrix.mode.group_commit_enabled && env.INT_TEST_GRADLE_OPTIONS_FOR_GROUP_COMMIT || '' }}

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ subprojects {
3434
mysqlDriverVersion = '8.4.0'
3535
postgresqlDriverVersion = '42.7.8'
3636
oracleDriverVersion = '23.9.0.25.07'
37-
sqlserverDriverVersion = '12.8.1.jre8'
37+
sqlserverDriverVersion = '12.8.2.jre8'
3838
sqliteDriverVersion = '3.50.3.0'
3939
yugabyteDriverVersion = '42.7.3-yb-4'
4040
db2DriverVersion = '12.1.2.0'

core/src/integration-test/java/com/scalar/db/storage/jdbc/JdbcAdminImportTableIntegrationTest.java

Lines changed: 192 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,15 @@
11
package com.scalar.db.storage.jdbc;
22

3+
import static org.assertj.core.api.Assertions.assertThat;
4+
35
import com.scalar.db.api.DistributedStorageAdminImportTableIntegrationTestBase;
6+
import com.scalar.db.api.TableMetadata;
47
import com.scalar.db.exception.storage.ExecutionException;
8+
import com.scalar.db.io.DataType;
59
import java.sql.SQLException;
10+
import java.util.Collections;
611
import java.util.List;
12+
import java.util.Objects;
713
import java.util.Properties;
814
import org.junit.jupiter.api.Test;
915
import org.junit.jupiter.api.condition.DisabledIf;
@@ -47,16 +53,51 @@ protected List<TestData> createExistingDatabaseWithAllDataTypes() throws SQLExce
4753
return testUtils.createExistingDatabaseWithAllDataTypes(getNamespace());
4854
}
4955

56+
@Override
57+
protected List<String> getIntCompatibleColumnNamesOnExistingDatabase(String table) {
58+
return testUtils.getIntCompatibleColumnNamesOnExistingDatabase(table);
59+
}
60+
61+
@Override
62+
protected List<String> getFloatCompatibleColumnNamesOnExistingDatabase(String table) {
63+
return testUtils.getFloatCompatibleColumnNamesOnExistingDatabase(table);
64+
}
65+
5066
@Override
5167
protected void dropNonImportableTable(String table) throws SQLException {
5268
testUtils.dropTable(getNamespace(), table);
5369
}
5470

71+
@SuppressWarnings("unused")
72+
private boolean isOracle() {
73+
return JdbcEnv.isOracle();
74+
}
75+
76+
@SuppressWarnings("unused")
77+
private boolean isSqlServer() {
78+
return JdbcEnv.isSqlServer();
79+
}
80+
81+
@SuppressWarnings("unused")
82+
private boolean isDb2() {
83+
return JdbcEnv.isDb2();
84+
}
85+
5586
@SuppressWarnings("unused")
5687
private boolean isSqlite() {
5788
return JdbcEnv.isSqlite();
5889
}
5990

91+
@SuppressWarnings("unused")
92+
private boolean isColumnTypeConversionToTextNotFullySupported() {
93+
return JdbcEnv.isDb2() || JdbcEnv.isSqlServer() || JdbcEnv.isOracle() || JdbcEnv.isSqlite();
94+
}
95+
96+
@SuppressWarnings("unused")
97+
private boolean isWideningColumnTypeConversionNotFullySupported() {
98+
return JdbcEnv.isOracle() || JdbcEnv.isSqlite();
99+
}
100+
60101
@Test
61102
@Override
62103
@DisabledIf("isSqlite")
@@ -71,4 +112,155 @@ public void importTable_ForUnsupportedDatabase_ShouldThrowUnsupportedOperationEx
71112
throws ExecutionException {
72113
super.importTable_ForUnsupportedDatabase_ShouldThrowUnsupportedOperationException();
73114
}
115+
116+
@Test
117+
@Override
118+
@DisabledIf("isColumnTypeConversionToTextNotFullySupported")
119+
public void
120+
alterColumnType_AlterColumnTypeFromEachExistingDataTypeToText_ForImportedTable_ShouldAlterColumnTypesCorrectly()
121+
throws Exception {
122+
super
123+
.alterColumnType_AlterColumnTypeFromEachExistingDataTypeToText_ForImportedTable_ShouldAlterColumnTypesCorrectly();
124+
}
125+
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 (Objects.equals(column, "col16")) {
165+
continue;
166+
}
167+
assertThat(newMetadata.getColumnDataType(column)).isEqualTo(DataType.TEXT);
168+
}
169+
}
170+
}
171+
}
172+
}
173+
174+
@Test
175+
@EnabledIf("isDb2")
176+
public void
177+
alterColumnType_Db2_AlterColumnTypeFromEachExistingDataTypeToText_ForImportedTable_ShouldAlterColumnTypesCorrectly()
178+
throws Exception {
179+
// Arrange
180+
testDataList.addAll(createExistingDatabaseWithAllDataTypes());
181+
for (TestData testData : testDataList) {
182+
if (testData.isImportableTable()) {
183+
admin.importTable(
184+
getNamespace(),
185+
testData.getTableName(),
186+
Collections.emptyMap(),
187+
testData.getOverrideColumnsType());
188+
}
189+
}
190+
191+
for (TestData testData : testDataList) {
192+
if (testData.isImportableTable()) {
193+
// Act
194+
TableMetadata metadata = testData.getTableMetadata();
195+
for (String column : metadata.getColumnNames()) {
196+
if (!metadata.getPartitionKeyNames().contains(column)
197+
&& !metadata.getClusteringKeyNames().contains(column)) {
198+
if (metadata.getColumnDataType(column).equals(DataType.BLOB)) {
199+
// Conversion from BLOB to TEXT is not supported in Db2 engine
200+
continue;
201+
}
202+
admin.alterColumnType(getNamespace(), testData.getTableName(), column, DataType.TEXT);
203+
}
204+
}
205+
206+
// Assert
207+
TableMetadata newMetadata = admin.getTableMetadata(getNamespace(), testData.getTableName());
208+
assertThat(newMetadata).isNotNull();
209+
for (String column : metadata.getColumnNames()) {
210+
if (!metadata.getPartitionKeyNames().contains(column)
211+
&& !metadata.getClusteringKeyNames().contains(column)) {
212+
if (metadata.getColumnDataType(column).equals(DataType.BLOB)) {
213+
continue;
214+
}
215+
assertThat(newMetadata.getColumnDataType(column)).isEqualTo(DataType.TEXT);
216+
}
217+
}
218+
}
219+
}
220+
}
221+
222+
@Test
223+
@Override
224+
@DisabledIf("isWideningColumnTypeConversionNotFullySupported")
225+
public void alterColumnType_WideningConversion_ForImportedTable_ShouldAlterProperly()
226+
throws Exception {
227+
super.alterColumnType_WideningConversion_ForImportedTable_ShouldAlterProperly();
228+
}
229+
230+
@Test
231+
@EnabledIf("isOracle")
232+
public void alterColumnType_Oracle_WideningConversion_ForImportedTable_ShouldAlterProperly()
233+
throws Exception {
234+
// Arrange
235+
testDataList.addAll(createExistingDatabaseWithAllDataTypes());
236+
for (TestData testData : testDataList) {
237+
if (testData.isImportableTable()) {
238+
admin.importTable(
239+
getNamespace(),
240+
testData.getTableName(),
241+
Collections.emptyMap(),
242+
testData.getOverrideColumnsType());
243+
}
244+
}
245+
246+
for (TestData testData : testDataList) {
247+
if (testData.isImportableTable()) {
248+
// Act
249+
for (String intCompatibleColumn :
250+
getIntCompatibleColumnNamesOnExistingDatabase(testData.getTableName())) {
251+
admin.alterColumnType(
252+
getNamespace(), testData.getTableName(), intCompatibleColumn, DataType.BIGINT);
253+
}
254+
// Conversion from FLOAT TO DOUBLE is not supported in Oracle engine
255+
256+
// Assert
257+
TableMetadata metadata = admin.getTableMetadata(getNamespace(), testData.getTableName());
258+
assertThat(metadata).isNotNull();
259+
for (String intCompatibleColumn :
260+
getIntCompatibleColumnNamesOnExistingDatabase(testData.getTableName())) {
261+
assertThat(metadata.getColumnDataType(intCompatibleColumn)).isEqualTo(DataType.BIGINT);
262+
}
263+
}
264+
}
265+
}
74266
}

0 commit comments

Comments
 (0)