Example #1
0
        private ISelectObjectContentEventStream GetSelectObjectContentEventStream(
            string bucketName,
            string key,
            string selectQuery,
            InputSerialization inputSerialization,
            OutputSerialization outputSerialization,
            ScanRange scanRange = null)
        {
            if (string.IsNullOrWhiteSpace(bucketName))
            {
                throw new ArgumentNullException("bucketName");
            }
            if (string.IsNullOrWhiteSpace(key))
            {
                throw new ArgumentNullException("key");
            }
            if (string.IsNullOrWhiteSpace(selectQuery))
            {
                throw new ArgumentNullException("selectQuery");
            }
            if (inputSerialization == null)
            {
                throw new ArgumentNullException("inputSerialization");
            }
            if (outputSerialization == null)
            {
                throw new ArgumentNullException("outputSerialization");
            }

            SelectObjectContentRequest selectObjectContentRequest = new SelectObjectContentRequest()
            {
                Bucket              = bucketName,
                Key                 = key,
                ExpressionType      = ExpressionType.SQL,
                Expression          = selectQuery,
                InputSerialization  = inputSerialization,
                OutputSerialization = outputSerialization
            };

            if (scanRange != null)
            {
                selectObjectContentRequest.ScanRange = scanRange;
            }

            return(Client.SelectObjectContent(selectObjectContentRequest).Payload);
        }
Example #2
0
        public void TestCallScanRangeEvents()
        {
            string             selectQuery        = "select * from s3object";
            InputSerialization inputSerialization = new InputSerialization()
            {
                CSV = new CSVInput()
                {
                    FileHeaderInfo  = FileHeaderInfo.Use,
                    RecordDelimiter = "\r\n"
                }
            };
            OutputSerialization outputSerialization = new OutputSerialization()
            {
                CSV = new CSVOutput()
                {
                    RecordDelimiter = "\n"
                }
            };

            var eventStream = GetSelectObjectContentEventStream(_bucketName, _csvKeyName, selectQuery, inputSerialization, outputSerialization, new ScanRange()
            {
                Start = 10, End = 20
            });

            var testContent   = string.Empty;
            var recordsEvents = new List <RecordsEvent>();

            eventStream.RecordsEventReceived += (sender, args) => recordsEvents.Add(args.EventStreamEvent);
            eventStream.StartProcessing();
            SpinWait.SpinUntil(() => recordsEvents.Count > 0, TimeSpan.FromSeconds(5));

            using (var streamReader = new StreamReader(recordsEvents[0].Payload, Encoding.UTF8))
            {
                testContent = streamReader.ReadToEnd();
            }
            eventStream.Dispose();

            Assert.IsTrue(string.Equals(CSVScanRangeVerificationContent, testContent));
        }