OmniSciDB  cde582ebc3
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups 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 4111 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 4170 of file SqlToRelConverter.java.

4171  {
4172  this.scope = scope;
4173  this.nameToNodeMap = nameToNodeMap;
4174  this.top = top;
4175  }

Member Function Documentation

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

Definition at line 4177 of file SqlToRelConverter.java.

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

4177  {
4178  try {
4179  if (null == scope) {
4180  return null;
4181  }
4182  return scope.getNode();
4183  } catch (Exception e) {
4184  return null;
4185  }
4186  }

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

References anonymous_namespace{Utm.h}.f, field(), and Integer.

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

4192  {
4193  return register(rel, joinType, null);
4194  }
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 4205 of file SqlToRelConverter.java.

References join(), and setup.root.

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

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

Definition at line 4188 of file SqlToRelConverter.java.

4188  {
4189  this.isPatternVarRef = isVarRef;
4190  }
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 4294 of file SqlToRelConverter.java.

References setup.root.

4294  {
4295  setRoot(Collections.singletonList(root), root, root instanceof LogicalJoin);
4296  if (leaf) {
4297  leaves.put(root, root.getRowType().getFieldCount());
4298  }
4299  this.columnMonotonicities.clear();
4300  }
void org.apache.calcite.sql2rel.SqlToRelConverter.Blackboard.setRoot ( List< RelNode >  inputs,
RelNode  root,
boolean  hasSystemFields 
)
inlineprivate

Definition at line 4302 of file SqlToRelConverter.java.

References setup.root.

4302  {
4303  this.inputs = inputs;
4304  this.root = root;
4305  this.systemFieldList.clear();
4306  if (hasSystemFields) {
4307  this.systemFieldList.addAll(getSystemFields());
4308  }
4309  }
void org.apache.calcite.sql2rel.SqlToRelConverter.Blackboard.setRoot ( List< RelNode >  inputs)
inlinepackage

Definition at line 4323 of file SqlToRelConverter.java.

4323  {
4324  setRoot(inputs, null, false);
4325  }

Member Data Documentation

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

Workspace for building aggregates.

Definition at line 4135 of file SqlToRelConverter.java.

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

Definition at line 4151 of file SqlToRelConverter.java.

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

Definition at line 4124 of file SqlToRelConverter.java.

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

Definition at line 4156 of file SqlToRelConverter.java.

List<RelNode> org.apache.calcite.sql2rel.SqlToRelConverter.Blackboard.inputs
private
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 4120 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 4148 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 4117 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 4130 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 4153 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 4141 of file SqlToRelConverter.java.


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