Search in sources :

Example 6 with JString

use of org.apache.asterix.external.library.java.JObjects.JString in project asterixdb by apache.

the class ParseTweetFunction method evaluate.

@Override
public void evaluate(IFunctionHelper functionHelper) throws Exception {
    list.clear();
    JRecord inputRecord = (JRecord) functionHelper.getArgument(0);
    JString id = (JString) inputRecord.getValueByName("id");
    JString text = (JString) inputRecord.getValueByName("text");
    String[] tokens = text.getValue().split(" ");
    for (String tk : tokens) {
        if (tk.startsWith("#")) {
            JString newField = (JString) functionHelper.getObject(JTypeTag.STRING);
            newField.setValue(tk);
            list.add(newField);
        }
    }
    JRecord result = (JRecord) functionHelper.getResultObject();
    result.setField("id", id);
    result.setField("username", inputRecord.getValueByName("username"));
    result.setField("location", inputRecord.getValueByName("location"));
    result.setField("text", text);
    result.setField("timestamp", inputRecord.getValueByName("timestamp"));
    result.setField("topics", list);
    functionHelper.setResult(result);
}
Also used : JRecord(org.apache.asterix.external.library.java.JObjects.JRecord) JString(org.apache.asterix.external.library.java.JObjects.JString) JString(org.apache.asterix.external.library.java.JObjects.JString)

Example 7 with JString

use of org.apache.asterix.external.library.java.JObjects.JString 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 8 with JString

use of org.apache.asterix.external.library.java.JObjects.JString in project asterixdb by apache.

the class UpperCaseFunction method evaluate.

@Override
public void evaluate(IFunctionHelper functionHelper) throws Exception {
    JRecord inputRecord = (JRecord) functionHelper.getArgument(0);
    JInt id = (JInt) inputRecord.getValueByName("id");
    // for maintaining uniqueness
    id.setValue(id.getValue() * -1);
    // constraint in the case when
    // output is re-inserted into source
    // dataset
    JString text = (JString) inputRecord.getValueByName("text");
    text.setValue(text.getValue().toUpperCase());
    JRecord result = (JRecord) functionHelper.getResultObject();
    result.setField("id", id);
    result.setField("text", text);
    functionHelper.setResult(result);
}
Also used : JRecord(org.apache.asterix.external.library.java.JObjects.JRecord) JInt(org.apache.asterix.external.library.java.JObjects.JInt) JString(org.apache.asterix.external.library.java.JObjects.JString)

Aggregations

JRecord (org.apache.asterix.external.library.java.JObjects.JRecord)8 JString (org.apache.asterix.external.library.java.JObjects.JString)8 JBoolean (org.apache.asterix.external.library.java.JObjects.JBoolean)3 JDouble (org.apache.asterix.external.library.java.JObjects.JDouble)3 JInt (org.apache.asterix.external.library.java.JObjects.JInt)3 JOrderedList (org.apache.asterix.external.library.java.JObjects.JOrderedList)3 JPoint (org.apache.asterix.external.library.java.JObjects.JPoint)3 JUnorderedList (org.apache.asterix.external.library.java.JObjects.JUnorderedList)3 IJObject (org.apache.asterix.external.api.IJObject)2 JCircle (org.apache.asterix.external.library.java.JObjects.JCircle)2 JDate (org.apache.asterix.external.library.java.JObjects.JDate)2 JDateTime (org.apache.asterix.external.library.java.JObjects.JDateTime)2 JDuration (org.apache.asterix.external.library.java.JObjects.JDuration)2 JFloat (org.apache.asterix.external.library.java.JObjects.JFloat)2 JLine (org.apache.asterix.external.library.java.JObjects.JLine)2 JPoint3D (org.apache.asterix.external.library.java.JObjects.JPoint3D)2 JPolygon (org.apache.asterix.external.library.java.JObjects.JPolygon)2 JTime (org.apache.asterix.external.library.java.JObjects.JTime)2 AOrderedListType (org.apache.asterix.om.types.AOrderedListType)2 ARecordType (org.apache.asterix.om.types.ARecordType)2