rtldynfield.hpp 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. /*##############################################################################
  2. HPCC SYSTEMS software Copyright (C) 2016 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. #ifndef rtldynfield_hpp
  14. #define rtldynfield_hpp
  15. #include "rtlfield.hpp"
  16. #include "rtlnewkey.hpp"
  17. //These classes support the dynamic creation of type and field information
  18. //-------------------------------------------------------------------------------------------------------------------
  19. /*
  20. * Used to represent the info that is needed to dynamically create an RtlTypeInfo object
  21. */
  22. struct ECLRTL_API FieldTypeInfoStruct
  23. {
  24. public:
  25. unsigned fieldType = 0;
  26. unsigned length = 0;
  27. const char *locale = nullptr;
  28. const char *className = nullptr;
  29. const RtlTypeInfo *childType = nullptr;
  30. const RtlFieldInfo * * fieldsArray = nullptr;
  31. const IFieldFilter * filter = nullptr;
  32. const RtlTypeInfo *createRtlTypeInfo(IThorIndexCallback *_callback) const;
  33. };
  34. interface ITypeInfo;
  35. /**
  36. * IRtlFieldTypeDeserializer is used to manage the creation of RtlTypeInfo structures dynamically.
  37. * All created structures are owned by the deserializer and will be destroyed when the deserializer is destroyed.
  38. */
  39. interface IRtlFieldTypeDeserializer : public IInterface
  40. {
  41. /*
  42. * Create RtlTypeInfo structures from a serialized json representation
  43. *
  44. * @param json The json representation
  45. * @return Deserialized RtlTypeInfo structure
  46. */
  47. virtual const RtlTypeInfo *deserialize(const char *json) = 0;
  48. /*
  49. * Create RtlTypeInfo structures from a serialized json representation
  50. *
  51. * @param jsonTree The json representation
  52. * @return Deserialized RtlTypeInfo structure
  53. */
  54. virtual const RtlTypeInfo *deserialize(IPropertyTree &jsonTree) = 0;
  55. /*
  56. * Create RtlTypeInfo structures from a serialized binary representation
  57. *
  58. * @param buf The binary representation
  59. * @return Deserialized RtlTypeInfo structure
  60. */
  61. virtual const RtlTypeInfo *deserialize(MemoryBuffer &buf) = 0;
  62. /*
  63. * Create a single RtlTypeInfo structure from a FieldTypeInfoStruct
  64. *
  65. * @param info The information used to create the type
  66. * @param key A unique pointer used to dedup typeinfo structures
  67. * @return RtlTypeInfo structure
  68. */
  69. virtual const RtlTypeInfo *addType(FieldTypeInfoStruct &info, const IInterface *typeOrIfblock) = 0;
  70. /*
  71. * Check if a type has already been created for a given key
  72. *
  73. * @param key A unique pointer used to dedup typeinfo structures
  74. * @return RtlTypeInfo structure, or nullptr if not yet created
  75. */
  76. virtual const RtlTypeInfo *lookupType(const IInterface *key) const = 0;
  77. /*
  78. * Create RtlFieldInfo structure as part of a RtlTypeInfo tree
  79. *
  80. * @param fieldName Field name
  81. * @param xpath XPath
  82. * @param type Field type
  83. * @param flags Field flags
  84. * @param init Field initializer, or nullptr
  85. * @return RtlFieldInfo structure. All strings will be owned by the deserializer object
  86. */
  87. virtual const RtlFieldInfo *addFieldInfo(const char *fieldName, const char *xpath, const RtlTypeInfo *type, unsigned flags, const char *init) = 0;
  88. };
  89. enum class RecordTranslationMode { None = 0, All = 1, Payload = 2, AlwaysDisk = 3, AlwaysECL = 4 }; // Latter 2 are for testing purposes only
  90. extern ECLRTL_API RecordTranslationMode getTranslationMode(const char *modeStr);
  91. extern ECLRTL_API const char *getTranslationModeText(RecordTranslationMode val);
  92. interface IDynamicTransform : public IInterface
  93. {
  94. virtual void describe() const = 0;
  95. virtual size32_t translate(ARowBuilder &builder, const byte *sourceRec) const = 0;
  96. virtual size32_t translate(ARowBuilder &builder, const RtlRow &sourceRow) const = 0;
  97. virtual bool canTranslate() const = 0;
  98. virtual bool needsTranslate() const = 0;
  99. virtual bool keyedTranslated() const = 0;
  100. };
  101. interface IKeyTranslator : public IInterface
  102. {
  103. virtual void describe() const = 0;
  104. virtual bool translate(RowFilter &filters) const = 0; // MORE - this should be deprecated
  105. virtual bool translate(RowFilter &result, IConstArrayOf<IFieldFilter> &_filters) const = 0;
  106. virtual bool needsTranslate() const = 0;
  107. };
  108. extern ECLRTL_API const IDynamicTransform *createRecordTranslator(const RtlRecord &_destRecInfo, const RtlRecord &_srcRecInfo);
  109. extern ECLRTL_API const IKeyTranslator *createKeyTranslator(const RtlRecord &_destRecInfo, const RtlRecord &_srcRecInfo);
  110. extern ECLRTL_API IRtlFieldTypeDeserializer *createRtlFieldTypeDeserializer(IThorIndexCallback *callback);
  111. extern ECLRTL_API StringBuffer &dumpTypeInfo(StringBuffer &ret, const RtlTypeInfo *t);
  112. extern ECLRTL_API bool dumpTypeInfo(MemoryBuffer &ret, const RtlTypeInfo *t);
  113. /**
  114. * Serialize metadata of supplied record to JSON, and return it to ECL caller as a string. Used for testing serializer.
  115. *
  116. */
  117. extern ECLRTL_API void dumpRecordType(size32_t & __lenResult, char * & __result, IOutputMetaData & metaVal);
  118. /**
  119. * Serialize metadata of supplied record to DATA.
  120. *
  121. */
  122. extern ECLRTL_API void serializeRecordType(size32_t & __lenResult, void * & __result, IOutputMetaData & metaVal);
  123. /**
  124. * Extract a field from a record via dynamic column number
  125. *
  126. */
  127. extern ECLRTL_API void getFieldVal(size32_t & __lenResult, char * & __result, int column, IOutputMetaData & metaVal, const byte *row);
  128. /**
  129. * Extract a column number from a record via dynamic fieldname
  130. *
  131. */
  132. extern ECLRTL_API int getFieldNum(const char *fieldName, IOutputMetaData & metaVal);
  133. extern ECLRTL_API IRowStream * transformRecord(IEngineRowAllocator * resultAllocator,IOutputMetaData & metaInput,IRowStream * input);
  134. #endif