OmniSciDB  ba1bac9284
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
org.apache.calcite.sql2rel.SqlToRelConverter.Blackboard Class Reference
+ Inheritance diagram for org.apache.calcite.sql2rel.SqlToRelConverter.Blackboard:
+ Collaboration diagram for org.apache.calcite.sql2rel.SqlToRelConverter.Blackboard:

Public Member Functions

SqlNode getTopNode ()
 
void setPatternVarRef (boolean isVarRef)
 
RexNode register (RelNode rel, JoinRelType joinType)
 
RexNode register (RelNode rel, JoinRelType joinType, List< RexNode > leftKeys)
 
void setRoot (RelNode root, boolean leaf)
 
void setDataset (String datasetName)
 

Public Attributes

final SqlValidatorScope scope
 
RelNode root
 

Protected Member Functions

 Blackboard (SqlValidatorScope scope, Map< String, RexNode > nameToNodeMap, boolean top)
 

Package Functions

void setRoot (List< RelNode > inputs)
 
Pair< RexNode, Map< String,
Integer > > 
lookupExp (SqlQualified qualified)
 

Package Attributes

final List< RelNode > cursors = new ArrayList<>()
 
AggConverter agg
 
SqlWindow window
 
final boolean top
 

Private Member Functions

void setRoot (List< RelNode > inputs, RelNode root, boolean hasSystemFields)
 

Private Attributes

final Map< String, RexNode > nameToNodeMap
 
List< RelNode > inputs
 
final Map< CorrelationId,
RexFieldAccess > 
mapCorrelateToRex = new HashMap<>()
 
boolean isPatternVarRef = false
 
final List< SubQuery > subQueryList = new ArrayList<>()
 
final Map< RelNode, Map
< Integer, Integer > > 
mapRootRelToFieldProjection
 
final List< SqlMonotonicity > columnMonotonicities = new ArrayList<>()
 
final List< RelDataTypeField > systemFieldList = new ArrayList<>()
 
final InitializerExpressionFactory initializerExpressionFactory
 

Detailed Description

Workspace for translating an individual SELECT statement (or sub-SELECT).

Definition at line 4106 of file SqlToRelConverter.java.

Constructor & Destructor Documentation

org.apache.calcite.sql2rel.SqlToRelConverter.Blackboard.Blackboard ( SqlValidatorScope  scope,
Map< String, RexNode >  nameToNodeMap,
boolean  top 
)
inlineprotected

Creates a Blackboard.

Parameters
scopeName-resolution scope for expressions validated within this query. Can be null if this Blackboard is for a leaf node, say
nameToNodeMapMap which translates the expression to map a given parameter into, if translating expressions; null otherwise
topWhether this is the root of the query

Definition at line 4165 of file SqlToRelConverter.java.

4166  {
4167  this.scope = scope;
4168  this.nameToNodeMap = nameToNodeMap;
4169  this.top = top;
4170  }

Member Function Documentation

SqlNode org.apache.calcite.sql2rel.SqlToRelConverter.Blackboard.getTopNode ( )
inline

Definition at line 4172 of file SqlToRelConverter.java.

Referenced by org.apache.calcite.sql2rel.SqlToRelConverter.substituteSubQuery().

4172  {
4173  try {
4174  if (null == scope) {
4175  return null;
4176  }
4177  return scope.getNode();
4178  } catch (Exception e) {
4179  return null;
4180  }
4181  }

+ Here is the caller graph for this function:

Pair<RexNode, Map<String, Integer> > org.apache.calcite.sql2rel.SqlToRelConverter.Blackboard.lookupExp ( SqlQualified  qualified)
inlinepackage

Returns an expression with which to reference a from-list item.

Parameters
qualifiedthe alias of the from item
Returns
a RexFieldAccess or RexRangeRef, or null if not found

Definition at line 4328 of file SqlToRelConverter.java.

References f, field(), i, and Integer.

4328  {
4329  if (nameToNodeMap != null && qualified.prefixLength == 1) {
4330  RexNode node = nameToNodeMap.get(qualified.identifier.names.get(0));
4331  if (node == null) {
4332  throw new AssertionError("Unknown identifier '" + qualified.identifier
4333  + "' encountered while expanding expression");
4334  }
4335  return Pair.of(node, null);
4336  }
4337  final SqlNameMatcher nameMatcher =
4338  scope.getValidator().getCatalogReader().nameMatcher();
4339  final SqlValidatorScope.ResolvedImpl resolved =
4340  new SqlValidatorScope.ResolvedImpl();
4341  scope.resolve(qualified.prefix(), nameMatcher, false, resolved);
4342  if (!(resolved.count() == 1)) {
4343  return null;
4344  }
4345  final SqlValidatorScope.Resolve resolve = resolved.only();
4346  final RelDataType rowType = resolve.rowType();
4347 
4348  // Found in current query's from list. Find which from item.
4349  // We assume that the order of the from clause items has been
4350  // preserved.
4351  final SqlValidatorScope ancestorScope = resolve.scope;
4352  boolean isParent = ancestorScope != scope;
4353  if ((inputs != null) && !isParent) {
4354  final LookupContext rels =
4355  new LookupContext(this, inputs, systemFieldList.size());
4356  final RexNode node = lookup(resolve.path.steps().get(0).i, rels);
4357  if (node == null) {
4358  return null;
4359  } else {
4360  final Map<String, Integer> fieldOffsets = new HashMap<>();
4361  for (RelDataTypeField f : resolve.rowType().getFieldList()) {
4362  if (!fieldOffsets.containsKey(f.getName())) {
4363  fieldOffsets.put(f.getName(), f.getIndex());
4364  }
4365  }
4366  final Map<String, Integer> map = ImmutableMap.copyOf(fieldOffsets);
4367  return Pair.of(node, map);
4368  }
4369  } else {
4370  // We're referencing a relational expression which has not been
4371  // converted yet. This occurs when from items are correlated,
4372  // e.g. "select from emp as emp join emp.getDepts() as dept".
4373  // Create a temporary expression.
4374  DeferredLookup lookup =
4375  new DeferredLookup(this, qualified.identifier.names.get(0));
4376  final CorrelationId correlId = cluster.createCorrel();
4377  mapCorrelToDeferred.put(correlId, lookup);
4378  if (resolve.path.steps().get(0).i < 0) {
4379  return Pair.of(rexBuilder.makeCorrel(rowType, correlId), null);
4380  } else {
4381  final RelDataTypeFactory.Builder builder = typeFactory.builder();
4382  final ListScope ancestorScope1 = (ListScope) resolve.scope;
4383  final ImmutableMap.Builder<String, Integer> fields = ImmutableMap.builder();
4384  int i = 0;
4385  int offset = 0;
4386  for (SqlValidatorNamespace c : ancestorScope1.getChildren()) {
4387  builder.addAll(c.getRowType().getFieldList());
4388  if (i == resolve.path.steps().get(0).i) {
4389  for (RelDataTypeField field : c.getRowType().getFieldList()) {
4390  fields.put(field.getName(), field.getIndex() + offset);
4391  }
4392  }
4393  ++i;
4394  offset += c.getRowType().getFieldCount();
4395  }
4396  final RexNode c = rexBuilder.makeCorrel(builder.uniquify().build(), correlId);
4397  return Pair.of(c, fields.build());
4398  }
4399  }
4400  }
const rapidjson::Value & field(const rapidjson::Value &obj, const char field[]) noexcept
Definition: JsonAccessors.h:31
char * f

+ Here is the call graph for this function:

RexNode org.apache.calcite.sql2rel.SqlToRelConverter.Blackboard.register ( RelNode  rel,
JoinRelType  joinType 
)
inline

Definition at line 4187 of file SqlToRelConverter.java.

4187  {
4188  return register(rel, joinType, null);
4189  }
RexNode org.apache.calcite.sql2rel.SqlToRelConverter.Blackboard.register ( RelNode  rel,
JoinRelType  joinType,
List< RexNode >  leftKeys 
)
inline

Registers a relational expression.

Parameters
relRelational expression
joinTypeJoin type
leftKeysLHS of IN clause, or null for expressions other than IN
Returns
Expression with which to refer to the row (or partial row) coming from this relational expression's side of the join

Definition at line 4200 of file SqlToRelConverter.java.

References i, join(), and setup.root.

4200  {
4201  assert joinType != null;
4202  if (root == null) {
4203  assert leftKeys == null;
4204  setRoot(rel, false);
4205  return rexBuilder.makeRangeReference(root.getRowType(), 0, false);
4206  }
4207 
4208  final RexNode joinCond;
4209  final int origLeftInputCount = root.getRowType().getFieldCount();
4210  if (leftKeys != null) {
4211  List<RexNode> newLeftInputExprs = new ArrayList<>();
4212  for (int i = 0; i < origLeftInputCount; i++) {
4213  newLeftInputExprs.add(rexBuilder.makeInputRef(root, i));
4214  }
4215 
4216  final List<Integer> leftJoinKeys = new ArrayList<>();
4217  for (RexNode leftKey : leftKeys) {
4218  int index = newLeftInputExprs.indexOf(leftKey);
4219  if (index < 0 || joinType == JoinRelType.LEFT) {
4220  index = newLeftInputExprs.size();
4221  newLeftInputExprs.add(leftKey);
4222  }
4223  leftJoinKeys.add(index);
4224  }
4225 
4226  RelNode newLeftInput = relBuilder.push(root).project(newLeftInputExprs).build();
4227 
4228  // maintain the group by mapping in the new LogicalProject
4229  if (mapRootRelToFieldProjection.containsKey(root)) {
4230  mapRootRelToFieldProjection.put(
4231  newLeftInput, mapRootRelToFieldProjection.get(root));
4232  }
4233 
4234  setRoot(newLeftInput, false);
4235 
4236  // right fields appear after the LHS fields.
4237  final int rightOffset = root.getRowType().getFieldCount()
4238  - newLeftInput.getRowType().getFieldCount();
4239  final List<Integer> rightKeys =
4240  Util.range(rightOffset, rightOffset + leftKeys.size());
4241 
4242  joinCond = RelOptUtil.createEquiJoinCondition(
4243  newLeftInput, leftJoinKeys, rel, rightKeys, rexBuilder);
4244  } else {
4245  joinCond = rexBuilder.makeLiteral(true);
4246  }
4247 
4248  int leftFieldCount = root.getRowType().getFieldCount();
4249  final RelNode join = createJoin(this, root, rel, joinCond, joinType);
4250 
4251  setRoot(join, false);
4252 
4253  if (leftKeys != null && joinType == JoinRelType.LEFT) {
4254  final int leftKeyCount = leftKeys.size();
4255  int rightFieldLength = rel.getRowType().getFieldCount();
4256  assert leftKeyCount == rightFieldLength - 1;
4257 
4258  final int rexRangeRefLength = leftKeyCount + rightFieldLength;
4259  RelDataType returnType = typeFactory.createStructType(
4260  new AbstractList<Map.Entry<String, RelDataType>>() {
4261  public Map.Entry<String, RelDataType> get(int index) {
4262  return join.getRowType().getFieldList().get(
4263  origLeftInputCount + index);
4264  }
4265 
4266  public int size() {
4267  return rexRangeRefLength;
4268  }
4269  });
4270 
4271  return rexBuilder.makeRangeReference(returnType, origLeftInputCount, false);
4272  } else {
4273  return rexBuilder.makeRangeReference(
4274  rel.getRowType(), leftFieldCount, joinType.generatesNullsOnRight());
4275  }
4276  }
std::string join(T const &container, std::string const &delim)
RelNode createJoin(Blackboard bb, RelNode leftRel, RelNode rightRel, RexNode joinCond, JoinRelType joinType)
final Map< RelNode, Map< Integer, Integer > > mapRootRelToFieldProjection

+ Here is the call graph for this function:

void org.apache.calcite.sql2rel.SqlToRelConverter.Blackboard.setDataset ( String  datasetName)
inline

Notifies this Blackboard that the root just set using setRoot(RelNode, boolean) was derived using dataset substitution.

The default implementation is not interested in such notifications, and does nothing.

Parameters
datasetNameDataset name

Definition at line 4316 of file SqlToRelConverter.java.

4316 {}
void org.apache.calcite.sql2rel.SqlToRelConverter.Blackboard.setPatternVarRef ( boolean  isVarRef)
inline

Definition at line 4183 of file SqlToRelConverter.java.

4183  {
4184  this.isPatternVarRef = isVarRef;
4185  }
void org.apache.calcite.sql2rel.SqlToRelConverter.Blackboard.setRoot ( RelNode  root,
boolean  leaf 
)
inline

Sets a new root relational expression, as the translation process backs its way further up the tree.

Parameters
rootNew root relational expression
leafWhether the relational expression is a leaf, that is, derived from an atomic relational expression such as a table name in the from clause, or the projection on top of a select-sub-query. In particular, relational expressions derived from JOIN operators are not leaves, but set expressions are.

Definition at line 4289 of file SqlToRelConverter.java.

References setup.root.

4289  {
4290  setRoot(Collections.singletonList(root), root, root instanceof LogicalJoin);
4291  if (leaf) {
4292  leaves.put(root, root.getRowType().getFieldCount());
4293  }
4294  this.columnMonotonicities.clear();
4295  }
void org.apache.calcite.sql2rel.SqlToRelConverter.Blackboard.setRoot ( List< RelNode >  inputs,
RelNode  root,
boolean  hasSystemFields 
)
inlineprivate

Definition at line 4297 of file SqlToRelConverter.java.

References setup.root.

4297  {
4298  this.inputs = inputs;
4299  this.root = root;
4300  this.systemFieldList.clear();
4301  if (hasSystemFields) {
4302  this.systemFieldList.addAll(getSystemFields());
4303  }
4304  }
void org.apache.calcite.sql2rel.SqlToRelConverter.Blackboard.setRoot ( List< RelNode >  inputs)
inlinepackage

Definition at line 4318 of file SqlToRelConverter.java.

4318  {
4319  setRoot(inputs, null, false);
4320  }

Member Data Documentation

AggConverter org.apache.calcite.sql2rel.SqlToRelConverter.Blackboard.agg
package

Workspace for building aggregates.

Definition at line 4130 of file SqlToRelConverter.java.

final List<SqlMonotonicity> org.apache.calcite.sql2rel.SqlToRelConverter.Blackboard.columnMonotonicities = new ArrayList<>()
private

Definition at line 4146 of file SqlToRelConverter.java.

final List<RelNode> org.apache.calcite.sql2rel.SqlToRelConverter.Blackboard.cursors = new ArrayList<>()
package

Definition at line 4119 of file SqlToRelConverter.java.

final InitializerExpressionFactory org.apache.calcite.sql2rel.SqlToRelConverter.Blackboard.initializerExpressionFactory
private
Initial value:
=
new NullInitializerExpressionFactory()

Definition at line 4151 of file SqlToRelConverter.java.

List<RelNode> org.apache.calcite.sql2rel.SqlToRelConverter.Blackboard.inputs
private

Definition at line 4114 of file SqlToRelConverter.java.

boolean org.apache.calcite.sql2rel.SqlToRelConverter.Blackboard.isPatternVarRef = false
private
final Map<CorrelationId, RexFieldAccess> org.apache.calcite.sql2rel.SqlToRelConverter.Blackboard.mapCorrelateToRex = new HashMap<>()
private

Definition at line 4115 of file SqlToRelConverter.java.

final Map<RelNode, Map<Integer, Integer> > org.apache.calcite.sql2rel.SqlToRelConverter.Blackboard.mapRootRelToFieldProjection
private
Initial value:
=
new HashMap<>()

Project the groupby expressions out of the root of this sub-select. Sub-queries can reference group by expressions projected from the "right" to the sub-query.

Definition at line 4143 of file SqlToRelConverter.java.

Referenced by org.apache.calcite.sql2rel.SqlToRelConverter.getCorrelationUse().

final Map<String, RexNode> org.apache.calcite.sql2rel.SqlToRelConverter.Blackboard.nameToNodeMap
private

Definition at line 4112 of file SqlToRelConverter.java.

final List<SubQuery> org.apache.calcite.sql2rel.SqlToRelConverter.Blackboard.subQueryList = new ArrayList<>()
private

List of IN and EXISTS nodes inside this SELECT statement (but not inside sub-queries).

Definition at line 4125 of file SqlToRelConverter.java.

Referenced by org.apache.calcite.sql2rel.SqlToRelConverter.replaceSubQueries().

final List<RelDataTypeField> org.apache.calcite.sql2rel.SqlToRelConverter.Blackboard.systemFieldList = new ArrayList<>()
private

Definition at line 4148 of file SqlToRelConverter.java.

final boolean org.apache.calcite.sql2rel.SqlToRelConverter.Blackboard.top
package
SqlWindow org.apache.calcite.sql2rel.SqlToRelConverter.Blackboard.window
package

When converting window aggregate, we need to know if the window is guaranteed to be non-empty.

Definition at line 4136 of file SqlToRelConverter.java.


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