Search in sources :

Example 6 with IJObject

use of org.apache.asterix.external.api.IJObject 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;
}
Also used : JRecord(org.apache.asterix.external.library.java.JObjects.JRecord) JPoint(org.apache.asterix.external.library.java.JObjects.JPoint) AUnionType(org.apache.asterix.om.types.AUnionType) JRectangle(org.apache.asterix.external.library.java.JObjects.JRectangle) JPolygon(org.apache.asterix.external.library.java.JObjects.JPolygon) JInterval(org.apache.asterix.external.library.java.JObjects.JInterval) JTime(org.apache.asterix.external.library.java.JObjects.JTime) JLong(org.apache.asterix.external.library.java.JObjects.JLong) JDouble(org.apache.asterix.external.library.java.JObjects.JDouble) JBoolean(org.apache.asterix.external.library.java.JObjects.JBoolean) JDuration(org.apache.asterix.external.library.java.JObjects.JDuration) JFloat(org.apache.asterix.external.library.java.JObjects.JFloat) JCircle(org.apache.asterix.external.library.java.JObjects.JCircle) JInt(org.apache.asterix.external.library.java.JObjects.JInt) AOrderedListType(org.apache.asterix.om.types.AOrderedListType) IJObject(org.apache.asterix.external.api.IJObject) JLine(org.apache.asterix.external.library.java.JObjects.JLine) JDate(org.apache.asterix.external.library.java.JObjects.JDate) AUnorderedListType(org.apache.asterix.om.types.AUnorderedListType) JPoint(org.apache.asterix.external.library.java.JObjects.JPoint) JUnorderedList(org.apache.asterix.external.library.java.JObjects.JUnorderedList) JDateTime(org.apache.asterix.external.library.java.JObjects.JDateTime) JPoint3D(org.apache.asterix.external.library.java.JObjects.JPoint3D) JOrderedList(org.apache.asterix.external.library.java.JObjects.JOrderedList) JString(org.apache.asterix.external.library.java.JObjects.JString) ARecordType(org.apache.asterix.om.types.ARecordType) IAType(org.apache.asterix.om.types.IAType)

Example 7 with IJObject

use of org.apache.asterix.external.api.IJObject in project asterixdb by apache.

the class JavaFunctionHelper method setArgument.

public void setArgument(int index, IValueReference valueReference) throws IOException, AsterixException {
    IVisitablePointable pointable = null;
    IJObject jObject = null;
    IAType type = finfo.getParamList().get(index);
    switch(type.getTypeTag()) {
        case OBJECT:
            pointable = pointableAllocator.allocateRecordValue(type);
            pointable.set(valueReference);
            jObject = pointableVisitor.visit((ARecordVisitablePointable) pointable, getTypeInfo(index, type));
            break;
        case ARRAY:
        case MULTISET:
            pointable = pointableAllocator.allocateListValue(type);
            pointable.set(valueReference);
            jObject = pointableVisitor.visit((AListVisitablePointable) pointable, getTypeInfo(index, type));
            break;
        case ANY:
            throw new RuntimeDataException(ErrorCode.LIBRARY_JAVA_FUNCTION_HELPER_CANNOT_HANDLE_ARGU_TYPE, type.getTypeTag());
        default:
            pointable = pointableAllocator.allocateFieldValue(type);
            pointable.set(valueReference);
            jObject = pointableVisitor.visit((AFlatValuePointable) pointable, getTypeInfo(index, type));
            break;
    }
    arguments[index] = jObject;
}
Also used : AFlatValuePointable(org.apache.asterix.om.pointables.AFlatValuePointable) ARecordVisitablePointable(org.apache.asterix.om.pointables.ARecordVisitablePointable) AListVisitablePointable(org.apache.asterix.om.pointables.AListVisitablePointable) IVisitablePointable(org.apache.asterix.om.pointables.base.IVisitablePointable) IJObject(org.apache.asterix.external.api.IJObject) IAType(org.apache.asterix.om.types.IAType) RuntimeDataException(org.apache.asterix.common.exceptions.RuntimeDataException)

Aggregations

IJObject (org.apache.asterix.external.api.IJObject)7 JPoint (org.apache.asterix.external.library.java.JObjects.JPoint)3 ARecordType (org.apache.asterix.om.types.ARecordType)3 IAType (org.apache.asterix.om.types.IAType)3 RuntimeDataException (org.apache.asterix.common.exceptions.RuntimeDataException)2 JBoolean (org.apache.asterix.external.library.java.JObjects.JBoolean)2 JOrderedList (org.apache.asterix.external.library.java.JObjects.JOrderedList)2 JRecord (org.apache.asterix.external.library.java.JObjects.JRecord)2 JString (org.apache.asterix.external.library.java.JObjects.JString)2 JUnorderedList (org.apache.asterix.external.library.java.JObjects.JUnorderedList)2 APoint (org.apache.asterix.om.base.APoint)2 AOrderedListType (org.apache.asterix.om.types.AOrderedListType)2 ATypeTag (org.apache.asterix.om.types.ATypeTag)2 AUnionType (org.apache.asterix.om.types.AUnionType)2 AUnorderedListType (org.apache.asterix.om.types.AUnorderedListType)2 ArrayList (java.util.ArrayList)1 List (java.util.List)1 IJListAccessor (org.apache.asterix.external.api.IJListAccessor)1 IJObjectAccessor (org.apache.asterix.external.api.IJObjectAccessor)1 IJRecordAccessor (org.apache.asterix.external.api.IJRecordAccessor)1