Changeset: 8854aa4e9064 for monetdb-java
URL: https://dev.monetdb.org/hg/monetdb-java/rev/8854aa4e9064
Modified Files:
src/test/java/JDBC_API_Tester.java
src/test/java/org/monetdb/jdbc/ApiTests.java
src/test/java/org/monetdb/testinfra/MonetVersionNumber.java
Branch: default
Log Message:
Convert Test_PlanExplainTraceDebugCmds() ->
ApiTest#{testLogicalPlan(),testExplain(),testTrace(),testDebug()}
diffs (257 lines):
diff --git a/src/test/java/JDBC_API_Tester.java
b/src/test/java/JDBC_API_Tester.java
--- a/src/test/java/JDBC_API_Tester.java
+++ b/src/test/java/JDBC_API_Tester.java
@@ -1024,134 +1024,6 @@ public final class JDBC_API_Tester exten
compareExpectedOutput("Test_DBCmetadata", "");
}
- @Test // CHANGED
- public void Test_PlanExplainTraceDebugCmds() {
- sb.setLength(0); // clear the output log buffer
-
- Statement stmt = null;
- ResultSet rs = null;
- try {
- final boolean isPreJan2022 = (dbmsMajorVersion == 11 &&
dbmsMinorVersion <= 41);
-
- stmt = con.createStatement();
- String qry = "SELECT 1;";
- rs = stmt.executeQuery(qry);
- while (rs.next()) {
- sb.append(rs.getString(1)).append("\n");
- }
- rs.close();
- rs = null;
- compareExpectedOutput("Test_PlanExplainTraceDebugCmds:
" + qry, "1\n");
- sb.setLength(0); // clear the output log buffer
-
- // plan statements are supported via JDBC
- qry = "plan SELECT 2;";
- rs = stmt.executeQuery(qry);
- if (!skipMALoutput) {
- compareResultSet(rs, qry,
- ! isPreJan2022 ?
- "Resultset with 1 columns\n" +
- "rel\n" +
- (isPostDec2023 ? "varchar" : "clob") +
"(37)\n" +
- "project (\n" +
- "| [ boolean(1) \"true\" as
\"%1\".\"%1\" ]\n" +
- ") [ tinyint(2) \"2\" ]\n"
- :
- "Resultset with 1 columns\n" +
- "rel\n" +
- "clob(21)\n" +
- "project (\n" +
- "| [ boolean \"true\" ]\n" +
- ") [ tinyint \"2\" ]\n");
- }
- rs.close();
- rs = null;
- sb.setLength(0); // clear the output log buffer
-
- // explain statements are supported via JDBC
- qry = "explain SELECT 3;";
- rs = stmt.executeQuery(qry);
- while (rs.next()) {
- String val = rs.getString(1);
- if (!val.startsWith("#"))
- sb.append(val).append("\n");
- }
- rs.close();
- rs = null;
- if (!skipMALoutput) {
-
compareExpectedOutput("Test_PlanExplainTraceDebugCmds: " + qry,
- "function user.main():void;\n" +
- " X_1:void :=
querylog.define(\"explain select 3;\":str, \"default_pipe\":str, " +
(isPostMar2025 ? "4" : "6") + ":int);\n" +
- " X_" + (isPostMar2025 ? "8" : "10")
+ ":int := sql.resultSet(\".%2\":str, \"%2\":str, \"tinyint\":str, 2:int,
0:int, 7:int, 3:bte);\n" +
- "end user.main;\n");
- }
- sb.setLength(0); // clear the output log buffer
-
- // trace statements are supported via JDBC. Note that
it returns two resultsets, one with the query result and next one with the
trace result.
- qry = "trace SELECT 4;";
- rs = stmt.executeQuery(qry);
- while (rs.next()) {
- sb.append(rs.getString(1)).append("\n");
- }
- if (stmt.getMoreResults()) {
- sb.append("Another resultset\n");
- rs = stmt.getResultSet();
- while (rs.next()) {
- sb.append(rs.getString(2)).append("\n");
- }
- }
- rs.close();
- rs = null;
- if (!skipMALoutput) {
-
compareExpectedOutput("Test_PlanExplainTraceDebugCmds: " + qry,
- isPostMar2025 ?
- "4\n" /* after Mar2025
release trace command no longer returns second resultset */
- : isPreJan2022 ?
- "4\n" +
- "Another resultset\n" +
- "X_0=0@0:void :=
querylog.define(\"trace select 4;\":str, \"default_pipe\":str, 6:int);\n" +
- "X_1=0:int :=
sql.resultSet(\".%2\":str, \"%2\":str, \"tinyint\":str, 3:int, 0:int, 7:int,
4:bte);\n"
- :
- "4\n" +
- "Another resultset\n" +
- " X_1=0@0:void :=
querylog.define(\"trace select 4;\":str, \"default_pipe\":str, 6:int);\n" +
- " X_10=0:int :=
sql.resultSet(\".%2\":str, \"%2\":str, \"tinyint\":str, 3:int, 0:int, 7:int,
4:bte);\n"
- );
- }
- sb.setLength(0); // clear the output log buffer
-
- // debug statements are NOT supported via JDBC driver,
so the execution should throw an SQLException
- // Note: as of release 11.47 (Jun2023) the debug
statement is not supported anymore, error msg: syntax error in: "debug"
- qry = "debug SELECT 5;";
- sb.append(qry).append("\n");
- rs = stmt.executeQuery(qry); // this should throw an
SQLException
- while (rs.next()) {
- sb.append(rs.getString(1)).append("\n");
- }
- rs.close();
- rs = null;
- compareExpectedOutput("Test_PlanExplainTraceDebugCmds:
" + qry, qry + "\n5\n");
- sb.setLength(0); // clear the output log buffer
- } catch (SQLException e) {
- sb.append("FAILED: ");
- while (e != null) {
- sb.append(e.getMessage()).append("\n");
- e = e.getNextException();
- }
-
- final boolean isPreJun2023 = (dbmsMajorVersion == 11 &&
dbmsMinorVersion <= 45);
- // From Jun2023 we skip the comparison as it gives a
different error msg on power8 platform: syntax error, unexpected IDENT in:
"debug"
- if (isPreJun2023) {
-
compareExpectedOutput("Test_PlanExplainTraceDebugCmds",
- "debug SELECT 5;\n" +
- "FAILED: SQL debugging only supported
in interactive mode in: \"debug\"\n" +
- "Current transaction is aborted (please
ROLLBACK)\n");
- }
- }
-
- closeStmtResSet(stmt, rs);
- }
-
@Test
public void Test_PSgeneratedkeys() {
sb.setLength(0); // clear the output log buffer
diff --git a/src/test/java/org/monetdb/jdbc/ApiTests.java
b/src/test/java/org/monetdb/jdbc/ApiTests.java
--- a/src/test/java/org/monetdb/jdbc/ApiTests.java
+++ b/src/test/java/org/monetdb/jdbc/ApiTests.java
@@ -564,4 +564,96 @@ public class ApiTests {
}
stmt.executeUpdate("DROP TABLE test_interval_type");
}
+
+ @Test
+ public void testLogicalPlan() throws SQLException {
+ String keyword = monetVersion.planHasBecomeExplain() ?
"EXPLAIN" : "PLAN";
+ String query = keyword + " SELECT * FROM sys.generate_series(1,
10)";
+ // EXPLAIN (PLAN) yields a one-column result set. One row
describes a projection operation1
+ try (ResultSet rs = stmt.executeQuery(query)) {
+ ResultSetMetaData md = rs.getMetaData();
+ assertEquals(1, md.getColumnCount());
+ int colType = md.getColumnType(1);
+ assertTrue(colType == Types.VARCHAR || colType ==
Types.CLOB, md.getColumnTypeName(1) + "=" + colType);
+ while (rs.next()) {
+ if (rs.getString(1).equals("project ("))
+ return;
+ }
+ fail("Could not find substring <" + "project (" + "> in
result set of query: " + query);
+ }
+ }
+
+ @Test
+ public void testExplain() throws SQLException {
+ String keyword = monetVersion.planHasBecomeExplain() ? "EXPLAIN
PHYSICAL" : "EXPLAIN";
+ String query = keyword + " SELECT 42";
+ // EXPLAIN PHYSICAL yields a one-column result set.
+ // The first line is 'function user.main()', the last
non-comment line is 'end user.main'
+ try (ResultSet rs = stmt.executeQuery(query)) {
+ ResultSetMetaData md = rs.getMetaData();
+ assertEquals(1, md.getColumnCount());
+ int colType = md.getColumnType(1);
+ assertTrue(colType == Types.VARCHAR || colType ==
Types.CLOB, md.getColumnTypeName(1) + "=" + colType);
+ String firstLine = null;
+ String lastLine = null;
+ while (rs.next()) {
+ String line = rs.getString(1);
+ if (line.startsWith("#"))
+ continue;
+ if (firstLine == null)
+ firstLine = line;
+ lastLine = line;
+ }
+ assertNotNull(lastLine); // implies same for firstLine
+ assertTrue(firstLine.startsWith("function user.main"),
firstLine);
+ assertTrue(lastLine.startsWith("end user.main"),
lastLine);
+ }
+ }
+
+ @Test
+ public void testTrace() throws SQLException {
+ String query = "TRACE SELECT 42";
+ ResultSet rs = null; // used twice, once for the result set
and once for the trace
+ try {
+ rs = stmt.executeQuery(query);
+
+ // first the result set
+ assertTrue(rs.next());
+ assertEquals(42, rs.getInt(1));
+ assertFalse(rs.next());
+
+ if (monetVersion.planHasBecomeExplain()) {
+ // Newer MonetDB's leave the trace in
sys.tracelog
+ assertFalse(stmt.getMoreResults());
+ rs.close(); // is this necessary?
+ rs = stmt.executeQuery("SELECT * FROM
sys.tracelog");
+ } else {
+ // Older MonetDB's send the trace as a second
result set
+ assertTrue(stmt.getMoreResults());
+ rs = stmt.getResultSet();
+ }
+
+ // Inspect the trace, is it really a trace?
+ ResultSetMetaData md = rs.getMetaData();
+ assertTrue(rs.next());
+ String line = rs.getString(2);
+ assertTrue(line.contains(":= querylog.define"), line);
+ assertTrue(line.contains("select 42"), line);
+ } finally {
+ if (rs != null)
+ rs.close();
+ }
+ }
+
+ @Test
+ public void testDebug() throws SQLException {
+ // DEBUG has not been supported by MonetDB for a while but the
old jdbc test
+ // suite had a test for it so we include it.
+ //
+ // The original test had the following comment:
+ // From Jun2023 we skip the comparison as it gives a
different error msg on power8 platform: syntax error, unexpected IDENT in:
"debug"
+ // let's see what happens and adjust this test accordingly
+ assertSQLException("unexpected IDENT", () ->
stmt.executeQuery("DEBUG SELECT 42"));
+ }
+
}
diff --git a/src/test/java/org/monetdb/testinfra/MonetVersionNumber.java
b/src/test/java/org/monetdb/testinfra/MonetVersionNumber.java
--- a/src/test/java/org/monetdb/testinfra/MonetVersionNumber.java
+++ b/src/test/java/org/monetdb/testinfra/MonetVersionNumber.java
@@ -88,4 +88,15 @@ public class MonetVersionNumber {
public boolean serverReturnsNewMetadata() {
return isAtLeast(11, 50, 0);
}
+
+ /**
+ * Equivalent to {@code isAtLeast 11, 54, 0)}
+ *
+ * From version 11.54 on, PLAN has been replaced with EXPLAIN and
EXPLAIN has been
+ * replaced with EXPLAIN PHYSICAL
+ * @return
+ */
+ public boolean planHasBecomeExplain() {
+ return isAtLeast(11, 54, 00);
+ }
}
_______________________________________________
checkin-list mailing list -- [email protected]
To unsubscribe send an email to [email protected]