use of org.apache.asterix.om.types.AbstractCollectionType in project asterixdb by apache.
the class TypeTranslator method secondPass.
private static void secondPass(MetadataTransactionContext mdTxnCtx, Map<TypeSignature, IAType> typeMap, Map<String, Map<ARecordType, List<Integer>>> incompleteFieldTypes, Map<TypeSignature, List<AbstractCollectionType>> incompleteItemTypes, Map<TypeSignature, List<TypeSignature>> incompleteTopLevelTypeReferences, String typeDataverse) throws AlgebricksException {
// solve remaining top level references
for (TypeSignature typeSignature : incompleteTopLevelTypeReferences.keySet()) {
IAType t;
Datatype dt = MetadataManager.INSTANCE.getDatatype(mdTxnCtx, typeSignature.getNamespace(), typeSignature.getName());
if (dt == null) {
throw new AlgebricksException("Could not resolve type " + typeSignature);
} else {
t = dt.getDatatype();
}
for (TypeSignature sign : incompleteTopLevelTypeReferences.get(typeSignature)) {
typeMap.put(sign, t);
}
}
// solve remaining field type references
for (String trefName : incompleteFieldTypes.keySet()) {
IAType t;
Datatype dt = MetadataManager.INSTANCE.getDatatype(mdTxnCtx, typeDataverse, trefName);
if (dt == null) {
dt = MetadataManager.INSTANCE.getDatatype(mdTxnCtx, MetadataConstants.METADATA_DATAVERSE_NAME, trefName);
}
if (dt == null) {
throw new AlgebricksException("Could not resolve type " + trefName);
} else {
t = dt.getDatatype();
}
Map<ARecordType, List<Integer>> fieldsToFix = incompleteFieldTypes.get(trefName);
for (ARecordType recType : fieldsToFix.keySet()) {
List<Integer> positions = fieldsToFix.get(recType);
IAType[] fldTypes = recType.getFieldTypes();
for (Integer pos : positions) {
if (fldTypes[pos] == null) {
fldTypes[pos] = t;
} else {
// nullable
AUnionType nullableUnion = (AUnionType) fldTypes[pos];
nullableUnion.setActualType(t);
}
}
}
}
// solve remaining item type references
for (TypeSignature typeSignature : incompleteItemTypes.keySet()) {
IAType t;
Datatype dt;
if (MetadataManager.INSTANCE != null) {
dt = MetadataManager.INSTANCE.getDatatype(mdTxnCtx, typeSignature.getNamespace(), typeSignature.getName());
if (dt == null) {
throw new AlgebricksException("Could not resolve type " + typeSignature);
}
t = dt.getDatatype();
} else {
t = typeMap.get(typeSignature);
}
for (AbstractCollectionType act : incompleteItemTypes.get(typeSignature)) {
act.setItemType(t);
}
}
}
use of org.apache.asterix.om.types.AbstractCollectionType in project asterixdb by apache.
the class CollectionToSequenceTypeComputer method getResultType.
@Override
protected IAType getResultType(ILogicalExpression expr, IAType... strippedInputTypes) throws AlgebricksException {
IAType argType = strippedInputTypes[0];
ATypeTag argTypeTag = argType.getTypeTag();
if (argTypeTag == ATypeTag.ARRAY || argTypeTag == ATypeTag.MULTISET) {
/** if the input is a singleton list, return it's item type if any */
AbstractCollectionType collectionType = (AbstractCollectionType) argType;
return collectionType.getItemType();
} else {
/** if the input is not a singleton list, return the original input type */
return argType;
}
}
use of org.apache.asterix.om.types.AbstractCollectionType in project asterixdb by apache.
the class DatatypeTupleTranslator method writeCollectionType.
private void writeCollectionType(Datatype instance, AbstractComplexType type, DataOutput out) throws HyracksDataException {
AbstractCollectionType listType = (AbstractCollectionType) type;
IAType itemType = listType.getItemType();
if (itemType.getTypeTag().isDerivedType()) {
handleNestedDerivedType(itemType.getTypeName(), (AbstractComplexType) itemType, instance, instance.getDataverseName(), instance.getDatatypeName());
}
aString.setValue(listType.getItemType().getTypeName());
stringSerde.serialize(aString, out);
}
use of org.apache.asterix.om.types.AbstractCollectionType in project asterixdb by apache.
the class ScalarVersionOfAggregateResultType method getResultType.
@Override
protected IAType getResultType(ILogicalExpression expr, IAType... strippedInputTypes) throws AlgebricksException {
ATypeTag tag = strippedInputTypes[0].getTypeTag();
if (tag == ATypeTag.ANY) {
return BuiltinType.ANY;
}
if (tag != ATypeTag.ARRAY && tag != ATypeTag.MULTISET) {
return strippedInputTypes[0];
}
AbstractCollectionType act = (AbstractCollectionType) strippedInputTypes[0];
IAType t = act.getItemType();
return AUnionType.createUnknownableType(t);
}
use of org.apache.asterix.om.types.AbstractCollectionType in project asterixdb by apache.
the class SubsetCollectionTypeComputer method computeType.
@Override
public IAType computeType(ILogicalExpression expression, IVariableTypeEnvironment env, IMetadataProvider<?, ?> mp) throws AlgebricksException {
AbstractFunctionCallExpression fun = (AbstractFunctionCallExpression) expression;
String funcName = fun.getFunctionIdentifier().getName();
IAType t = (IAType) env.getType(fun.getArguments().get(0).getValue());
ATypeTag actualTypeTag = t.getTypeTag();
switch(actualTypeTag) {
case MULTISET:
case ARRAY:
{
AbstractCollectionType act = (AbstractCollectionType) t;
return act.getItemType();
}
case UNION:
{
AUnionType ut = (AUnionType) t;
if (!ut.isUnknownableType()) {
throw new TypeMismatchException(funcName, 0, actualTypeTag, ATypeTag.MULTISET, ATypeTag.ARRAY);
}
IAType t2 = ut.getActualType();
ATypeTag tag2 = t2.getTypeTag();
if (tag2 == ATypeTag.MULTISET || tag2 == ATypeTag.ARRAY) {
AbstractCollectionType act = (AbstractCollectionType) t2;
return act.getItemType();
}
throw new TypeMismatchException(funcName, 0, actualTypeTag, ATypeTag.MULTISET, ATypeTag.ARRAY);
}
case ANY:
return BuiltinType.ANY;
default:
throw new TypeMismatchException(funcName, 0, actualTypeTag, ATypeTag.MULTISET, ATypeTag.ARRAY);
}
}
Aggregations