use of org.apache.asterix.om.types.AUnionType in project asterixdb by apache.
the class InvertedIndexAccessMethod method addSearchKeyType.
private void addSearchKeyType(IOptimizableFuncExpr optFuncExpr, OptimizableOperatorSubTree indexSubTree, IOptimizationContext context, InvertedIndexJobGenParams jobGenParams) throws AlgebricksException {
// If we have two variables in the optFunxExpr, then we are optimizing a join.
IAType type = null;
ATypeTag typeTag = null;
if (optFuncExpr.getNumLogicalVars() == 2) {
// Find the type of the variable that is going to feed into the index search.
if (optFuncExpr.getOperatorSubTree(0) == indexSubTree) {
// If the index is on a dataset in subtree 0, then subtree 1 will feed.
type = optFuncExpr.getFieldType(1);
} else {
// If the index is on a dataset in subtree 1, then subtree 0 will feed.
type = optFuncExpr.getFieldType(0);
}
typeTag = type.getTypeTag();
if (type.getTypeTag() == ATypeTag.UNION) {
// If this is a nullable field, then we need to get the actual type tag.
typeTag = ((AUnionType) type).getActualType().getTypeTag();
}
} else {
// We are optimizing a selection query. Add the type of the search key constant.
type = optFuncExpr.getConstantType(0);
typeTag = type.getTypeTag();
if (typeTag == ATypeTag.UNION) {
// If this is a nullable field, then we need to get the actual type tag.
typeTag = ((AUnionType) type).getActualType().getTypeTag();
}
if (typeTag != ATypeTag.ARRAY && typeTag != ATypeTag.STRING && typeTag != ATypeTag.MULTISET) {
throw CompilationException.create(ErrorCode.NO_SUPPORTED_TYPE);
}
}
jobGenParams.setSearchKeyType(typeTag);
}
use of org.apache.asterix.om.types.AUnionType 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.AUnionType in project asterixdb by apache.
the class JTypeObjectFactory method create.
@Override
public IJObject create(IAType type) {
IJObject retValue = null;
switch(type.getTypeTag()) {
case INTEGER:
retValue = new JInt(0);
break;
case STRING:
retValue = new JString("");
break;
case FLOAT:
retValue = new JFloat(0);
break;
case DOUBLE:
retValue = new JDouble(0);
break;
case BOOLEAN:
retValue = new JBoolean(false);
break;
case CIRCLE:
retValue = new JCircle(new JPoint(0, 0), 0);
break;
case POINT:
retValue = new JPoint(0, 0);
break;
case POINT3D:
retValue = new JPoint3D(0, 0, 0);
break;
case POLYGON:
retValue = new JPolygon(new JPoint[] {});
break;
case LINE:
retValue = new JLine(new JPoint(0, 0), new JPoint(0, 0));
break;
case RECTANGLE:
retValue = new JRectangle(new JPoint(0, 0), new JPoint(1, 1));
break;
case DATE:
retValue = new JDate(0);
break;
case DATETIME:
retValue = new JDateTime(0);
break;
case DURATION:
retValue = new JDuration(0, 0);
break;
case INTERVAL:
retValue = new JInterval(0, 0);
break;
case TIME:
retValue = new JTime(0);
break;
case BIGINT:
retValue = new JLong(0);
break;
case NULL:
retValue = JObjects.JNull.INSTANCE;
break;
case MISSING:
retValue = JObjects.JMissing.INSTANCE;
break;
case ARRAY:
AOrderedListType ot = (AOrderedListType) type;
IAType orderedItemType = ot.getItemType();
IJObject orderedItemObject = create(orderedItemType);
retValue = new JOrderedList(orderedItemObject);
break;
case MULTISET:
AUnorderedListType ut = (AUnorderedListType) type;
IAType unorderedItemType = ut.getItemType();
IJObject unorderedItemObject = create(unorderedItemType);
retValue = new JUnorderedList(unorderedItemObject);
break;
case OBJECT:
IAType[] fieldTypes = ((ARecordType) type).getFieldTypes();
IJObject[] fieldObjects = new IJObject[fieldTypes.length];
int index = 0;
for (IAType fieldType : fieldTypes) {
fieldObjects[index] = create(fieldType);
index++;
}
retValue = new JRecord((ARecordType) type, fieldObjects);
break;
case UNION:
AUnionType unionType = (AUnionType) type;
IJObject itemObject = null;
if (unionType.isMissableType()) {
itemObject = create(unionType);
}
retValue = itemObject;
break;
default:
break;
}
return retValue;
}
use of org.apache.asterix.om.types.AUnionType in project asterixdb by apache.
the class AbstractIfMissingOrNullTypeComputer method computeType.
@Override
public IAType computeType(ILogicalExpression expression, IVariableTypeEnvironment env, IMetadataProvider<?, ?> metadataProvider) throws AlgebricksException {
AbstractFunctionCallExpression fce = (AbstractFunctionCallExpression) expression;
IAType outPrimeType = null;
// could be 'missing' or 'null'
ATypeTag outQuantifier = null;
for (Mutable<ILogicalExpression> argRef : fce.getArguments()) {
ILogicalExpression arg = argRef.getValue();
IAType argType = (IAType) env.getType(arg);
ATypeTag argTypeTag = argType.getTypeTag();
if (equalsIfType(argTypeTag)) {
continue;
}
if (argTypeTag == ATypeTag.UNION) {
AUnionType unionType = (AUnionType) argType;
if (intersectsIfType(unionType)) {
IAType primeType = getOutputPrimeType(unionType);
outPrimeType = outPrimeType == null ? primeType : TypeResolverUtil.resolve(outPrimeType, primeType);
if (outQuantifier == null) {
outQuantifier = getOutputQuantifier(unionType);
}
} else {
// no intersection
if (outPrimeType == null) {
return argType;
} else {
IAType primeType = getOutputPrimeType(unionType);
ATypeTag quantifier = outQuantifier != null ? outQuantifier : getOutputQuantifier(unionType);
return createOutputType(TypeResolverUtil.resolve(outPrimeType, primeType), quantifier);
}
}
} else {
// ANY or no intersection
return outPrimeType == null ? argType : createOutputType(TypeResolverUtil.resolve(outPrimeType, argType), outQuantifier);
}
}
if (outPrimeType == null) {
return BuiltinType.ANULL;
}
IAType outType = createOutputType(outPrimeType, ATypeTag.NULL);
if (outQuantifier == ATypeTag.MISSING) {
outType = createOutputType(outType, ATypeTag.MISSING);
}
return outType;
}
use of org.apache.asterix.om.types.AUnionType in project asterixdb by apache.
the class ClosedRecordConstructorResultType method computeType.
@Override
public IAType computeType(ILogicalExpression expression, IVariableTypeEnvironment env, IMetadataProvider<?, ?> metadataProvider) throws AlgebricksException {
AbstractFunctionCallExpression f = (AbstractFunctionCallExpression) expression;
String funcName = f.getFunctionIdentifier().getName();
/**
* if type has been top-down propagated, use the enforced type
*/
ARecordType type = (ARecordType) TypeCastUtils.getRequiredType(f);
if (type != null) {
return type;
}
int n = f.getArguments().size() / 2;
String[] fieldNames = new String[n];
IAType[] fieldTypes = new IAType[n];
int i = 0;
Iterator<Mutable<ILogicalExpression>> argIter = f.getArguments().iterator();
while (argIter.hasNext()) {
ILogicalExpression e1 = argIter.next().getValue();
ILogicalExpression e2 = argIter.next().getValue();
IAType e2Type = (IAType) env.getType(e2);
if (e2Type.getTypeTag() == ATypeTag.UNION) {
AUnionType unionType = (AUnionType) e2Type;
e2Type = AUnionType.createUnknownableType(unionType.getActualType());
}
fieldTypes[i] = e2Type;
fieldNames[i] = ConstantExpressionUtil.getStringConstant(e1);
if (fieldNames[i] == null) {
throw new InvalidExpressionException(funcName, 2 * i, e1, LogicalExpressionTag.CONSTANT);
}
i++;
}
return new ARecordType(null, fieldNames, fieldTypes, false);
}
Aggregations