Unverified 提交 e26ab316 authored 作者: Evgenij Ryazanov's avatar Evgenij Ryazanov 提交者: GitHub

Merge pull request #1234 from katzyn/mergeUsing

Fix NPE in Parser.parseMergeUsing()
......@@ -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 {
......@@ -1552,7 +1556,7 @@ public class Parser {
if (readIf("AS")) {
alias = readAliasIdentifier();
} else if (currentTokenType == IDENTIFIER && !isTokenInList(excludeIdentifiers)) {
alias = readAliasIdentifier();
alias = readAliasIdentifier();
}
return alias;
}
......
......@@ -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 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论