提交 c716cc9c authored 作者: Evgenij Ryazanov's avatar Evgenij Ryazanov

Fix NPE in Parser.parseMergeUsing()

上级 d4ed1a5d
......@@ -1135,19 +1135,23 @@ public class Parser {
command.setQuery(parseSelect());
read(")");
}
command.setQueryAlias(readFromAlias(null, Collections.singletonList("ON")));
String queryAlias = readFromAlias(null, Collections.singletonList("ON"));
if (queryAlias == null) {
queryAlias = Constants.PREFIX_QUERY_ALIAS + parseIndex;
}
command.setQueryAlias(queryAlias);
String[] querySQLOutput = {null};
List<Column> columnTemplateList = TableView.createQueryColumnTemplateList(null, command.getQuery(),
querySQLOutput);
TableView temporarySourceTableView = createCTEView(
command.getQueryAlias(), querySQLOutput[0],
queryAlias, querySQLOutput[0],
columnTemplateList, false/* no recursion */,
false/* do not add to session */,
false /* isPersistent */,
session);
TableFilter sourceTableFilter = new TableFilter(session,
temporarySourceTableView, command.getQueryAlias(),
temporarySourceTableView, queryAlias,
rightsChecked, (Select) command.getQuery(), 0, null);
command.setSourceTableFilter(sourceTableFilter);
} else {
......
......@@ -386,6 +386,11 @@ public class Constants {
*/
public static final String PREFIX_PRIMARY_KEY = "PRIMARY_KEY_";
/**
* The name prefix used for query aliases that are not explicitly named.
*/
public static final String PREFIX_QUERY_ALIAS = "QUERY_ALIAS_";
/**
* Every user belongs to this role.
*/
......
......@@ -147,6 +147,18 @@ SELECT * FROM TEST ORDER BY C1, C2;
> 11 22 32
> rows (ordered): 2
MERGE INTO TEST USING (SELECT 1 FROM DUAL) ON (C1 = 11 AND C2 = 21)
WHEN NOT MATCHED THEN INSERT (C1, C2, C3) VALUES (11, 21, 33)
WHEN MATCHED THEN UPDATE SET C3 = 34;
> update count: 1
SELECT * FROM TEST ORDER BY C1, C2;
> C1 C2 C3
> -- -- --
> 11 21 34
> 11 22 32
> rows (ordered): 2
DROP TABLE TEST;
> ok
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论