diff --git a/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/optimizer/rules/am/AbstractIntroduceAccessMethodRule.java b/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/optimizer/rules/am/AbstractIntroduceAccessMethodRule.java index 9996e1fa0b7..0d19d069aae 100644 --- a/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/optimizer/rules/am/AbstractIntroduceAccessMethodRule.java +++ b/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/optimizer/rules/am/AbstractIntroduceAccessMethodRule.java @@ -559,12 +559,12 @@ private boolean isMatched(IAType type1, IAType type2, boolean useListDomain) thr if (type1 == null || type2 == null) { return false; } - if (ATypeHierarchy.isSameTypeDomain(Index.getNonNullableType(type1).first.getTypeTag(), - Index.getNonNullableType(type2).first.getTypeTag(), useListDomain)) { + if (ATypeHierarchy.isSameTypeDomain(Index.getNonNullableType(type1, null).first.getTypeTag(), + Index.getNonNullableType(type2, null).first.getTypeTag(), useListDomain)) { return true; } - return ATypeHierarchy.canPromote(Index.getNonNullableType(type1).first.getTypeTag(), - Index.getNonNullableType(type2).first.getTypeTag()); + return ATypeHierarchy.canPromote(Index.getNonNullableType(type1, null).first.getTypeTag(), + Index.getNonNullableType(type2, null).first.getTypeTag()); } private Set fetchSecondaryIndexPreferences(IAccessMethod accessMethod, diff --git a/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/optimizer/rules/am/BTreeAccessMethod.java b/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/optimizer/rules/am/BTreeAccessMethod.java index ee3fee050d2..e67d7bf7ebb 100644 --- a/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/optimizer/rules/am/BTreeAccessMethod.java +++ b/asterixdb/asterix-algebra/src/main/java/org/apache/asterix/optimizer/rules/am/BTreeAccessMethod.java @@ -1088,7 +1088,7 @@ public boolean acceptsFunction(AbstractFunctionCallExpression functionExpr, Inde if (!CAST_NULL_TYPE_CONSTRUCTORS.contains(funId)) { return false; } - IAType nonNullableType = Index.getNonNullableType(indexedFieldType).first; + IAType nonNullableType = Index.getNonNullableType(indexedFieldType, index.getIndexType()).first; Pair constructorWithFmt = IndexUtil.getTypeConstructorDefaultNull(index, nonNullableType, functionExpr.getSourceLocation()); FunctionIdentifier indexedFieldConstructorFun = constructorWithFmt.first; diff --git a/asterixdb/asterix-metadata/src/main/java/org/apache/asterix/metadata/entities/Index.java b/asterixdb/asterix-metadata/src/main/java/org/apache/asterix/metadata/entities/Index.java index 963b3ff87d9..7540eafacbf 100644 --- a/asterixdb/asterix-metadata/src/main/java/org/apache/asterix/metadata/entities/Index.java +++ b/asterixdb/asterix-metadata/src/main/java/org/apache/asterix/metadata/entities/Index.java @@ -153,7 +153,7 @@ public boolean isPrimaryKeyIndex() { return indexType == IndexType.BTREE && ((ValueIndexDetails) indexDetails).keyFieldNames.isEmpty(); } - public static Pair getNonNullableType(IAType keyType) { + public static Pair getNonNullableType(IAType keyType, IndexType indexType) { boolean nullable = false; IAType actualKeyType = keyType; if (NonTaggedFormatUtil.isOptional(keyType)) { @@ -166,7 +166,7 @@ public static Pair getNonNullableType(IAType keyType) { public static Pair getNonNullableOpenFieldType(Index index, IAType fieldType, List fieldName, ARecordType recType) throws AlgebricksException { if (IndexUtil.castDefaultNull(index)) { - Pair nonNullableType = getNonNullableType(fieldType); + Pair nonNullableType = getNonNullableType(fieldType, index.getIndexType()); nonNullableType.second = true; return nonNullableType; } @@ -185,21 +185,21 @@ public static Pair getNonNullableOpenFieldType(Index index, IAT } if (subType == null) { - keyPairType = Index.getNonNullableType(fieldType); + keyPairType = Index.getNonNullableType(fieldType, index.getIndexType()); break; } } if (subType != null) { - keyPairType = Index.getNonNullableKeyFieldType(fieldName, recType); + keyPairType = Index.getNonNullableKeyFieldType(fieldName, recType, index.getIndexType()); } keyPairType.second = keyPairType.second || nullable; return keyPairType; } - public static Pair getNonNullableKeyFieldType(List expr, ARecordType recType) - throws AlgebricksException { + public static Pair getNonNullableKeyFieldType(List expr, ARecordType recType, + IndexType indexType) throws AlgebricksException { IAType keyType = Index.keyFieldType(expr, recType); - Pair pair = getNonNullableType(keyType); + Pair pair = getNonNullableType(keyType, indexType); pair.second = pair.second || recType.isSubFieldNullable(expr); return pair; } diff --git a/asterixdb/asterix-metadata/src/main/java/org/apache/asterix/metadata/utils/ArrayIndexUtil.java b/asterixdb/asterix-metadata/src/main/java/org/apache/asterix/metadata/utils/ArrayIndexUtil.java index 1abf30017fb..aaa1551ca12 100644 --- a/asterixdb/asterix-metadata/src/main/java/org/apache/asterix/metadata/utils/ArrayIndexUtil.java +++ b/asterixdb/asterix-metadata/src/main/java/org/apache/asterix/metadata/utils/ArrayIndexUtil.java @@ -22,6 +22,7 @@ import java.util.Collections; import java.util.List; +import org.apache.asterix.common.config.DatasetConfig; import org.apache.asterix.common.exceptions.AsterixException; import org.apache.asterix.common.exceptions.CompilationException; import org.apache.asterix.common.exceptions.ErrorCode; @@ -166,14 +167,14 @@ public static Pair getNonNullableOpenFieldType(IAType fieldType } if (subType == null) { - keyPairType = Index.getNonNullableType(fieldType); + keyPairType = Index.getNonNullableType(fieldType, DatasetConfig.IndexType.ARRAY); break; } } if (subType != null) { IAType keyType = ArrayIndexUtil.getSubFieldType(recType, unnestList, projectList); - Pair pair = Index.getNonNullableType(keyType); + Pair pair = Index.getNonNullableType(keyType, DatasetConfig.IndexType.ARRAY); pair.second = pair.second || ArrayIndexUtil.isSubFieldNullable(recType, unnestList, projectList); keyPairType = pair; } diff --git a/asterixdb/asterix-metadata/src/main/java/org/apache/asterix/metadata/utils/SecondaryArrayIndexBTreeOperationsHelper.java b/asterixdb/asterix-metadata/src/main/java/org/apache/asterix/metadata/utils/SecondaryArrayIndexBTreeOperationsHelper.java index 5b4fac84f60..242f335b6f1 100644 --- a/asterixdb/asterix-metadata/src/main/java/org/apache/asterix/metadata/utils/SecondaryArrayIndexBTreeOperationsHelper.java +++ b/asterixdb/asterix-metadata/src/main/java/org/apache/asterix/metadata/utils/SecondaryArrayIndexBTreeOperationsHelper.java @@ -206,7 +206,7 @@ protected void setSecondaryRecDescAndComparators() throws AlgebricksException { : metaType; addSKEvalFactories(itemType, numSecondaryKeys, true); Pair keyTypePair; - keyTypePair = Index.getNonNullableKeyFieldType(filterFieldName, filterItemType); + keyTypePair = Index.getNonNullableKeyFieldType(filterFieldName, filterItemType, index.getIndexType()); IAType type = keyTypePair.first; ISerializerDeserializer serde = serdeProvider.getSerializerDeserializer(type); secondaryRecFields[numPrimaryKeys + numSecondaryKeys] = serde; @@ -535,7 +535,7 @@ private void addFilterFieldToBuilder(ARecordType recordType) throws AlgebricksEx IScalarEvaluatorFactory sef = metadataProvider.getDataFormat().getFieldAccessEvaluatorFactory( metadataProvider.getFunctionManager(), recordType, filterFieldName, numPrimaryKeys, sourceLoc); evalFactoryAndRecDescStackBuilder.addFilter(sef, - Index.getNonNullableKeyFieldType(filterFieldName, recordType).first); + Index.getNonNullableKeyFieldType(filterFieldName, recordType, index.getIndexType()).first); } class EvalFactoryAndRecDescInvoker implements ArrayIndexUtil.TypeTrackerCommandExecutor { diff --git a/asterixdb/asterix-metadata/src/main/java/org/apache/asterix/metadata/utils/SecondaryBTreeOperationsHelper.java b/asterixdb/asterix-metadata/src/main/java/org/apache/asterix/metadata/utils/SecondaryBTreeOperationsHelper.java index 1889aa14e48..18810a512d0 100644 --- a/asterixdb/asterix-metadata/src/main/java/org/apache/asterix/metadata/utils/SecondaryBTreeOperationsHelper.java +++ b/asterixdb/asterix-metadata/src/main/java/org/apache/asterix/metadata/utils/SecondaryBTreeOperationsHelper.java @@ -238,7 +238,8 @@ protected void setSecondaryRecDescAndComparators() throws AlgebricksException { sourceColumn = recordColumn + 1; enforcedType = enforcedMetaType; } - IAType filterType = Index.getNonNullableKeyFieldType(filterFieldName, sourceType).first; + IAType filterType = + Index.getNonNullableKeyFieldType(filterFieldName, sourceType, index.getIndexType()).first; IScalarEvaluatorFactory filterAccessor = createFieldAccessor(sourceType, sourceColumn, filterFieldName); secondaryFieldAccessEvalFactories[numSecondaryKeys] = createFieldCast(filterAccessor, isOverridingKeyFieldTypes, enforcedType, sourceType, filterType); diff --git a/asterixdb/asterix-metadata/src/main/java/org/apache/asterix/metadata/utils/SecondaryCorrelatedBTreeOperationsHelper.java b/asterixdb/asterix-metadata/src/main/java/org/apache/asterix/metadata/utils/SecondaryCorrelatedBTreeOperationsHelper.java index 2b948ef623a..41fcb9a8a72 100644 --- a/asterixdb/asterix-metadata/src/main/java/org/apache/asterix/metadata/utils/SecondaryCorrelatedBTreeOperationsHelper.java +++ b/asterixdb/asterix-metadata/src/main/java/org/apache/asterix/metadata/utils/SecondaryCorrelatedBTreeOperationsHelper.java @@ -200,7 +200,8 @@ protected void setSecondaryRecDescAndComparators() throws AlgebricksException { sourceColumn = recordColumn + 1; enforcedType = enforcedMetaType; } - IAType filterType = Index.getNonNullableKeyFieldType(filterFieldName, sourceType).first; + IAType filterType = + Index.getNonNullableKeyFieldType(filterFieldName, sourceType, index.getIndexType()).first; IScalarEvaluatorFactory filterAccessor = createFieldAccessor(sourceType, sourceColumn, filterFieldName); secondaryFieldAccessEvalFactories[numSecondaryKeys] = createFieldCast(filterAccessor, isOverridingKeyTypes, enforcedType, sourceType, filterType); diff --git a/asterixdb/asterix-metadata/src/main/java/org/apache/asterix/metadata/utils/SecondaryCorrelatedInvertedIndexOperationsHelper.java b/asterixdb/asterix-metadata/src/main/java/org/apache/asterix/metadata/utils/SecondaryCorrelatedInvertedIndexOperationsHelper.java index cd3f01c85d0..a437217fa59 100644 --- a/asterixdb/asterix-metadata/src/main/java/org/apache/asterix/metadata/utils/SecondaryCorrelatedInvertedIndexOperationsHelper.java +++ b/asterixdb/asterix-metadata/src/main/java/org/apache/asterix/metadata/utils/SecondaryCorrelatedInvertedIndexOperationsHelper.java @@ -131,7 +131,8 @@ protected void setSecondaryRecDescAndComparators() throws AlgebricksException { secondaryFieldAccessEvalFactories[numSecondaryKeys] = metadataProvider.getDataFormat() .getFieldAccessEvaluatorFactory(metadataProvider.getFunctionManager(), filterItemType, filterFieldName, recordColumn, sourceLoc); - Pair keyTypePair = Index.getNonNullableKeyFieldType(filterFieldName, filterItemType); + Pair keyTypePair = + Index.getNonNullableKeyFieldType(filterFieldName, filterItemType, indexType); IAType type = keyTypePair.first; ISerializerDeserializer serde = serdeProvider.getSerializerDeserializer(type); secondaryRecFields[numPrimaryKeys + numSecondaryKeys] = serde; diff --git a/asterixdb/asterix-metadata/src/main/java/org/apache/asterix/metadata/utils/SecondaryCorrelatedRTreeOperationsHelper.java b/asterixdb/asterix-metadata/src/main/java/org/apache/asterix/metadata/utils/SecondaryCorrelatedRTreeOperationsHelper.java index 302ad74a013..f50853f2820 100644 --- a/asterixdb/asterix-metadata/src/main/java/org/apache/asterix/metadata/utils/SecondaryCorrelatedRTreeOperationsHelper.java +++ b/asterixdb/asterix-metadata/src/main/java/org/apache/asterix/metadata/utils/SecondaryCorrelatedRTreeOperationsHelper.java @@ -134,7 +134,8 @@ protected void setSecondaryRecDescAndComparators() throws AlgebricksException { rtreeFields[i] = i; } - Pair typePair = Index.getNonNullableKeyFieldType(filterFieldName, filterItemType); + Pair typePair = + Index.getNonNullableKeyFieldType(filterFieldName, filterItemType, index.getIndexType()); IAType type = typePair.first; ISerializerDeserializer serde = SerializerDeserializerProvider.INSTANCE.getSerializerDeserializer(type); secondaryRecFields[numPrimaryKeys + numNestedSecondaryKeyFields] = serde; diff --git a/asterixdb/asterix-metadata/src/main/java/org/apache/asterix/metadata/utils/SecondaryInvertedIndexOperationsHelper.java b/asterixdb/asterix-metadata/src/main/java/org/apache/asterix/metadata/utils/SecondaryInvertedIndexOperationsHelper.java index fa5510524dd..b3fda76baf7 100644 --- a/asterixdb/asterix-metadata/src/main/java/org/apache/asterix/metadata/utils/SecondaryInvertedIndexOperationsHelper.java +++ b/asterixdb/asterix-metadata/src/main/java/org/apache/asterix/metadata/utils/SecondaryInvertedIndexOperationsHelper.java @@ -135,7 +135,8 @@ protected void setSecondaryRecDescAndComparators() throws AlgebricksException { secondaryFieldAccessEvalFactories[numSecondaryKeys] = metadataProvider.getDataFormat() .getFieldAccessEvaluatorFactory(metadataProvider.getFunctionManager(), filterItemType, filterFieldName, numPrimaryKeys, sourceLoc); - Pair keyTypePair = Index.getNonNullableKeyFieldType(filterFieldName, filterItemType); + Pair keyTypePair = + Index.getNonNullableKeyFieldType(filterFieldName, filterItemType, indexType); IAType type = keyTypePair.first; ISerializerDeserializer serde = serdeProvider.getSerializerDeserializer(type); secondaryRecFields[numPrimaryKeys + numSecondaryKeys] = serde; diff --git a/asterixdb/asterix-metadata/src/main/java/org/apache/asterix/metadata/utils/SecondaryRTreeOperationsHelper.java b/asterixdb/asterix-metadata/src/main/java/org/apache/asterix/metadata/utils/SecondaryRTreeOperationsHelper.java index 1c20eff23c3..7b2499fe38c 100644 --- a/asterixdb/asterix-metadata/src/main/java/org/apache/asterix/metadata/utils/SecondaryRTreeOperationsHelper.java +++ b/asterixdb/asterix-metadata/src/main/java/org/apache/asterix/metadata/utils/SecondaryRTreeOperationsHelper.java @@ -147,7 +147,8 @@ protected void setSecondaryRecDescAndComparators() throws AlgebricksException { rtreeFields[i] = i; } - Pair typePair = Index.getNonNullableKeyFieldType(filterFieldName, filterItemType); + Pair typePair = + Index.getNonNullableKeyFieldType(filterFieldName, filterItemType, index.getIndexType()); IAType type = typePair.first; ISerializerDeserializer serde = SerializerDeserializerProvider.INSTANCE.getSerializerDeserializer(type); secondaryRecFields[numPrimaryKeys + numNestedSecondaryKeyFields] = serde;