hqlcpp.hpp 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  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 __HQLCPP_HPP_
  14. #define __HQLCPP_HPP_
  15. #ifdef HQLCPP_EXPORTS
  16. #define HQLCPP_API __declspec(dllexport)
  17. #else
  18. #define HQLCPP_API __declspec(dllimport)
  19. #endif
  20. #include "jlib.hpp"
  21. #include "hqlexpr.hpp"
  22. #include "workunit.hpp"
  23. /*
  24. The following debug options are currently supported by the code generator:
  25. 1. Generally useful
  26. "checkRowOverflow" true - check for potential overflows of records...
  27. "expandRepeatAnyAsDfa" true - is ANY* expanded in a DFA
  28. "forceFakeThor" false - force code to use hthor.
  29. "freezePersists" false - stop persists being recreated.
  30. "globalFoldOptions" 0xffff - options for global folding.
  31. "globalOptimize" false - perform a global optimize?
  32. "groupAllDistribute" false - does group,all generate a distribute or a global sort?
  33. "maximizeLexer" false - maximize the amount of work done in the lexer (?default on?)
  34. "maxLength" 4096 - default maximum length of a record, unless specified.
  35. "minimizeSpillSize", false - if a spill is filter/deduped etc when read, reduce the spill file size by splitting, filtering and then writing.
  36. "optimizeGraph" true - optimize expressions in a graph before generation
  37. "orderDiskFunnel" true - if all inputs to a funnel are disk reads, pull in order.
  38. "parseDfaComplexity" 2000 - maximum complexity of expression to convert to a DFA.
  39. "pickBestEngine" true - use hthor if it is more efficient than thor
  40. "sortIndexPayload" true - do we sort by the non-keyed elements in an index.
  41. "targetClusterType" ---- - hthor|thor|roxie - who are we generating code for?
  42. "topnLimit" 10000 - maximum number of records to do topN on.
  43. "traceRowXml" false - add information to allow rows to be traced as XML in the meta information.
  44. 2. Useful for debugging.
  45. "clusterSize" ---- - override the number of nodes in the cluster (for testing)
  46. "debugNlp" false - output debug information about the NLP processing to the .cpp file.
  47. "resourceMaxMemory" ?400M - maximum amount of memory a subgraph can use.
  48. "resourceMaxSockets" 2000 - maximum number of sockets a subgraph can use
  49. "resourceMaxActivities" 200 - maximum number of activities a subgraph can contain
  50. "unlimitedResources" false - assume lots of resources when resourcing the graphs.
  51. 3. Minor code generation tweaks
  52. "filteredReadSpillThreshold" 2 - filtered disk reads are spilt if will be duplicated more than N times.
  53. "foldConstantCast" true - Is (cast)value folded at generate time?
  54. "foldFilter" true - should filters be constant folded?
  55. "foldAssign" true - should transforms be constant folded?
  56. "foldGraph" false - fold expressions at the graph level if optimizeGraph is set.
  57. "foldOptimized" false - fold expressions when internal optimizer called.
  58. "peephole" true - peephole optimize memcpy/memsets etc.
  59. "spotCSE" true - Look for common sub-expressions in transforms/filters?
  60. "spotTopN" true - Convert choosen(sort()) into a topN activity.
  61. "spotLocalMerge" false - if local join, and both sides sorted generate a light-weight merge
  62. "allowThroughSpill" true - allow through spills.
  63. "spillMultiCondition" false - another roxie variant.
  64. "spotThroughAggregate" true - whether aggregates are done as through aggregates (generally more efficient)
  65. 4. Temporary flags
  66. "optimizeBoolReturn" true - improve code when returning boolean from a function
  67. */
  68. #define DEFAULT_conditionalStatements false
  69. #define STRING_RESOURCES
  70. #define CREATE_DEAULT_ROW_IF_NULL
  71. //interface that represents a implementation of a query
  72. //ready for passing to the thing that executes it.
  73. interface HQLCPP_API IHqlQueryInstance : public IInterface
  74. {
  75. public:
  76. virtual void serialise(MemoryBuffer & out) = 0;
  77. virtual void serialiseDll(MemoryBuffer & out) = 0;
  78. };
  79. interface IHqlDelayedCodeGenerator : public IInterface
  80. {
  81. virtual void generateCpp(StringBuffer & out) = 0;
  82. };
  83. interface IFunctionDatabase;
  84. class HqlStmts;
  85. interface HQLCPP_API IHqlCppInstance : public IInterface
  86. {
  87. public:
  88. virtual HqlStmts * ensureSection(IAtom * section) = 0;
  89. virtual const char * queryLibrary(unsigned idx) = 0;
  90. virtual const char * queryObjectFile(unsigned idx) = 0;
  91. virtual const char * querySourceFile(unsigned idx) = 0;
  92. virtual HqlStmts * querySection(IAtom * section) = 0;
  93. virtual void addResource(const char * type, unsigned len, const void * data, IPropertyTree *manifestEntry, unsigned id=(unsigned)-1) = 0;
  94. virtual void addCompressResource(const char * type, unsigned len, const void * data, IPropertyTree *manifestEntry, unsigned id=(unsigned)-1) = 0;
  95. virtual void addManifest(const char *filename) = 0;
  96. virtual void addManifestFromArchive(IPropertyTree *archive) = 0;
  97. virtual void addWebServiceInfo(IPropertyTree *wsinfo) = 0;
  98. virtual void flushHints() = 0;
  99. virtual void flushResources(const char *filename, ICodegenContextCallback * ctxCallback) = 0;
  100. };
  101. // A class used to hold the context about the expression being processed at this point in time.
  102. // Note: expr is updated as the query is processed to ensure that the parsed tree etc. get freed up early.
  103. class HQLCPP_API HqlQueryContext
  104. {
  105. public:
  106. OwnedHqlExpr expr; // Modified as the query is processed.
  107. };
  108. interface HQLCPP_API IHqlCppTranslator : public IInterface
  109. {
  110. public:
  111. virtual bool buildCpp(IHqlCppInstance & _code, HqlQueryContext & query) = 0;
  112. };
  113. extern HQLCPP_API IHqlCppInstance * createCppInstance(IWorkUnit * wu, const char * wupathname);
  114. extern HQLCPP_API IHqlExpression * ensureIndexable(IHqlExpression * expr);
  115. extern HQLCPP_API bool isChildOf(IHqlExpression * parent, IHqlExpression * child);
  116. extern HQLCPP_API bool isProjectedInRecord(IHqlExpression * record, IHqlExpression * child);
  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