rtldynfield.hpp 5.3 KB

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