1 /*
2  * Copyright 2009-2017 Alibaba Cloud All rights reserved.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #pragma once
18 #include <alibabacloud/oss/Export.h>
19 #include <alibabacloud/oss/OssRequest.h>
20 #include <alibabacloud/oss/Types.h>
21 
22 namespace AlibabaCloud
23 {
24 namespace OSS
25 {
26 	enum CompressionType
27 	{
28 		NONE = 0,
29 		GZIP
30 	};
31 
32     enum CSVHeader
33     {
34         None = 0, // there is no csv header
35         Ignore,   // we should ignore csv header and should not use csv header in select sql
36         Use       // we can use csv header in select sql
37     };
38 
39     enum JsonType
40     {
41         DOCUMENT = 0,
42         LINES
43     };
44 
45     class SelectObjectRequest;
46     class CreateSelectObjectMetaRequest;
47 
48 	class ALIBABACLOUD_OSS_EXPORT InputFormat
49 	{
50 	public:
51         void setCompressionType(CompressionType compressionType);
52 
53         void setLineRange(int64_t start, int64_t end);
54         void setSplitRange(int64_t start, int64_t end);
55 
56 		const std::string CompressionTypeInfo() const;
57 
58 
59 
60     protected:
61         InputFormat();
62         friend SelectObjectRequest;
63         friend CreateSelectObjectMetaRequest;
64         virtual int validate() const;
65         virtual std::string toXML(int flag) const = 0;
66         virtual std::string Type() const = 0;
67         std::string RangeToString() const;
68 	private:
69 		CompressionType compressionType_;
70         bool lineRangeIsSet_;
71         int64_t lineRange_[2];
72         bool splitRangeIsSet_;
73         int64_t splitRange_[2];
74 	};
75 
76     class ALIBABACLOUD_OSS_EXPORT CSVInputFormat : public InputFormat
77     {
78     public:
79         CSVInputFormat();
80         CSVInputFormat(CSVHeader headerInfo,
81             const std::string& recordDelimiter,
82             const std::string& fieldDelimiter,
83             const std::string& quoteChar,
84             const std::string& commentChar);
85 
86         void setHeaderInfo(CSVHeader headerInfo);
87         void setRecordDelimiter(const std::string& recordDelimiter);
88         void setFieldDelimiter(const std::string& fieldDelimiter);
89         void setQuoteChar(const std::string& quoteChar);
90         void setCommentChar(const std::string& commentChar);
91 
92         CSVHeader HeaderInfo() const;
93         const std::string& RecordDelimiter() const;
94         const std::string& FieldDelimiter() const;
95         const std::string& QuoteChar() const;
96         const std::string& CommentChar() const;
97 
98     protected:
99         std::string Type() const;
100         std::string toXML(int flag) const;
101 
102     private:
103         CSVHeader headerInfo_;
104         std::string recordDelimiter_;
105         std::string fieldDelimiter_;
106         std::string quoteChar_;
107         std::string commentChar_;
108     };
109 
110     class ALIBABACLOUD_OSS_EXPORT JSONInputFormat : public InputFormat
111     {
112     public:
113         JSONInputFormat();
114         JSONInputFormat(JsonType jsonType);
115 
116         void setJsonType(JsonType jsonType);
117         void setParseJsonNumberAsString(bool parseJsonNumberAsString);
118 
119         JsonType JsonInfo() const;
120         bool ParseJsonNumberAsString() const;
121 
122     protected:
123         std::string Type() const;
124         std::string toXML(int flag) const;
125 
126     private:
127         JsonType jsonType_;
128         bool parseJsonNumberAsString_;
129     };
130 
131 }
132 }
133