OmniSciDB  72180abbfe
 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 4101 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 4160 of file SqlToRelConverter.java.

4161  {
4162  this.scope = scope;
4163  this.nameToNodeMap = nameToNodeMap;
4164  this.top = top;
4165  }

Member Function Documentation

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

Definition at line 4167 of file SqlToRelConverter.java.

Referenced by org.apache.calcite.sql2rel.SqlToRelConverter.createJoin(), and org.apache.calcite.sql2rel.SqlToRelConverter.substituteSubQuery().

4167  {
4168  try {
4169  if (null == scope) {
4170  return null;
4171  }
4172  return scope.getNode();
4173  } catch (Exception e) {
4174  return null;
4175  }
4176  }

+ 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 4323 of file SqlToRelConverter.java.

References field().

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

+ Here is the call graph for this function:

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

Definition at line 4182 of file SqlToRelConverter.java.

4182  {
4183  return register(rel, joinType, null);
4184  }
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 4195 of file SqlToRelConverter.java.

References assert(), and join().

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

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

Definition at line 4178 of file SqlToRelConverter.java.

4178  {
4179  this.isPatternVarRef = isVarRef;
4180  }
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 4284 of file SqlToRelConverter.java.

4284  {
4285  setRoot(Collections.singletonList(root), root, root instanceof LogicalJoin);
4286  if (leaf) {
4287  leaves.put(root, root.getRowType().getFieldCount());
4288  }
4289  this.columnMonotonicities.clear();
4290  }
void org.apache.calcite.sql2rel.SqlToRelConverter.Blackboard.setRoot ( List< RelNode >  inputs,
RelNode  root,
boolean  hasSystemFields 
)
inlineprivate

Definition at line 4292 of file SqlToRelConverter.java.

4292  {
4293  this.inputs = inputs;
4294  this.root = root;
4295  this.systemFieldList.clear();
4296  if (hasSystemFields) {
4297  this.systemFieldList.addAll(getSystemFields());
4298  }
4299  }
void org.apache.calcite.sql2rel.SqlToRelConverter.Blackboard.setRoot ( List< RelNode >  inputs)
inlinepackage

Definition at line 4313 of file SqlToRelConverter.java.

4313  {
4314  setRoot(inputs, null, false);
4315  }

Member Data Documentation

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

Workspace for building aggregates.

Definition at line 4125 of file SqlToRelConverter.java.

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

Definition at line 4141 of file SqlToRelConverter.java.

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

Definition at line 4114 of file SqlToRelConverter.java.

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

Definition at line 4146 of file SqlToRelConverter.java.

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

Definition at line 4109 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 4110 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 4138 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 4107 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 4120 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 4143 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 4131 of file SqlToRelConverter.java.


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