OmniSciDB  a5dc49c757
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
org.apache.calcite.prepare.HeavyDBPlanner Class Reference
+ Inheritance diagram for org.apache.calcite.prepare.HeavyDBPlanner:
+ Collaboration diagram for org.apache.calcite.prepare.HeavyDBPlanner:

Classes

class  CompletionResult
 

Public Member Functions

 HeavyDBPlanner (FrameworkConfig config)
 
void advanceToValidate ()
 
void ready ()
 
CompletionResult getCompletionHints (final String sql, final int cursor, final List< String > visibleTables)
 
RelRoot rel (SqlNode sql)
 
RelRoot getRelRoot (SqlNode sqlNode)
 
RelNode optimizeRATree (RelNode rootNode, boolean viewOptimizationEnabled, boolean foundView)
 
RelRoot buildRATreeAndPerformQueryOptimization (String query, HeavyDBSchema schema) throws IOException
 
void setFilterPushDownInfo (final List< HeavyDBParserOptions.FilterPushDownInfo > filterPushDownInfo)
 
void setRestrictions (List< Restriction > restrictions)
 

Static Public Member Functions

static HepPlanner getHepPlanner (HepProgram hepProgram, boolean doNotEliminateSharedNodesInQueryPlanDag)
 

Package Attributes

FrameworkConfig config
 

Static Package Attributes

static final Logger HEAVYDBLOGGER = LoggerFactory.getLogger(HeavyDBPlanner.class)
 

Private Member Functions

CalciteCatalogReader createCatalogReader ()
 
RelRoot applyInjectFilterRule (RelRoot root, List< Restriction > restrictions)
 
RelRoot applyFilterPushdown (RelRoot root)
 
RelRoot applyOptimizationsRules (RelRoot root, ImmutableSet< RelOptRule > rules)
 

Static Private Member Functions

static SchemaPlus rootSchema (SchemaPlus schema)
 

Private Attributes

List
< HeavyDBParserOptions.FilterPushDownInfo > 
filterPushDownInfo
 
List< Restriction > restrictions = null
 

Detailed Description

Customised version of the PlannerImpl for HEAVY.AI. Used to be a copy of PlannerImpl, refactored now to use inheritance to minimize maintenance efforts. Implementation of org.apache.calcite.tools.Planner.

Definition at line 69 of file HeavyDBPlanner.java.

Constructor & Destructor Documentation

org.apache.calcite.prepare.HeavyDBPlanner.HeavyDBPlanner ( FrameworkConfig  config)
inline

Definition at line 76 of file HeavyDBPlanner.java.

References org.apache.calcite.prepare.HeavyDBPlanner.config.

76  {
77  super(config);
78  this.config = config;
79  }

Member Function Documentation

void org.apache.calcite.prepare.HeavyDBPlanner.advanceToValidate ( )
inline

Definition at line 120 of file HeavyDBPlanner.java.

120  {
121  try {
122  String dummySql = "SELECT 1";
123  super.parse(dummySql);
124  } catch (SqlParseException e) {
125  throw new RuntimeException(e);
126  }
127  }
RelRoot org.apache.calcite.prepare.HeavyDBPlanner.applyFilterPushdown ( RelRoot  root)
inlineprivate

Definition at line 265 of file HeavyDBPlanner.java.

References org.apache.calcite.prepare.HeavyDBPlanner.filterPushDownInfo, and setup.root.

Referenced by org.apache.calcite.prepare.HeavyDBPlanner.buildRATreeAndPerformQueryOptimization().

265  {
266  if (filterPushDownInfo.isEmpty()) {
267  return root;
268  }
269  final DynamicFilterJoinRule dynamicFilterJoinRule = new DynamicFilterJoinRule(true,
270  RelFactories.LOGICAL_BUILDER,
271  FilterJoinRule.TRUE_PREDICATE,
273  final HepProgram program =
274  HepProgram.builder().addRuleInstance(dynamicFilterJoinRule).build();
275  HepPlanner prePlanner = HeavyDBPlanner.getHepPlanner(program, false);
276  prePlanner.setRoot(root.rel);
277  final RelNode rootRelNode = prePlanner.findBestExp();
278  filterPushDownInfo.clear();
279  return root.withRel(rootRelNode);
280  }
List< HeavyDBParserOptions.FilterPushDownInfo > filterPushDownInfo
tuple root
Definition: setup.in.py:14

+ Here is the caller graph for this function:

RelRoot org.apache.calcite.prepare.HeavyDBPlanner.applyInjectFilterRule ( RelRoot  root,
List< Restriction >  restrictions 
)
inlineprivate

Definition at line 251 of file HeavyDBPlanner.java.

References org.apache.calcite.prepare.HeavyDBPlanner.restrictions.

Referenced by org.apache.calcite.prepare.HeavyDBPlanner.buildRATreeAndPerformQueryOptimization().

251  {
252  // TODO consider doing these rules in one preplan pass
253 
254  final InjectFilterRule injectFilterRule =
255  InjectFilterRule.Config.DEFAULT.toRule(restrictions);
256 
257  final HepProgram program =
258  HepProgram.builder().addRuleInstance(injectFilterRule).build();
259  HepPlanner prePlanner = HeavyDBPlanner.getHepPlanner(program, false);
260  prePlanner.setRoot(root.rel);
261  final RelNode rootRelNode = prePlanner.findBestExp();
262  return root.withRel(rootRelNode);
263  }

+ Here is the caller graph for this function:

RelRoot org.apache.calcite.prepare.HeavyDBPlanner.applyOptimizationsRules ( RelRoot  root,
ImmutableSet< RelOptRule >  rules 
)
inlineprivate

Definition at line 282 of file HeavyDBPlanner.java.

Referenced by org.apache.calcite.prepare.HeavyDBPlanner.buildRATreeAndPerformQueryOptimization().

282  {
283  HepProgramBuilder programBuilder = new HepProgramBuilder();
284  for (RelOptRule rule : rules) {
285  programBuilder.addRuleInstance(rule);
286  }
287  HepPlanner hepPlanner = HeavyDBPlanner.getHepPlanner(programBuilder.build(), false);
288  hepPlanner.setRoot(root.rel);
289  return root.withRel(hepPlanner.findBestExp());
290  }

+ Here is the caller graph for this function:

RelRoot org.apache.calcite.prepare.HeavyDBPlanner.buildRATreeAndPerformQueryOptimization ( String  query,
HeavyDBSchema  schema 
) throws IOException
inline

Definition at line 292 of file HeavyDBPlanner.java.

References org.apache.calcite.prepare.HeavyDBPlanner.applyFilterPushdown(), org.apache.calcite.prepare.HeavyDBPlanner.applyInjectFilterRule(), org.apache.calcite.prepare.HeavyDBPlanner.applyOptimizationsRules(), org.apache.calcite.prepare.HeavyDBPlanner.createCatalogReader(), com.mapd.calcite.parser.ProjectProjectRemoveRule.INSTANCE, org.apache.calcite.prepare.HeavyDBPlanner.ready(), and org.apache.calcite.prepare.HeavyDBPlanner.restrictions.

293  {
294  ready();
295  RexBuilder builder = new RexBuilder(getTypeFactory());
296  RelOptCluster cluster = RelOptCluster.create(new VolcanoPlanner(), builder);
297  CalciteCatalogReader catalogReader = createCatalogReader();
298  HeavyDBRelJsonReader reader =
299  new HeavyDBRelJsonReader(cluster, catalogReader, schema);
300 
301  RelRoot relR = RelRoot.of(reader.read(query), SqlKind.SELECT);
302 
303  if (restrictions != null) {
304  relR = applyInjectFilterRule(relR, restrictions);
305  }
306  QueryOptimizationRules outerJoinOptRule =
307  new OuterJoinOptViaNullRejectionRule(RelFactories.LOGICAL_BUILDER);
309  relR, ImmutableSet.of(CoreRules.AGGREGATE_MERGE, outerJoinOptRule));
310  relR = applyFilterPushdown(relR);
311  relR = applyOptimizationsRules(relR,
312  ImmutableSet.of(CoreRules.JOIN_PROJECT_BOTH_TRANSPOSE_INCLUDE_OUTER,
313  CoreRules.FILTER_REDUCE_EXPRESSIONS,
314  ProjectProjectRemoveRule.INSTANCE,
315  CoreRules.PROJECT_FILTER_TRANSPOSE));
316  relR = applyOptimizationsRules(relR, ImmutableSet.of(CoreRules.PROJECT_MERGE));
317  relR = applyOptimizationsRules(relR,
318  ImmutableSet.of(
319  CoreRules.FILTER_PROJECT_TRANSPOSE, CoreRules.PROJECT_REMOVE));
320  return RelRoot.of(relR.project(), relR.kind);
321  }
RelRoot applyOptimizationsRules(RelRoot root, ImmutableSet< RelOptRule > rules)
RelRoot applyInjectFilterRule(RelRoot root, List< Restriction > restrictions)

+ Here is the call graph for this function:

CalciteCatalogReader org.apache.calcite.prepare.HeavyDBPlanner.createCatalogReader ( )
inlineprivate

Definition at line 100 of file HeavyDBPlanner.java.

References org.apache.calcite.prepare.HeavyDBPlanner.config, and org.apache.calcite.prepare.HeavyDBPlanner.rootSchema().

Referenced by org.apache.calcite.prepare.HeavyDBPlanner.buildRATreeAndPerformQueryOptimization(), and org.apache.calcite.prepare.HeavyDBPlanner.getCompletionHints().

100  {
101  final SchemaPlus rootSchema = rootSchema(config.getDefaultSchema());
102  final Context context = config.getContext();
103  final CalciteConnectionConfig connectionConfig;
104 
105  if (context != null) {
106  connectionConfig = context.unwrap(CalciteConnectionConfig.class);
107  } else {
108  Properties properties = new Properties();
109  properties.setProperty(CalciteConnectionProperty.CASE_SENSITIVE.camelName(),
110  String.valueOf(config.getParserConfig().caseSensitive()));
111  connectionConfig = new CalciteConnectionConfigImpl(properties);
112  }
113 
114  return new CalciteCatalogReader(CalciteSchema.from(rootSchema),
115  CalciteSchema.from(config.getDefaultSchema()).path(null),
116  getTypeFactory(),
117  connectionConfig);
118  }
static SchemaPlus rootSchema(SchemaPlus schema)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

CompletionResult org.apache.calcite.prepare.HeavyDBPlanner.getCompletionHints ( final String  sql,
final int  cursor,
final List< String >  visibleTables 
)
inline

Definition at line 147 of file HeavyDBPlanner.java.

References org.apache.calcite.prepare.HeavyDBPlanner.config, org.apache.calcite.prepare.HeavyDBPlanner.createCatalogReader(), and org.apache.calcite.prepare.HeavyDBPlanner.ready().

148  {
149  ready();
150 
151  SqlValidator.Config validatorConfig = SqlValidator.Config.DEFAULT;
152  validatorConfig = validatorConfig.withSqlConformance(SqlConformanceEnum.LENIENT);
153 
154  HeavyDBSqlAdvisorValidator advisor_validator =
155  new HeavyDBSqlAdvisorValidator(visibleTables,
156  config.getOperatorTable(),
158  getTypeFactory(),
159  validatorConfig);
160  SqlAdvisor advisor =
161  new HeavyDBSqlAdvisor(advisor_validator, config.getParserConfig());
162  String[] replaced = new String[1];
163  int adjusted_cursor = cursor < 0 ? sql.length() : cursor;
164  java.util.List<SqlMoniker> hints =
165  advisor.getCompletionHints(sql, adjusted_cursor, replaced);
166  return new CompletionResult(hints, replaced[0]);
167  }

+ Here is the call graph for this function:

static HepPlanner org.apache.calcite.prepare.HeavyDBPlanner.getHepPlanner ( HepProgram  hepProgram,
boolean  doNotEliminateSharedNodesInQueryPlanDag 
)
inlinestatic

Definition at line 169 of file HeavyDBPlanner.java.

170  {
171  if (doNotEliminateSharedNodesInQueryPlanDag) {
172  return new HepPlanner(
173  hepProgram, null, true, Functions.ignore2(), RelOptCostImpl.FACTORY);
174  } else {
175  return new HepPlanner(hepProgram);
176  }
177  }
RelRoot org.apache.calcite.prepare.HeavyDBPlanner.getRelRoot ( SqlNode  sqlNode)
inline

Definition at line 184 of file HeavyDBPlanner.java.

184  {
185  return super.rel(sqlNode);
186  }
RelNode org.apache.calcite.prepare.HeavyDBPlanner.optimizeRATree ( RelNode  rootNode,
boolean  viewOptimizationEnabled,
boolean  foundView 
)
inline

Definition at line 188 of file HeavyDBPlanner.java.

References org.apache.calcite.prepare.HeavyDBPlanner.filterPushDownInfo, com.mapd.calcite.parser.ProjectProjectRemoveRule.INSTANCE, and org.apache.calcite.prepare.HeavyDBPlanner.restrictions.

189  {
190  HepProgramBuilder firstOptPhaseProgram = HepProgram.builder();
191  firstOptPhaseProgram.addRuleInstance(CoreRules.AGGREGATE_MERGE)
192  .addRuleInstance(
193  new OuterJoinOptViaNullRejectionRule(RelFactories.LOGICAL_BUILDER))
194  .addRuleInstance(CoreRules.AGGREGATE_UNION_TRANSPOSE);
195  if (!viewOptimizationEnabled) {
196  firstOptPhaseProgram.addRuleInstance(CoreRules.FILTER_PROJECT_TRANSPOSE)
197  .addRuleInstance(
198  FilterTableFunctionMultiInputTransposeRule.Config.DEFAULT.toRule())
199  .addRuleInstance(CoreRules.FILTER_PROJECT_TRANSPOSE);
200  } else {
201  if (foundView) {
202  firstOptPhaseProgram.addRuleInstance(
203  CoreRules.JOIN_PROJECT_BOTH_TRANSPOSE_INCLUDE_OUTER);
204  firstOptPhaseProgram.addRuleInstance(CoreRules.FILTER_MERGE);
205  }
206  firstOptPhaseProgram.addRuleInstance(CoreRules.FILTER_PROJECT_TRANSPOSE);
207  firstOptPhaseProgram.addRuleInstance(
208  FilterTableFunctionMultiInputTransposeRule.Config.DEFAULT.toRule());
209  firstOptPhaseProgram.addRuleInstance(CoreRules.FILTER_PROJECT_TRANSPOSE);
210  if (foundView) {
211  firstOptPhaseProgram.addRuleInstance(CoreRules.PROJECT_MERGE);
212  firstOptPhaseProgram.addRuleInstance(ProjectProjectRemoveRule.INSTANCE);
213  }
214  }
215  HepProgram firstOptPhase = firstOptPhaseProgram.build();
216  HepPlanner firstPlanner = HeavyDBPlanner.getHepPlanner(firstOptPhase, true);
217  firstPlanner.setRoot(rootNode);
218  final RelNode firstOptimizedPlanRoot = firstPlanner.findBestExp();
219 
220  boolean hasRLSFilter = null != restrictions && !restrictions.isEmpty();
221  boolean needsSecondOptPhase = hasRLSFilter || !filterPushDownInfo.isEmpty();
222  if (needsSecondOptPhase) {
223  HepProgramBuilder secondOptPhaseProgram = HepProgram.builder();
224  if (hasRLSFilter) {
225  final InjectFilterRule injectFilterRule =
226  InjectFilterRule.Config.DEFAULT.toRule(restrictions);
227  secondOptPhaseProgram.addRuleInstance(injectFilterRule);
228  }
229  if (!filterPushDownInfo.isEmpty()) {
230  final DynamicFilterJoinRule dynamicFilterJoinRule =
231  new DynamicFilterJoinRule(true,
232  RelFactories.LOGICAL_BUILDER,
233  FilterJoinRule.TRUE_PREDICATE,
235  secondOptPhaseProgram.addRuleInstance(dynamicFilterJoinRule);
236  }
237 
238  HepProgram secondOptPhase = secondOptPhaseProgram.build();
239  HepPlanner secondPlanner = HeavyDBPlanner.getHepPlanner(secondOptPhase, true);
240  secondPlanner.setRoot(firstOptimizedPlanRoot);
241  final RelNode secondOptimizedPlanRoot = secondPlanner.findBestExp();
242  if (!filterPushDownInfo.isEmpty()) {
243  filterPushDownInfo.clear();
244  }
245  return secondOptimizedPlanRoot;
246  } else {
247  return firstOptimizedPlanRoot;
248  }
249  }
List< HeavyDBParserOptions.FilterPushDownInfo > filterPushDownInfo
void org.apache.calcite.prepare.HeavyDBPlanner.ready ( )
inline

Definition at line 129 of file HeavyDBPlanner.java.

Referenced by org.apache.calcite.prepare.HeavyDBPlanner.buildRATreeAndPerformQueryOptimization(), and org.apache.calcite.prepare.HeavyDBPlanner.getCompletionHints().

129  {
130  // need to call ready on the super class, but that method is marked private
131  // circumventing via reflection for now
132  try {
133  Method readyMethod = getClass().getSuperclass().getDeclaredMethod("ready");
134  readyMethod.setAccessible(true);
135  readyMethod.invoke(this);
136  } catch (InvocationTargetException e) {
137  if (e.getCause() instanceof RuntimeException) {
138  throw(RuntimeException) e.getCause();
139  } else {
140  throw new RuntimeException(e.getCause());
141  }
142  } catch (Exception e) {
143  throw new RuntimeException(e);
144  }
145  }

+ Here is the caller graph for this function:

RelRoot org.apache.calcite.prepare.HeavyDBPlanner.rel ( SqlNode  sql)
inline

Definition at line 180 of file HeavyDBPlanner.java.

180  {
181  return super.rel(sql);
182  }
static SchemaPlus org.apache.calcite.prepare.HeavyDBPlanner.rootSchema ( SchemaPlus  schema)
inlinestaticprivate

Definition at line 81 of file HeavyDBPlanner.java.

Referenced by org.apache.calcite.prepare.HeavyDBPlanner.createCatalogReader().

81  {
82  for (;;) {
83  if (schema.getParentSchema() == null) {
84  return schema;
85  }
86  schema = schema.getParentSchema();
87  }
88  }

+ Here is the caller graph for this function:

void org.apache.calcite.prepare.HeavyDBPlanner.setFilterPushDownInfo ( final List< HeavyDBParserOptions.FilterPushDownInfo >  filterPushDownInfo)
inline

Definition at line 323 of file HeavyDBPlanner.java.

References org.apache.calcite.prepare.HeavyDBPlanner.filterPushDownInfo.

324  {
325  this.filterPushDownInfo = filterPushDownInfo;
326  }
List< HeavyDBParserOptions.FilterPushDownInfo > filterPushDownInfo
void org.apache.calcite.prepare.HeavyDBPlanner.setRestrictions ( List< Restriction >  restrictions)
inline

Definition at line 328 of file HeavyDBPlanner.java.

References org.apache.calcite.prepare.HeavyDBPlanner.restrictions.

328  {
329  this.restrictions = restrictions;
330  }

Member Data Documentation

List<HeavyDBParserOptions.FilterPushDownInfo> org.apache.calcite.prepare.HeavyDBPlanner.filterPushDownInfo
private
final Logger org.apache.calcite.prepare.HeavyDBPlanner.HEAVYDBLOGGER = LoggerFactory.getLogger(HeavyDBPlanner.class)
staticpackage

Definition at line 74 of file HeavyDBPlanner.java.


The documentation for this class was generated from the following file: