OmniSciDB  340b00dbf6
 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)
 

Package Attributes

FrameworkConfig config
 

Private Member Functions

CalciteCatalogReader createCatalogReader ()
 
RelRoot applyFilterPushdown (RelRoot root)
 
RelRoot applyQueryOptimizationRules (RelRoot root)
 

Static Private Member Functions

static SchemaPlus rootSchema (SchemaPlus schema)
 

Private Attributes

List
< MapDParserOptions.FilterPushDownInfo > 
filterPushDownInfo
 

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

Constructor & Destructor Documentation

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

Definition at line 84 of file MapDPlanner.java.

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

84  {
85  super(config);
86  this.config = config;
87  }

Member Function Documentation

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

Definition at line 128 of file MapDPlanner.java.

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

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

183  {
184  if (filterPushDownInfo.isEmpty()) {
185  return root;
186  }
187  final DynamicFilterJoinRule dynamicFilterJoinRule = new DynamicFilterJoinRule(true,
188  RelFactories.LOGICAL_BUILDER,
189  FilterJoinRule.TRUE_PREDICATE,
191  final HepProgram program =
192  HepProgram.builder().addRuleInstance(dynamicFilterJoinRule).build();
193  HepPlanner prePlanner = new HepPlanner(program);
194  prePlanner.setRoot(root.rel);
195  final RelNode rootRelNode = prePlanner.findBestExp();
196  filterPushDownInfo.clear();
197  return root.withRel(rootRelNode);
198  }
List< MapDParserOptions.FilterPushDownInfo > filterPushDownInfo

+ Here is the caller graph for this function:

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

Definition at line 200 of file MapDPlanner.java.

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

200  {
201  QueryOptimizationRules outerJoinOptRule =
202  new OuterJoinOptViaNullRejectionRule(RelFactories.LOGICAL_BUILDER);
203 
204  HepProgram opt_program =
205  HepProgram.builder().addRuleInstance(outerJoinOptRule).build();
206  HepPlanner prePlanner = new HepPlanner(
207  opt_program, null, true, Functions.ignore2(), RelOptCostImpl.FACTORY);
208  prePlanner.setRoot(root.rel);
209  final RelNode rootRelNode = prePlanner.findBestExp();
210  return root.withRel(rootRelNode);
211  }

+ Here is the caller graph for this function:

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

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

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

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

156  {
157  ready();
158 
159  SqlValidator.Config validatorConfig = SqlValidator.Config.DEFAULT;
160  validatorConfig = validatorConfig.withSqlConformance(SqlConformanceEnum.LENIENT);
161 
162  MapDSqlAdvisorValidator advisor_validator = new MapDSqlAdvisorValidator(visibleTables,
163  config.getOperatorTable(),
165  getTypeFactory(),
166  validatorConfig);
167  SqlAdvisor advisor = new MapDSqlAdvisor(advisor_validator);
168  String[] replaced = new String[1];
169  int adjusted_cursor = cursor < 0 ? sql.length() : cursor;
170  java.util.List<SqlMoniker> hints =
171  advisor.getCompletionHints(sql, adjusted_cursor, replaced);
172  return new CompletionResult(hints, replaced[0]);
173  }
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 213 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().

213  {
214  ready();
215  RexBuilder builder = new RexBuilder(getTypeFactory());
216  RelOptCluster cluster = RelOptCluster.create(new VolcanoPlanner(), builder);
217  CalciteCatalogReader catalogReader = createCatalogReader();
218  MapDRelJsonReader reader = new MapDRelJsonReader(cluster, catalogReader, schema);
219 
220  RelRoot relR = RelRoot.of(reader.read(query), SqlKind.SELECT);
222  applyFilterPushdown(relR);
223 
224  ProjectMergeRule projectMergeRule =
225  new ProjectMergeRule(true, RelFactories.LOGICAL_BUILDER);
226  final Program program =
227  Programs.hep(ImmutableList.of(FilterProjectTransposeRule.INSTANCE,
228  projectMergeRule,
230  FilterMergeRule.INSTANCE),
231  true,
232  DefaultRelMetadataProvider.INSTANCE);
233  RelNode oldRel;
234  RelNode newRel = relR.project();
235 
236  do {
237  oldRel = newRel;
238  newRel = program.run(null,
239  oldRel,
240  null,
241  ImmutableList.<RelOptMaterialization>of(),
242  ImmutableList.<RelOptLattice>of());
243  // there must be a better way to compare these
244  } while (!RelOptUtil.toString(oldRel).equals(RelOptUtil.toString(newRel)));
245 
246  return RelRoot.of(newRel, relR.kind);
247  }
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 137 of file MapDPlanner.java.

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

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

+ Here is the caller graph for this function:

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

Definition at line 176 of file MapDPlanner.java.

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

176  {
177  RelRoot root = super.rel(sql);
178  root = applyQueryOptimizationRules(root);
179  root = applyFilterPushdown(root);
180  return root;
181  }
RelRoot applyQueryOptimizationRules(RelRoot root)
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 89 of file MapDPlanner.java.

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

89  {
90  for (;;) {
91  if (schema.getParentSchema() == null) {
92  return schema;
93  }
94  schema = schema.getParentSchema();
95  }
96  }

+ Here is the caller graph for this function:

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

Definition at line 249 of file MapDPlanner.java.

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

250  {
251  this.filterPushDownInfo = filterPushDownInfo;
252  }
List< MapDParserOptions.FilterPushDownInfo > filterPushDownInfo

Member Data Documentation

List<MapDParserOptions.FilterPushDownInfo> org.apache.calcite.prepare.MapDPlanner.filterPushDownInfo
private

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