hqltcppc.hpp 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  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. #ifndef __HQLTCPPC_HPP_
  14. #define __HQLTCPPC_HPP_
  15. #include "hqlattr.hpp"
  16. class ColumnToOffsetMap;
  17. class HQLCPP_API BoundRow : public HqlExprAssociation
  18. {
  19. public:
  20. BoundRow(const BoundRow & other, IHqlExpression * _newBound); // other row
  21. BoundRow(BoundRow * row, IHqlExpression * dataset, node_operator side, IHqlExpression * selSeq);
  22. BoundRow(IHqlExpression * _dataset, IHqlExpression * _bound, ColumnToOffsetMap * _columnMap); // row
  23. BoundRow(IHqlExpression * _dataset, IHqlExpression * _bound, ColumnToOffsetMap * _columnMap, node_operator side, IHqlExpression * selSeq); // cursor
  24. ~BoundRow();
  25. virtual AssocKind getKind() { return (AssocKind)kind; }
  26. virtual bool isRowAssociation() { return true; }
  27. virtual IHqlExpression * queryExpr() const { return bound; }
  28. virtual BoundRow * clone(IHqlExpression * _newBound) { return new BoundRow(*this, _newBound); }
  29. virtual IHqlExpression * getMappedSelector(BuildCtx & ctx, IReferenceSelector * selector);
  30. virtual IHqlExpression * getFinalFixedSizeExpr();
  31. //meta information about the cursor...
  32. virtual bool isBinary();
  33. virtual bool isInherited() const { return inherited; } // inherited in any way.
  34. virtual bool beenSerialized() const { return false; } // serialized at some point in the parent row tree.
  35. virtual bool isSerialization() const { return false; } // a serialized row (not added to nonlocal children)
  36. virtual bool isNonLocal() const { return false; } // is this on demand? i.e. being serialized at this level.
  37. virtual IHqlExpression * queryAliasExpansion() { return NULL; }
  38. virtual ActivityInstance * queryActivity() { return NULL; }
  39. inline bool isConstant() const { return false; }
  40. inline bool isModifyable() const { return !isConstant() && !isInherited(); }
  41. inline bool isBuilder() const { return hasModifier(bound->queryType(), typemod_builder); }
  42. inline bool isLinkCounted() const { return hasLinkCountedModifier(bound->queryType()); }
  43. inline bool isConditional() const { return conditional; }
  44. inline bool isResultAlias() const { return resultAlias; }
  45. inline IHqlExpression * queryBound() const { return bound; }
  46. inline IHqlExpression * queryBuilder() const { return builder; }
  47. inline IHqlExpression * queryDataset() const { return dataset; }
  48. inline IHqlExpression * queryRecord() const { return dataset->queryRecord(); }
  49. inline node_operator querySide() const { return side; }
  50. inline IHqlExpression * querySelector() const { return represents; }
  51. inline IHqlExpression * querySelSeq() const { return (side != no_none) ? represents->queryChild(1) : NULL; }
  52. inline void setBuilder(IHqlExpression * value) { builder.set(value); }
  53. inline void setResultAlias() { resultAlias = true; }
  54. AColumnInfo * queryRootColumn();
  55. inline void setConditional(bool _value) { conditional = _value; }
  56. inline void setInherited(bool _value) { inherited = _value; }
  57. unsigned getMaxSize();
  58. IHqlExpression * bindToRow(IHqlExpression * expr, IHqlExpression * exprSelector);
  59. void setAlias(IReferenceSelector * selector) { alias.set(selector); }
  60. IReferenceSelector * queryAlias() { return alias; }
  61. IHqlExpression * queryBuilderEnsureMarker();
  62. protected:
  63. HqlExprAttr dataset;
  64. HqlExprAttr bound;
  65. HqlExprAttr builder;
  66. HqlExprAttr builderEnsureMarker;
  67. ColumnToOffsetMap * columnMap;
  68. Owned<IReferenceSelector> alias;
  69. node_operator side;
  70. #ifdef _DEBUG
  71. AssocKind kind;
  72. #else
  73. byte kind;
  74. #endif
  75. bool conditional;
  76. bool resultAlias;
  77. bool inherited;
  78. };
  79. //---------------------------------------------------------------------------
  80. //Inherited row, parent is a simple row, so only need to add a colocal-> prefix onto the bound cursor name.
  81. class CoLocalSimpleRow : public BoundRow
  82. {
  83. public:
  84. CoLocalSimpleRow(const BoundRow & other, IHqlExpression * _newBound) : BoundRow(other, _newBound) { inherited = true; }
  85. virtual BoundRow * clone(IHqlExpression * _newBound) { return new CoLocalSimpleRow(*this, _newBound); }
  86. };
  87. class DynamicColumnToOffsetMap;
  88. class SerializationRow : public BoundRow
  89. {
  90. public:
  91. static SerializationRow * create(HqlCppTranslator & _translator, IHqlExpression * _bound, ActivityInstance * activity);
  92. virtual BoundRow * clone(IHqlExpression * _newBound);
  93. virtual IHqlExpression * getFinalFixedSizeExpr() { return LINK(finalFixedSizeExpr); }
  94. virtual bool isSerialization() const { return true; }
  95. virtual ActivityInstance * queryActivity() { return activity; }
  96. IHqlExpression * createField(IIdAtom * id, ITypeInfo * type); // returns a no_select reference to the field
  97. IHqlExpression * addSerializedValue(IHqlExpression * path, ITypeInfo * type, IHqlExpression * colocal, bool isConditional);
  98. IHqlExpression * ensureSerialized(IHqlExpression * path, IHqlExpression * colocal, bool isConditional);
  99. IHqlExpression * ensureSerialized(BuildCtx & ctx, IHqlExpression * colocal, IReferenceSelector * selector);
  100. void finalize();
  101. size32_t getTotalMinimumSize() const;
  102. bool isFixedSize() const;
  103. unsigned numFields() const;
  104. IHqlExpression * queryRecord();
  105. void setBuilder(ParentExtract * _builder) { extractBuilder = _builder; }
  106. protected:
  107. SerializationRow(HqlCppTranslator & _translator, IHqlExpression * _dataset, IHqlExpression * _bound, DynamicColumnToOffsetMap * _columnMap, ActivityInstance * _activity);
  108. protected:
  109. MapOwnedToOwned<IHqlExpression, IHqlExpression> mapping;
  110. ParentExtract * extractBuilder;
  111. HqlCppTranslator & translator;
  112. DynamicColumnToOffsetMap * serializedMap;
  113. OwnedHqlExpr finalFixedSizeExpr;
  114. ActivityInstance * activity;
  115. OwnedHqlExpr record;
  116. };
  117. class NonLocalIndirectRow : public BoundRow
  118. {
  119. public:
  120. NonLocalIndirectRow(const BoundRow & other, IHqlExpression * _newBound, SerializationRow * _serialization);
  121. virtual BoundRow * clone(IHqlExpression * _newBound) { UNIMPLEMENTED; }
  122. virtual IHqlExpression * getMappedSelector(BuildCtx & ctx, IReferenceSelector * selector);
  123. virtual bool isInherited() const { return true; }
  124. virtual bool isNonLocal() const { return true; }
  125. protected:
  126. SerializationRow * serialization;
  127. };
  128. //Inherited row, parent is a simple row, so only need to add a colocal-> prefix onto the bound cursor name.
  129. class BoundAliasRow : public BoundRow
  130. {
  131. public:
  132. BoundAliasRow(const BoundRow & other, IHqlExpression * _newBound, IHqlExpression * _expansion) : BoundRow(other, _newBound) { expansion.set(_expansion); }
  133. BoundAliasRow(const BoundAliasRow & other, IHqlExpression * _newBound) : BoundRow(other, _newBound) { expansion.set(other.expansion); }
  134. virtual BoundRow * clone(IHqlExpression * _newBound) { return new BoundAliasRow(*this, _newBound); }
  135. virtual IHqlExpression * queryAliasExpansion() { return expansion; }
  136. protected:
  137. HqlExprAttr expansion;
  138. };
  139. extern bool canReadFromCsv(IHqlExpression * record);
  140. extern bool isSimpleLength(IHqlExpression * expr);
  141. #endif