Skip to content

Commit f46e7d4

Browse files
committed
IGNITE-17190 Review fixes
1 parent ee5e7a1 commit f46e7d4

File tree

54 files changed

+822
-1245
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+822
-1245
lines changed

modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/exec/ddl/SchemaManager.java

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@
1717

1818
package org.apache.ignite.internal.processors.query.calcite.exec.ddl;
1919

20-
import java.util.List;
21-
import java.util.function.BiConsumer;
2220
import java.util.function.Supplier;
2321
import org.apache.calcite.schema.SchemaPlus;
2422
import org.apache.calcite.schema.Table;
@@ -27,7 +25,6 @@
2725
import org.apache.ignite.internal.processors.query.GridQueryTypeDescriptor;
2826
import org.apache.ignite.internal.processors.query.calcite.schema.IgniteCacheTable;
2927
import org.apache.ignite.internal.processors.query.calcite.schema.IgniteTable;
30-
import org.jetbrains.annotations.NotNull;
3128

3229
/**
3330
* Schema manager.
@@ -85,24 +82,4 @@ class SchemaManager implements GridQuerySchemaManager {
8582

8683
return cachetbl == null ? null : (GridCacheContextInfo<K, V>)cachetbl.descriptor().cacheInfo();
8784
}
88-
89-
/** {@inheritDoc} */
90-
@Override public void registerDropColumnsListener(@NotNull BiConsumer<GridQueryTypeDescriptor, List<String>> lsnr) {
91-
92-
}
93-
94-
/** {@inheritDoc} */
95-
@Override public void unregisterDropColumnsListener(@NotNull BiConsumer<GridQueryTypeDescriptor, List<String>> lsnr) {
96-
97-
}
98-
99-
/** {@inheritDoc} */
100-
@Override public void registerDropTableListener(@NotNull BiConsumer<String, String> lsnr) {
101-
102-
}
103-
104-
/** {@inheritDoc} */
105-
@Override public void unregisterDropTableListener(@NotNull BiConsumer<String, String> lsnr) {
106-
107-
}
10885
}

modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/metadata/IgniteMdSelectivity.java

Lines changed: 8 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,7 @@
1818
package org.apache.ignite.internal.processors.query.calcite.metadata;
1919

2020
import java.math.BigDecimal;
21-
import java.math.BigInteger;
2221
import java.math.MathContext;
23-
import java.sql.Timestamp;
2422
import java.util.HashMap;
2523
import java.util.List;
2624
import java.util.Map;
@@ -49,9 +47,6 @@
4947
import org.apache.calcite.util.DateString;
5048
import org.apache.calcite.util.TimeString;
5149
import org.apache.calcite.util.TimestampString;
52-
import org.apache.ignite.internal.cache.query.index.sorted.keys.DateIndexKey;
53-
import org.apache.ignite.internal.cache.query.index.sorted.keys.IndexKey;
54-
import org.apache.ignite.internal.cache.query.index.sorted.keys.TimeIndexKey;
5550
import org.apache.ignite.internal.processors.query.QueryUtils;
5651
import org.apache.ignite.internal.processors.query.calcite.rel.IgniteExchange;
5752
import org.apache.ignite.internal.processors.query.calcite.rel.IgniteHashIndexSpool;
@@ -65,8 +60,6 @@
6560
import org.apache.ignite.internal.processors.query.stat.ColumnStatistics;
6661
import org.jetbrains.annotations.Nullable;
6762

68-
import static org.apache.ignite.internal.cache.query.index.sorted.IndexKeyType.BOOLEAN;
69-
7063
/** */
7164
public class IgniteMdSelectivity extends RelMdSelectivity {
7265
/** Default selectivity for IS NULL conditions. */
@@ -171,74 +164,6 @@ private BigDecimal toComparableValue(RexLiteral val) {
171164
return null;
172165
}
173166

174-
/**
175-
* Convert specified value into comparable type: BigDecimal,
176-
*
177-
* @param val Value to convert to comparable form.
178-
* @return Comparable form of value.
179-
*/
180-
private BigDecimal toComparableValue(IndexKey val) {
181-
if (val == null)
182-
return null;
183-
184-
switch (val.type()) {
185-
case NULL:
186-
throw new IllegalArgumentException("Can't compare null values");
187-
188-
case BOOLEAN:
189-
return ((Boolean)val.key()) ? BigDecimal.ONE : BigDecimal.ZERO;
190-
191-
case BYTE:
192-
return new BigDecimal((Byte)val.key());
193-
194-
case SHORT:
195-
return new BigDecimal((Short)val.key());
196-
197-
case INT:
198-
return new BigDecimal((Integer)val.key());
199-
200-
case LONG:
201-
return new BigDecimal((Long)val.key());
202-
203-
case DECIMAL:
204-
return (BigDecimal)val.key();
205-
206-
case DOUBLE:
207-
return BigDecimal.valueOf((Double)val.key());
208-
209-
case FLOAT:
210-
return BigDecimal.valueOf((Float)val.key());
211-
212-
case DATE:
213-
return BigDecimal.valueOf(((DateIndexKey)val).dateValue());
214-
215-
case TIME:
216-
return BigDecimal.valueOf(((TimeIndexKey)val).nanos());
217-
218-
case TIMESTAMP:
219-
return BigDecimal.valueOf(((Timestamp)val.key()).getTime());
220-
221-
case BYTES:
222-
BigInteger bigInteger = new BigInteger(1, (byte[])val.key());
223-
return new BigDecimal(bigInteger);
224-
225-
case STRING:
226-
case STRING_FIXED:
227-
case STRING_IGNORECASE:
228-
case ARRAY:
229-
case JAVA_OBJECT:
230-
case GEOMETRY:
231-
return null;
232-
233-
case UUID:
234-
BigInteger bigInt = new BigInteger(1, val.bytes());
235-
return new BigDecimal(bigInt);
236-
237-
default:
238-
throw new IllegalStateException("Unsupported H2 type: " + val.type());
239-
}
240-
}
241-
242167
/**
243168
* Predicate based selectivity for table. Estimate condition on each column taking in comparison it's statistics.
244169
*
@@ -404,11 +329,12 @@ private double estimateRefSelectivity(ProjectableFilterableTableScan rel, RelMet
404329
return res;
405330
}
406331

407-
if (colStat.max() == null || colStat.max().type() != BOOLEAN)
332+
if (colStat.max() == null || colStat.max().compareTo(BigDecimal.ONE) != 0
333+
|| colStat.max().compareTo(BigDecimal.ZERO) != 0)
408334
return res;
409335

410-
Boolean min = (Boolean)colStat.min().key();
411-
Boolean max = (Boolean)colStat.max().key();
336+
Boolean min = colStat.min().compareTo(BigDecimal.ONE) == 0;
337+
Boolean max = colStat.max().compareTo(BigDecimal.ONE) == 0;
412338

413339
if (!max)
414340
return 0;
@@ -454,8 +380,8 @@ private double estimateSelectivity(ColumnStatistics colStat, BigDecimal val, Rex
454380

455381
SqlOperator op = ((RexCall)pred).op;
456382

457-
BigDecimal min = toComparableValue(colStat.min());
458-
BigDecimal max = toComparableValue(colStat.max());
383+
BigDecimal min = colStat.min();
384+
BigDecimal max = colStat.max();
459385
BigDecimal total = (min == null || max == null) ? null : max.subtract(min).abs();
460386

461387
if (total == null)
@@ -541,13 +467,13 @@ private double estimateEqualsSelectivity(ColumnStatistics colStat, RexCall pred)
541467
return guessSelectivity(pred);
542468

543469
if (colStat.min() != null) {
544-
BigDecimal minComparable = toComparableValue(colStat.min());
470+
BigDecimal minComparable = colStat.min();
545471
if (minComparable != null && minComparable.compareTo(comparableVal) > 0)
546472
return 0.;
547473
}
548474

549475
if (colStat.max() != null) {
550-
BigDecimal maxComparable = toComparableValue(colStat.max());
476+
BigDecimal maxComparable = colStat.max();
551477
if (maxComparable != null && maxComparable.compareTo(comparableVal) < 0)
552478
return 0.;
553479
}

modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/prepare/QueryPlanCacheImpl.java

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,15 @@
1818
package org.apache.ignite.internal.processors.query.calcite.prepare;
1919

2020
import java.lang.reflect.Method;
21+
import java.util.List;
2122
import java.util.Map;
2223
import java.util.function.Supplier;
2324
import org.apache.ignite.internal.GridKernalContext;
2425
import org.apache.ignite.internal.cache.query.index.Index;
2526
import org.apache.ignite.internal.processors.cache.GridCacheContextInfo;
2627
import org.apache.ignite.internal.processors.query.GridQueryIndexDescriptor;
2728
import org.apache.ignite.internal.processors.query.GridQueryTypeDescriptor;
29+
import org.apache.ignite.internal.processors.query.QueryField;
2830
import org.apache.ignite.internal.processors.query.calcite.util.AbstractService;
2931
import org.apache.ignite.internal.processors.query.schema.SchemaChangeListener;
3032
import org.apache.ignite.internal.processors.subscription.GridInternalSubscriptionProcessor;
@@ -100,7 +102,12 @@ public void subscriptionProcessor(GridInternalSubscriptionProcessor subscription
100102
}
101103

102104
/** {@inheritDoc} */
103-
@Override public void onSqlTypeDropped(String schemaName, GridQueryTypeDescriptor typeDescriptor) {
105+
@Override public void onSqlTypeDropped(
106+
String schemaName,
107+
GridQueryTypeDescriptor typeDescriptor,
108+
boolean destroy,
109+
boolean clearIdx
110+
) {
104111
clear();
105112
}
106113

@@ -140,8 +147,24 @@ public void subscriptionProcessor(GridInternalSubscriptionProcessor subscription
140147
}
141148

142149
/** {@inheritDoc} */
143-
@Override public void onSqlTypeUpdated(String schemaName, GridQueryTypeDescriptor typeDesc,
144-
GridCacheContextInfo<?, ?> cacheInfo) {
150+
@Override public void onColumnsAdded(
151+
String schemaName,
152+
GridQueryTypeDescriptor typeDesc,
153+
GridCacheContextInfo<?, ?> cacheInfo,
154+
List<QueryField> cols,
155+
boolean ifColNotExists
156+
) {
157+
clear();
158+
}
159+
160+
/** {@inheritDoc} */
161+
@Override public void onColumnsDropped(
162+
String schemaName,
163+
GridQueryTypeDescriptor typeDesc,
164+
GridCacheContextInfo<?, ?> cacheInfo,
165+
List<String> cols,
166+
boolean ifColExists
167+
) {
145168
clear();
146169
}
147170

modules/calcite/src/main/java/org/apache/ignite/internal/processors/query/calcite/schema/SchemaHolderImpl.java

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
import org.apache.ignite.internal.processors.cache.GridCacheContextInfo;
3838
import org.apache.ignite.internal.processors.query.GridQueryIndexDescriptor;
3939
import org.apache.ignite.internal.processors.query.GridQueryTypeDescriptor;
40+
import org.apache.ignite.internal.processors.query.QueryField;
4041
import org.apache.ignite.internal.processors.query.calcite.exec.exp.IgniteScalarFunction;
4142
import org.apache.ignite.internal.processors.query.calcite.trait.TraitUtils;
4243
import org.apache.ignite.internal.processors.query.calcite.type.IgniteTypeFactory;
@@ -188,11 +189,25 @@ public void subscriptionProcessor(GridInternalSubscriptionProcessor subscription
188189
}
189190

190191
/** {@inheritDoc} */
191-
@Override public void onSqlTypeUpdated(
192+
@Override public void onColumnsAdded(
192193
String schemaName,
193194
GridQueryTypeDescriptor typeDesc,
194-
GridCacheContextInfo<?, ?> cacheInfo
195+
GridCacheContextInfo<?, ?> cacheInfo,
196+
List<QueryField> cols,
197+
boolean ifColNotExists
198+
) {
199+
onSqlTypeCreated(schemaName, typeDesc, cacheInfo);
200+
}
201+
202+
/** {@inheritDoc} */
203+
@Override public void onColumnsDropped(
204+
String schemaName,
205+
GridQueryTypeDescriptor typeDesc,
206+
GridCacheContextInfo<?, ?> cacheInfo,
207+
List<String> cols,
208+
boolean ifColExists
195209
) {
210+
196211
onSqlTypeCreated(schemaName, typeDesc, cacheInfo);
197212
}
198213

@@ -206,7 +221,9 @@ private static Object affinityIdentity(CacheConfiguration<?, ?> ccfg) {
206221
/** {@inheritDoc} */
207222
@Override public synchronized void onSqlTypeDropped(
208223
String schemaName,
209-
GridQueryTypeDescriptor typeDesc
224+
GridQueryTypeDescriptor typeDesc,
225+
boolean destroy,
226+
boolean clearIdx
210227
) {
211228
IgniteSchema schema = igniteSchemas.computeIfAbsent(schemaName, IgniteSchema::new);
212229

modules/calcite/src/test/java/org/apache/ignite/internal/processors/query/calcite/planner/StatisticsPlannerTest.java

Lines changed: 17 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -27,17 +27,6 @@
2727
import org.apache.calcite.rel.type.RelDataType;
2828
import org.apache.calcite.rel.type.RelDataTypeFactory;
2929
import org.apache.calcite.rel.type.RelDataTypeField;
30-
import org.apache.ignite.internal.cache.query.index.sorted.keys.BooleanIndexKey;
31-
import org.apache.ignite.internal.cache.query.index.sorted.keys.ByteIndexKey;
32-
import org.apache.ignite.internal.cache.query.index.sorted.keys.DateIndexKey;
33-
import org.apache.ignite.internal.cache.query.index.sorted.keys.DoubleIndexKey;
34-
import org.apache.ignite.internal.cache.query.index.sorted.keys.FloatIndexKey;
35-
import org.apache.ignite.internal.cache.query.index.sorted.keys.IntegerIndexKey;
36-
import org.apache.ignite.internal.cache.query.index.sorted.keys.LongIndexKey;
37-
import org.apache.ignite.internal.cache.query.index.sorted.keys.ShortIndexKey;
38-
import org.apache.ignite.internal.cache.query.index.sorted.keys.StringIndexKey;
39-
import org.apache.ignite.internal.cache.query.index.sorted.keys.TimeIndexKey;
40-
import org.apache.ignite.internal.cache.query.index.sorted.keys.TimestampIndexKey;
4130
import org.apache.ignite.internal.processors.query.calcite.rel.IgniteIndexScan;
4231
import org.apache.ignite.internal.processors.query.calcite.rel.IgniteRel;
4332
import org.apache.ignite.internal.processors.query.calcite.schema.CacheTableDescriptor;
@@ -51,6 +40,8 @@
5140
import org.junit.Before;
5241
import org.junit.Test;
5342

43+
import static org.apache.ignite.internal.processors.query.stat.StatisticsUtils.toDecimal;
44+
5445
/**
5546
* Statistic related simple tests.
5647
*/
@@ -150,40 +141,35 @@ public class StatisticsPlannerTest extends AbstractPlannerTest {
150141
tbl4.addIndex("TBL4_SHORT_LONG", 6, 7);
151142

152143
HashMap<String, ColumnStatistics> colStat1 = new HashMap<>();
153-
colStat1.put("T1C1INT", new ColumnStatistics(new IntegerIndexKey(1), new IntegerIndexKey(1000),
154-
0, 1000, t1rc, 4, null, 1, 0));
144+
colStat1.put("T1C1INT", new ColumnStatistics(toDecimal(1), toDecimal(1000), 0, 1000, t1rc, 4, null, 1, 0));
155145

156-
colStat1.put("T1C2STR", new ColumnStatistics(new StringIndexKey("A1"), new StringIndexKey("Z9"),
157-
100, 20, t1rc, 2, null, 1, 0));
146+
colStat1.put("T1C2STR", new ColumnStatistics(null, null, 100, 20, t1rc, 2, null, 1, 0));
158147

159-
colStat1.put("T1C3DBL", new ColumnStatistics(new DoubleIndexKey(0.01), new DoubleIndexKey(0.99),
160-
10, 1000, t1rc, 8, null, 1, 0));
148+
colStat1.put("T1C3DBL", new ColumnStatistics(toDecimal(0.01), toDecimal(0.99), 10, 1000, t1rc, 8, null, 1, 0));
161149

162-
colStat1.put("T1C4BYTE", new ColumnStatistics(new ByteIndexKey((byte)0), new ByteIndexKey((byte)255),
163-
10, 1000, t1rc, 8, null, 1, 0));
150+
colStat1.put("T1C4BYTE", new ColumnStatistics(toDecimal((byte)0), toDecimal((byte)255), 10, 1000, t1rc, 8, null,
151+
1, 0));
164152

165-
colStat1.put("T1C5BOOLEAN", new ColumnStatistics(new BooleanIndexKey(false), new BooleanIndexKey(true),
166-
0, 2, t1rc, 1, null, 1, 0));
153+
colStat1.put("T1C5BOOLEAN", new ColumnStatistics(toDecimal(false), toDecimal(true), 0, 2, t1rc, 1, null, 1, 0));
167154

168-
colStat1.put("T1C6CHARACTER", new ColumnStatistics(new StringIndexKey("A"), new StringIndexKey("Z"),
169-
10, 10, t1rc, 1, null, 1, 0));
155+
colStat1.put("T1C6CHARACTER", new ColumnStatistics(null, null, 10, 10, t1rc, 1, null, 1, 0));
170156

171-
colStat1.put("T1C7SHORT", new ColumnStatistics(new ShortIndexKey((short)1), new ShortIndexKey((short)5000),
157+
colStat1.put("T1C7SHORT", new ColumnStatistics(toDecimal((short)1), toDecimal((short)5000),
172158
110, 500, t1rc, 2, null, 1, 0));
173159

174-
colStat1.put("T1C8LONG", new ColumnStatistics(new LongIndexKey(1L), new LongIndexKey(100000L),
160+
colStat1.put("T1C8LONG", new ColumnStatistics(toDecimal(1L), toDecimal(100000L),
175161
10, 100000, t1rc, 8, null, 1, 0));
176162

177-
colStat1.put("T1C9FLOAT", new ColumnStatistics(new FloatIndexKey((float)0.1), new FloatIndexKey((float)0.9),
163+
colStat1.put("T1C9FLOAT", new ColumnStatistics(toDecimal((float)0.1), toDecimal((float)0.9),
178164
10, 1000, t1rc, 8, null, 1, 0));
179165

180-
colStat1.put("T1C10DATE", new ColumnStatistics(new DateIndexKey(MIN_DATE), new DateIndexKey(MAX_DATE),
166+
colStat1.put("T1C10DATE", new ColumnStatistics(toDecimal(MIN_DATE), toDecimal(MAX_DATE),
181167
20, 1000, t1rc, 8, null, 1, 0));
182168

183-
colStat1.put("T1C11TIME", new ColumnStatistics(new TimeIndexKey(MIN_TIME), new TimeIndexKey(MAX_TIME),
169+
colStat1.put("T1C11TIME", new ColumnStatistics(toDecimal(MIN_TIME), toDecimal(MAX_TIME),
184170
10, 1000, t1rc, 8, null, 1, 0));
185171

186-
colStat1.put("T1C12TIMESTAMP", new ColumnStatistics(new TimestampIndexKey(MIN_TIMESTAMP), new TimestampIndexKey(MAX_TIMESTAMP),
172+
colStat1.put("T1C12TIMESTAMP", new ColumnStatistics(toDecimal(MIN_TIMESTAMP), toDecimal(MAX_TIMESTAMP),
187173
20, 1000, t1rc, 8, null, 1, 0));
188174

189175
tbl1stat = new IgniteStatisticsImpl(new ObjectStatisticsImpl(1000, colStat1));
@@ -437,10 +423,9 @@ public void testIndexWithBetterSelectivityPreferred() throws Exception {
437423
int rowCnt = 10_000;
438424

439425
HashMap<String, ColumnStatistics> colStat1 = new HashMap<>();
440-
colStat1.put("T1C2STR", new ColumnStatistics(new StringIndexKey("A1"), new StringIndexKey("Z9"),
441-
0, 1, rowCnt, 2, null, 1, 0));
426+
colStat1.put("T1C2STR", new ColumnStatistics(null, null, 0, 1, rowCnt, 2, null, 1, 0));
442427

443-
colStat1.put("T1C7SHORT", new ColumnStatistics(new ShortIndexKey((short)1), new ShortIndexKey((short)5000),
428+
colStat1.put("T1C7SHORT", new ColumnStatistics(toDecimal((short)1), toDecimal((short)5000),
444429
0, rowCnt, rowCnt, 2, null, 1, 0));
445430

446431
IgniteStatisticsImpl stat = new IgniteStatisticsImpl(new ObjectStatisticsImpl(1000, colStat1));

0 commit comments

Comments
 (0)