InputFormat.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  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. #pragma once
  17. #include <alibabacloud/oss/Export.h>
  18. #include <alibabacloud/oss/OssRequest.h>
  19. #include <alibabacloud/oss/Types.h>
  20. namespace AlibabaCloud
  21. {
  22. namespace OSS
  23. {
  24. enum CompressionType
  25. {
  26. NONE = 0,
  27. GZIP
  28. };
  29. enum CSVHeader
  30. {
  31. None = 0, // there is no csv header
  32. Ignore, // we should ignore csv header and should not use csv header in select sql
  33. Use // we can use csv header in select sql
  34. };
  35. enum JsonType
  36. {
  37. DOCUMENT = 0,
  38. LINES
  39. };
  40. class SelectObjectRequest;
  41. class CreateSelectObjectMetaRequest;
  42. class ALIBABACLOUD_OSS_EXPORT InputFormat
  43. {
  44. public:
  45. void setCompressionType(CompressionType compressionType);
  46. void setLineRange(int64_t start, int64_t end);
  47. void setSplitRange(int64_t start, int64_t end);
  48. const std::string CompressionTypeInfo() const;
  49. protected:
  50. InputFormat();
  51. friend SelectObjectRequest;
  52. friend CreateSelectObjectMetaRequest;
  53. virtual int validate() const;
  54. virtual std::string toXML(int flag) const = 0;
  55. virtual std::string Type() const = 0;
  56. std::string RangeToString() const;
  57. private:
  58. CompressionType compressionType_;
  59. bool lineRangeIsSet_;
  60. int64_t lineRange_[2];
  61. bool splitRangeIsSet_;
  62. int64_t splitRange_[2];
  63. };
  64. class ALIBABACLOUD_OSS_EXPORT CSVInputFormat : public InputFormat
  65. {
  66. public:
  67. CSVInputFormat();
  68. CSVInputFormat(CSVHeader headerInfo,
  69. const std::string& recordDelimiter,
  70. const std::string& fieldDelimiter,
  71. const std::string& quoteChar,
  72. const std::string& commentChar);
  73. void setHeaderInfo(CSVHeader headerInfo);
  74. void setRecordDelimiter(const std::string& recordDelimiter);
  75. void setFieldDelimiter(const std::string& fieldDelimiter);
  76. void setQuoteChar(const std::string& quoteChar);
  77. void setCommentChar(const std::string& commentChar);
  78. CSVHeader HeaderInfo() const;
  79. const std::string& RecordDelimiter() const;
  80. const std::string& FieldDelimiter() const;
  81. const std::string& QuoteChar() const;
  82. const std::string& CommentChar() const;
  83. protected:
  84. std::string Type() const;
  85. std::string toXML(int flag) const;
  86. private:
  87. CSVHeader headerInfo_;
  88. std::string recordDelimiter_;
  89. std::string fieldDelimiter_;
  90. std::string quoteChar_;
  91. std::string commentChar_;
  92. };
  93. class ALIBABACLOUD_OSS_EXPORT JSONInputFormat : public InputFormat
  94. {
  95. public:
  96. JSONInputFormat();
  97. JSONInputFormat(JsonType jsonType);
  98. void setJsonType(JsonType jsonType);
  99. void setParseJsonNumberAsString(bool parseJsonNumberAsString);
  100. JsonType JsonInfo() const;
  101. bool ParseJsonNumberAsString() const;
  102. protected:
  103. std::string Type() const;
  104. std::string toXML(int flag) const;
  105. private:
  106. JsonType jsonType_;
  107. bool parseJsonNumberAsString_;
  108. };
  109. }
  110. }