OmniSciDB  94e8789169
 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)
 

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)
 

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 72 of file MapDPlanner.java.

Constructor & Destructor Documentation

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

Definition at line 79 of file MapDPlanner.java.

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

79  {
80  super(config);
81  this.config = config;
82  }

Member Function Documentation

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

Definition at line 123 of file MapDPlanner.java.

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

Definition at line 195 of file MapDPlanner.java.

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

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

195  {
196  if (filterPushDownInfo.isEmpty()) {
197  return root;
198  }
199  final DynamicFilterJoinRule dynamicFilterJoinRule = new DynamicFilterJoinRule(true,
200  RelFactories.LOGICAL_BUILDER,
201  FilterJoinRule.TRUE_PREDICATE,
203  final HepProgram program =
204  HepProgram.builder().addRuleInstance(dynamicFilterJoinRule).build();
205  HepPlanner prePlanner = new HepPlanner(program);
206  prePlanner.setRoot(root.rel);
207  final RelNode rootRelNode = prePlanner.findBestExp();
208  filterPushDownInfo.clear();
209  return root.withRel(rootRelNode);
210  }
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 181 of file MapDPlanner.java.

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

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

181  {
182  // TODO consider doing these rules in one preplan pass
183 
184  final InjectFilterRule injectFilterRule =
185  InjectFilterRule.Config.DEFAULT.toRule(restriction);
186 
187  final HepProgram program =
188  HepProgram.builder().addRuleInstance(injectFilterRule).build();
189  HepPlanner prePlanner = new HepPlanner(program);
190  prePlanner.setRoot(root.rel);
191  final RelNode rootRelNode = prePlanner.findBestExp();
192  return root.withRel(rootRelNode);
193  }

+ Here is the caller graph for this function:

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

Definition at line 212 of file MapDPlanner.java.

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

212  {
213  QueryOptimizationRules outerJoinOptRule =
214  new OuterJoinOptViaNullRejectionRule(RelFactories.LOGICAL_BUILDER);
215 
216  HepProgram opt_program =
217  HepProgram.builder().addRuleInstance(outerJoinOptRule).build();
218  HepPlanner prePlanner = new HepPlanner(
219  opt_program, null, true, Functions.ignore2(), RelOptCostImpl.FACTORY);
220  prePlanner.setRoot(root.rel);
221  final RelNode rootRelNode = prePlanner.findBestExp();
222  return root.withRel(rootRelNode);
223  }

+ Here is the caller graph for this function:

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

Definition at line 103 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().

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

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

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

+ Here is the call graph for this function:

RelRoot org.apache.calcite.prepare.MapDPlanner.optimizeRaQuery ( String  query,
MapDSchema  schema 
) throws IOException
inline

Definition at line 225 of file MapDPlanner.java.

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

225  {
226  ready();
227  RexBuilder builder = new RexBuilder(getTypeFactory());
228  RelOptCluster cluster = RelOptCluster.create(new VolcanoPlanner(), builder);
229  CalciteCatalogReader catalogReader = createCatalogReader();
230  MapDRelJsonReader reader = new MapDRelJsonReader(cluster, catalogReader, schema);
231 
232  RelRoot relR = RelRoot.of(reader.read(query), SqlKind.SELECT);
234  applyFilterPushdown(relR);
235 
236  HepProgramBuilder hepBuilder = new HepProgramBuilder();
237  hepBuilder.addRuleInstance(CoreRules.JOIN_PROJECT_BOTH_TRANSPOSE_INCLUDE_OUTER);
238  hepBuilder.addRuleInstance(CoreRules.FILTER_MERGE);
239  hepBuilder.addRuleInstance(CoreRules.FILTER_PROJECT_TRANSPOSE);
240  hepBuilder.addRuleInstance(CoreRules.PROJECT_MERGE);
241  hepBuilder.addRuleInstance(ProjectProjectRemoveRule.INSTANCE);
242 
243  HepPlanner hepPlanner = new HepPlanner(hepBuilder.build());
244  final RelNode root = relR.project();
245  hepPlanner.setRoot(root);
246  final RelNode newRel = hepPlanner.findBestExp();
247 
248  return RelRoot.of(newRel, relR.kind);
249  }
RelRoot applyQueryOptimizationRules(RelRoot root)
CalciteCatalogReader createCatalogReader()
RelRoot applyFilterPushdown(RelRoot root)

+ Here is the call graph for this function:

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

Definition at line 132 of file MapDPlanner.java.

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

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

+ Here is the caller graph for this function:

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

Definition at line 171 of file MapDPlanner.java.

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

171  {
172  RelRoot root = super.rel(sql);
173  if (restriction != null) {
174  root = applyInjectFilterRule(root, restriction);
175  }
176  root = applyQueryOptimizationRules(root);
177  root = applyFilterPushdown(root);
178  return root;
179  }
RelRoot applyQueryOptimizationRules(RelRoot root)
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 84 of file MapDPlanner.java.

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

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

+ Here is the caller graph for this function:

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

Definition at line 251 of file MapDPlanner.java.

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

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

Definition at line 256 of file MapDPlanner.java.

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

256  {
257  this.restriction = restriction;
258  }

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 77 of file MapDPlanner.java.


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