Search in sources :

Example 1 with ITupleForwarder

use of org.apache.asterix.external.api.ITupleForwarder in project asterixdb by apache.

the class TestTypedAdapterFactory method createAdapter.

@Override
public IDataSourceAdapter createAdapter(IHyracksTaskContext ctx, int partition) throws HyracksDataException {
    final String nodeId = ctx.getJobletContext().getServiceContext().getNodeId();
    final ITupleParserFactory tupleParserFactory = new ITupleParserFactory() {

        private static final long serialVersionUID = 1L;

        @Override
        public ITupleParser createTupleParser(IHyracksTaskContext ctx) throws HyracksDataException {
            ADMDataParser parser;
            ITupleForwarder forwarder;
            ArrayTupleBuilder tb;
            IApplicationContext appCtx = (IApplicationContext) ctx.getJobletContext().getServiceContext().getApplicationContext();
            ClusterPartition nodePartition = appCtx.getMetadataProperties().getNodePartitions().get(nodeId)[0];
            parser = new ADMDataParser(outputType, true);
            forwarder = DataflowUtils.getTupleForwarder(configuration, FeedUtils.getFeedLogManager(ctx, FeedUtils.splitsForAdapter(ExternalDataUtils.getDataverse(configuration), ExternalDataUtils.getFeedName(configuration), nodeId, nodePartition)));
            tb = new ArrayTupleBuilder(1);
            return new ITupleParser() {

                @Override
                public void parse(InputStream in, IFrameWriter writer) throws HyracksDataException {
                    try {
                        parser.setInputStream(in);
                        forwarder.initialize(ctx, writer);
                        while (true) {
                            tb.reset();
                            if (!parser.parse(tb.getDataOutput())) {
                                break;
                            }
                            tb.addFieldEndOffset();
                            forwarder.addTuple(tb);
                        }
                        forwarder.close();
                    } catch (Exception e) {
                        throw new HyracksDataException(e);
                    }
                }
            };
        }
    };
    try {
        return new TestTypedAdapter(tupleParserFactory, outputType, ctx, configuration, partition);
    } catch (IOException e) {
        throw new HyracksDataException(e);
    }
}
Also used : IFrameWriter(org.apache.hyracks.api.comm.IFrameWriter) ITupleParser(org.apache.hyracks.dataflow.std.file.ITupleParser) InputStream(java.io.InputStream) ArrayTupleBuilder(org.apache.hyracks.dataflow.common.comm.io.ArrayTupleBuilder) IApplicationContext(org.apache.asterix.common.api.IApplicationContext) IOException(java.io.IOException) AlgebricksException(org.apache.hyracks.algebricks.common.exceptions.AlgebricksException) HyracksDataException(org.apache.hyracks.api.exceptions.HyracksDataException) IOException(java.io.IOException) HyracksDataException(org.apache.hyracks.api.exceptions.HyracksDataException) ADMDataParser(org.apache.asterix.external.parser.ADMDataParser) ITupleForwarder(org.apache.asterix.external.api.ITupleForwarder) ITupleParserFactory(org.apache.hyracks.dataflow.std.file.ITupleParserFactory) IHyracksTaskContext(org.apache.hyracks.api.context.IHyracksTaskContext) ClusterPartition(org.apache.asterix.common.cluster.ClusterPartition)

Example 2 with ITupleForwarder

use of org.apache.asterix.external.api.ITupleForwarder 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

ITupleForwarder (org.apache.asterix.external.api.ITupleForwarder)2 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 IApplicationContext (org.apache.asterix.common.api.IApplicationContext)1 ClusterPartition (org.apache.asterix.common.cluster.ClusterPartition)1 RuntimeDataException (org.apache.asterix.common.exceptions.RuntimeDataException)1 TupleForwardPolicy (org.apache.asterix.external.api.ITupleForwarder.TupleForwardPolicy)1 FeedTupleForwarder (org.apache.asterix.external.dataflow.FeedTupleForwarder)1 FrameFullTupleForwarder (org.apache.asterix.external.dataflow.FrameFullTupleForwarder)1 ADMDataParser (org.apache.asterix.external.parser.ADMDataParser)1 AlgebricksException (org.apache.hyracks.algebricks.common.exceptions.AlgebricksException)1 IFrameWriter (org.apache.hyracks.api.comm.IFrameWriter)1 IHyracksTaskContext (org.apache.hyracks.api.context.IHyracksTaskContext)1 HyracksDataException (org.apache.hyracks.api.exceptions.HyracksDataException)1 ArrayTupleBuilder (org.apache.hyracks.dataflow.common.comm.io.ArrayTupleBuilder)1 ITupleParser (org.apache.hyracks.dataflow.std.file.ITupleParser)1 ITupleParserFactory (org.apache.hyracks.dataflow.std.file.ITupleParserFactory)1