Search in sources :

Example 6 with IACursor

use of org.apache.asterix.om.base.IACursor in project asterixdb by apache.

the class FunctionTupleTranslator method createFunctionFromARecord.

private Function createFunctionFromARecord(ARecord functionRecord) {
    String dataverseName = ((AString) functionRecord.getValueByPos(MetadataRecordTypes.FUNCTION_ARECORD_DATAVERSENAME_FIELD_INDEX)).getStringValue();
    String functionName = ((AString) functionRecord.getValueByPos(MetadataRecordTypes.FUNCTION_ARECORD_FUNCTIONNAME_FIELD_INDEX)).getStringValue();
    String arity = ((AString) functionRecord.getValueByPos(MetadataRecordTypes.FUNCTION_ARECORD_FUNCTION_ARITY_FIELD_INDEX)).getStringValue();
    IACursor cursor = ((AOrderedList) functionRecord.getValueByPos(MetadataRecordTypes.FUNCTION_ARECORD_FUNCTION_PARAM_LIST_FIELD_INDEX)).getCursor();
    List<String> params = new ArrayList<>();
    while (cursor.next()) {
        params.add(((AString) cursor.get()).getStringValue());
    }
    String returnType = ((AString) functionRecord.getValueByPos(MetadataRecordTypes.FUNCTION_ARECORD_FUNCTION_RETURN_TYPE_FIELD_INDEX)).getStringValue();
    String definition = ((AString) functionRecord.getValueByPos(MetadataRecordTypes.FUNCTION_ARECORD_FUNCTION_DEFINITION_FIELD_INDEX)).getStringValue();
    String language = ((AString) functionRecord.getValueByPos(MetadataRecordTypes.FUNCTION_ARECORD_FUNCTION_LANGUAGE_FIELD_INDEX)).getStringValue();
    String functionKind = ((AString) functionRecord.getValueByPos(MetadataRecordTypes.FUNCTION_ARECORD_FUNCTION_KIND_FIELD_INDEX)).getStringValue();
    String referenceCount = ((AString) functionRecord.getValueByPos(MetadataRecordTypes.FUNCTION_ARECORD_FUNCTION_REFERENCE_COUNT_INDEX)).getStringValue();
    return new Function(dataverseName, functionName, Integer.parseInt(arity), params, returnType, definition, language, functionKind, Integer.parseInt(referenceCount));
}
Also used : Function(org.apache.asterix.metadata.entities.Function) AOrderedList(org.apache.asterix.om.base.AOrderedList) ArrayList(java.util.ArrayList) AString(org.apache.asterix.om.base.AString) IACursor(org.apache.asterix.om.base.IACursor) AString(org.apache.asterix.om.base.AString)

Example 7 with IACursor

use of org.apache.asterix.om.base.IACursor in project asterixdb by apache.

the class FeedConnectionTupleTranslator method createFeedConnFromRecord.

private FeedConnection createFeedConnFromRecord(ARecord feedConnRecord) {
    String dataverseName = ((AString) feedConnRecord.getValueByPos(MetadataRecordTypes.FEED_CONN_DATAVERSE_NAME_FIELD_INDEX)).getStringValue();
    String feedName = ((AString) feedConnRecord.getValueByPos(MetadataRecordTypes.FEED_CONN_FEED_NAME_FIELD_INDEX)).getStringValue();
    String datasetName = ((AString) feedConnRecord.getValueByPos(MetadataRecordTypes.FEED_CONN_DATASET_NAME_FIELD_INDEX)).getStringValue();
    String outputType = ((AString) feedConnRecord.getValueByPos(MetadataRecordTypes.FEED_CONN_OUTPUT_TYPE_INDEX)).getStringValue();
    String policyName = ((AString) feedConnRecord.getValueByPos(MetadataRecordTypes.FEED_CONN_POLICY_FIELD_INDEX)).getStringValue();
    ArrayList<FunctionSignature> appliedFunctions = null;
    Object o = feedConnRecord.getValueByPos(MetadataRecordTypes.FEED_CONN_APPLIED_FUNCTIONS_FIELD_INDEX);
    IACursor cursor;
    if (!(o instanceof ANull) && !(o instanceof AMissing)) {
        appliedFunctions = new ArrayList<>();
        FunctionSignature functionSignature;
        cursor = ((AUnorderedList) feedConnRecord.getValueByPos(MetadataRecordTypes.FEED_CONN_APPLIED_FUNCTIONS_FIELD_INDEX)).getCursor();
        while (cursor.next()) {
            //TODO: allow different arity
            functionSignature = new FunctionSignature(dataverseName, ((AString) cursor.get()).getStringValue(), 1);
            appliedFunctions.add(functionSignature);
        }
    }
    return new FeedConnection(dataverseName, feedName, datasetName, appliedFunctions, policyName, outputType);
}
Also used : ANull(org.apache.asterix.om.base.ANull) FeedConnection(org.apache.asterix.metadata.entities.FeedConnection) AMissing(org.apache.asterix.om.base.AMissing) AString(org.apache.asterix.om.base.AString) IACursor(org.apache.asterix.om.base.IACursor) AString(org.apache.asterix.om.base.AString) FunctionSignature(org.apache.asterix.common.functions.FunctionSignature)

Example 8 with IACursor

use of org.apache.asterix.om.base.IACursor in project asterixdb by apache.

the class FeedPolicyTupleTranslator method createFeedPolicyFromARecord.

private FeedPolicyEntity createFeedPolicyFromARecord(ARecord feedPolicyRecord) {
    FeedPolicyEntity feedPolicy = null;
    String dataverseName = ((AString) feedPolicyRecord.getValueByPos(MetadataRecordTypes.FEED_POLICY_ARECORD_DATAVERSE_NAME_FIELD_INDEX)).getStringValue();
    String policyName = ((AString) feedPolicyRecord.getValueByPos(MetadataRecordTypes.FEED_POLICY_ARECORD_POLICY_NAME_FIELD_INDEX)).getStringValue();
    String description = ((AString) feedPolicyRecord.getValueByPos(MetadataRecordTypes.FEED_POLICY_ARECORD_DESCRIPTION_FIELD_INDEX)).getStringValue();
    IACursor cursor = ((AUnorderedList) feedPolicyRecord.getValueByPos(MetadataRecordTypes.FEED_POLICY_ARECORD_PROPERTIES_FIELD_INDEX)).getCursor();
    Map<String, String> policyParamters = new HashMap<>();
    String key;
    String value;
    while (cursor.next()) {
        ARecord field = (ARecord) cursor.get();
        key = ((AString) field.getValueByPos(MetadataRecordTypes.PROPERTIES_NAME_FIELD_INDEX)).getStringValue();
        value = ((AString) field.getValueByPos(MetadataRecordTypes.PROPERTIES_VALUE_FIELD_INDEX)).getStringValue();
        policyParamters.put(key, value);
    }
    feedPolicy = new FeedPolicyEntity(dataverseName, policyName, description, policyParamters);
    return feedPolicy;
}
Also used : ARecord(org.apache.asterix.om.base.ARecord) FeedPolicyEntity(org.apache.asterix.metadata.entities.FeedPolicyEntity) HashMap(java.util.HashMap) AUnorderedList(org.apache.asterix.om.base.AUnorderedList) AString(org.apache.asterix.om.base.AString) AMutableString(org.apache.asterix.om.base.AMutableString) IACursor(org.apache.asterix.om.base.IACursor) AString(org.apache.asterix.om.base.AString)

Example 9 with IACursor

use of org.apache.asterix.om.base.IACursor in project asterixdb by apache.

the class AccessMethodUtils method checkFTSearchConstantExpression.

// Checks whether a proper constant expression is in place for the full-text search.
// A proper constant expression in the full-text search should be among string, string type (Un)ordered list.
public static void checkFTSearchConstantExpression(ILogicalExpression constExpression) throws AlgebricksException {
    IAObject objectFromExpr = ConstantExpressionUtil.getConstantIaObject(constExpression, null);
    String arg2Value;
    IACursor oListCursor;
    switch(objectFromExpr.getType().getTypeTag()) {
        case STRING:
            arg2Value = ConstantExpressionUtil.getStringConstant(objectFromExpr);
            checkAndGenerateFTSearchExceptionForStringPhrase(arg2Value);
            break;
        case ARRAY:
            oListCursor = ConstantExpressionUtil.getOrderedListConstant(objectFromExpr).getCursor();
            checkEachElementInFTSearchListPredicate(oListCursor);
            break;
        case MULTISET:
            oListCursor = ConstantExpressionUtil.getUnorderedListConstant(objectFromExpr).getCursor();
            checkEachElementInFTSearchListPredicate(oListCursor);
            break;
        default:
            throw new CompilationException(ErrorCode.COMPILATION_TYPE_UNSUPPORTED, BuiltinFunctions.FULLTEXT_CONTAINS.getName(), objectFromExpr.getType().getTypeTag());
    }
}
Also used : CompilationException(org.apache.asterix.common.exceptions.CompilationException) IAObject(org.apache.asterix.om.base.IAObject) AString(org.apache.asterix.om.base.AString) IACursor(org.apache.asterix.om.base.IACursor)

Example 10 with IACursor

use of org.apache.asterix.om.base.IACursor in project asterixdb by apache.

the class AUnorderedListSerializerDeserializer method serialize.

@SuppressWarnings("unchecked")
@Override
public void serialize(AUnorderedList instance, DataOutput out) throws HyracksDataException {
    // TODO: schemaless ordered list serializer
    UnorderedListBuilder listBuilder = new UnorderedListBuilder();
    ArrayBackedValueStorage itemValue = new ArrayBackedValueStorage();
    listBuilder.reset(unorderedlistType);
    IACursor cursor = instance.getCursor();
    while (cursor.next()) {
        itemValue.reset();
        serializer.serialize(cursor.get(), itemValue.getDataOutput());
        listBuilder.addItem(itemValue);
    }
    listBuilder.write(out, false);
}
Also used : ArrayBackedValueStorage(org.apache.hyracks.data.std.util.ArrayBackedValueStorage) IACursor(org.apache.asterix.om.base.IACursor) UnorderedListBuilder(org.apache.asterix.builders.UnorderedListBuilder)

Aggregations

IACursor (org.apache.asterix.om.base.IACursor)12 AString (org.apache.asterix.om.base.AString)10 ARecord (org.apache.asterix.om.base.ARecord)7 AUnorderedList (org.apache.asterix.om.base.AUnorderedList)5 ArrayList (java.util.ArrayList)4 HashMap (java.util.HashMap)4 AMutableString (org.apache.asterix.om.base.AMutableString)4 AOrderedList (org.apache.asterix.om.base.AOrderedList)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 DataInput (java.io.DataInput)2 DataInputStream (java.io.DataInputStream)2 LinkedHashMap (java.util.LinkedHashMap)2 List (java.util.List)2 Dataset (org.apache.asterix.metadata.entities.Dataset)2 ABoolean (org.apache.asterix.om.base.ABoolean)2 AInt32 (org.apache.asterix.om.base.AInt32)2 ARecordType (org.apache.asterix.om.types.ARecordType)2 IAType (org.apache.asterix.om.types.IAType)2 RemoteException (java.rmi.RemoteException)1 Date (java.util.Date)1