hqlcpp.hpp 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. /*##############################################################################
  2. Copyright (C) 2011 HPCC Systems.
  3. All rights reserved. This program is free software: you can redistribute it and/or modify
  4. it under the terms of the GNU Affero General Public License as
  5. published by the Free Software Foundation, either version 3 of the
  6. License, or (at your option) any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU Affero General Public License for more details.
  11. You should have received a copy of the GNU Affero General Public License
  12. along with this program. If not, see <http://www.gnu.org/licenses/>.
  13. ############################################################################## */
  14. #ifndef __HQLCPP_HPP_
  15. #define __HQLCPP_HPP_
  16. #ifdef HQLCPP_EXPORTS
  17. #define HQLCPP_API __declspec(dllexport)
  18. #else
  19. #define HQLCPP_API __declspec(dllimport)
  20. #endif
  21. #include "jlib.hpp"
  22. #include "hqlexpr.hpp"
  23. #include "workunit.hpp"
  24. /*
  25. The following debug options are currently supported by the code generator:
  26. 1. Generally useful
  27. "checkRowOverflow" true - check for potential overflows of records...
  28. "expandRepeatAnyAsDfa" true - is ANY* expanded in a DFA
  29. "forceFakeThor" false - force code to use hthor.
  30. "freezePersists" false - stop persists being recreated.
  31. "globalFold" true - perform a global constant fold before generating
  32. "globalFoldOptions" - options for above.
  33. "globalOptimize" false - perform a global optimize?
  34. "groupAllDistribute" false - does group,all generate a distribute or a global sort?
  35. "maximizeLexer" false - maximize the amount of work done in the lexer (?default on?)
  36. "maxLength" 4096 - default maximum length of a record, unless specified.
  37. "minimizeSpillSize", false - if a spill is filter/deduped etc when read, reduce the spill file size by splitting, filtering and then writing.
  38. "optimizeGraph" true - optimize expressions in a graph before generation
  39. "orderDiskFunnel" true - if all inputs to a funnel are disk reads, pull in order.
  40. "parseDfaComplexity" 2000 - maximum complexity of expression to convert to a DFA.
  41. "pickBestEngine" true - use hthor if it is more efficient than thor
  42. "sortIndexPayload" true - do we sort by the non-keyed elements in an index.
  43. "targetClusterType" ---- - hthor|thor|roxie - who are we generating code for?
  44. "topnLimit" 10000 - maximum number of records to do topN on.
  45. "traceRowXml" false - add information to allow rows to be traced as XML in the meta information.
  46. 2. Useful for debugging.
  47. "clusterSize" ---- - override the number of nodes in the cluster (for testing)
  48. "debugNlp" false - output debug information about the NLP processing to the .cpp file.
  49. "resourceMaxMemory" ?400M - maximum amount of memory a subgraph can use.
  50. "resourceMaxSockets" 2000 - maximum number of sockets a subgraph can use
  51. "resourceMaxActivities" 200 - maximum number of activities a subgraph can contain
  52. "unlimitedResources" false - assume lots of resources when resourcing the graphs.
  53. 3. Minor code generation tweaks
  54. "filteredReadSpillThreshold" 2 - filtered disk reads are spilt if will be duplicated more than N times.
  55. "foldConstantCast" true - Is (cast)value folded at generate time?
  56. "foldFilter" true - should filters be constant folded?
  57. "foldAssign" true - should transforms be constant folded?
  58. "foldGraph" false - fold expressions at the graph level if optimizeGraph is set.
  59. "foldOptimized" false - fold expressions when internal optimizer called.
  60. "peephole" true - peephole optimize memcpy/memsets etc.
  61. "spotCSE" true - Look for common sub-expressions in transforms/filters?
  62. "spotTopN" true - Convert choosen(sort()) into a topN activity.
  63. "spotLocalMerge" false - if local join, and both sides sorted generate a light-weight merge
  64. "allowThroughSpill" true - allow through spills.
  65. "spillMultiCondition" false - another roxie variant.
  66. "spotThroughAggregate" true - whether aggregates are done as through aggregates (generally more efficient)
  67. 4. Temporary flags
  68. "optimizeBoolReturn" true - improve code when returning boolean from a function
  69. */
  70. #define DEFAULT_conditionalStatements false
  71. #define STRING_RESOURCES
  72. #define CREATE_DEAULT_ROW_IF_NULL
  73. interface ICodegenContextCallback : public IInterface
  74. {
  75. virtual void noteCluster(const char *clusterName) = 0;
  76. virtual void registerFile(const char * filename, const char * description) = 0;
  77. virtual bool allowAccess(const char * category) = 0;
  78. };
  79. //interface that represents a implementation of a query
  80. //ready for passing to the thing that executes it.
  81. interface HQLCPP_API IHqlQueryInstance : public IInterface
  82. {
  83. public:
  84. virtual void serialise(MemoryBuffer & out) = 0;
  85. virtual void serialiseDll(MemoryBuffer & out) = 0;
  86. };
  87. interface IHqlDelayedCodeGenerator : public IInterface
  88. {
  89. virtual void generateCpp(StringBuffer & out) = 0;
  90. };
  91. interface IFunctionDatabase;
  92. class HqlStmts;
  93. interface HQLCPP_API IHqlCppInstance : public IInterface
  94. {
  95. public:
  96. virtual HqlStmts * ensureSection(_ATOM section) = 0;
  97. virtual const char * queryLibrary(unsigned idx) = 0;
  98. virtual HqlStmts * querySection(_ATOM section) = 0;
  99. virtual void addResource(const char * type, unsigned len, const void * data, IPropertyTree *manifestEntry, unsigned id=(unsigned)-1) = 0;
  100. virtual void addCompressResource(const char * type, unsigned len, const void * data, IPropertyTree *manifestEntry, unsigned id=(unsigned)-1) = 0;
  101. virtual void addManifest(const char *filename) = 0;
  102. virtual void addManifestFromArchive(IPropertyTree *archive) = 0;
  103. virtual void addWebServiceInfo(IPropertyTree *wsinfo) = 0;
  104. virtual void flushHints() = 0;
  105. virtual void flushResources(const char *filename, ICodegenContextCallback * ctxCallback) = 0;
  106. };
  107. interface HQLCPP_API IHqlCppTranslator : public IInterface
  108. {
  109. public:
  110. virtual bool buildCpp(IHqlCppInstance & _code, IHqlExpression * expr) = 0;
  111. };
  112. extern HQLCPP_API IHqlCppInstance * createCppInstance(IWorkUnit * wu, const char * wupathname);
  113. extern HQLCPP_API IHqlExpression * ensureIndexable(IHqlExpression * expr);
  114. extern HQLCPP_API bool isChildOf(IHqlExpression * parent, IHqlExpression * child);
  115. extern HQLCPP_API bool isProjectedInRecord(IHqlExpression * record, IHqlExpression * child);
  116. extern HQLCPP_API IHqlExpression * queryStripCasts(IHqlExpression * expr);
  117. extern HQLCPP_API IHqlExpression * adjustValue(IHqlExpression * value, __int64 delta);
  118. extern HQLCPP_API bool matchesConstValue(IHqlExpression * expr, __int64 matchValue);
  119. extern HQLCPP_API IHqlExpression * createTranslated(IHqlExpression * expr);
  120. extern HQLCPP_API IHqlExpression * createTranslatedOwned(IHqlExpression * expr);
  121. extern HQLCPP_API IHqlExpression * createTranslated(IHqlExpression * expr, IHqlExpression * length);
  122. extern HQLCPP_API IHqlExpression * getSimplifyCompareArg(IHqlExpression * expr);
  123. #endif