Pouria Pirzadeh has submitted this change and it was merged. Change subject: 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 ......................................................................
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 <[email protected]> Reviewed-by: Taewoo Kim <[email protected]> Reviewed-by: Yingyi Bu <[email protected]> Reviewed-by: Pouria Pirzadeh <[email protected]> --- M asterix-metadata/src/main/java/org/apache/asterix/metadata/declared/AqlMetadataProvider.java 1 file changed, 42 insertions(+), 5 deletions(-) Approvals: Pouria Pirzadeh: Looks good to me, but someone else must approve Taewoo Kim: Looks good to me, approved Yingyi Bu: Looks good to me, approved Jenkins: Verified 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, -- To view, visit https://asterix-gerrit.ics.uci.edu/412 To unsubscribe, visit https://asterix-gerrit.ics.uci.edu/settings Gerrit-MessageType: merged Gerrit-Change-Id: I648d808b77910582a6b52a0e730d7271f9d2c213 Gerrit-PatchSet: 2 Gerrit-Project: asterixdb Gerrit-Branch: master Gerrit-Owner: Taewoo Kim <[email protected]> Gerrit-Reviewer: Ian Maxon <[email protected]> Gerrit-Reviewer: Jenkins <[email protected]> Gerrit-Reviewer: Pouria Pirzadeh <[email protected]> Gerrit-Reviewer: Taewoo Kim <[email protected]> Gerrit-Reviewer: Yingyi Bu <[email protected]> Gerrit-Reviewer: Young-Seok Kim <[email protected]>
