ASTERIXDB-1115 fixed: Incorrect comparators are given for a secondary btree index when AsterixDB instance with a preloaded/inserted data stop/starts and sends a query without having any dml operation
Note: this fix is created by Young-Seok Kim and submitted by Taewoo Kim on behalf of him.
Change-Id: I648d808b77910582a6b52a0e730d7271f9d2c213
Reviewed-on: https://asterix-gerrit.ics.uci.edu/412
Tested-by: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Reviewed-by: Taewoo Kim <wangsaeu@gmail.com>
Reviewed-by: Yingyi Bu <buyingyi@gmail.com>
Reviewed-by: Pouria Pirzadeh <pouria.pirzadeh@gmail.com>
diff --git a/asterix-metadata/src/main/java/org/apache/asterix/metadata/declared/AqlMetadataProvider.java b/asterix-metadata/src/main/java/org/apache/asterix/metadata/declared/AqlMetadataProvider.java
index d68a159..2478dc7 100644
--- a/asterix-metadata/src/main/java/org/apache/asterix/metadata/declared/AqlMetadataProvider.java
+++ b/asterix-metadata/src/main/java/org/apache/asterix/metadata/declared/AqlMetadataProvider.java
@@ -584,7 +584,7 @@
iterator.remove();
}
}
- // TODO Check this call, result of merge from master!
+ // TODO Check this call, result of merge from master!
// ((IGenericAdapterFactory) adapterFactory).setFiles(files);
}
@@ -706,10 +706,11 @@
for (int i = 0; i < numSecondaryKeys; i++) {
bloomFilterKeyFields[i] = i;
}
- typeTraits = JobGenHelper.variablesToTypeTraits(outputVars, 0, outputVars.size(), typeEnv, context);
- comparatorFactories = JobGenHelper.variablesToAscBinaryComparatorFactories(outputVars, 0,
- outputVars.size(), typeEnv, context);
-
+ Pair<IBinaryComparatorFactory[], ITypeTraits[]> comparatorFactoriesAndTypeTraits = getComparatorFactoriesAndTypeTraitsOfSecondaryBTreeIndex(
+ secondaryIndex.getIndexType(), secondaryIndex.getKeyFieldNames(),
+ secondaryIndex.getKeyFieldTypes(), DatasetUtils.getPartitioningKeys(dataset), itemType);
+ comparatorFactories = comparatorFactoriesAndTypeTraits.first;
+ typeTraits = comparatorFactoriesAndTypeTraits.second;
if (filterTypeTraits != null) {
filterFields = new int[1];
filterFields[0] = numSecondaryKeys + numPrimaryKeys;
@@ -807,6 +808,42 @@
}
}
+ private Pair<IBinaryComparatorFactory[], ITypeTraits[]> getComparatorFactoriesAndTypeTraitsOfSecondaryBTreeIndex(
+ IndexType indexType, List<List<String>> sidxKeyFieldNames, List<IAType> sidxKeyFieldTypes,
+ List<List<String>> pidxKeyFieldNames, ARecordType recType) throws AlgebricksException {
+
+ IBinaryComparatorFactory[] comparatorFactories;
+ ITypeTraits[] typeTraits;
+ int sidxKeyFieldCount = sidxKeyFieldNames.size();
+ int pidxKeyFieldCount = pidxKeyFieldNames.size();
+ typeTraits = new ITypeTraits[sidxKeyFieldCount + pidxKeyFieldCount];
+ comparatorFactories = new IBinaryComparatorFactory[sidxKeyFieldCount + pidxKeyFieldCount];
+
+ int i = 0;
+ for (; i < sidxKeyFieldCount; ++i) {
+ Pair<IAType, Boolean> keyPairType = Index.getNonNullableOpenFieldType(sidxKeyFieldTypes.get(i),
+ sidxKeyFieldNames.get(i), recType);
+ IAType keyType = keyPairType.first;
+ comparatorFactories[i] = AqlBinaryComparatorFactoryProvider.INSTANCE.getBinaryComparatorFactory(keyType,
+ true);
+ typeTraits[i] = AqlTypeTraitProvider.INSTANCE.getTypeTrait(keyType);
+ }
+
+ for (int j = 0; j < pidxKeyFieldCount; ++j, ++i) {
+ IAType keyType = null;
+ try {
+ keyType = recType.getSubFieldType(pidxKeyFieldNames.get(j));
+ } catch (IOException e) {
+ throw new AlgebricksException(e);
+ }
+ comparatorFactories[i] = AqlBinaryComparatorFactoryProvider.INSTANCE.getBinaryComparatorFactory(keyType,
+ true);
+ typeTraits[i] = AqlTypeTraitProvider.INSTANCE.getTypeTrait(keyType);
+ }
+
+ return new Pair<IBinaryComparatorFactory[], ITypeTraits[]>(comparatorFactories, typeTraits);
+ }
+
public Pair<IOperatorDescriptor, AlgebricksPartitionConstraint> buildRtreeRuntime(JobSpecification jobSpec,
List<LogicalVariable> outputVars, IOperatorSchema opSchema, IVariableTypeEnvironment typeEnv,
JobGenContext context, boolean retainInput, boolean retainNull, Dataset dataset, String indexName,