use of org.apache.asterix.common.functions.FunctionSignature in project asterixdb by apache.
the class QueryTranslator method handleConnectFeedStatement.
private void handleConnectFeedStatement(MetadataProvider metadataProvider, Statement stmt) throws Exception {
FeedConnection fc;
ConnectFeedStatement cfs = (ConnectFeedStatement) stmt;
String dataverseName = getActiveDataverse(cfs.getDataverseName());
String feedName = cfs.getFeedName();
String datasetName = cfs.getDatasetName().getValue();
String policyName = cfs.getPolicy();
MetadataTransactionContext mdTxnCtx = MetadataManager.INSTANCE.beginTransaction();
metadataProvider.setMetadataTxnContext(mdTxnCtx);
// Check whether feed is alive
ActiveLifecycleListener activeListener = (ActiveLifecycleListener) appCtx.getActiveLifecycleListener();
ActiveJobNotificationHandler activeEventHandler = activeListener.getNotificationHandler();
if (activeEventHandler.getActiveEntityListener(new EntityId(Feed.EXTENSION_NAME, dataverseName, feedName)) != null) {
throw new CompilationException(ErrorCode.FEED_CHANGE_FEED_CONNECTIVITY_ON_ALIVE_FEED, feedName);
}
// Transaction handling
MetadataLockManager.INSTANCE.connectFeedBegin(metadataProvider.getLocks(), dataverseName, dataverseName + "." + datasetName, dataverseName + "." + feedName);
try {
// validation
FeedMetadataUtil.validateIfDatasetExists(metadataProvider, dataverseName, datasetName, mdTxnCtx);
Feed feed = FeedMetadataUtil.validateIfFeedExists(dataverseName, feedName, metadataProvider.getMetadataTxnContext());
ARecordType outputType = FeedMetadataUtil.getOutputType(feed, feed.getAdapterConfiguration(), ExternalDataConstants.KEY_TYPE_NAME);
List<FunctionSignature> appliedFunctions = cfs.getAppliedFunctions();
for (FunctionSignature func : appliedFunctions) {
if (MetadataManager.INSTANCE.getFunction(mdTxnCtx, func) == null) {
throw new CompilationException(ErrorCode.FEED_CONNECT_FEED_APPLIED_INVALID_FUNCTION, func.getName());
}
}
fc = MetadataManager.INSTANCE.getFeedConnection(metadataProvider.getMetadataTxnContext(), dataverseName, feedName, datasetName);
if (fc != null) {
throw new AlgebricksException("Feed" + feedName + " is already connected dataset " + datasetName);
}
fc = new FeedConnection(dataverseName, feedName, datasetName, appliedFunctions, policyName, outputType.toString());
MetadataManager.INSTANCE.addFeedConnection(metadataProvider.getMetadataTxnContext(), fc);
// Increase function reference count.
for (FunctionSignature funcSig : appliedFunctions) {
// The function should be cached in Metadata manager, so this operation is not that expensive.
Function func = MetadataManager.INSTANCE.getFunction(mdTxnCtx, funcSig);
func.reference();
MetadataManager.INSTANCE.updateFunction(mdTxnCtx, func);
}
MetadataManager.INSTANCE.commitTransaction(mdTxnCtx);
} catch (Exception e) {
abort(e, e, mdTxnCtx);
throw e;
} finally {
metadataProvider.getLocks().unlock();
}
}
use of org.apache.asterix.common.functions.FunctionSignature in project asterixdb by apache.
the class LangExpressionToPlanTranslator method visit.
@Override
public Pair<ILogicalOperator, LogicalVariable> visit(CallExpr fcall, Mutable<ILogicalOperator> tupSource) throws CompilationException {
LogicalVariable v = context.newVar();
FunctionSignature signature = fcall.getFunctionSignature();
List<Mutable<ILogicalExpression>> args = new ArrayList<>();
Mutable<ILogicalOperator> topOp = tupSource;
for (Expression expr : fcall.getExprList()) {
switch(expr.getKind()) {
case VARIABLE_EXPRESSION:
LogicalVariable var = context.getVar(((VariableExpr) expr).getVar().getId());
args.add(new MutableObject<>(new VariableReferenceExpression(var)));
break;
case LITERAL_EXPRESSION:
LiteralExpr val = (LiteralExpr) expr;
args.add(new MutableObject<>(new ConstantExpression(new AsterixConstantValue(ConstantHelper.objectFromLiteral(val.getValue())))));
break;
default:
Pair<ILogicalExpression, Mutable<ILogicalOperator>> eo = langExprToAlgExpression(expr, topOp);
AbstractLogicalOperator o1 = (AbstractLogicalOperator) eo.second.getValue();
args.add(new MutableObject<>(eo.first));
if (o1 != null && !(o1.getOperatorTag() == LogicalOperatorTag.ASSIGN && hasOnlyChild(o1, topOp))) {
topOp = eo.second;
}
break;
}
}
AbstractFunctionCallExpression f;
if ((f = lookupUserDefinedFunction(signature, args)) == null) {
f = lookupBuiltinFunction(signature.getName(), signature.getArity(), args);
}
if (f == null) {
throw new CompilationException(" Unknown function " + signature.getName() + "@" + signature.getArity());
}
// Put hints into function call expr.
if (fcall.hasHints()) {
for (IExpressionAnnotation hint : fcall.getHints()) {
f.getAnnotations().put(hint, hint);
}
}
AssignOperator op = new AssignOperator(v, new MutableObject<>(f));
if (topOp != null) {
op.getInputs().add(topOp);
}
return new Pair<>(op, v);
}
use of org.apache.asterix.common.functions.FunctionSignature in project asterixdb by apache.
the class QueryTranslator method handleFunctionDropStatement.
protected void handleFunctionDropStatement(MetadataProvider metadataProvider, Statement stmt) throws Exception {
FunctionDropStatement stmtDropFunction = (FunctionDropStatement) stmt;
FunctionSignature signature = stmtDropFunction.getFunctionSignature();
signature.setNamespace(getActiveDataverseName(signature.getNamespace()));
MetadataTransactionContext mdTxnCtx = MetadataManager.INSTANCE.beginTransaction();
metadataProvider.setMetadataTxnContext(mdTxnCtx);
MetadataLockManager.INSTANCE.functionStatementBegin(metadataProvider.getLocks(), signature.getNamespace(), signature.getNamespace() + "." + signature.getName());
try {
Function function = MetadataManager.INSTANCE.getFunction(mdTxnCtx, signature);
if (function == null) {
if (!stmtDropFunction.getIfExists()) {
throw new AlgebricksException("Unknonw function " + signature);
}
} else if (function.getReferenceCount() != 0) {
throw new AlgebricksException("Function " + signature + " is being used. It cannot be dropped.");
} else {
MetadataManager.INSTANCE.dropFunction(mdTxnCtx, signature);
}
MetadataManager.INSTANCE.commitTransaction(mdTxnCtx);
} catch (Exception e) {
abort(e, e, mdTxnCtx);
throw e;
} finally {
metadataProvider.getLocks().unlock();
}
}
use of org.apache.asterix.common.functions.FunctionSignature in project asterixdb by apache.
the class MetadataCache method dropDataverse.
public Dataverse dropDataverse(Dataverse dataverse) {
synchronized (dataverses) {
synchronized (datasets) {
synchronized (indexes) {
synchronized (datatypes) {
synchronized (functions) {
synchronized (adapters) {
synchronized (libraries) {
synchronized (feeds) {
synchronized (compactionPolicies) {
datasets.remove(dataverse.getDataverseName());
indexes.remove(dataverse.getDataverseName());
datatypes.remove(dataverse.getDataverseName());
adapters.remove(dataverse.getDataverseName());
compactionPolicies.remove(dataverse.getDataverseName());
List<FunctionSignature> markedFunctionsForRemoval = new ArrayList<>();
for (FunctionSignature signature : functions.keySet()) {
if (signature.getNamespace().equals(dataverse.getDataverseName())) {
markedFunctionsForRemoval.add(signature);
}
}
for (FunctionSignature signature : markedFunctionsForRemoval) {
functions.remove(signature);
}
libraries.remove(dataverse.getDataverseName());
feeds.remove(dataverse.getDataverseName());
return dataverses.remove(dataverse.getDataverseName());
}
}
}
}
}
}
}
}
}
}
use of org.apache.asterix.common.functions.FunctionSignature in project asterixdb by apache.
the class MetadataCache method dropFunction.
public Function dropFunction(Function function) {
synchronized (functions) {
FunctionSignature signature = new FunctionSignature(function.getDataverseName(), function.getName(), function.getArity());
Function fun = functions.get(signature);
if (fun == null) {
return null;
}
return functions.remove(signature);
}
}
Aggregations