Unverified 提交 3a7253d5 authored 作者: Noel Grandin's avatar Noel Grandin 提交者: GitHub

Merge pull request #749 from katzyn/build_errors

Fix some build checks in sources
......@@ -1136,7 +1136,8 @@ public class Parser {
command.setQueryAlias(readFromAlias(null, Arrays.asList("ON")));
String[] querySQLOutput = new String[]{null};
List<Column> columnTemplateList = TableView.createQueryColumnTemplateList(null, command.getQuery(), querySQLOutput);
List<Column> columnTemplateList = TableView.createQueryColumnTemplateList(null, command.getQuery(),
querySQLOutput);
TableView temporarySourceTableView = createCTEView(
command.getQueryAlias(), querySQLOutput[0],
columnTemplateList, false/* no recursion */,
......@@ -5154,8 +5155,8 @@ public class Parser {
List<TableView> viewsCreated = new ArrayList<>();
readIf("RECURSIVE");
// this WITH statement might not be a temporary view - allow optional keyword to tell us that
// this keyword. This feature will not be documented - H2 internal use only.
// this WITH statement might not be a temporary view - allow optional keyword to
// tell us that this keyword. This feature will not be documented - H2 internal use only.
boolean isPersistent = readIf("PERSISTENT");
// this WITH statement is not a temporary view - it is part of a persistent view
......@@ -5307,7 +5308,8 @@ public class Parser {
synchronized (targetSession) {
view = new TableView(schema, id, cteViewName, querySQL,
parameters, columnTemplateArray, targetSession,
allowRecursiveQueryDetection, false /* literalsChecked */, true /* isTableExpression */, isPersistent);
allowRecursiveQueryDetection, false /* literalsChecked */, true /* isTableExpression */,
isPersistent);
if (!view.isRecursiveQueryDetected() && allowRecursiveQueryDetection) {
if (isPersistent) {
db.addSchemaObject(targetSession, view);
......@@ -5318,7 +5320,8 @@ public class Parser {
}
view = new TableView(schema, id, cteViewName, querySQL, parameters,
columnTemplateArray, targetSession,
false/* assume recursive */, false /* literalsChecked */, true /* isTableExpression */, isPersistent);
false/* assume recursive */, false /* literalsChecked */, true /* isTableExpression */,
isPersistent);
}
// both removeSchemaObject and removeLocalTempTable hold meta locks
targetSession.getDatabase().unlockMeta(targetSession);
......
......@@ -117,9 +117,12 @@ public class CreateView extends SchemaCommand {
}
if (view == null) {
if (isTableExpression) {
view = TableView.createTableViewMaybeRecursive(getSchema(), id, viewName, querySQL, null, columnTemplatesAsStrings, session, false /* literalsChecked */, isTableExpression, true /*isPersistent*/, db);
view = TableView.createTableViewMaybeRecursive(getSchema(), id, viewName, querySQL, null,
columnTemplatesAsStrings, session, false /* literalsChecked */, isTableExpression,
true /* isPersistent */, db);
} else {
view = new TableView(getSchema(), id, viewName, querySQL, null, columnTemplatesAsUnknowns, session, false/* allow recursive */, false/* literalsChecked */, isTableExpression, true);
view = new TableView(getSchema(), id, viewName, querySQL, null, columnTemplatesAsUnknowns, session,
false/* allow recursive */, false/* literalsChecked */, isTableExpression, true);
}
} else {
// TODO support isTableExpression in replace function...
......
......@@ -1064,8 +1064,9 @@ public class Select extends Query {
if (tableView != null && tableView.isRecursive() && tableView.isTableExpression()) {
if (tableView.isPersistent()) {
// skip the generation of plan SQL for this already recursive persistent ctes, since using a with
// statement will re-create the common table expression views.
// skip the generation of plan SQL for this already recursive persistent CTEs,
// since using a with statement will re-create the common table expression
// views.
continue;
} else {
buff.append("WITH RECURSIVE ").append(t.getName()).append('(');
......
......@@ -229,6 +229,16 @@ public class Session extends SessionWithState {
return subQueryInfo;
}
/**
* Stores name of currently parsed view in a stack so it can be determined
* during {@code prepare()}.
*
* @param parsingView
* {@code true} to store one more name, {@code false} to remove it
* from stack
* @param viewName
* name of the view
*/
public void setParsingCreateView(boolean parsingView, String viewName) {
// It can be recursive, thus implemented as counter.
this.parsingView += parsingView ? 1 : -1;
......
......@@ -67,7 +67,8 @@ public class TableView extends Table {
ArrayList<Parameter> params, Column[] columnTemplates, Session session,
boolean allowRecursive, boolean literalsChecked, boolean isTableExpression, boolean isPersistent) {
super(schema, id, name, false, true);
init(querySQL, params, columnTemplates, session, allowRecursive, literalsChecked, isTableExpression, isPersistent);
init(querySQL, params, columnTemplates, session, allowRecursive, literalsChecked, isTableExpression,
isPersistent);
}
/**
......@@ -746,15 +747,17 @@ public class TableView extends Table {
parameters, columnTemplateList.toArray(columnTemplates), session,
true/* try recursive */, literalsChecked, isTableExpression, isPersistent);
// is recursion really detected ? if not - recreate it without recursion flag and no recursive index
// is recursion really detected ? if not - recreate it without recursion flag
// and no recursive index
if (!view.isRecursiveQueryDetected()) {
if (isPersistent) {
db.addSchemaObject(session, view);
view.lock(session, true, true);
session.getDatabase().removeSchemaObject(session, view);
// during database startup - this method does not normally get called - and it needs to be
// to correctly un-register the table which the table expression uses...
// during database startup - this method does not normally get called - and it
// needs to be to correctly un-register the table which the table expression
// uses...
view.removeChildrenAndResources(session);
} else {
session.removeLocalTempTable(view);
......
......@@ -11,27 +11,29 @@ import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
import org.h2.test.TestBase;
/**
* Base class for common table expression tests
*/
public abstract class AbstractBaseForCommonTableExpressions extends TestBase {
protected void testRepeatedQueryWithSetup(int maxRetries, String[] expectedRowData, String[] expectedColumnNames, int expectedNumbeOfRows, String setupSQL,
String withQuery, int closeAndReopenDatabaseConnectionOnIteration, String[] expectedColumnTypes) throws SQLException {
protected void testRepeatedQueryWithSetup(int maxRetries, String[] expectedRowData, String[] expectedColumnNames,
int expectedNumberOfRows, String setupSQL, String withQuery,
int closeAndReopenDatabaseConnectionOnIteration, String[] expectedColumnTypes) throws SQLException {
deleteDb("commonTableExpressionQueries");
Connection conn = getConnection("commonTableExpressionQueries");
PreparedStatement prep;
ResultSet rs;
for (int queryRunTries = 1; queryRunTries <= maxRetries; queryRunTries++) {
Statement stat = conn.createStatement();
stat.execute(setupSQL);
stat.close();
// close and re-open connection for one iteration to make sure the query work between connections
// close and re-open connection for one iteration to make sure the query work
// between connections
if (queryRunTries == closeAndReopenDatabaseConnectionOnIteration) {
conn.close();
......@@ -44,7 +46,9 @@ public abstract class AbstractBaseForCommonTableExpressions extends TestBase {
assertTrue(rs.getMetaData().getColumnLabel(columnIndex) != null);
assertEquals(expectedColumnNames[columnIndex - 1], rs.getMetaData().getColumnLabel(columnIndex));
assertEquals("wrongly type column "+rs.getMetaData().getColumnLabel(columnIndex)+" on iteration#"+queryRunTries,
assertEquals(
"wrong type of column " + rs.getMetaData().getColumnLabel(columnIndex) + " on iteration #"
+ queryRunTries,
expectedColumnTypes[columnIndex - 1], rs.getMetaData().getColumnTypeName(columnIndex));
}
......@@ -52,13 +56,13 @@ public abstract class AbstractBaseForCommonTableExpressions extends TestBase {
while (rs.next()) {
StringBuffer buf = new StringBuffer();
for (int columnIndex = 1; columnIndex <= rs.getMetaData().getColumnCount(); columnIndex++) {
buf.append("|"+rs.getString(columnIndex));
buf.append("|" + rs.getString(columnIndex));
}
assertEquals(expectedRowData[rowNdx], buf.toString());
rowNdx++;
}
assertEquals(expectedNumbeOfRows, rowNdx);
assertEquals(expectedNumberOfRows, rowNdx);
rs.close();
prep.close();
......
......@@ -302,7 +302,8 @@ public class TestCases extends TestBase {
throws SQLException {
assertThrows(expectedDropSuccess ? 0 : ErrorCode.CANNOT_DROP_2, stat)
.execute("drop table test " + (restrict ? "restrict" : "cascade"));
assertThrows(expectedDropSuccess ? ErrorCode.TABLE_OR_VIEW_NOT_FOUND_1 : 0, stat).execute("select * from test");
assertThrows(expectedDropSuccess ? ErrorCode.TABLE_OR_VIEW_NOT_FOUND_1 : 0, stat)
.execute("select * from test");
}
private void testDropTableNoReference(final boolean stdDropTableRestrict, final boolean restrict)
......
......@@ -2061,7 +2061,8 @@ public class TestFunctions extends TestBase implements AggregateFunction {
assertThrows(ErrorCode.INVALID_VALUE_2, stat).execute("select signal('00145', 'success class is invalid')");
assertThrows(ErrorCode.INVALID_VALUE_2, stat).execute("select signal('foo', 'SQLSTATE has 5 chars')");
assertThrows(ErrorCode.INVALID_VALUE_2, stat).execute("select signal('Ab123', 'SQLSTATE has only digits or upper-case letters')");
assertThrows(ErrorCode.INVALID_VALUE_2, stat)
.execute("select signal('Ab123', 'SQLSTATE has only digits or upper-case letters')");
try {
stat.execute("select signal('AB123', 'some custom error')");
fail("Should have thrown");
......
......@@ -526,8 +526,10 @@ public class TestGeneralCommonTableQueries extends AbstractBaseForCommonTableExp
config = new TestAll();
try {
//Test with settings: lazy mvStore memory mvcc multiThreaded
// connection url is =mem:script;MV_STORE=true;LOG=1;LOCK_TIMEOUT=50;MVCC=TRUE;MULTI_THREADED=TRUE;LAZY_QUERY_EXECUTION=1
// Test with settings: lazy mvStore memory mvcc multiThreaded
// connection url is
// mem:script;MV_STORE=true;LOG=1;LOCK_TIMEOUT=50;MVCC=TRUE;
// MULTI_THREADED=TRUE;LAZY_QUERY_EXECUTION=1
config.lazy = true;
config.mvStore = true;
config.memory = true;
......@@ -545,8 +547,8 @@ public class TestGeneralCommonTableQueries extends AbstractBaseForCommonTableExp
int maxRetries = 10;
int expectedNumberOfRows = expectedRowData.length;
testRepeatedQueryWithSetup(maxRetries, expectedRowData, expectedColumnNames, expectedNumberOfRows, setupSQL,
withQuery, maxRetries - 1, expectedColumnTypes);
testRepeatedQueryWithSetup(maxRetries, expectedRowData, expectedColumnNames, expectedNumberOfRows,
setupSQL, withQuery, maxRetries - 1, expectedColumnTypes);
} finally {
config = backupConfig;
}
......
......@@ -94,7 +94,7 @@ public class TestPersistentCommonTableExpressions extends AbstractBaseForCommonT
}
private void testPersistentRecursiveTableInCreateView() throws Exception {
String setuoSQL = "--SET TRACE_LEVEL_SYSTEM_OUT 3;\n"
String setupSQL = "--SET TRACE_LEVEL_SYSTEM_OUT 3;\n"
+"DROP TABLE IF EXISTS my_tree; \n"
+"DROP VIEW IF EXISTS v_my_tree; \n"
+"CREATE TABLE my_tree ( \n"
......@@ -137,7 +137,7 @@ public class TestPersistentCommonTableExpressions extends AbstractBaseForCommonT
String[] expectedColumnNames = new String[]{"SUB_TREE_ROOT_ID", "TREE_LEVEL", "PARENT_FK", "CHILD_FK"};
String[] expectedColumnTypes = new String[]{"INTEGER", "INTEGER", "INTEGER", "INTEGER"};
int expectedNumberOfRows = 11;
testRepeatedQueryWithSetup(maxRetries, expectedRowData, expectedColumnNames, expectedNumberOfRows, setuoSQL,
testRepeatedQueryWithSetup(maxRetries, expectedRowData, expectedColumnNames, expectedNumberOfRows, setupSQL,
withQuery, maxRetries - 1, expectedColumnTypes);
}
......
......@@ -506,7 +506,8 @@ public class TestTriggersConstraints extends TestBase implements Trigger {
} else if ("javascript".equals(sourceLang)) {
String triggerClassName = this.getClass().getName() + "."
+ TestTriggerAlterTable.class.getSimpleName();
final String body = "//javascript\nnew Packages." + triggerClassName + "();";
final String body = "//javascript\n"
+ "new Packages." + triggerClassName + "();";
stat.execute("create trigger test_upd before insert on test as $$"
+ body + " $$");
} else {
......
......@@ -93,10 +93,11 @@ public class TestMvccMultiThreaded2 extends TestBase {
}
if (DISPLAY_STATS) {
System.out.println(String.format("+ INFO: TestMvccMultiThreaded2 RUN STATS threads=%d, minProcessed=%d, maxProcessed=%d, "+
"totalProcessed=%d, averagePerThread=%d, averagePerThreadPerSecond=%d\n",
TEST_THREAD_COUNT, minProcessed, maxProcessed, totalProcessed, totalProcessed/TEST_THREAD_COUNT,
totalProcessed/(TEST_THREAD_COUNT * TEST_TIME_SECONDS)));
System.out.println(String.format(
"+ INFO: TestMvccMultiThreaded2 RUN STATS threads=%d, minProcessed=%d, maxProcessed=%d, "
+ "totalProcessed=%d, averagePerThread=%d, averagePerThreadPerSecond=%d\n",
TEST_THREAD_COUNT, minProcessed, maxProcessed, totalProcessed, totalProcessed / TEST_THREAD_COUNT,
totalProcessed / (TEST_THREAD_COUNT * TEST_TIME_SECONDS)));
}
IOUtils.closeSilently(conn);
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论