This is an automated email from the ASF dual-hosted git repository. vozerov pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/ignite.git
The following commit(s) were added to refs/heads/master by this push: new 89ba43f IGNITE-11604: SQL: Fixed problem with DROP COLUMN which was not able remove a column properly in some cases. This closes #6399. 89ba43f is described below commit 89ba43f527ab89e561fc95c003568fedbd117c9b Author: tledkov <tled...@gridgain.com> AuthorDate: Fri Apr 5 13:07:28 2019 +0300 IGNITE-11604: SQL: Fixed problem with DROP COLUMN which was not able remove a column properly in some cases. This closes #6399. --- .../processors/query/GridQueryProcessor.java | 14 +---------- .../internal/processors/query/QuerySchema.java | 8 ++++-- .../internal/processors/query/QueryUtils.java | 29 ++++++++++++++++++++++ 3 files changed, 36 insertions(+), 15 deletions(-) diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/query/GridQueryProcessor.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/query/GridQueryProcessor.java index d91c2aa..0c21646 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/query/GridQueryProcessor.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/query/GridQueryProcessor.java @@ -1252,23 +1252,11 @@ public class GridQueryProcessor extends GridProcessorAdapter { op0.tableName()); } else { - Map<String, String> aliases = e.getAliases(); - for (String colName : op0.columns()) { if (err != null) break; - String fldName = colName; - - if (!F.isEmpty(aliases)) { - for (Map.Entry<String, String> a : aliases.entrySet()) { - if (colName.equals(a.getValue())) { - fldName = a.getKey(); - - break; - } - } - } + String fldName = QueryUtils.fieldNameByAlias(e, colName); if (!e.getFields().containsKey(fldName)) { if (op0.ifExists()) { diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/query/QuerySchema.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/query/QuerySchema.java index 569a02e..082d52f 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/query/QuerySchema.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/query/QuerySchema.java @@ -298,8 +298,12 @@ public class QuerySchema implements Serializable { QueryEntity entity = ((List<QueryEntity>)entities).get(targetIdx); - for (String field : op0.columns()) - entity.getFields().remove(field); + for (String field : op0.columns()) { + boolean rmv = QueryUtils.removeField(entity, field); + + assert rmv || op0.ifExists() : "Invalid operation state [removed=" + rmv + + ", ifExists=" + op0.ifExists() + ']'; + } } } } diff --git a/modules/core/src/main/java/org/apache/ignite/internal/processors/query/QueryUtils.java b/modules/core/src/main/java/org/apache/ignite/internal/processors/query/QueryUtils.java index da9279d..de0f743 100644 --- a/modules/core/src/main/java/org/apache/ignite/internal/processors/query/QueryUtils.java +++ b/modules/core/src/main/java/org/apache/ignite/internal/processors/query/QueryUtils.java @@ -1547,6 +1547,35 @@ public class QueryUtils { } /** + * Get field name by alias. + * + * @param entity Query entity. + * @param alias Filed's alias. + * @return Field name. + */ + public static String fieldNameByAlias(QueryEntity entity, String alias) { + if (!F.isEmpty(entity.getAliases())) { + for (Map.Entry<String, String> aliasEntry : entity.getAliases().entrySet()) { + if (F.eq(aliasEntry.getValue(), alias)) + return aliasEntry.getKey(); + } + } + + return alias; + } + + /** + * Remove field by alias. + * + * @param entity Query entity. + * @param alias Filed's alias. + * @return {@code true} if the field is removed. Otherwise returns {@code false}. + */ + public static boolean removeField(QueryEntity entity, String alias) { + return entity.getFields().remove(fieldNameByAlias(entity, alias)) != null; + } + + /** * Private constructor. */ private QueryUtils() {