zixi-bwang commented on a change in pull request #11874: URL: https://github.com/apache/arrow/pull/11874#discussion_r776843933
########## File path: csharp/examples/IoTExample/Model/SampleDataPipeline.cs ########## @@ -0,0 +1,197 @@ +// Licensed to the Apache Software Foundation (ASF) under one or more +// contributor license agreements. See the NOTICE file distributed with +// this work for additional information regarding copyright ownership. +// The ASF licenses this file to You under the Apache License, Version 2.0 +// (the "License"); you may not use this file except in compliance with +// the License. You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +using System; +using System.IO; +using System.Threading.Tasks; +using System.Collections.Generic; +using Apache.Arrow; +using Apache.Arrow.Ipc; +using Apache.Arrow.Memory; +using System.Threading.Channels; +using System.Threading; +using System.Collections.Concurrent; + +namespace IoTPipelineExample +{ + public class SampleDataPipeline + { + private int _size; + private int _partitions; + private readonly int _inputs; + private readonly int _capacity; + private readonly Channel<SensorData> _channel; + ChannelWriter<SensorData> _writer; + ChannelReader<SensorData> _reader; + + private readonly List<ConcurrentBag<int>> _colSubjectIdArrays; + private readonly List<ConcurrentBag<string>> _colActivityLabelArrays; + private readonly List<ConcurrentBag<long>> _colTimestampArrays; + private readonly List<ConcurrentBag<double>> _colXAxisArrays; + private readonly List<ConcurrentBag<double>> _colYAxisArrays; + private readonly List<ConcurrentBag<double>> _colZAxisArrays; + + public Dictionary<string, string> activityLabel = new Dictionary<string, string>() + { + {"walking", "A"}, + {"jogging", "B"}, + {"stairs", "C"}, + {"sitting", "D"}, + {"standing", "E"}, + {"typing", "F"}, + {"teeth", "G"}, + {"soup", "H"}, + {"chips", "I"}, + {"pasta", "J"}, + {"drinking", "K"}, + {"sandwich", "L"}, + {"kicking", "M"}, + {"catch", "O"}, + {"dribbling", "P"}, + {"writing", "Q"}, + {"clapping", "R"}, + {"folding", "S"}, + }; + + public SampleDataPipeline(int concurrencyLevel, int totalSensorData, int queueCapacity) + { + _partitions = concurrencyLevel; + _inputs = totalSensorData; + _capacity = queueCapacity; + _channel = Channel.CreateBounded<SensorData>(_capacity); + _writer = _channel.Writer; + _reader = _channel.Reader; + + _colSubjectIdArrays = new List<ConcurrentBag<int>>(); + _colActivityLabelArrays = new List<ConcurrentBag<string>>(); + _colTimestampArrays = new List<ConcurrentBag<long>>(); + _colXAxisArrays = new List<ConcurrentBag<double>>(); + _colYAxisArrays = new List<ConcurrentBag<double>>(); + _colZAxisArrays = new List<ConcurrentBag<double>>(); + + for (int i = 0; i < _partitions; i++) + { + _colSubjectIdArrays.Add(new ConcurrentBag<int>()); Review comment: I have refactored the code per your suggestion to use multiple writers and 1 reader only, and writes data directly to builder. And I also modified the example to emulate below scenario: - There are around 9,000 sensors(subjects) in total - Each sensor can send hundreds or thousands events during a short time of period - When reading from channel, data is appended to each array builder hashed by SubjectId as the key of builderId - When building RecordBatch, the array builders with the same builderId are built together - The final Arrow file contains 9,000 RecordBatches Do you think this is a good scenario for real world use cases in terms of utilizing Arrow file and RecordBatch? -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
