Search in sources :

Example 1 with FeedTupleForwarder

use of org.apache.asterix.external.dataflow.FeedTupleForwarder in project asterixdb by apache.

the class DataflowControllerProvider method getDataflowController.

// TODO: Instead, use a factory just like data source and data parser.
@SuppressWarnings({ "rawtypes", "unchecked" })
public static IDataFlowController getDataflowController(ARecordType recordType, IHyracksTaskContext ctx, int partition, IExternalDataSourceFactory dataSourceFactory, IDataParserFactory dataParserFactory, Map<String, String> configuration, boolean indexingOp, boolean isFeed, FeedLogManager feedLogManager) throws HyracksDataException {
    try {
        switch(dataSourceFactory.getDataSourceType()) {
            case RECORDS:
                IRecordReaderFactory<?> recordReaderFactory = (IRecordReaderFactory<?>) dataSourceFactory;
                IRecordReader<?> recordReader = recordReaderFactory.createRecordReader(ctx, partition);
                IRecordDataParserFactory<?> recordParserFactory = (IRecordDataParserFactory<?>) dataParserFactory;
                IRecordDataParser<?> dataParser = recordParserFactory.createRecordParser(ctx);
                if (indexingOp) {
                    return new IndexingDataFlowController(ctx, DataflowUtils.getTupleForwarder(configuration, feedLogManager), dataParser, recordReader, ((IIndexingDatasource) recordReader).getIndexer());
                } else if (isFeed) {
                    FeedTupleForwarder tupleForwarder = (FeedTupleForwarder) DataflowUtils.getTupleForwarder(configuration, feedLogManager);
                    boolean isChangeFeed = ExternalDataUtils.isChangeFeed(configuration);
                    boolean isRecordWithMeta = ExternalDataUtils.isRecordWithMeta(configuration);
                    if (isRecordWithMeta) {
                        if (isChangeFeed) {
                            int numOfKeys = ExternalDataUtils.getNumberOfKeys(configuration);
                            return new ChangeFeedWithMetaDataFlowController(ctx, tupleForwarder, feedLogManager, numOfKeys + 2, (IRecordWithMetadataParser) dataParser, recordReader);
                        } else {
                            return new FeedWithMetaDataFlowController(ctx, tupleForwarder, feedLogManager, 2, (IRecordWithMetadataParser) dataParser, recordReader);
                        }
                    } else if (isChangeFeed) {
                        int numOfKeys = ExternalDataUtils.getNumberOfKeys(configuration);
                        return new ChangeFeedDataFlowController(ctx, tupleForwarder, feedLogManager, numOfKeys + 1, (IRecordWithPKDataParser) dataParser, recordReader);
                    } else {
                        return new FeedRecordDataFlowController(ctx, tupleForwarder, feedLogManager, 1, dataParser, recordReader);
                    }
                } else {
                    return new RecordDataFlowController(ctx, DataflowUtils.getTupleForwarder(configuration, feedLogManager), dataParser, recordReader, 1);
                }
            case STREAM:
                IInputStreamFactory streamFactory = (IInputStreamFactory) dataSourceFactory;
                AsterixInputStream stream = streamFactory.createInputStream(ctx, partition);
                IStreamDataParserFactory streamParserFactory = (IStreamDataParserFactory) dataParserFactory;
                IStreamDataParser streamParser = streamParserFactory.createInputStreamParser(ctx, partition);
                streamParser.setInputStream(stream);
                if (isFeed) {
                    return new FeedStreamDataFlowController(ctx, (FeedTupleForwarder) DataflowUtils.getTupleForwarder(configuration, feedLogManager), feedLogManager, streamParser, stream);
                } else {
                    return new StreamDataFlowController(ctx, DataflowUtils.getTupleForwarder(configuration, null), streamParser);
                }
            default:
                throw new RuntimeDataException(ErrorCode.PROVIDER_DATAFLOW_CONTROLLER_UNKNOWN_DATA_SOURCE, dataSourceFactory.getDataSourceType());
        }
    } catch (IOException | AsterixException e) {
        throw new HyracksDataException(e);
    }
}
Also used : ChangeFeedDataFlowController(org.apache.asterix.external.dataflow.ChangeFeedDataFlowController) IndexingDataFlowController(org.apache.asterix.external.dataflow.IndexingDataFlowController) IRecordWithMetadataParser(org.apache.asterix.external.api.IRecordWithMetadataParser) AsterixException(org.apache.asterix.common.exceptions.AsterixException) FeedTupleForwarder(org.apache.asterix.external.dataflow.FeedTupleForwarder) ChangeFeedWithMetaDataFlowController(org.apache.asterix.external.dataflow.ChangeFeedWithMetaDataFlowController) FeedWithMetaDataFlowController(org.apache.asterix.external.dataflow.FeedWithMetaDataFlowController) FeedStreamDataFlowController(org.apache.asterix.external.dataflow.FeedStreamDataFlowController) FeedStreamDataFlowController(org.apache.asterix.external.dataflow.FeedStreamDataFlowController) StreamDataFlowController(org.apache.asterix.external.dataflow.StreamDataFlowController) RuntimeDataException(org.apache.asterix.common.exceptions.RuntimeDataException) RecordDataFlowController(org.apache.asterix.external.dataflow.RecordDataFlowController) FeedRecordDataFlowController(org.apache.asterix.external.dataflow.FeedRecordDataFlowController) IStreamDataParser(org.apache.asterix.external.api.IStreamDataParser) IStreamDataParserFactory(org.apache.asterix.external.api.IStreamDataParserFactory) IRecordDataParserFactory(org.apache.asterix.external.api.IRecordDataParserFactory) FeedRecordDataFlowController(org.apache.asterix.external.dataflow.FeedRecordDataFlowController) IInputStreamFactory(org.apache.asterix.external.api.IInputStreamFactory) IOException(java.io.IOException) HyracksDataException(org.apache.hyracks.api.exceptions.HyracksDataException) IRecordReaderFactory(org.apache.asterix.external.api.IRecordReaderFactory) ChangeFeedWithMetaDataFlowController(org.apache.asterix.external.dataflow.ChangeFeedWithMetaDataFlowController) AsterixInputStream(org.apache.asterix.external.api.AsterixInputStream)

Example 2 with FeedTupleForwarder

use of org.apache.asterix.external.dataflow.FeedTupleForwarder in project asterixdb by apache.

the class DataflowUtils method getTupleForwarder.

public static ITupleForwarder getTupleForwarder(Map<String, String> configuration, FeedLogManager feedLogManager) throws HyracksDataException {
    ITupleForwarder.TupleForwardPolicy policyType = null;
    String propValue = configuration.get(ITupleForwarder.FORWARD_POLICY);
    if (ExternalDataUtils.isFeed(configuration)) {
        // TODO pass this value in the configuration and avoid this check for feeds
        policyType = TupleForwardPolicy.FEED;
    } else if (propValue == null) {
        policyType = TupleForwardPolicy.FRAME_FULL;
    } else {
        policyType = TupleForwardPolicy.valueOf(propValue.trim().toUpperCase());
    }
    switch(policyType) {
        case FEED:
            return new FeedTupleForwarder(feedLogManager);
        case FRAME_FULL:
            return new FrameFullTupleForwarder();
        case COUNTER_TIMER_EXPIRED:
            return CounterTimerTupleForwarder.create(configuration);
        case RATE_CONTROLLED:
            return RateControlledTupleForwarder.create(configuration);
        default:
            throw new RuntimeDataException(ErrorCode.UTIL_DATAFLOW_UTILS_UNKNOWN_FORWARD_POLICY);
    }
}
Also used : ITupleForwarder(org.apache.asterix.external.api.ITupleForwarder) FrameFullTupleForwarder(org.apache.asterix.external.dataflow.FrameFullTupleForwarder) FeedTupleForwarder(org.apache.asterix.external.dataflow.FeedTupleForwarder) TupleForwardPolicy(org.apache.asterix.external.api.ITupleForwarder.TupleForwardPolicy) RuntimeDataException(org.apache.asterix.common.exceptions.RuntimeDataException)

Aggregations

RuntimeDataException (org.apache.asterix.common.exceptions.RuntimeDataException)2 FeedTupleForwarder (org.apache.asterix.external.dataflow.FeedTupleForwarder)2 IOException (java.io.IOException)1 AsterixException (org.apache.asterix.common.exceptions.AsterixException)1 AsterixInputStream (org.apache.asterix.external.api.AsterixInputStream)1 IInputStreamFactory (org.apache.asterix.external.api.IInputStreamFactory)1 IRecordDataParserFactory (org.apache.asterix.external.api.IRecordDataParserFactory)1 IRecordReaderFactory (org.apache.asterix.external.api.IRecordReaderFactory)1 IRecordWithMetadataParser (org.apache.asterix.external.api.IRecordWithMetadataParser)1 IStreamDataParser (org.apache.asterix.external.api.IStreamDataParser)1 IStreamDataParserFactory (org.apache.asterix.external.api.IStreamDataParserFactory)1 ITupleForwarder (org.apache.asterix.external.api.ITupleForwarder)1 TupleForwardPolicy (org.apache.asterix.external.api.ITupleForwarder.TupleForwardPolicy)1 ChangeFeedDataFlowController (org.apache.asterix.external.dataflow.ChangeFeedDataFlowController)1 ChangeFeedWithMetaDataFlowController (org.apache.asterix.external.dataflow.ChangeFeedWithMetaDataFlowController)1 FeedRecordDataFlowController (org.apache.asterix.external.dataflow.FeedRecordDataFlowController)1 FeedStreamDataFlowController (org.apache.asterix.external.dataflow.FeedStreamDataFlowController)1 FeedWithMetaDataFlowController (org.apache.asterix.external.dataflow.FeedWithMetaDataFlowController)1 FrameFullTupleForwarder (org.apache.asterix.external.dataflow.FrameFullTupleForwarder)1 IndexingDataFlowController (org.apache.asterix.external.dataflow.IndexingDataFlowController)1