use of org.apache.asterix.om.types.IAType in project asterixdb by apache.
the class NumericAggTypeComputer method getResultType.
@Override
protected IAType getResultType(ILogicalExpression expr, IAType... strippedInputTypes) throws AlgebricksException {
ATypeTag tag = strippedInputTypes[0].getTypeTag();
IAType type = null;
switch(tag) {
case DOUBLE:
case FLOAT:
case BIGINT:
case INTEGER:
case SMALLINT:
case TINYINT:
case ANY:
type = strippedInputTypes[0];
break;
default:
break;
}
return AUnionType.createNullableType(type, "AggResult");
}
use of org.apache.asterix.om.types.IAType in project asterixdb by apache.
the class FieldAccessByIndexResultType method getResultType.
@Override
protected IAType getResultType(ILogicalExpression expr, IAType... strippedInputTypes) throws AlgebricksException {
IAType firstArgType = strippedInputTypes[0];
if (firstArgType.getTypeTag() != ATypeTag.OBJECT) {
return BuiltinType.ANY;
}
AbstractFunctionCallExpression funcExpr = (AbstractFunctionCallExpression) expr;
Integer pos = ConstantExpressionUtil.getIntArgument(funcExpr, 1);
if (pos == null) {
return BuiltinType.ANY;
}
ARecordType recType = (ARecordType) firstArgType;
return recType.getFieldTypes()[pos];
}
use of org.apache.asterix.om.types.IAType in project asterixdb by apache.
the class FieldAccessByNameResultType method getResultType.
@Override
protected IAType getResultType(ILogicalExpression expr, IAType... strippedInputTypes) throws AlgebricksException {
IAType firstArgType = strippedInputTypes[0];
if (firstArgType.getTypeTag() != ATypeTag.OBJECT) {
return BuiltinType.ANY;
}
AbstractFunctionCallExpression funcExpr = (AbstractFunctionCallExpression) expr;
String fieldName = ConstantExpressionUtil.getStringArgument(funcExpr, 1);
if (fieldName == null) {
return BuiltinType.ANY;
}
ARecordType recType = (ARecordType) firstArgType;
IAType fieldType = recType.getFieldType(fieldName);
return fieldType == null ? BuiltinType.ANY : fieldType;
}
use of org.apache.asterix.om.types.IAType in project asterixdb by apache.
the class TypeComputeUtils method resolveCateogry.
private static byte resolveCateogry(IAType... inputTypes) {
byte category = CERTAIN;
boolean meetNull = false;
for (IAType inputType : inputTypes) {
switch(inputType.getTypeTag()) {
case UNION:
AUnionType unionType = (AUnionType) inputType;
if (unionType.isNullableType()) {
category |= NULLABLE;
}
if (unionType.isMissableType()) {
category |= MISSABLE;
}
break;
case MISSING:
return MISSING;
case NULL:
meetNull = true;
break;
case ANY:
category |= NULLABLE;
category |= MISSABLE;
break;
default:
break;
}
}
if (meetNull) {
return NULL;
}
return category;
}
use of org.apache.asterix.om.types.IAType in project asterixdb by apache.
the class TypeResolverUtilTest method testOrderedListType.
@Test
public void testOrderedListType() {
// Constructs input types.
ARecordType leftRecordType = new ARecordType("null", new String[] { "a", "b" }, new IAType[] { BuiltinType.ASTRING, BuiltinType.AINT32 }, true, Collections.singleton("d"));
AOrderedListType leftListType = new AOrderedListType(leftRecordType, "null");
ARecordType rightRecordType = new ARecordType("null", new String[] { "b", "c" }, new IAType[] { BuiltinType.AINT32, BuiltinType.ABINARY }, true, Collections.singleton("e"));
AOrderedListType rightListType = new AOrderedListType(rightRecordType, "null");
// Gets the actual resolved type.
List<IAType> inputTypes = new ArrayList<>();
inputTypes.add(leftListType);
inputTypes.add(rightListType);
AbstractCollectionType resolvedType = (AbstractCollectionType) TypeResolverUtil.resolve(inputTypes);
ARecordType resolvedRecordType = (ARecordType) resolvedType.getItemType();
// Gets the expected generalized type.
Set<String> possibleAdditionalFields = new HashSet<>();
possibleAdditionalFields.add("a");
possibleAdditionalFields.add("c");
possibleAdditionalFields.add("d");
possibleAdditionalFields.add("e");
ARecordType expectedRecordType = new ARecordType(null, new String[] { "b" }, new IAType[] { BuiltinType.AINT32 }, true, possibleAdditionalFields);
AOrderedListType expectedListType = new AOrderedListType(expectedRecordType, null);
// Compares the resolved type and the expected type.
Assert.assertEquals(resolvedType, expectedListType);
Assert.assertEquals(resolvedRecordType.getAllPossibleAdditonalFieldNames(), expectedRecordType.getAllPossibleAdditonalFieldNames());
}
Aggregations