This is an automated email from the ASF dual-hosted git repository. alexpl pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/ignite-extensions.git
The following commit(s) were added to refs/heads/master by this push: new 159a715 IGNITE-17046 Indexes refactoring (classes moved from ignite-indexing to the ignite-core module) - Fixes #159. 159a715 is described below commit 159a71520329039f82da5a9bab87b26bf0f9b00e Author: Aleksey Plekhanov <plehanov.a...@gmail.com> AuthorDate: Fri Jul 8 14:59:57 2022 +0500 IGNITE-17046 Indexes refactoring (classes moved from ignite-indexing to the ignite-core module) - Fixes #159. Signed-off-by: Aleksey Plekhanov <plehanov.a...@gmail.com> --- .../query/h2/opt/GeoSpatialClientIndex.java | 2 +- .../query/h2/opt/GeoSpatialIndexDefinition.java | 20 ++++++++++++++--- .../query/h2/opt/GeoSpatialIndexFactory.java | 25 +++++++++------------- .../query/h2/opt/GeoSpatialIndexImpl.java | 8 +++---- .../processors/query/h2/opt/GeoSpatialUtils.java | 18 ++++++++-------- .../processors/query/h2/opt/GeometryIndexKey.java | 6 +++--- .../query/h2/opt/GridH2SpatialClientIndex.java | 2 +- .../query/h2/opt/GridH2SpatialIndex.java | 7 +++--- 8 files changed, 49 insertions(+), 39 deletions(-) diff --git a/modules/geospatial-ext/geospatial/src/main/java/org/apache/ignite/internal/processors/query/h2/opt/GeoSpatialClientIndex.java b/modules/geospatial-ext/geospatial/src/main/java/org/apache/ignite/internal/processors/query/h2/opt/GeoSpatialClientIndex.java index 847ed88..b643703 100644 --- a/modules/geospatial-ext/geospatial/src/main/java/org/apache/ignite/internal/processors/query/h2/opt/GeoSpatialClientIndex.java +++ b/modules/geospatial-ext/geospatial/src/main/java/org/apache/ignite/internal/processors/query/h2/opt/GeoSpatialClientIndex.java @@ -20,7 +20,7 @@ package org.apache.ignite.internal.processors.query.h2.opt; import java.util.List; import java.util.UUID; import org.apache.ignite.internal.cache.query.index.sorted.IndexRow; -import org.apache.ignite.internal.processors.query.h2.index.client.AbstractClientIndex; +import org.apache.ignite.internal.cache.query.index.sorted.client.AbstractClientIndex; import org.apache.ignite.internal.util.lang.GridCursor; import org.h2.table.IndexColumn; import org.h2.table.TableFilter; diff --git a/modules/geospatial-ext/geospatial/src/main/java/org/apache/ignite/internal/processors/query/h2/opt/GeoSpatialIndexDefinition.java b/modules/geospatial-ext/geospatial/src/main/java/org/apache/ignite/internal/processors/query/h2/opt/GeoSpatialIndexDefinition.java index 83c6ed5..db87ff6 100644 --- a/modules/geospatial-ext/geospatial/src/main/java/org/apache/ignite/internal/processors/query/h2/opt/GeoSpatialIndexDefinition.java +++ b/modules/geospatial-ext/geospatial/src/main/java/org/apache/ignite/internal/processors/query/h2/opt/GeoSpatialIndexDefinition.java @@ -21,12 +21,15 @@ import java.util.LinkedHashMap; import org.apache.ignite.internal.cache.query.index.IndexDefinition; import org.apache.ignite.internal.cache.query.index.IndexName; import org.apache.ignite.internal.cache.query.index.sorted.IndexKeyDefinition; -import org.apache.ignite.internal.processors.query.h2.index.QueryIndexRowHandler; +import org.apache.ignite.internal.cache.query.index.sorted.QueryIndexRowHandler; /** * Definition of geo spatial index. */ public class GeoSpatialIndexDefinition implements IndexDefinition { + /** */ + private final GridH2Table tbl; + /** */ private final QueryIndexRowHandler rowHnd; @@ -40,8 +43,14 @@ public class GeoSpatialIndexDefinition implements IndexDefinition { private final IndexName idxName; /** */ - public GeoSpatialIndexDefinition(IndexName idxName, LinkedHashMap<String, IndexKeyDefinition> keyDefs, - QueryIndexRowHandler rowHnd, int segmentsCnt) { + public GeoSpatialIndexDefinition( + GridH2Table tbl, + IndexName idxName, + LinkedHashMap<String, IndexKeyDefinition> keyDefs, + QueryIndexRowHandler rowHnd, + int segmentsCnt + ) { + this.tbl = tbl; this.idxName = idxName; this.rowHnd = rowHnd; this.keyDefs = keyDefs; @@ -58,6 +67,11 @@ public class GeoSpatialIndexDefinition implements IndexDefinition { return segmentsCnt; } + /** */ + public GridH2Table getTable() { + return tbl; + } + /** {@inheritDoc} */ @Override public IndexName idxName() { return idxName; diff --git a/modules/geospatial-ext/geospatial/src/main/java/org/apache/ignite/internal/processors/query/h2/opt/GeoSpatialIndexFactory.java b/modules/geospatial-ext/geospatial/src/main/java/org/apache/ignite/internal/processors/query/h2/opt/GeoSpatialIndexFactory.java index f9223a2..03df8e9 100644 --- a/modules/geospatial-ext/geospatial/src/main/java/org/apache/ignite/internal/processors/query/h2/opt/GeoSpatialIndexFactory.java +++ b/modules/geospatial-ext/geospatial/src/main/java/org/apache/ignite/internal/processors/query/h2/opt/GeoSpatialIndexFactory.java @@ -22,11 +22,11 @@ import org.apache.ignite.IgniteException; import org.apache.ignite.internal.cache.query.index.Index; import org.apache.ignite.internal.cache.query.index.IndexDefinition; import org.apache.ignite.internal.cache.query.index.IndexFactory; +import org.apache.ignite.internal.cache.query.index.SortOrder; +import org.apache.ignite.internal.cache.query.index.sorted.IndexKeyDefinition; +import org.apache.ignite.internal.cache.query.index.sorted.IndexKeyType; import org.apache.ignite.internal.processors.cache.GridCacheContext; import org.h2.message.DbException; -import org.h2.result.SortOrder; -import org.h2.table.IndexColumn; -import org.h2.value.Value; import org.jetbrains.annotations.Nullable; /** @@ -41,24 +41,19 @@ public class GeoSpatialIndexFactory implements IndexFactory { GeoSpatialIndexDefinition def = (GeoSpatialIndexDefinition)definition; try { - List<IndexColumn> cols = def.rowHandler().getH2IdxColumns(); + List<IndexKeyDefinition> keyDefs = def.rowHandler().indexKeyDefinitions(); - if (cols.size() > 1) + if (keyDefs.size() > 1) throw DbException.getUnsupportedException("can only do one column"); - if ((cols.get(0).sortType & SortOrder.DESCENDING) != 0) + if ((keyDefs.get(0).order().sortOrder() == SortOrder.DESC)) throw DbException.getUnsupportedException("cannot do descending"); - if ((cols.get(0).sortType & SortOrder.NULLS_FIRST) != 0) - throw DbException.getUnsupportedException("cannot do nulls first"); + if (keyDefs.get(0).order().nullsOrder() != null) + throw DbException.getUnsupportedException("cannot do nulls ordering"); - if ((cols.get(0).sortType & SortOrder.NULLS_LAST) != 0) - throw DbException.getUnsupportedException("cannot do nulls last"); - - if (cols.get(0).column.getType() != Value.GEOMETRY) { - throw DbException.getUnsupportedException("spatial index on non-geometry column, " + - cols.get(0).column.getCreateSQL()); - } + if (keyDefs.get(0).idxType() != IndexKeyType.GEOMETRY) + throw DbException.getUnsupportedException("spatial index on non-geometry column"); return new GeoSpatialIndexImpl(cctx, def); } diff --git a/modules/geospatial-ext/geospatial/src/main/java/org/apache/ignite/internal/processors/query/h2/opt/GeoSpatialIndexImpl.java b/modules/geospatial-ext/geospatial/src/main/java/org/apache/ignite/internal/processors/query/h2/opt/GeoSpatialIndexImpl.java index a4bf9b4..0c66ab5 100644 --- a/modules/geospatial-ext/geospatial/src/main/java/org/apache/ignite/internal/processors/query/h2/opt/GeoSpatialIndexImpl.java +++ b/modules/geospatial-ext/geospatial/src/main/java/org/apache/ignite/internal/processors/query/h2/opt/GeoSpatialIndexImpl.java @@ -105,7 +105,7 @@ public class GeoSpatialIndexImpl extends AbstractIndex implements GeoSpatialInde /** */ IndexLookupBatch createLookupBatch(TableFilter[] filters, int filter) { - GridH2Table table = def.rowHandler().getTable(); + GridH2Table table = def.getTable(); if (table.isPartitioned()) { assert filter > 0; // Lookup batch will not be created for the first table filter. @@ -187,7 +187,7 @@ public class GeoSpatialIndexImpl extends AbstractIndex implements GeoSpatialInde private boolean put(CacheDataRow row) { checkClosed(); - Object key = def.rowHandler().key(row); + Object key = def.rowHandler().cacheKey(row); assert key != null; @@ -220,7 +220,7 @@ public class GeoSpatialIndexImpl extends AbstractIndex implements GeoSpatialInde private boolean remove(CacheDataRow row) { checkClosed(); - Object key = def.rowHandler().key(row); + Object key = def.rowHandler().cacheKey(row); assert key != null; @@ -299,7 +299,7 @@ public class GeoSpatialIndexImpl extends AbstractIndex implements GeoSpatialInde qryFilter = qctx.filter(); IndexingQueryCacheFilter qryCacheFilter = qryFilter != null ? - qryFilter.forCache(def.rowHandler().getTable().cacheName()) : null; + qryFilter.forCache(def.getTable().cacheName()) : null; List<IndexRow> rows = new ArrayList<>(); diff --git a/modules/geospatial-ext/geospatial/src/main/java/org/apache/ignite/internal/processors/query/h2/opt/GeoSpatialUtils.java b/modules/geospatial-ext/geospatial/src/main/java/org/apache/ignite/internal/processors/query/h2/opt/GeoSpatialUtils.java index bb09b98..68cd2fa 100644 --- a/modules/geospatial-ext/geospatial/src/main/java/org/apache/ignite/internal/processors/query/h2/opt/GeoSpatialUtils.java +++ b/modules/geospatial-ext/geospatial/src/main/java/org/apache/ignite/internal/processors/query/h2/opt/GeoSpatialUtils.java @@ -24,13 +24,13 @@ import org.apache.ignite.internal.cache.query.index.Index; import org.apache.ignite.internal.cache.query.index.IndexDefinition; import org.apache.ignite.internal.cache.query.index.IndexName; import org.apache.ignite.internal.cache.query.index.sorted.IndexKeyDefinition; +import org.apache.ignite.internal.cache.query.index.sorted.IndexKeyType; import org.apache.ignite.internal.cache.query.index.sorted.IndexKeyTypeSettings; -import org.apache.ignite.internal.cache.query.index.sorted.IndexKeyTypes; +import org.apache.ignite.internal.cache.query.index.sorted.QueryIndexRowHandler; import org.apache.ignite.internal.cache.query.index.sorted.inline.InlineIndexKeyType; import org.apache.ignite.internal.cache.query.index.sorted.inline.InlineIndexKeyTypeRegistry; import org.apache.ignite.internal.cache.query.index.sorted.keys.IndexKeyFactory; -import org.apache.ignite.internal.processors.query.h2.index.QueryIndexKeyDefinitionProvider; -import org.apache.ignite.internal.processors.query.h2.index.QueryIndexRowHandler; +import org.apache.ignite.internal.processors.query.h2.H2Utils; import org.h2.table.IndexColumn; import org.locationtech.jts.geom.Geometry; @@ -42,7 +42,7 @@ public class GeoSpatialUtils { private static final IndexKeyTypeSettings DUMMY_SETTINGS = new IndexKeyTypeSettings(); static { - IndexKeyFactory.register(IndexKeyTypes.GEOMETRY, k -> new GeometryIndexKey((Geometry)k)); + IndexKeyFactory.register(IndexKeyType.GEOMETRY, k -> new GeometryIndexKey((Geometry)k)); } /** */ @@ -50,7 +50,7 @@ public class GeoSpatialUtils { try { IndexName name = new IndexName(tbl.cacheName(), tbl.getSchema().getName(), tbl.getName(), idxName); - LinkedHashMap<String, IndexKeyDefinition> keyDefs = new QueryIndexKeyDefinitionProvider(tbl, cols).keyDefinitions(); + LinkedHashMap<String, IndexKeyDefinition> keyDefs = H2Utils.columnsToKeyDefinitions(tbl, cols); if (tbl.cacheInfo().affinityNode()) return createIndex(tbl, name, keyDefs, cols); @@ -71,15 +71,15 @@ public class GeoSpatialUtils { ) { List<InlineIndexKeyType> idxKeyTypes = InlineIndexKeyTypeRegistry.types(keyDefs.values(), DUMMY_SETTINGS); - QueryIndexRowHandler rowHnd = new QueryIndexRowHandler(tbl, cols, keyDefs, idxKeyTypes, DUMMY_SETTINGS); + QueryIndexRowHandler rowHnd = new QueryIndexRowHandler(tbl.rowDescriptor(), keyDefs, idxKeyTypes, DUMMY_SETTINGS); - final int segments = tbl.rowDescriptor().cacheInfo().config().getQueryParallelism(); + final int segments = tbl.cacheInfo().config().getQueryParallelism(); - IndexDefinition def = new GeoSpatialIndexDefinition(name, keyDefs, rowHnd, segments); + IndexDefinition def = new GeoSpatialIndexDefinition(tbl, name, keyDefs, rowHnd, segments); Index idx = tbl.idxProc().createIndex(tbl.cacheContext(), GeoSpatialIndexFactory.INSTANCE, def); - return new GridH2SpatialIndex(idx.unwrap(GeoSpatialIndexImpl.class)); + return new GridH2SpatialIndex(tbl, cols, idx.unwrap(GeoSpatialIndexImpl.class)); } /** Creates index for client Ignite nodes. */ diff --git a/modules/geospatial-ext/geospatial/src/main/java/org/apache/ignite/internal/processors/query/h2/opt/GeometryIndexKey.java b/modules/geospatial-ext/geospatial/src/main/java/org/apache/ignite/internal/processors/query/h2/opt/GeometryIndexKey.java index 0532d0c..52b6a81 100644 --- a/modules/geospatial-ext/geospatial/src/main/java/org/apache/ignite/internal/processors/query/h2/opt/GeometryIndexKey.java +++ b/modules/geospatial-ext/geospatial/src/main/java/org/apache/ignite/internal/processors/query/h2/opt/GeometryIndexKey.java @@ -17,7 +17,7 @@ package org.apache.ignite.internal.processors.query.h2.opt; -import org.apache.ignite.internal.cache.query.index.sorted.IndexKeyTypes; +import org.apache.ignite.internal.cache.query.index.sorted.IndexKeyType; import org.apache.ignite.internal.cache.query.index.sorted.keys.IndexKey; import org.h2.value.ValueGeometry; import org.locationtech.jts.geom.Geometry; @@ -38,8 +38,8 @@ public class GeometryIndexKey implements IndexKey { } /** {@inheritDoc} */ - @Override public int type() { - return IndexKeyTypes.GEOMETRY; + @Override public IndexKeyType type() { + return IndexKeyType.GEOMETRY; } /** {@inheritDoc} */ diff --git a/modules/geospatial-ext/geospatial/src/main/java/org/apache/ignite/internal/processors/query/h2/opt/GridH2SpatialClientIndex.java b/modules/geospatial-ext/geospatial/src/main/java/org/apache/ignite/internal/processors/query/h2/opt/GridH2SpatialClientIndex.java index 5712fef..fd7d197 100644 --- a/modules/geospatial-ext/geospatial/src/main/java/org/apache/ignite/internal/processors/query/h2/opt/GridH2SpatialClientIndex.java +++ b/modules/geospatial-ext/geospatial/src/main/java/org/apache/ignite/internal/processors/query/h2/opt/GridH2SpatialClientIndex.java @@ -17,7 +17,7 @@ package org.apache.ignite.internal.processors.query.h2.opt; -import org.apache.ignite.internal.processors.query.h2.index.client.AbstractClientIndex; +import org.apache.ignite.internal.cache.query.index.sorted.client.AbstractClientIndex; import org.apache.ignite.spi.indexing.IndexingQueryCacheFilter; import org.h2.engine.Session; import org.h2.index.Cursor; diff --git a/modules/geospatial-ext/geospatial/src/main/java/org/apache/ignite/internal/processors/query/h2/opt/GridH2SpatialIndex.java b/modules/geospatial-ext/geospatial/src/main/java/org/apache/ignite/internal/processors/query/h2/opt/GridH2SpatialIndex.java index 6132323..74d602b 100644 --- a/modules/geospatial-ext/geospatial/src/main/java/org/apache/ignite/internal/processors/query/h2/opt/GridH2SpatialIndex.java +++ b/modules/geospatial-ext/geospatial/src/main/java/org/apache/ignite/internal/processors/query/h2/opt/GridH2SpatialIndex.java @@ -17,6 +17,7 @@ package org.apache.ignite.internal.processors.query.h2.opt; +import java.util.List; import org.apache.ignite.internal.cache.query.index.sorted.IndexRow; import org.apache.ignite.internal.cache.query.index.sorted.IndexValueCursor; import org.apache.ignite.internal.processors.query.h2.H2Cursor; @@ -42,10 +43,10 @@ public class GridH2SpatialIndex extends GridH2SpatialBaseIndex { private final GeoSpatialIndexImpl delegate; /** */ - public GridH2SpatialIndex(GeoSpatialIndexImpl idx) { - super(idx.def.rowHandler().getTable(), + public GridH2SpatialIndex(GridH2Table tbl, List<IndexColumn> cols, GeoSpatialIndexImpl idx) { + super(tbl, idx.def.idxName().idxName(), - idx.def.rowHandler().getH2IdxColumns().toArray(new IndexColumn[0]), + cols.toArray(new IndexColumn[0]), IndexType.createNonUnique(false, false, true)); delegate = idx;