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

Classes

class  CompletionResult
 

Public Member Functions

 MapDPlanner (FrameworkConfig config)
 
void advanceToValidate ()
 
void ready ()
 
CompletionResult getCompletionHints (final String sql, final int cursor, final List< String > visibleTables)
 
RelRoot rel (SqlNode sql)
 
RelRoot optimizeRaQuery (String query, MapDSchema schema) throws IOException
 
void setFilterPushDownInfo (final List< MapDParserOptions.FilterPushDownInfo > filterPushDownInfo)
 
void setRestriction (Restriction restriction)
 

Static Public Member Functions

static HepPlanner getHepPlanner (HepProgram hepProgram, boolean noDag)
 

Package Attributes

FrameworkConfig config
 

Static Package Attributes

static final Logger MAPDLOGGER = LoggerFactory.getLogger(MapDPlanner.class)
 

Private Member Functions

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

Static Private Member Functions

static SchemaPlus rootSchema (SchemaPlus schema)
 

Private Attributes

List
< MapDParserOptions.FilterPushDownInfo > 
filterPushDownInfo
 
Restriction restriction = null
 

Detailed Description

Customised version of the PlannerImpl for MapD. 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 74 of file MapDPlanner.java.

Constructor & Destructor Documentation

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

Definition at line 81 of file MapDPlanner.java.

References org.apache.calcite.prepare.MapDPlanner.config.

81  {
82  super(config);
83  this.config = config;
84  }

Member Function Documentation

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

Definition at line 125 of file MapDPlanner.java.

125  {
126  try {
127  String dummySql = "SELECT 1";
128  super.parse(dummySql);
129  } catch (SqlParseException e) {
130  throw new RuntimeException(e);
131  }
132  }
RelRoot org.apache.calcite.prepare.MapDPlanner.applyFilterPushdown ( RelRoot  root)
inlineprivate

Definition at line 206 of file MapDPlanner.java.

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

Referenced by org.apache.calcite.prepare.MapDPlanner.optimizeRaQuery(), and org.apache.calcite.prepare.MapDPlanner.rel().

206  {
207  if (filterPushDownInfo.isEmpty()) {
208  return root;
209  }
210  final DynamicFilterJoinRule dynamicFilterJoinRule = new DynamicFilterJoinRule(true,
211  RelFactories.LOGICAL_BUILDER,
212  FilterJoinRule.TRUE_PREDICATE,
214  final HepProgram program =
215  HepProgram.builder().addRuleInstance(dynamicFilterJoinRule).build();
216  HepPlanner prePlanner = MapDPlanner.getHepPlanner(program, false);
217  prePlanner.setRoot(root.rel);
218  final RelNode rootRelNode = prePlanner.findBestExp();
219  filterPushDownInfo.clear();
220  return root.withRel(rootRelNode);
221  }
tuple root
Definition: setup.in.py:14
List< MapDParserOptions.FilterPushDownInfo > filterPushDownInfo

+ Here is the caller graph for this function:

RelRoot org.apache.calcite.prepare.MapDPlanner.applyInjectFilterRule ( RelRoot  root,
Restriction  restriction 
)
inlineprivate

Definition at line 192 of file MapDPlanner.java.

References org.apache.calcite.prepare.MapDPlanner.restriction.

Referenced by org.apache.calcite.prepare.MapDPlanner.optimizeRaQuery(), and org.apache.calcite.prepare.MapDPlanner.rel().

192  {
193  // TODO consider doing these rules in one preplan pass
194 
195  final InjectFilterRule injectFilterRule =
196  InjectFilterRule.Config.DEFAULT.toRule(restriction);
197 
198  final HepProgram program =
199  HepProgram.builder().addRuleInstance(injectFilterRule).build();
200  HepPlanner prePlanner = MapDPlanner.getHepPlanner(program, false);
201  prePlanner.setRoot(root.rel);
202  final RelNode rootRelNode = prePlanner.findBestExp();
203  return root.withRel(rootRelNode);
204  }

+ Here is the caller graph for this function:

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

Definition at line 234 of file MapDPlanner.java.

Referenced by org.apache.calcite.prepare.MapDPlanner.optimizeRaQuery().

234  {
235  HepProgramBuilder programBuilder = new HepProgramBuilder();
236  for (RelOptRule rule : rules) {
237  programBuilder.addRuleInstance(rule);
238  }
239  HepPlanner hepPlanner = MapDPlanner.getHepPlanner(programBuilder.build(), false);
240  hepPlanner.setRoot(root.rel);
241  return root.withRel(hepPlanner.findBestExp());
242  }

+ Here is the caller graph for this function:

RelRoot org.apache.calcite.prepare.MapDPlanner.applyQueryOptimizationRules ( RelRoot  root)
inlineprivate

Definition at line 223 of file MapDPlanner.java.

Referenced by org.apache.calcite.prepare.MapDPlanner.optimizeRaQuery(), and org.apache.calcite.prepare.MapDPlanner.rel().

223  {
224  QueryOptimizationRules outerJoinOptRule =
225  new OuterJoinOptViaNullRejectionRule(RelFactories.LOGICAL_BUILDER);
226 
227  HepProgram program = HepProgram.builder().addRuleInstance(outerJoinOptRule).build();
228  HepPlanner prePlanner = MapDPlanner.getHepPlanner(program, true);
229  prePlanner.setRoot(root.rel);
230  final RelNode rootRelNode = prePlanner.findBestExp();
231  return root.withRel(rootRelNode);
232  }

+ Here is the caller graph for this function:

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

Definition at line 105 of file MapDPlanner.java.

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

Referenced by org.apache.calcite.prepare.MapDPlanner.getCompletionHints(), and org.apache.calcite.prepare.MapDPlanner.optimizeRaQuery().

105  {
106  final SchemaPlus rootSchema = rootSchema(config.getDefaultSchema());
107  final Context context = config.getContext();
108  final CalciteConnectionConfig connectionConfig;
109 
110  if (context != null) {
111  connectionConfig = context.unwrap(CalciteConnectionConfig.class);
112  } else {
113  Properties properties = new Properties();
114  properties.setProperty(CalciteConnectionProperty.CASE_SENSITIVE.camelName(),
115  String.valueOf(config.getParserConfig().caseSensitive()));
116  connectionConfig = new CalciteConnectionConfigImpl(properties);
117  }
118 
119  return new CalciteCatalogReader(CalciteSchema.from(rootSchema),
120  CalciteSchema.from(config.getDefaultSchema()).path(null),
121  getTypeFactory(),
122  connectionConfig);
123  }
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.MapDPlanner.getCompletionHints ( final String  sql,
final int  cursor,
final List< String >  visibleTables 
)
inline

Definition at line 152 of file MapDPlanner.java.

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

153  {
154  ready();
155 
156  SqlValidator.Config validatorConfig = SqlValidator.Config.DEFAULT;
157  validatorConfig = validatorConfig.withSqlConformance(SqlConformanceEnum.LENIENT);
158 
159  MapDSqlAdvisorValidator advisor_validator = new MapDSqlAdvisorValidator(visibleTables,
160  config.getOperatorTable(),
162  getTypeFactory(),
163  validatorConfig);
164  SqlAdvisor advisor = new MapDSqlAdvisor(advisor_validator, config.getParserConfig());
165  String[] replaced = new String[1];
166  int adjusted_cursor = cursor < 0 ? sql.length() : cursor;
167  java.util.List<SqlMoniker> hints =
168  advisor.getCompletionHints(sql, adjusted_cursor, replaced);
169  return new CompletionResult(hints, replaced[0]);
170  }
CalciteCatalogReader createCatalogReader()
#define DEFAULT

+ Here is the call graph for this function:

static HepPlanner org.apache.calcite.prepare.MapDPlanner.getHepPlanner ( HepProgram  hepProgram,
boolean  noDag 
)
inlinestatic

Definition at line 172 of file MapDPlanner.java.

172  {
173  if (noDag) {
174  return new HepPlanner(
175  hepProgram, null, true, Functions.ignore2(), RelOptCostImpl.FACTORY);
176  } else {
177  return new HepPlanner(hepProgram);
178  }
179  }
RelRoot org.apache.calcite.prepare.MapDPlanner.optimizeRaQuery ( String  query,
MapDSchema  schema 
) throws IOException
inline

Definition at line 244 of file MapDPlanner.java.

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

244  {
245  ready();
246  RexBuilder builder = new RexBuilder(getTypeFactory());
247  RelOptCluster cluster = RelOptCluster.create(new VolcanoPlanner(), builder);
248  CalciteCatalogReader catalogReader = createCatalogReader();
249  MapDRelJsonReader reader = new MapDRelJsonReader(cluster, catalogReader, schema);
250 
251  RelRoot relR = RelRoot.of(reader.read(query), SqlKind.SELECT);
252 
253  if (restriction != null) {
254  relR = applyInjectFilterRule(relR, restriction);
255  }
256 
257  relR = applyQueryOptimizationRules(relR);
258  relR = applyFilterPushdown(relR);
259  relR = applyOptimizationsRules(relR,
260  ImmutableSet.of(CoreRules.JOIN_PROJECT_BOTH_TRANSPOSE_INCLUDE_OUTER,
261  CoreRules.FILTER_REDUCE_EXPRESSIONS,
262  ProjectProjectRemoveRule.INSTANCE,
263  CoreRules.PROJECT_FILTER_TRANSPOSE));
264  relR = applyOptimizationsRules(relR, ImmutableSet.of(CoreRules.PROJECT_MERGE));
265  relR = applyOptimizationsRules(relR,
266  ImmutableSet.of(
267  CoreRules.FILTER_PROJECT_TRANSPOSE, CoreRules.PROJECT_REMOVE));
268  return RelRoot.of(relR.project(), relR.kind);
269  }
RelRoot applyQueryOptimizationRules(RelRoot root)
RelRoot applyOptimizationsRules(RelRoot root, ImmutableSet< RelOptRule > rules)
CalciteCatalogReader createCatalogReader()
RelRoot applyInjectFilterRule(RelRoot root, Restriction restriction)
RelRoot applyFilterPushdown(RelRoot root)

+ Here is the call graph for this function:

void org.apache.calcite.prepare.MapDPlanner.ready ( )
inline

Definition at line 134 of file MapDPlanner.java.

Referenced by org.apache.calcite.prepare.MapDPlanner.getCompletionHints(), and org.apache.calcite.prepare.MapDPlanner.optimizeRaQuery().

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

+ Here is the caller graph for this function:

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

Definition at line 182 of file MapDPlanner.java.

References org.apache.calcite.prepare.MapDPlanner.applyFilterPushdown(), org.apache.calcite.prepare.MapDPlanner.applyInjectFilterRule(), org.apache.calcite.prepare.MapDPlanner.applyQueryOptimizationRules(), org.apache.calcite.prepare.MapDPlanner.restriction, and setup.root.

182  {
183  RelRoot root = super.rel(sql);
184  if (restriction != null) {
185  root = applyInjectFilterRule(root, restriction);
186  }
187  root = applyQueryOptimizationRules(root);
188  root = applyFilterPushdown(root);
189  return root;
190  }
RelRoot applyQueryOptimizationRules(RelRoot root)
tuple root
Definition: setup.in.py:14
RelRoot applyInjectFilterRule(RelRoot root, Restriction restriction)
RelRoot applyFilterPushdown(RelRoot root)

+ Here is the call graph for this function:

static SchemaPlus org.apache.calcite.prepare.MapDPlanner.rootSchema ( SchemaPlus  schema)
inlinestaticprivate

Definition at line 86 of file MapDPlanner.java.

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

86  {
87  for (;;) {
88  if (schema.getParentSchema() == null) {
89  return schema;
90  }
91  schema = schema.getParentSchema();
92  }
93  }

+ Here is the caller graph for this function:

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

Definition at line 271 of file MapDPlanner.java.

References org.apache.calcite.prepare.MapDPlanner.filterPushDownInfo.

272  {
273  this.filterPushDownInfo = filterPushDownInfo;
274  }
List< MapDParserOptions.FilterPushDownInfo > filterPushDownInfo
void org.apache.calcite.prepare.MapDPlanner.setRestriction ( Restriction  restriction)
inline

Definition at line 276 of file MapDPlanner.java.

References org.apache.calcite.prepare.MapDPlanner.restriction.

276  {
277  this.restriction = restriction;
278  }

Member Data Documentation

List<MapDParserOptions.FilterPushDownInfo> org.apache.calcite.prepare.MapDPlanner.filterPushDownInfo
private
final Logger org.apache.calcite.prepare.MapDPlanner.MAPDLOGGER = LoggerFactory.getLogger(MapDPlanner.class)
staticpackage

Definition at line 79 of file MapDPlanner.java.


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