use of org.apache.asterix.metadata.entities.Function 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));
}
use of org.apache.asterix.metadata.entities.Function in project asterixdb by apache.
the class ExternalLibraryUtils method uninstallLibrary.
/**
* Remove the library from metadata completely.
* TODO Currently, external libraries only include functions and adapters. we need to extend this to include:
* 1. external data source
* 2. data parser
*
* @param dataverse
* @param libraryName
* @return true if the library was found and removed, false otherwise
* @throws AsterixException
* @throws RemoteException
* @throws ACIDException
*/
protected static boolean uninstallLibrary(String dataverse, String libraryName) throws AsterixException, RemoteException, ACIDException {
MetadataTransactionContext mdTxnCtx = null;
try {
// begin transaction
mdTxnCtx = MetadataManager.INSTANCE.beginTransaction();
// make sure dataverse exists
Dataverse dv = MetadataManager.INSTANCE.getDataverse(mdTxnCtx, dataverse);
if (dv == null) {
return false;
}
// make sure library exists
Library library = MetadataManager.INSTANCE.getLibrary(mdTxnCtx, dataverse, libraryName);
if (library == null) {
return false;
}
// get dataverse functions
List<Function> functions = MetadataManager.INSTANCE.getDataverseFunctions(mdTxnCtx, dataverse);
for (Function function : functions) {
// does function belong to library?
if (function.getName().startsWith(libraryName + "#")) {
// drop the function
MetadataManager.INSTANCE.dropFunction(mdTxnCtx, new FunctionSignature(dataverse, function.getName(), function.getArity()));
}
}
// get the dataverse adapters
List<DatasourceAdapter> adapters = MetadataManager.INSTANCE.getDataverseAdapters(mdTxnCtx, dataverse);
for (DatasourceAdapter adapter : adapters) {
// belong to the library?
if (adapter.getAdapterIdentifier().getName().startsWith(libraryName + "#")) {
// remove adapter <! we didn't check if there are feeds which use this adapter>
MetadataManager.INSTANCE.dropAdapter(mdTxnCtx, dataverse, adapter.getAdapterIdentifier().getName());
}
}
// drop the library itself
MetadataManager.INSTANCE.dropLibrary(mdTxnCtx, dataverse, libraryName);
MetadataManager.INSTANCE.commitTransaction(mdTxnCtx);
} catch (Exception e) {
MetadataManager.INSTANCE.abortTransaction(mdTxnCtx);
throw new AsterixException(e);
}
return true;
}
use of org.apache.asterix.metadata.entities.Function in project asterixdb by apache.
the class MetadataNode method dropFunction.
@Override
public void dropFunction(JobId jobId, FunctionSignature functionSignature) throws MetadataException, RemoteException {
Function function = getFunction(jobId, functionSignature);
if (function == null) {
throw new MetadataException("Cannot drop function '" + functionSignature.toString() + "' because it doesn't exist.");
}
try {
// Delete entry from the 'function' dataset.
ITupleReference searchKey = createTuple(functionSignature.getNamespace(), functionSignature.getName(), "" + functionSignature.getArity());
// Searches the index for the tuple to be deleted. Acquires an S
// lock on the 'function' dataset.
ITupleReference functionTuple = getTupleToBeDeleted(jobId, MetadataPrimaryIndexes.FUNCTION_DATASET, searchKey);
deleteTupleFromIndex(jobId, MetadataPrimaryIndexes.FUNCTION_DATASET, functionTuple);
// TODO: Change this to be a BTree specific exception, e.g.,
// BTreeKeyDoesNotExistException.
} catch (HyracksDataException e) {
if (e.getComponent().equals(ErrorCode.HYRACKS) && e.getErrorCode() == ErrorCode.UPDATE_OR_DELETE_NON_EXISTENT_KEY) {
throw new MetadataException("There is no function with the name " + functionSignature.getName() + " and arity " + functionSignature.getArity(), e);
} else {
throw new MetadataException(e);
}
} catch (ACIDException e) {
throw new MetadataException(e);
}
}
use of org.apache.asterix.metadata.entities.Function 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);
}
}
use of org.apache.asterix.metadata.entities.Function in project asterixdb by apache.
the class MetadataTransactionContext method dropFunction.
public void dropFunction(FunctionSignature signature) {
Function function = new Function(signature.getNamespace(), signature.getName(), signature.getArity(), null, null, null, null, null, 0);
droppedCache.addFunctionIfNotExists(function);
logAndApply(new MetadataLogicalOperation(function, false));
}
Aggregations