Repository: ignite Updated Branches: refs/heads/ignite-5054-splitter-2 [created] 1455e5327
WIP. Project: http://git-wip-us.apache.org/repos/asf/ignite/repo Commit: http://git-wip-us.apache.org/repos/asf/ignite/commit/aa90badd Tree: http://git-wip-us.apache.org/repos/asf/ignite/tree/aa90badd Diff: http://git-wip-us.apache.org/repos/asf/ignite/diff/aa90badd Branch: refs/heads/ignite-5054-splitter-2 Commit: aa90badd2278fa74fcc1d7a4f66dda740bfc2fc9 Parents: 00ff656 Author: devozerov <voze...@gridgain.com> Authored: Tue May 16 11:04:27 2017 +0300 Committer: devozerov <voze...@gridgain.com> Committed: Tue May 16 11:04:27 2017 +0300 ---------------------------------------------------------------------- .../cache/query/GridCacheTwoStepQuery.java | 15 ++-- .../processors/cache/query/QueryTable.java | 83 ++++++++++++++++++++ .../processors/query/h2/IgniteH2Indexing.java | 12 ++- .../query/h2/sql/GridSqlQuerySplitter.java | 21 ++--- 4 files changed, 109 insertions(+), 22 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/ignite/blob/aa90badd/modules/indexing/src/main/java/org/apache/ignite/internal/processors/cache/query/GridCacheTwoStepQuery.java ---------------------------------------------------------------------- diff --git a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/cache/query/GridCacheTwoStepQuery.java b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/cache/query/GridCacheTwoStepQuery.java index 0e31dc0..2b723b3 100644 --- a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/cache/query/GridCacheTwoStepQuery.java +++ b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/cache/query/GridCacheTwoStepQuery.java @@ -55,7 +55,7 @@ public class GridCacheTwoStepQuery { private Set<String> schemas; /** */ - private Set<String> tbls; + private Set<QueryTable> tbls; /** */ private boolean distributedJoins; @@ -74,12 +74,10 @@ public class GridCacheTwoStepQuery { /** * @param originalSql Original query SQL. - * @param schemas Schema names in query. * @param tbls Tables in query. */ - public GridCacheTwoStepQuery(String originalSql, Set<String> schemas, Set<String> tbls) { + public GridCacheTwoStepQuery(String originalSql, Set<QueryTable> tbls) { this.originalSql = originalSql; - this.schemas = schemas; this.tbls = tbls; } @@ -262,7 +260,7 @@ public class GridCacheTwoStepQuery { public GridCacheTwoStepQuery copy() { assert !explain; - GridCacheTwoStepQuery cp = new GridCacheTwoStepQuery(originalSql, schemas, tbls); + GridCacheTwoStepQuery cp = new GridCacheTwoStepQuery(originalSql, tbls); cp.caches = caches; cp.extraCaches = extraCaches; @@ -279,6 +277,13 @@ public class GridCacheTwoStepQuery { } /** + * @return Nuumber of tables. + */ + public int tablesCount() { + return tbls.size(); + } + + /** * @return Tables. */ public Set<String> tables() { http://git-wip-us.apache.org/repos/asf/ignite/blob/aa90badd/modules/indexing/src/main/java/org/apache/ignite/internal/processors/cache/query/QueryTable.java ---------------------------------------------------------------------- diff --git a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/cache/query/QueryTable.java b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/cache/query/QueryTable.java new file mode 100644 index 0000000..81a6446 --- /dev/null +++ b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/cache/query/QueryTable.java @@ -0,0 +1,83 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.ignite.internal.processors.cache.query; + +import org.apache.ignite.internal.util.typedef.F; +import org.apache.ignite.internal.util.typedef.internal.S; + +import java.io.Serializable; + +/** + * Query table descriptor. + */ +public class QueryTable implements Serializable { + /** */ + private static final long serialVersionUID = 0L; + + /** Schema. */ + private final String schema; + + /** Table. */ + private final String tbl; + + /** + * Constructor. + * + * @param schema Schema. + * @param tbl Table. + */ + public QueryTable(String schema, String tbl) { + this.schema = schema; + this.tbl = tbl; + } + + /** + * @return Schema. + */ + public String schema() { + return schema; + } + + /** + * @return Table. + */ + public String table() { + return tbl; + } + + /** {@inheritDoc} */ + @Override public int hashCode() { + return 31 * (schema != null ? schema.hashCode() : 0) + (tbl != null ? tbl.hashCode() : 0); + } + + /** {@inheritDoc} */ + @Override public boolean equals(Object obj) { + if (obj instanceof QueryTable) { + QueryTable other = (QueryTable)obj; + + return F.eq(tbl, other.tbl) && F.eq(schema, other.schema); + } + + return super.equals(obj); + } + + /** {@inheritDoc} */ + @Override public String toString() { + return S.toString(QueryTable.class, this); + } +} http://git-wip-us.apache.org/repos/asf/ignite/blob/aa90badd/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/IgniteH2Indexing.java ---------------------------------------------------------------------- diff --git a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/IgniteH2Indexing.java b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/IgniteH2Indexing.java index 1c49fc7..4de5adc 100644 --- a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/IgniteH2Indexing.java +++ b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/IgniteH2Indexing.java @@ -1676,9 +1676,15 @@ public class IgniteH2Indexing implements GridQueryIndexing { List<Integer> extraCaches = null; // Setup spaces from schemas. - if (!twoStepQry.schemas().isEmpty()) { - Collection<String> spaces = new ArrayList<>(twoStepQry.schemas().size()); - caches = new ArrayList<>(twoStepQry.schemas().size() + 1); + assert twoStepQry != null; + + int tblCnt = twoStepQry.tablesCount(); + + if (tblCnt > 0) { + Collection<String> spaces = new ArrayList<>(tblCnt); + + caches = new ArrayList<>(tblCnt + 1); + caches.add(cctx.cacheId()); for (String schema : twoStepQry.schemas()) { http://git-wip-us.apache.org/repos/asf/ignite/blob/aa90badd/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/sql/GridSqlQuerySplitter.java ---------------------------------------------------------------------- diff --git a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/sql/GridSqlQuerySplitter.java b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/sql/GridSqlQuerySplitter.java index 26c6b08..b557e35 100644 --- a/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/sql/GridSqlQuerySplitter.java +++ b/modules/indexing/src/main/java/org/apache/ignite/internal/processors/query/h2/sql/GridSqlQuerySplitter.java @@ -36,6 +36,7 @@ import org.apache.ignite.IgniteCheckedException; import org.apache.ignite.IgniteException; import org.apache.ignite.internal.processors.cache.query.GridCacheSqlQuery; import org.apache.ignite.internal.processors.cache.query.GridCacheTwoStepQuery; +import org.apache.ignite.internal.processors.cache.query.QueryTable; import org.apache.ignite.internal.processors.query.h2.IgniteH2Indexing; import org.apache.ignite.internal.util.tostring.GridToStringInclude; import org.apache.ignite.internal.util.typedef.F; @@ -93,11 +94,8 @@ public class GridSqlQuerySplitter { /** */ private int splitId = -1; // The first one will be 0. - /** */ - private Set<String> schemas = new HashSet<>(); - - /** */ - private Set<String> tbls = new HashSet<>(); + /** Query tables. */ + private Set<QueryTable> tbls = new HashSet<>(); /** */ private boolean rdcQrySimple; @@ -224,7 +222,7 @@ public class GridSqlQuerySplitter { } // Setup resulting two step query and return it. - GridCacheTwoStepQuery twoStepQry = new GridCacheTwoStepQuery(originalSql, splitter.schemas, splitter.tbls); + GridCacheTwoStepQuery twoStepQry = new GridCacheTwoStepQuery(originalSql, splitter.tbls); twoStepQry.reduceQuery(splitter.rdcSqlQry); @@ -1500,15 +1498,10 @@ public class GridSqlQuerySplitter { if (from instanceof GridSqlTable) { GridSqlTable tbl = (GridSqlTable)from; - String schema = tbl.schema(); - - boolean addSchema = tbls == null; - - if (tbls != null) - addSchema = tbls.add(tbl.dataTable().identifier()); + String schemaName = tbl.schema(); + String tblName = tbl.dataTable().identifier(); - if (addSchema && schema != null && schemas != null) - schemas.add(schema); + tbls.add(new QueryTable(schemaName, tblName)); // In case of alias parent we need to replace the alias itself. if (!prntAlias)