Search in sources :

Example 11 with IActivity

use of org.apache.hyracks.api.dataflow.IActivity in project asterixdb by apache.

the class SuperActivity method createPushRuntime.

@Override
public IOperatorNodePushable createPushRuntime(IHyracksTaskContext ctx, final IRecordDescriptorProvider recordDescProvider, final int partition, final int nPartitions) throws HyracksDataException {
    final Map<ActivityId, IActivity> startActivities = new HashMap<ActivityId, IActivity>();
    Map<ActivityId, IActivity> activities = getActivityMap();
    for (Entry<ActivityId, IActivity> entry : activities.entrySet()) {
        /**
             * extract start activities
             */
        List<IConnectorDescriptor> conns = getActivityInputMap().get(entry.getKey());
        if (conns == null || conns.isEmpty()) {
            startActivities.put(entry.getKey(), entry.getValue());
        }
    }
    /**
         * wrap a RecordDescriptorProvider for the super activity
         */
    IRecordDescriptorProvider wrappedRecDescProvider = new IRecordDescriptorProvider() {

        @Override
        public RecordDescriptor getInputRecordDescriptor(ActivityId aid, int inputIndex) {
            if (startActivities.get(aid) != null) {
                /**
                     * if the activity is a start (input boundary) activity
                     */
                int superActivityInputChannel = SuperActivity.this.getClusterInputIndex(Pair.of(aid, inputIndex));
                if (superActivityInputChannel >= 0) {
                    return recordDescProvider.getInputRecordDescriptor(activityId, superActivityInputChannel);
                }
            }
            if (SuperActivity.this.getActivityMap().get(aid) != null) {
                /**
                     * if the activity is an internal activity of the super activity
                     */
                IConnectorDescriptor conn = getActivityInputMap().get(aid).get(inputIndex);
                return getConnectorRecordDescriptorMap().get(conn.getConnectorId());
            }
            /**
                 * the following is for the case where the activity is in other SuperActivities
                 */
            ActivityClusterGraph acg = SuperActivity.this.getActivityClusterGraph();
            for (Entry<ActivityClusterId, ActivityCluster> entry : acg.getActivityClusterMap().entrySet()) {
                ActivityCluster ac = entry.getValue();
                for (Entry<ActivityId, IActivity> saEntry : ac.getActivityMap().entrySet()) {
                    SuperActivity sa = (SuperActivity) saEntry.getValue();
                    if (sa.getActivityMap().get(aid) != null) {
                        List<IConnectorDescriptor> conns = sa.getActivityInputMap().get(aid);
                        if (conns != null && conns.size() >= inputIndex) {
                            IConnectorDescriptor conn = conns.get(inputIndex);
                            return sa.getConnectorRecordDescriptorMap().get(conn.getConnectorId());
                        } else {
                            int superActivityInputChannel = sa.getClusterInputIndex(Pair.of(aid, inputIndex));
                            if (superActivityInputChannel >= 0) {
                                return recordDescProvider.getInputRecordDescriptor(sa.getActivityId(), superActivityInputChannel);
                            }
                        }
                    }
                }
            }
            return null;
        }

        @Override
        public RecordDescriptor getOutputRecordDescriptor(ActivityId aid, int outputIndex) {
            /**
                 * if the activity is an output-boundary activity
                 */
            int superActivityOutputChannel = SuperActivity.this.getClusterOutputIndex(Pair.of(aid, outputIndex));
            if (superActivityOutputChannel >= 0) {
                return recordDescProvider.getOutputRecordDescriptor(activityId, superActivityOutputChannel);
            }
            if (SuperActivity.this.getActivityMap().get(aid) != null) {
                /**
                     * if the activity is an internal activity of the super activity
                     */
                IConnectorDescriptor conn = getActivityOutputMap().get(aid).get(outputIndex);
                return getConnectorRecordDescriptorMap().get(conn.getConnectorId());
            }
            /**
                 * the following is for the case where the activity is in other SuperActivities
                 */
            ActivityClusterGraph acg = SuperActivity.this.getActivityClusterGraph();
            for (Entry<ActivityClusterId, ActivityCluster> entry : acg.getActivityClusterMap().entrySet()) {
                ActivityCluster ac = entry.getValue();
                for (Entry<ActivityId, IActivity> saEntry : ac.getActivityMap().entrySet()) {
                    SuperActivity sa = (SuperActivity) saEntry.getValue();
                    if (sa.getActivityMap().get(aid) != null) {
                        List<IConnectorDescriptor> conns = sa.getActivityOutputMap().get(aid);
                        if (conns != null && conns.size() >= outputIndex) {
                            IConnectorDescriptor conn = conns.get(outputIndex);
                            return sa.getConnectorRecordDescriptorMap().get(conn.getConnectorId());
                        } else {
                            superActivityOutputChannel = sa.getClusterOutputIndex(Pair.of(aid, outputIndex));
                            if (superActivityOutputChannel >= 0) {
                                return recordDescProvider.getOutputRecordDescriptor(sa.getActivityId(), superActivityOutputChannel);
                            }
                        }
                    }
                }
            }
            return null;
        }
    };
    return new SuperActivityOperatorNodePushable(this, startActivities, ctx, wrappedRecDescProvider, partition, nPartitions);
}
Also used : IConnectorDescriptor(org.apache.hyracks.api.dataflow.IConnectorDescriptor) HashMap(java.util.HashMap) ActivityId(org.apache.hyracks.api.dataflow.ActivityId) IRecordDescriptorProvider(org.apache.hyracks.api.dataflow.value.IRecordDescriptorProvider) ActivityCluster(org.apache.hyracks.api.job.ActivityCluster) OneToOneConnectedActivityCluster(org.apache.hyracks.api.rewriter.OneToOneConnectedActivityCluster) IActivity(org.apache.hyracks.api.dataflow.IActivity) ActivityClusterId(org.apache.hyracks.api.job.ActivityClusterId) ActivityClusterGraph(org.apache.hyracks.api.job.ActivityClusterGraph)

Aggregations

IActivity (org.apache.hyracks.api.dataflow.IActivity)11 ActivityId (org.apache.hyracks.api.dataflow.ActivityId)9 IConnectorDescriptor (org.apache.hyracks.api.dataflow.IConnectorDescriptor)6 HashMap (java.util.HashMap)5 ActivityCluster (org.apache.hyracks.api.job.ActivityCluster)5 Pair (org.apache.commons.lang3.tuple.Pair)4 ActivityClusterGraph (org.apache.hyracks.api.job.ActivityClusterGraph)4 LinkedList (java.util.LinkedList)3 SuperActivity (org.apache.hyracks.api.rewriter.runtime.SuperActivity)3 ArrayList (java.util.ArrayList)2 HashSet (java.util.HashSet)2 List (java.util.List)2 Set (java.util.Set)2 ConnectorDescriptorId (org.apache.hyracks.api.dataflow.ConnectorDescriptorId)2 IOperatorNodePushable (org.apache.hyracks.api.dataflow.IOperatorNodePushable)2 IRecordDescriptorProvider (org.apache.hyracks.api.dataflow.value.IRecordDescriptorProvider)2 RecordDescriptor (org.apache.hyracks.api.dataflow.value.RecordDescriptor)2 ActivityClusterId (org.apache.hyracks.api.job.ActivityClusterId)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)1