hqllib.ipp 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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 __HQLLIB_IPP_
  14. #define __HQLLIB_IPP_
  15. #include "hqlhtcpp.ipp"
  16. #include "hqlecl.hpp"
  17. #define EMBEDDED_GRAPH_DELTA 1000000000
  18. class HqlCppLibrary : public CInterface
  19. {
  20. public:
  21. HqlCppLibrary(HqlCppTranslator & _translator, IHqlExpression * libraryInterface, ClusterType _clusterType);
  22. unsigned numStreamedInputs() const { return streamedCount; }
  23. unsigned totalInputs() const { return inputMapper.numParameters(); }
  24. unsigned getInterfaceHash() const;
  25. unsigned queryOutputIndex(IAtom * name) const;
  26. IHqlExpression * queryParameter(unsigned i) { return &inputMapper.queryRealParameters().item(i); }
  27. protected:
  28. void extractOutputs();
  29. unsigned getHash(const HqlExprArray & values, unsigned crc) const;
  30. public:
  31. HqlCppTranslator & translator;
  32. LinkedHqlExpr libraryInterface;
  33. IHqlExpression * scopeExpr;
  34. ClusterType clusterType;
  35. unsigned streamedCount;
  36. LibraryInputMapper inputMapper;
  37. HqlExprArray outputs; // Only the names and types are significant, not the values
  38. };
  39. class HqlCppLibraryImplementation : public HqlCppLibrary
  40. {
  41. public:
  42. HqlCppLibraryImplementation(HqlCppTranslator & _translator, IHqlExpression * libraryInterface, IHqlExpression * libraryId, ClusterType _clusterType);
  43. void mapLogicalToImplementation(HqlExprArray & exprs, IHqlExpression * libraryExpr);
  44. unsigned numResultsUsed() { return numStreamedInputs() + outputs.ordinality(); }
  45. IHqlExpression * queryInputExpr(unsigned i) { return &inputExprs.item(i); }
  46. public:
  47. LinkedHqlExpr libraryId;
  48. HqlExprArray inputExprs;
  49. HqlExprArray logicalParams;
  50. };
  51. class HqlCppLibraryInstance : public CInterface
  52. {
  53. public:
  54. HqlCppLibraryInstance(HqlCppTranslator & _translator, IHqlExpression * libraryInstance, ClusterType _clusterType);
  55. unsigned numStreamedInputs() { return library->numStreamedInputs(); }
  56. unsigned numParameters() { return libraryFuncdef->queryChild(1)->numChildren(); }
  57. IHqlExpression * queryActual(unsigned i) { return instanceExpr->queryChild(i); }
  58. IHqlExpression * queryParameter(unsigned i) { return libraryFuncdef->queryChild(1)->queryChild(i); }
  59. public:
  60. Owned<HqlCppLibrary> library;
  61. LinkedHqlExpr instanceExpr;
  62. IHqlExpression * libraryFuncdef;
  63. };
  64. class ThorBoundLibraryActivity : public ThorBoundActivity
  65. {
  66. public:
  67. ThorBoundLibraryActivity(ABoundActivity * activity, IPropertyTree * _graphNode, HqlCppLibraryInstance * _libraryInstance)
  68. : ThorBoundActivity(activity->queryDataset(), activity->queryBound(), activity->queryActivityId(), activity->queryContainerId(), activity->queryGraphId(), activity->queryActivityKind())
  69. {
  70. graphNode.set(_graphNode);
  71. libraryInstance.set(_libraryInstance);
  72. }
  73. void noteOutputUsed(IAtom * name);
  74. public:
  75. Linked<IPropertyTree> graphNode;
  76. Linked<HqlCppLibraryInstance> libraryInstance;
  77. };
  78. #endif