Search in sources :

Example 1 with FunctionTupleTranslator

use of org.apache.asterix.metadata.entitytupletranslators.FunctionTupleTranslator in project asterixdb by apache.

the class MetadataNode method addFunction.

@Override
public void addFunction(JobId jobId, Function function) throws MetadataException, RemoteException {
    try {
        // Insert into the 'function' dataset.
        FunctionTupleTranslator tupleReaderWriter = tupleTranslatorProvider.getFunctionTupleTranslator(true);
        ITupleReference functionTuple = tupleReaderWriter.getTupleFromMetadataEntity(function);
        insertTupleIntoIndex(jobId, MetadataPrimaryIndexes.FUNCTION_DATASET, functionTuple);
    } catch (HyracksDataException e) {
        if (e.getComponent().equals(ErrorCode.HYRACKS) && e.getErrorCode() == ErrorCode.DUPLICATE_KEY) {
            throw new MetadataException("A function with this name " + function.getName() + " and arity " + function.getArity() + " already exists in dataverse '" + function.getDataverseName() + "'.", e);
        } else {
            throw new MetadataException(e);
        }
    } catch (ACIDException e) {
        throw new MetadataException(e);
    }
}
Also used : ITupleReference(org.apache.hyracks.dataflow.common.data.accessors.ITupleReference) FunctionTupleTranslator(org.apache.asterix.metadata.entitytupletranslators.FunctionTupleTranslator) HyracksDataException(org.apache.hyracks.api.exceptions.HyracksDataException) ACIDException(org.apache.asterix.common.exceptions.ACIDException)

Example 2 with FunctionTupleTranslator

use of org.apache.asterix.metadata.entitytupletranslators.FunctionTupleTranslator in project asterixdb by apache.

the class MetadataNode method getFunction.

@Override
public Function getFunction(JobId jobId, FunctionSignature functionSignature) throws MetadataException, RemoteException {
    try {
        ITupleReference searchKey = createTuple(functionSignature.getNamespace(), functionSignature.getName(), "" + functionSignature.getArity());
        FunctionTupleTranslator tupleReaderWriter = tupleTranslatorProvider.getFunctionTupleTranslator(false);
        List<Function> results = new ArrayList<>();
        IValueExtractor<Function> valueExtractor = new MetadataEntityValueExtractor<>(tupleReaderWriter);
        searchIndex(jobId, MetadataPrimaryIndexes.FUNCTION_DATASET, searchKey, valueExtractor, results);
        if (results.isEmpty()) {
            return null;
        }
        return results.get(0);
    } catch (HyracksDataException e) {
        throw new MetadataException(e);
    }
}
Also used : Function(org.apache.asterix.metadata.entities.Function) MetadataEntityValueExtractor(org.apache.asterix.metadata.valueextractors.MetadataEntityValueExtractor) ITupleReference(org.apache.hyracks.dataflow.common.data.accessors.ITupleReference) ArrayList(java.util.ArrayList) FunctionTupleTranslator(org.apache.asterix.metadata.entitytupletranslators.FunctionTupleTranslator) HyracksDataException(org.apache.hyracks.api.exceptions.HyracksDataException)

Example 3 with FunctionTupleTranslator

use of org.apache.asterix.metadata.entitytupletranslators.FunctionTupleTranslator in project asterixdb by apache.

the class MetadataNode method updateFunction.

@Override
public void updateFunction(JobId jobId, Function function) throws MetadataException, RemoteException {
    try {
        // remove old function
        ITupleReference searchKey;
        searchKey = createTuple(function.getDataverseName(), function.getName(), Integer.toString(function.getArity()));
        ITupleReference functionTuple = getTupleToBeDeleted(jobId, MetadataPrimaryIndexes.FUNCTION_DATASET, searchKey);
        deleteTupleFromIndex(jobId, MetadataPrimaryIndexes.FUNCTION_DATASET, functionTuple);
        // add new function
        FunctionTupleTranslator functionTupleTranslator = tupleTranslatorProvider.getFunctionTupleTranslator(true);
        functionTuple = functionTupleTranslator.getTupleFromMetadataEntity(function);
        insertTupleIntoIndex(jobId, MetadataPrimaryIndexes.FUNCTION_DATASET, functionTuple);
    } catch (HyracksDataException | ACIDException e) {
        throw new MetadataException(e);
    }
}
Also used : ITupleReference(org.apache.hyracks.dataflow.common.data.accessors.ITupleReference) FunctionTupleTranslator(org.apache.asterix.metadata.entitytupletranslators.FunctionTupleTranslator) HyracksDataException(org.apache.hyracks.api.exceptions.HyracksDataException) ACIDException(org.apache.asterix.common.exceptions.ACIDException)

Example 4 with FunctionTupleTranslator

use of org.apache.asterix.metadata.entitytupletranslators.FunctionTupleTranslator in project asterixdb by apache.

the class MetadataNode method getDataverseFunctions.

@Override
public List<Function> getDataverseFunctions(JobId jobId, String dataverseName) throws MetadataException, RemoteException {
    try {
        ITupleReference searchKey = createTuple(dataverseName);
        FunctionTupleTranslator tupleReaderWriter = tupleTranslatorProvider.getFunctionTupleTranslator(false);
        IValueExtractor<Function> valueExtractor = new MetadataEntityValueExtractor<>(tupleReaderWriter);
        List<Function> results = new ArrayList<>();
        searchIndex(jobId, MetadataPrimaryIndexes.FUNCTION_DATASET, searchKey, valueExtractor, results);
        return results;
    } catch (HyracksDataException e) {
        throw new MetadataException(e);
    }
}
Also used : Function(org.apache.asterix.metadata.entities.Function) MetadataEntityValueExtractor(org.apache.asterix.metadata.valueextractors.MetadataEntityValueExtractor) ITupleReference(org.apache.hyracks.dataflow.common.data.accessors.ITupleReference) ArrayList(java.util.ArrayList) FunctionTupleTranslator(org.apache.asterix.metadata.entitytupletranslators.FunctionTupleTranslator) HyracksDataException(org.apache.hyracks.api.exceptions.HyracksDataException)

Aggregations

FunctionTupleTranslator (org.apache.asterix.metadata.entitytupletranslators.FunctionTupleTranslator)4 HyracksDataException (org.apache.hyracks.api.exceptions.HyracksDataException)4 ITupleReference (org.apache.hyracks.dataflow.common.data.accessors.ITupleReference)4 ArrayList (java.util.ArrayList)2 ACIDException (org.apache.asterix.common.exceptions.ACIDException)2 Function (org.apache.asterix.metadata.entities.Function)2 MetadataEntityValueExtractor (org.apache.asterix.metadata.valueextractors.MetadataEntityValueExtractor)2