Search in sources :

Example 1 with LibraryTupleTranslator

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

the class MetadataNode method getDataverseLibraries.

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

Example 2 with LibraryTupleTranslator

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

the class MetadataNode method addLibrary.

@Override
public void addLibrary(JobId jobId, Library library) throws MetadataException, RemoteException {
    try {
        // Insert into the 'Library' dataset.
        LibraryTupleTranslator tupleReaderWriter = tupleTranslatorProvider.getLibraryTupleTranslator(true);
        ITupleReference libraryTuple = tupleReaderWriter.getTupleFromMetadataEntity(library);
        insertTupleIntoIndex(jobId, MetadataPrimaryIndexes.LIBRARY_DATASET, libraryTuple);
    } catch (HyracksDataException e) {
        if (e.getComponent().equals(ErrorCode.HYRACKS) && e.getErrorCode() == ErrorCode.DUPLICATE_KEY) {
            throw new MetadataException("A library with this name " + library.getDataverseName() + " already exists in dataverse '" + library.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) LibraryTupleTranslator(org.apache.asterix.metadata.entitytupletranslators.LibraryTupleTranslator) HyracksDataException(org.apache.hyracks.api.exceptions.HyracksDataException) ACIDException(org.apache.asterix.common.exceptions.ACIDException)

Example 3 with LibraryTupleTranslator

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

the class MetadataNode method getLibrary.

@Override
public Library getLibrary(JobId jobId, String dataverseName, String libraryName) throws MetadataException, RemoteException {
    try {
        ITupleReference searchKey = createTuple(dataverseName, libraryName);
        LibraryTupleTranslator tupleReaderWriter = tupleTranslatorProvider.getLibraryTupleTranslator(false);
        List<Library> results = new ArrayList<>();
        IValueExtractor<Library> valueExtractor = new MetadataEntityValueExtractor<>(tupleReaderWriter);
        searchIndex(jobId, MetadataPrimaryIndexes.LIBRARY_DATASET, searchKey, valueExtractor, results);
        if (results.isEmpty()) {
            return null;
        }
        return results.get(0);
    } catch (HyracksDataException e) {
        throw new MetadataException(e);
    }
}
Also used : MetadataEntityValueExtractor(org.apache.asterix.metadata.valueextractors.MetadataEntityValueExtractor) ITupleReference(org.apache.hyracks.dataflow.common.data.accessors.ITupleReference) ArrayList(java.util.ArrayList) Library(org.apache.asterix.metadata.entities.Library) LibraryTupleTranslator(org.apache.asterix.metadata.entitytupletranslators.LibraryTupleTranslator) HyracksDataException(org.apache.hyracks.api.exceptions.HyracksDataException)

Aggregations

LibraryTupleTranslator (org.apache.asterix.metadata.entitytupletranslators.LibraryTupleTranslator)3 HyracksDataException (org.apache.hyracks.api.exceptions.HyracksDataException)3 ITupleReference (org.apache.hyracks.dataflow.common.data.accessors.ITupleReference)3 ArrayList (java.util.ArrayList)2 Library (org.apache.asterix.metadata.entities.Library)2 MetadataEntityValueExtractor (org.apache.asterix.metadata.valueextractors.MetadataEntityValueExtractor)2 ACIDException (org.apache.asterix.common.exceptions.ACIDException)1