Skip to content

Commit 50b747b

Browse files
committed
Updated tests for SQLWarning
1 parent 3adbf11 commit 50b747b

File tree

2 files changed

+46
-74
lines changed

2 files changed

+46
-74
lines changed

jdbc/src/test/java/tech/ydb/jdbc/impl/YdbConnectionImplTest.java

Lines changed: 23 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
import java.sql.SQLException;
88
import java.sql.SQLWarning;
99
import java.sql.Statement;
10-
import java.util.Arrays;
1110
import java.util.HashMap;
1211
import java.util.Map;
1312
import java.util.Properties;
@@ -30,10 +29,6 @@
3029
import tech.ydb.jdbc.impl.helper.JdbcConnectionExtention;
3130
import tech.ydb.jdbc.impl.helper.SqlQueries;
3231
import tech.ydb.jdbc.impl.helper.TableAssert;
33-
import tech.ydb.table.values.ListType;
34-
import tech.ydb.table.values.ListValue;
35-
import tech.ydb.table.values.PrimitiveType;
36-
import tech.ydb.table.values.PrimitiveValue;
3732
import tech.ydb.test.junit5.YdbHelperExtension;
3833

3934
public class YdbConnectionImplTest {
@@ -665,38 +660,30 @@ public void testDDLInsideTransaction() throws SQLException {
665660
}
666661

667662
@Test
668-
public void testWarningInIndexUsage() throws SQLException {
663+
public void testWarningsInQuery() throws SQLException {
664+
String createTempTable = QUERIES.withTableName(
665+
"CREATE TABLE #tableName_idx(id Int32, value Int32, PRIMARY KEY(id), INDEX idx_value GLOBAL ON(value))"
666+
);
667+
String dropTempTable = QUERIES.withTableName("DROP TABLE #tableName_idx");
668+
669669
try (Statement statement = jdbc.connection().createStatement()) {
670-
statement.execute("" +
671-
"create table unit_0_indexed (" +
672-
"id Int32, value Int32, " +
673-
"primary key (id), " +
674-
"index idx_value global on (value))");
675-
676-
String query = "--!syntax_v1\n" +
677-
"declare $list as List<Int32>;\n" +
678-
"select * from unit_0_indexed view idx_value where value in $list;";
679-
680-
ListValue value = ListType.of(PrimitiveType.Int32).newValue(
681-
Arrays.asList(PrimitiveValue.newInt32(1), PrimitiveValue.newInt32(2)));
682-
try (PreparedStatement ps = jdbc.connection().prepareStatement(query)) {
683-
ps.setObject(1, value);
684-
685-
ResultSet rs = ps.executeQuery();
686-
Assertions.assertFalse(rs.next());
687-
688-
SQLWarning warnings = ps.getWarnings();
689-
Assertions.assertNotNull(warnings);
690-
691-
Assertions.assertEquals("#1030 Type annotation (S_WARNING)\n"
692-
+ " 1:3 - 1:3: At function: RemovePrefixMembers, At function: RemoveSystemMembers, "
693-
+ "At function: PersistableRepr, At function: SqlProject (S_WARNING)\n"
694-
+ " 35:3 - 35:3: At function: Filter, At function: Coalesce (S_WARNING)\n"
695-
+ " 51:3 - 51:3: At function: SqlIn (S_WARNING)\n"
696-
+ " 51:3 - 51:3: #1108 IN may produce unexpected result when used with nullable arguments. "
697-
+ "Consider adding 'PRAGMA AnsiInForEmptyOrNullableItemsCollections;' (S_WARNING)",
698-
warnings.getMessage());
699-
Assertions.assertNull(warnings.getNextWarning());
670+
statement.execute(createTempTable);
671+
672+
try {
673+
String query = QUERIES.withTableName("SELECT * FROM #tableName_idx VIEW idx_value WHERE id = 1;");
674+
try (ResultSet rs = statement.executeQuery(query)) {
675+
Assertions.assertFalse(rs.next());
676+
677+
SQLWarning warnings = statement.getWarnings();
678+
Assertions.assertNotNull(warnings);
679+
680+
Assertions.assertEquals("#1060 Execution (S_WARNING)\n "
681+
+ "1:1 - 1:1: #2503 Given predicate is not suitable for used index: idx_value (S_WARNING)",
682+
warnings.getMessage());
683+
Assertions.assertNull(warnings.getNextWarning());
684+
}
685+
} finally {
686+
statement.execute(dropTempTable);
700687
}
701688
}
702689
}

jdbc/src/test/java/tech/ydb/jdbc/impl/YdbQueryConnectionImplTest.java

Lines changed: 23 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
import java.sql.SQLException;
88
import java.sql.SQLWarning;
99
import java.sql.Statement;
10-
import java.util.Arrays;
1110
import java.util.HashMap;
1211
import java.util.Map;
1312
import java.util.Properties;
@@ -17,7 +16,6 @@
1716
import org.junit.jupiter.api.Assertions;
1817
import org.junit.jupiter.api.BeforeAll;
1918
import org.junit.jupiter.api.BeforeEach;
20-
import org.junit.jupiter.api.Disabled;
2119
import org.junit.jupiter.api.DisplayName;
2220
import org.junit.jupiter.api.Test;
2321
import org.junit.jupiter.api.extension.RegisterExtension;
@@ -31,10 +29,6 @@
3129
import tech.ydb.jdbc.impl.helper.JdbcConnectionExtention;
3230
import tech.ydb.jdbc.impl.helper.SqlQueries;
3331
import tech.ydb.jdbc.impl.helper.TableAssert;
34-
import tech.ydb.table.values.ListType;
35-
import tech.ydb.table.values.ListValue;
36-
import tech.ydb.table.values.PrimitiveType;
37-
import tech.ydb.table.values.PrimitiveValue;
3832
import tech.ydb.test.junit5.YdbHelperExtension;
3933

4034
public class YdbQueryConnectionImplTest {
@@ -667,39 +661,30 @@ public void testDDLInsideTransaction() throws SQLException {
667661
}
668662

669663
@Test
670-
@Disabled
671-
public void testWarningInIndexUsage() throws SQLException {
664+
public void testWarningsInQuery() throws SQLException {
665+
String createTempTable = QUERIES.withTableName(
666+
"CREATE TABLE #tableName_idx(id Int32, value Int32, PRIMARY KEY(id), INDEX idx_value GLOBAL ON(value))"
667+
);
668+
String dropTempTable = QUERIES.withTableName("DROP TABLE #tableName_idx");
669+
672670
try (Statement statement = jdbc.connection().createStatement()) {
673-
statement.execute("" +
674-
"create table unit_0_indexed (" +
675-
"id Int32, value Int32, " +
676-
"primary key (id), " +
677-
"index idx_value global on (value))");
678-
679-
String query = "--!syntax_v1\n" +
680-
"declare $list as List<Int32>;\n" +
681-
"select * from unit_0_indexed view idx_value where value in $list;";
682-
683-
ListValue value = ListType.of(PrimitiveType.Int32).newValue(
684-
Arrays.asList(PrimitiveValue.newInt32(1), PrimitiveValue.newInt32(2)));
685-
try (PreparedStatement ps = jdbc.connection().prepareStatement(query)) {
686-
ps.setObject(1, value);
687-
688-
ResultSet rs = ps.executeQuery();
689-
Assertions.assertFalse(rs.next());
690-
691-
SQLWarning warnings = ps.getWarnings();
692-
Assertions.assertNotNull(warnings);
693-
694-
Assertions.assertEquals("#1030 Type annotation (S_WARNING)\n"
695-
+ " 1:3 - 1:3: At function: RemovePrefixMembers, At function: RemoveSystemMembers, "
696-
+ "At function: PersistableRepr, At function: SqlProject (S_WARNING)\n"
697-
+ " 35:3 - 35:3: At function: Filter, At function: Coalesce (S_WARNING)\n"
698-
+ " 51:3 - 51:3: At function: SqlIn (S_WARNING)\n"
699-
+ " 51:3 - 51:3: #1108 IN may produce unexpected result when used with nullable arguments. "
700-
+ "Consider adding 'PRAGMA AnsiInForEmptyOrNullableItemsCollections;' (S_WARNING)",
701-
warnings.getMessage());
702-
Assertions.assertNull(warnings.getNextWarning());
671+
statement.execute(createTempTable);
672+
673+
try {
674+
String query = QUERIES.withTableName("SELECT * FROM #tableName_idx VIEW idx_value WHERE id = 1;");
675+
try (ResultSet rs = statement.executeQuery(query)) {
676+
Assertions.assertFalse(rs.next());
677+
678+
SQLWarning warnings = statement.getWarnings();
679+
Assertions.assertNotNull(warnings);
680+
681+
Assertions.assertEquals("#1060 Execution (S_WARNING)\n "
682+
+ "1:1 - 1:1: #2503 Given predicate is not suitable for used index: idx_value (S_WARNING)",
683+
warnings.getMessage());
684+
Assertions.assertNull(warnings.getNextWarning());
685+
}
686+
} finally {
687+
statement.execute(dropTempTable);
703688
}
704689
}
705690
}

0 commit comments

Comments
 (0)