MCPcopy Create free account
hub / github.com/comnik/declarative-dataflow / source

Method source

src/sources/csv_file.rs:42–214  ·  view source on GitHub ↗
(
        &self,
        scope: &mut S,
        context: SourcingContext<S::Timestamp>,
    )

Source from the content-addressed store, hash-verified

40
41impl<S: Scope<Timestamp = Duration>> Sourceable<S> for CsvFile {
42 fn source(
43 &self,
44 scope: &mut S,
45 context: SourcingContext<S::Timestamp>,
46 ) -> Vec<(
47 Aid,
48 AttributeConfig,
49 Stream<S, ((Value, Value), Duration, isize)>,
50 )> {
51 let filename = self.path.clone();
52
53 // The following is mostly the innards of
54 // `generic::source`. We use a builder directly, because we
55 // need multiple outputs (one for each attribute the user has
56 // epxressed interest in).
57 let mut demux = OperatorBuilder::new(format!("CsvFile({})", filename), scope.clone());
58 let operator_info = demux.operator_info();
59 demux.set_notify(false);
60
61 // Order is very important here, because otherwise the
62 // capabilities won't match up with the output streams later
63 // on (when creating sessions). We stick to the order dictated
64 // by the schema.
65 let mut wrappers = Vec::with_capacity(self.schema.len());
66 let mut streams = Vec::with_capacity(self.schema.len());
67
68 for _ in self.schema.iter() {
69 let (wrapper, stream) = demux.new_output();
70 wrappers.push(wrapper);
71 streams.push(stream);
72 }
73
74 demux.build(move |mut capabilities| {
75 let activator = Rc::new(scope.activator_for(&operator_info.address[..]));
76
77 let worker_index = scope.index();
78 // let num_workers = scope.peers();
79
80 let reader = csv::ReaderBuilder::new()
81 .has_headers(self.has_headers)
82 .delimiter(self.delimiter)
83 .comment(self.comment)
84 .from_path(&filename)
85 .expect("failed to create reader");
86
87 let mut iterator = reader.into_records();
88
89 let mut num_datums_read = 0;
90 let mut datum_index = 0;
91
92 let schema = self.schema.clone();
93 let eid_offset = self.eid_offset;
94 // let timestamp_offset = self.timestamp_offset;
95 let total_fuel: i64 = self.fuel.unwrap_or(256) as i64;
96
97 // Grab scheduler handle for deferred re-activation.
98 let scheduler = context.scheduler;
99 let t0 = context.t0;

Callers

nothing calls this directly

Calls 3

indexMethod · 0.80
schedule_afterMethod · 0.80
nextMethod · 0.45

Tested by

no test coverage detected