OmniSciDB  c0231cc57d
 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 noDag)
 

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 264 of file HeavyDBPlanner.java.

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

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

264  {
265  if (filterPushDownInfo.isEmpty()) {
266  return root;
267  }
268  final DynamicFilterJoinRule dynamicFilterJoinRule = new DynamicFilterJoinRule(true,
269  RelFactories.LOGICAL_BUILDER,
270  FilterJoinRule.TRUE_PREDICATE,
272  final HepProgram program =
273  HepProgram.builder().addRuleInstance(dynamicFilterJoinRule).build();
274  HepPlanner prePlanner = HeavyDBPlanner.getHepPlanner(program, false);
275  prePlanner.setRoot(root.rel);
276  final RelNode rootRelNode = prePlanner.findBestExp();
277  filterPushDownInfo.clear();
278  return root.withRel(rootRelNode);
279  }
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 250 of file HeavyDBPlanner.java.

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

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

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

+ Here is the caller graph for this function:

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

Definition at line 281 of file HeavyDBPlanner.java.

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

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

+ 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 291 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.

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

Definition at line 169 of file HeavyDBPlanner.java.

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

Definition at line 183 of file HeavyDBPlanner.java.

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

Definition at line 187 of file HeavyDBPlanner.java.

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

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

179  {
180  return super.rel(sql);
181  }
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 322 of file HeavyDBPlanner.java.

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

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

Definition at line 327 of file HeavyDBPlanner.java.

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

327  {
328  this.restrictions = restrictions;
329  }

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: