thdiskwrite.cpp 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. /*##############################################################################
  2. HPCC SYSTEMS software Copyright (C) 2012 HPCC Systems.
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6. http://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. ############################################################################## */
  13. #include "jiface.hpp"
  14. #include "jtime.hpp"
  15. #include "thexception.hpp"
  16. #include "thmfilemanager.hpp"
  17. #include "eclhelper.hpp"
  18. #include "deftype.hpp"
  19. #include "thdiskwrite.ipp"
  20. class CDiskWriteActivityMaster : public CWriteMasterBase
  21. {
  22. public:
  23. CDiskWriteActivityMaster(CMasterGraphElement *info) : CWriteMasterBase(info) {}
  24. void init()
  25. {
  26. CWriteMasterBase::init();
  27. IHThorDiskWriteArg *helper=(IHThorDiskWriteArg *)queryHelper();
  28. IOutputMetaData *irecsize = helper->queryDiskRecordSize()->querySerializedMeta();
  29. IPropertyTree &props = fileDesc->queryProperties();
  30. if (0 != (helper->getFlags() & TDXgrouped))
  31. props.setPropBool("@grouped", true);
  32. if (irecsize->isFixedSize()) // fixed size
  33. {
  34. size32_t rSz = irecsize->getMinRecordSize();
  35. if (0 != (helper->getFlags() & TDXgrouped))
  36. ++rSz;
  37. props.setPropInt("@recordSize", rSz);
  38. }
  39. props.setPropInt("@formatCrc", helper->getFormatCrc());
  40. }
  41. };
  42. //---------------------------------------------------------------------------
  43. class CsvWriteActivityMaster : public CWriteMasterBase
  44. {
  45. public:
  46. CsvWriteActivityMaster(CMasterGraphElement *info) : CWriteMasterBase(info) {}
  47. void done()
  48. {
  49. IPropertyTree &props = fileDesc->queryProperties();
  50. props.setPropBool("@csv", true);
  51. props.setProp("@format", "utf8n");
  52. IHThorCsvWriteArg *helper=(IHThorCsvWriteArg *)queryHelper();
  53. ICsvParameters *csvParameters = helper->queryCsvParameters();
  54. StringBuffer separator;
  55. const char *s = csvParameters->querySeparator(0);
  56. while (*s)
  57. {
  58. if (',' == *s)
  59. separator.append("\\,");
  60. else
  61. separator.append(*s);
  62. ++s;
  63. }
  64. props.setProp("@csvSeparate", separator.str());
  65. props.setProp("@csvQuote", csvParameters->queryQuote(0));
  66. props.setProp("@csvTerminate", csvParameters->queryTerminator(0));
  67. props.setProp("@csvEscape", csvParameters->queryEscape(0));
  68. CWriteMasterBase::done(); // will publish
  69. }
  70. };
  71. CActivityBase *createDiskWriteActivityMaster(CMasterGraphElement *info)
  72. {
  73. return new CDiskWriteActivityMaster(info);
  74. }
  75. CActivityBase *createCsvWriteActivityMaster(CMasterGraphElement *info)
  76. {
  77. return new CsvWriteActivityMaster(info);
  78. }