Search in sources :

Example 1 with Feed

use of org.apache.asterix.metadata.entities.Feed in project asterixdb by apache.

the class SubscribeFeedStatement method getOutputType.

private String getOutputType(MetadataTransactionContext mdTxnCtx) throws MetadataException {
    String outputType;
    EntityId feedId = connectionRequest.getReceivingFeedId();
    Feed feed = MetadataManager.INSTANCE.getFeed(mdTxnCtx, feedId.getDataverse(), feedId.getEntityName());
    try {
        outputType = FeedMetadataUtil.getOutputType(feed, feed.getAdapterConfiguration(), ExternalDataConstants.KEY_TYPE_NAME).getTypeName();
        return outputType;
    } catch (MetadataException ae) {
        throw new MetadataException(ae);
    }
}
Also used : EntityId(org.apache.asterix.active.EntityId) MetadataException(org.apache.asterix.metadata.MetadataException) Feed(org.apache.asterix.metadata.entities.Feed)

Example 2 with Feed

use of org.apache.asterix.metadata.entities.Feed in project asterixdb by apache.

the class UnnestToDataScanRule method createFeedDataSource.

private FeedDataSource createFeedDataSource(DataSourceId aqlId, String targetDataset, String sourceFeedName, String subscriptionLocation, MetadataProvider metadataProvider, FeedPolicyEntity feedPolicy, String outputType, String locations, LogicalVariable recordVar, IOptimizationContext context, List<LogicalVariable> pkVars) throws AlgebricksException {
    if (!aqlId.getDataverseName().equals(metadataProvider.getDefaultDataverse() == null ? null : metadataProvider.getDefaultDataverse().getDataverseName())) {
        return null;
    }
    Dataset dataset = metadataProvider.findDataset(aqlId.getDataverseName(), targetDataset);
    ARecordType feedOutputType = (ARecordType) metadataProvider.findType(aqlId.getDataverseName(), outputType);
    Feed sourceFeed = metadataProvider.findFeed(aqlId.getDataverseName(), sourceFeedName);
    FeedConnection feedConnection = metadataProvider.findFeedConnection(aqlId.getDataverseName(), sourceFeedName, targetDataset);
    ARecordType metaType = null;
    // Does dataset have meta?
    if (dataset.hasMetaPart()) {
        String metaTypeName = FeedUtils.getFeedMetaTypeName(sourceFeed.getAdapterConfiguration());
        if (metaTypeName == null) {
            throw new AlgebricksException("Feed to a dataset with metadata doesn't have meta type specified");
        }
        String dataverseName = aqlId.getDataverseName();
        if (metaTypeName.contains(".")) {
            dataverseName = metaTypeName.substring(0, metaTypeName.indexOf('.'));
            metaTypeName = metaTypeName.substring(metaTypeName.indexOf('.') + 1);
        }
        metaType = (ARecordType) metadataProvider.findType(dataverseName, metaTypeName);
    }
    // Is a change feed?
    List<IAType> pkTypes = null;
    List<List<String>> partitioningKeys = null;
    List<Integer> keySourceIndicator = null;
    List<Mutable<ILogicalExpression>> keyAccessExpression = null;
    List<ScalarFunctionCallExpression> keyAccessScalarFunctionCallExpression;
    if (ExternalDataUtils.isChangeFeed(sourceFeed.getAdapterConfiguration())) {
        keyAccessExpression = new ArrayList<>();
        keyAccessScalarFunctionCallExpression = new ArrayList<>();
        pkTypes = ((InternalDatasetDetails) dataset.getDatasetDetails()).getPrimaryKeyType();
        partitioningKeys = ((InternalDatasetDetails) dataset.getDatasetDetails()).getPartitioningKey();
        if (dataset.hasMetaPart()) {
            keySourceIndicator = ((InternalDatasetDetails) dataset.getDatasetDetails()).getKeySourceIndicator();
        }
        for (int i = 0; i < partitioningKeys.size(); i++) {
            List<String> key = partitioningKeys.get(i);
            if (keySourceIndicator == null || keySourceIndicator.get(i).intValue() == 0) {
                PlanTranslationUtil.prepareVarAndExpression(key, recordVar, pkVars, keyAccessExpression, null, context);
            } else {
                PlanTranslationUtil.prepareMetaKeyAccessExpression(key, recordVar, keyAccessExpression, pkVars, null, context);
            }
        }
        keyAccessExpression.forEach(expr -> keyAccessScalarFunctionCallExpression.add((ScalarFunctionCallExpression) expr.getValue()));
    } else {
        keyAccessExpression = null;
        keyAccessScalarFunctionCallExpression = null;
    }
    FeedDataSource feedDataSource = new FeedDataSource(sourceFeed, aqlId, targetDataset, feedOutputType, metaType, pkTypes, partitioningKeys, keyAccessScalarFunctionCallExpression, sourceFeed.getFeedId(), FeedRuntimeType.valueOf(subscriptionLocation), locations.split(","), context.getComputationNodeDomain(), feedConnection);
    feedDataSource.getProperties().put(BuiltinFeedPolicies.CONFIG_FEED_POLICY_KEY, feedPolicy);
    return feedDataSource;
}
Also used : FeedConnection(org.apache.asterix.metadata.entities.FeedConnection) Dataset(org.apache.asterix.metadata.entities.Dataset) AlgebricksException(org.apache.hyracks.algebricks.common.exceptions.AlgebricksException) AString(org.apache.asterix.om.base.AString) FeedDataSource(org.apache.asterix.metadata.declared.FeedDataSource) Mutable(org.apache.commons.lang3.mutable.Mutable) ArrayList(java.util.ArrayList) List(java.util.List) ARecordType(org.apache.asterix.om.types.ARecordType) Feed(org.apache.asterix.metadata.entities.Feed) IAType(org.apache.asterix.om.types.IAType) ScalarFunctionCallExpression(org.apache.hyracks.algebricks.core.algebra.expressions.ScalarFunctionCallExpression)

Example 3 with Feed

use of org.apache.asterix.metadata.entities.Feed in project asterixdb by apache.

the class FeedTupleTranslator method createFeedFromARecord.

private Feed createFeedFromARecord(ARecord feedRecord) {
    Feed feed;
    String dataverseName = ((AString) feedRecord.getValueByPos(MetadataRecordTypes.FEED_ARECORD_DATAVERSE_NAME_FIELD_INDEX)).getStringValue();
    String feedName = ((AString) feedRecord.getValueByPos(MetadataRecordTypes.FEED_ARECORD_FEED_NAME_FIELD_INDEX)).getStringValue();
    AUnorderedList feedConfig = (AUnorderedList) feedRecord.getValueByPos(MetadataRecordTypes.FEED_ARECORD_ADAPTOR_CONFIG_INDEX);
    String adapterName = ((AString) feedRecord.getValueByPos(MetadataRecordTypes.FEED_ARECORD_ADAPTOR_NAME_INDEX)).getStringValue();
    IACursor cursor = feedConfig.getCursor();
    // restore configurations
    String key;
    String value;
    Map<String, String> adaptorConfiguration = new HashMap<>();
    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();
        adaptorConfiguration.put(key, value);
    }
    feed = new Feed(dataverseName, feedName, adapterName, adaptorConfiguration);
    return feed;
}
Also used : ARecord(org.apache.asterix.om.base.ARecord) 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) Feed(org.apache.asterix.metadata.entities.Feed)

Example 4 with Feed

use of org.apache.asterix.metadata.entities.Feed in project asterixdb by apache.

the class MetadataNode method getDataverseFeeds.

@Override
public List<Feed> getDataverseFeeds(JobId jobId, String dataverseName) throws MetadataException, RemoteException {
    try {
        ITupleReference searchKey = createTuple(dataverseName);
        FeedTupleTranslator tupleReaderWriter = tupleTranslatorProvider.getFeedTupleTranslator(false);
        IValueExtractor<Feed> valueExtractor = new MetadataEntityValueExtractor<>(tupleReaderWriter);
        List<Feed> results = new ArrayList<>();
        searchIndex(jobId, MetadataPrimaryIndexes.FEED_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) FeedTupleTranslator(org.apache.asterix.metadata.entitytupletranslators.FeedTupleTranslator) HyracksDataException(org.apache.hyracks.api.exceptions.HyracksDataException) Feed(org.apache.asterix.metadata.entities.Feed)

Example 5 with Feed

use of org.apache.asterix.metadata.entities.Feed in project asterixdb by apache.

the class MetadataTransactionContext method dropFeed.

public void dropFeed(String dataverseName, String feedName) {
    Feed feed = null;
    feed = new Feed(dataverseName, feedName, null, null);
    droppedCache.addFeedIfNotExists(feed);
    logAndApply(new MetadataLogicalOperation(feed, false));
}
Also used : Feed(org.apache.asterix.metadata.entities.Feed)

Aggregations

Feed (org.apache.asterix.metadata.entities.Feed)14 HyracksDataException (org.apache.hyracks.api.exceptions.HyracksDataException)7 MetadataException (org.apache.asterix.metadata.MetadataException)6 RemoteException (java.rmi.RemoteException)5 ArrayList (java.util.ArrayList)5 EntityId (org.apache.asterix.active.EntityId)5 ACIDException (org.apache.asterix.common.exceptions.ACIDException)5 CompilationException (org.apache.asterix.common.exceptions.CompilationException)5 FeedConnection (org.apache.asterix.metadata.entities.FeedConnection)5 AlgebricksException (org.apache.hyracks.algebricks.common.exceptions.AlgebricksException)5 IOException (java.io.IOException)4 AsterixException (org.apache.asterix.common.exceptions.AsterixException)4 MetadataTransactionContext (org.apache.asterix.metadata.MetadataTransactionContext)4 ActiveJobNotificationHandler (org.apache.asterix.active.ActiveJobNotificationHandler)3 ActiveLifecycleListener (org.apache.asterix.active.ActiveLifecycleListener)3 FunctionSignature (org.apache.asterix.common.functions.FunctionSignature)3 Dataset (org.apache.asterix.metadata.entities.Dataset)3 Function (org.apache.asterix.metadata.entities.Function)3 FeedEventsListener (org.apache.asterix.external.feed.management.FeedEventsListener)2 FeedTupleTranslator (org.apache.asterix.metadata.entitytupletranslators.FeedTupleTranslator)2