Exemplo n.º 1
0
 private CreateSelectObjectMetaCommand(IServiceClient client, Uri endpoint, ExecutionContext context,
                                       IDeserializer <ServiceResponse, CreateSelectObjectMetaResult> deserializer,
                                       CreateSelectObjectMetaRequest request)
     : base(client, endpoint, context, deserializer)
 {
     _request = request;
 }
Exemplo n.º 2
0
        public void CSVSelectObjectCommentCharacterTest()
        {
            const string key = "CSVSelectObjectCommentCharacterTest";

            try
            {
                var    buffer     = new byte[256];
                byte[] binaryData = Encoding.ASCII.GetBytes("abc,def\n`123,456\n#ghi,jkl\n");
                var    stream     = new MemoryStream(binaryData);

                _ossClient.PutObject(_bucketName, key, stream);

                var metaRequest = new CreateSelectObjectMetaRequest(_bucketName, key);
                metaRequest.InputFormat = new CreateSelectObjectMetaCSVInputFormat();
                _ossClient.CreateSelectObjectMeta(metaRequest);

                var request = new SelectObjectRequest(_bucketName, key);
                request.Expression = "select _1 from ossobject";

                var inputFormat = new SelectObjectCSVInputFormat();
                inputFormat.CommentCharacter = "`";
                request.InputFormat          = inputFormat;

                var result = _ossClient.SelectObject(request);

                var got = result.Content.Read(buffer, 0, buffer.Length);

                Assert.AreEqual("abc\n#ghi\n", Encoding.Default.GetString(buffer, 0, got));
            }
            finally
            {
                _ossClient.DeleteObject(_bucketName, key);
            }
        }
Exemplo n.º 3
0
 public static CreateSelectObjectMetaCommand Create(IServiceClient client, Uri endpoint,
                                                    ExecutionContext context,
                                                    CreateSelectObjectMetaRequest request)
 {
     OssUtils.CheckBucketName(request.BucketName);
     OssUtils.CheckObjectKey(request.Key);
     if (request.InputFormat == null)
     {
         throw new ArgumentException("InputFormat should not be null");
     }
     return(new CreateSelectObjectMetaCommand(client, endpoint, context,
                                              DeserializerFactory.GetFactory().CreateSelectObjectMetaRequestDeserializer(),
                                              request));
 }
Exemplo n.º 4
0
        public void NormalSelectObjectWithJsonType()
        {
            const string key = "SqlObjectWithJsonType";

            try
            {
                byte[] binaryData = Encoding.ASCII.GetBytes(_jsonMessage);
                var    stream     = new MemoryStream(binaryData);

                _ossClient.PutObject(_bucketName, key, stream);

                var request = new SelectObjectRequest(_bucketName, key);
                request.Expression = "select * from ossobject";

                var inputFormat = new SelectObjectJSONInputFormat();
                inputFormat.CompressionType = CompressionType.None;
                inputFormat.Type            = JSONType.LINES;
                request.InputFormat         = inputFormat;

                var outputFormat = new SelectObjectCSVOutputFormat();
                outputFormat.KeepAllColumns   = false;
                outputFormat.OutputRawData    = false;
                outputFormat.OutputHeader     = false;
                outputFormat.EnablePayloadCrc = true;

                outputFormat.RecordDelimiter = "\n";

                request.OutputFormat = outputFormat;

                _ossClient.SelectObject(request);

                var metarequest = new CreateSelectObjectMetaRequest(_bucketName, key);
                metarequest.OverwriteIfExists = false;

                var input = new CreateSelectObjectMetaJSONInputFormat();
                input.CompressionType   = CompressionType.None;
                input.Type              = JSONType.LINES;
                metarequest.InputFormat = input;

                var metaresult = _ossClient.CreateSelectObjectMeta(metarequest);

                Assert.AreEqual(metaresult.SplitsCount, 1);
                Assert.AreEqual(metaresult.RowsCount, 4);
            }
            finally
            {
                _ossClient.DeleteObject(_bucketName, key);
            }
        }
Exemplo n.º 5
0
        public void CSVSelectObjectLineRangeTest()
        {
            const string key = "CSVSelectObjectLineRangeTest";

            try
            {
                var    buffer     = new byte[256];
                byte[] binaryData = Encoding.ASCII.GetBytes("abc,def\n123,456\n789,efg\nhij,klm\n");
                var    stream     = new MemoryStream(binaryData);

                _ossClient.PutObject(_bucketName, key, stream);

                var metaRequest = new CreateSelectObjectMetaRequest(_bucketName, key);
                metaRequest.InputFormat = new CreateSelectObjectMetaCSVInputFormat();
                _ossClient.CreateSelectObjectMeta(metaRequest);

                var request = new SelectObjectRequest(_bucketName, key);
                request.Expression = "select _1, _2 from ossobject";

                var inputFormat = new SelectObjectCSVInputFormat();
                inputFormat.Range   = "line-range=1-2";
                request.InputFormat = inputFormat;

                var outputFormat = new SelectObjectCSVOutputFormat();
                request.OutputFormat = outputFormat;

                var result = _ossClient.SelectObject(request);

                var got = result.Content.Read(buffer, 0, buffer.Length);

                Assert.AreEqual("123,456\n789,efg\n", Encoding.Default.GetString(buffer, 0, got));
            }
            finally
            {
                _ossClient.DeleteObject(_bucketName, key);
            }
        }
Exemplo n.º 6
0
        public void CreateSelectObjectWithCsvDataTest()
        {
            const string key = "CreateSelectObjectWithCsvDataTest";

            try
            {
                byte[] binaryData = Encoding.ASCII.GetBytes(_sqlMessage);
                var    stream     = new MemoryStream(binaryData);

                _ossClient.PutObject(_bucketName, key, stream);

                var metarequest = new CreateSelectObjectMetaRequest(_bucketName, key);
                metarequest.OverwriteIfExists = false;

                var input = new CreateSelectObjectMetaCSVInputFormat();
                Assert.AreEqual(input.CompressionType, CompressionType.None);
                Assert.AreEqual(input.RecordDelimiter, null);
                Assert.AreEqual(input.FieldDelimiter, null);
                Assert.AreEqual(input.QuoteCharacter, null);

                input.RecordDelimiter = "\r\n";
                input.FieldDelimiter  = ",";
                input.QuoteCharacter  = "\"";

                metarequest.InputFormat = input;

                var metaresult = _ossClient.CreateSelectObjectMeta(metarequest);
                Assert.AreEqual(metaresult.SplitsCount, 1);
                Assert.AreEqual(metaresult.RowsCount, 5);
                Assert.AreEqual(metaresult.ColumnsCount, 4);
            }
            finally
            {
                _ossClient.DeleteObject(_bucketName, key);
            }
        }