OmniSciDB  b24e664e58
 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)
 
void flatten (List< RelNode > rels, int systemFieldCount, int[] start, List< Pair< RelNode, Integer >> relOffsetList)
 
RexNode convertExpression (SqlNode expr)
 
RexFieldCollation convertSortExpression (SqlNode expr, RelFieldCollation.Direction direction, RelFieldCollation.NullDirection nullDirection)
 
int getGroupCount ()
 
RexBuilder getRexBuilder ()
 
RexRangeRef getSubQueryExpr (SqlCall call)
 
RelDataTypeFactory getTypeFactory ()
 
InitializerExpressionFactory getInitializerExpressionFactory ()
 
SqlValidator getValidator ()
 
RexNode convertLiteral (SqlLiteral literal)
 
RexNode convertInterval (SqlIntervalQualifier intervalQualifier)
 
RexNode visit (SqlLiteral literal)
 
RexNode visit (SqlCall call)
 
RexNode visit (SqlNodeList nodeList)
 
RexNode visit (SqlIdentifier id)
 
RexNode visit (SqlDataTypeSpec type)
 
RexNode visit (SqlDynamicParam param)
 
RexNode visit (SqlIntervalQualifier intervalQualifier)
 
List< SqlMonotonicity > getColumnMonotonicities ()
 

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)
 
RexNode lookup (int offset, LookupContext lookupContext)
 
RelDataTypeField getRootField (RexInputRef inputRef)
 
void registerSubQuery (SqlNode node, RelOptUtil.Logic logic)
 
SubQuery getSubQuery (SqlNode expr)
 
ImmutableList< RelNode > retrieveCursors ()
 

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)
 
boolean isConvertedSubq (RexNode rex)
 

Private Attributes

final Map< String, RexNode > nameToNodeMap
 
List< RelNode > inputs
 
final Map< CorrelationId,
RexFieldAccess > 
mapCorrelateToRex = new HashMap<>()
 
boolean isPatternVarRef = false
 
final Set< SubQuerysubQueryList = new LinkedHashSet<>()
 
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 3880 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 3939 of file SqlToRelConverter.java.

3940  {
3941  this.scope = scope;
3942  this.nameToNodeMap = nameToNodeMap;
3943  this.top = top;
3944  }

Member Function Documentation

RexNode org.apache.calcite.sql2rel.SqlToRelConverter.Blackboard.convertExpression ( SqlNode  expr)
inline

Definition at line 4249 of file SqlToRelConverter.java.

References assert().

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

4249  {
4250  // If we're in aggregation mode and this is an expression in the
4251  // GROUP BY clause, return a reference to the field.
4252  if (agg != null) {
4253  final SqlNode expandedGroupExpr = validator.expand(expr, scope);
4254  final int ref = agg.lookupGroupExpr(expandedGroupExpr);
4255  if (ref >= 0) {
4256  return rexBuilder.makeInputRef(root, ref);
4257  }
4258  if (expr instanceof SqlCall) {
4259  final RexNode rex = agg.lookupAggregates((SqlCall) expr);
4260  if (rex != null) {
4261  return rex;
4262  }
4263  }
4264  }
4265 
4266  // Allow the derived class chance to override the standard
4267  // behavior for special kinds of expressions.
4268  RexNode rex = convertExtendedExpression(expr, this);
4269  if (rex != null) {
4270  return rex;
4271  }
4272 
4273  // Sub-queries and OVER expressions are not like ordinary
4274  // expressions.
4275  final SqlKind kind = expr.getKind();
4276  final SubQuery subQuery;
4277 
4278  boolean isExpand = config.getExpandPredicate().test(getTopNode(), expr);
4279  if (!isExpand) {
4280  final SqlCall call;
4281  final SqlNode query;
4282  final RelRoot root;
4283  switch (kind) {
4284  case IN:
4285  case NOT_IN:
4286  case SOME:
4287  case ALL:
4288  call = (SqlCall) expr;
4289  query = call.operand(1);
4290  if (!(query instanceof SqlNodeList)) {
4291  root = convertQueryRecursive(query, false, null);
4292  final SqlNode operand = call.operand(0);
4293  List<SqlNode> nodes;
4294  switch (operand.getKind()) {
4295  case ROW:
4296  nodes = ((SqlCall) operand).getOperandList();
4297  break;
4298  default:
4299  nodes = ImmutableList.of(operand);
4300  }
4301  final ImmutableList.Builder<RexNode> builder = ImmutableList.builder();
4302  for (SqlNode node : nodes) {
4303  builder.add(convertExpression(node));
4304  }
4305  final ImmutableList<RexNode> list = builder.build();
4306  switch (kind) {
4307  case IN:
4308  return RexSubQuery.in(root.rel, list);
4309  case NOT_IN:
4310  return rexBuilder.makeCall(
4311  SqlStdOperatorTable.NOT, RexSubQuery.in(root.rel, list));
4312  case SOME:
4313  return RexSubQuery.some(
4314  root.rel, list, (SqlQuantifyOperator) call.getOperator());
4315  case ALL:
4316  return rexBuilder.makeCall(SqlStdOperatorTable.NOT,
4317  RexSubQuery.some(root.rel,
4318  list,
4319  negate((SqlQuantifyOperator) call.getOperator())));
4320  default:
4321  throw new AssertionError(kind);
4322  }
4323  }
4324  break;
4325 
4326  case EXISTS:
4327  call = (SqlCall) expr;
4328  query = Iterables.getOnlyElement(call.getOperandList());
4329  root = convertQueryRecursive(query, false, null);
4330  RelNode rel = root.rel;
4331  while (rel instanceof Project
4332  || rel instanceof Sort && ((Sort) rel).fetch == null
4333  && ((Sort) rel).offset == null) {
4334  rel = ((SingleRel) rel).getInput();
4335  }
4336  return RexSubQuery.exists(rel);
4337 
4338  case SCALAR_QUERY:
4339  call = (SqlCall) expr;
4340  query = Iterables.getOnlyElement(call.getOperandList());
4341  root = convertQueryRecursive(query, false, null);
4342  return RexSubQuery.scalar(root.rel);
4343  }
4344  }
4345 
4346  switch (kind) {
4347  case SOME:
4348  case ALL:
4349  if (isExpand) {
4350  throw new RuntimeException(kind + " is only supported if expand = false");
4351  }
4352  // fall through
4353  case CURSOR:
4354  case IN:
4355  case NOT_IN:
4356  subQuery = Objects.requireNonNull(getSubQuery(expr));
4357  rex = Objects.requireNonNull(subQuery.expr);
4358  return StandardConvertletTable.castToValidatedType(
4359  expr, rex, validator, rexBuilder);
4360 
4361  case SELECT:
4362  case EXISTS:
4363  case SCALAR_QUERY:
4364  subQuery = getSubQuery(expr);
4365  assert subQuery != null;
4366  rex = subQuery.expr;
4367  assert rex != null : "rex != null";
4368 
4369  if (((kind == SqlKind.SCALAR_QUERY) || (kind == SqlKind.EXISTS))
4370  && isConvertedSubq(rex)) {
4371  // scalar sub-query or EXISTS has been converted to a
4372  // constant
4373  return rex;
4374  }
4375 
4376  // The indicator column is the last field of the sub-query.
4377  RexNode fieldAccess =
4378  rexBuilder.makeFieldAccess(rex, rex.getType().getFieldCount() - 1);
4379 
4380  // The indicator column will be nullable if it comes from
4381  // the null-generating side of the join. For EXISTS, add an
4382  // "IS TRUE" check so that the result is "BOOLEAN NOT NULL".
4383  if (fieldAccess.getType().isNullable() && kind == SqlKind.EXISTS) {
4384  fieldAccess =
4385  rexBuilder.makeCall(SqlStdOperatorTable.IS_NOT_NULL, fieldAccess);
4386  }
4387  return fieldAccess;
4388 
4389  case OVER:
4390  return convertOver(this, expr);
4391 
4392  default:
4393  // fall through
4394  }
4395 
4396  // Apply standard conversions.
4397  rex = expr.accept(this);
4398  return Objects.requireNonNull(rex);
4399  }
SqlQuantifyOperator negate(SqlQuantifyOperator operator)
RelRoot convertQueryRecursive(SqlNode query, boolean top, RelDataType targetRowType)
int64_t const int32_t sz assert(dest)
RexNode convertOver(Blackboard bb, SqlNode node)
RexNode convertExtendedExpression(SqlNode node, Blackboard bb)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

RexNode org.apache.calcite.sql2rel.SqlToRelConverter.Blackboard.convertInterval ( SqlIntervalQualifier  intervalQualifier)
inline

Definition at line 4512 of file SqlToRelConverter.java.

4512  {
4513  return exprConverter.convertInterval(this, intervalQualifier);
4514  }
RexNode org.apache.calcite.sql2rel.SqlToRelConverter.Blackboard.convertLiteral ( SqlLiteral  literal)
inline

Definition at line 4508 of file SqlToRelConverter.java.

4508  {
4509  return exprConverter.convertLiteral(this, literal);
4510  }
RexFieldCollation org.apache.calcite.sql2rel.SqlToRelConverter.Blackboard.convertSortExpression ( SqlNode  expr,
RelFieldCollation.Direction  direction,
RelFieldCollation.NullDirection  nullDirection 
)
inline

Converts an item in an ORDER BY clause inside a window (OVER) clause, extracting DESC, NULLS LAST and NULLS FIRST flags first.

Definition at line 4405 of file SqlToRelConverter.java.

References FIRST, and LAST.

4407  {
4408  switch (expr.getKind()) {
4409  case DESCENDING:
4410  return convertSortExpression(((SqlCall) expr).operand(0),
4411  RelFieldCollation.Direction.DESCENDING,
4412  nullDirection);
4413  case NULLS_LAST:
4414  return convertSortExpression(((SqlCall) expr).operand(0),
4415  direction,
4416  RelFieldCollation.NullDirection.LAST);
4417  case NULLS_FIRST:
4418  return convertSortExpression(((SqlCall) expr).operand(0),
4419  direction,
4420  RelFieldCollation.NullDirection.FIRST);
4421  default:
4422  final Set<SqlKind> flags = EnumSet.noneOf(SqlKind.class);
4423  switch (direction) {
4424  case DESCENDING:
4425  flags.add(SqlKind.DESCENDING);
4426  }
4427  switch (nullDirection) {
4428  case UNSPECIFIED:
4429  final RelFieldCollation.NullDirection nullDefaultDirection =
4430  validator.getDefaultNullCollation().last(desc(direction))
4431  ? RelFieldCollation.NullDirection.LAST
4432  : RelFieldCollation.NullDirection.FIRST;
4433  if (nullDefaultDirection != direction.defaultNullDirection()) {
4434  SqlKind nullDirectionSqlKind =
4435  validator.getDefaultNullCollation().last(desc(direction))
4436  ? SqlKind.NULLS_LAST
4437  : SqlKind.NULLS_FIRST;
4438  flags.add(nullDirectionSqlKind);
4439  }
4440  break;
4441  case FIRST:
4442  flags.add(SqlKind.NULLS_FIRST);
4443  break;
4444  case LAST:
4445  flags.add(SqlKind.NULLS_LAST);
4446  break;
4447  }
4448  return new RexFieldCollation(convertExpression(expr), flags);
4449  }
4450  }
RexFieldCollation convertSortExpression(SqlNode expr, RelFieldCollation.Direction direction, RelFieldCollation.NullDirection nullDirection)
static boolean desc(RelFieldCollation.Direction direction)
void org.apache.calcite.sql2rel.SqlToRelConverter.Blackboard.flatten ( List< RelNode >  rels,
int  systemFieldCount,
int[]  start,
List< Pair< RelNode, Integer >>  relOffsetList 
)
inline

Definition at line 4205 of file SqlToRelConverter.java.

4208  {
4209  for (RelNode rel : rels) {
4210  if (leaves.contains(rel) || rel instanceof LogicalMatch) {
4211  relOffsetList.add(Pair.of(rel, start[0]));
4212  start[0] += rel.getRowType().getFieldCount();
4213  } else {
4214  if (rel instanceof LogicalJoin || rel instanceof LogicalAggregate) {
4215  start[0] += systemFieldCount;
4216  }
4217  flatten(rel.getInputs(), systemFieldCount, start, relOffsetList);
4218  }
4219  }
4220  }
void flatten(List< RelNode > rels, int systemFieldCount, int[] start, List< Pair< RelNode, Integer >> relOffsetList)
List<SqlMonotonicity> org.apache.calcite.sql2rel.SqlToRelConverter.Blackboard.getColumnMonotonicities ( )
inline

Definition at line 4553 of file SqlToRelConverter.java.

4553  {
4554  return columnMonotonicities;
4555  }
int org.apache.calcite.sql2rel.SqlToRelConverter.Blackboard.getGroupCount ( )
inline

Definition at line 4476 of file SqlToRelConverter.java.

4476  {
4477  if (agg != null) {
4478  return agg.groupExprs.size();
4479  }
4480  if (window != null) {
4481  return window.isAlwaysNonEmpty() ? 1 : 0;
4482  }
4483  return -1;
4484  }
InitializerExpressionFactory org.apache.calcite.sql2rel.SqlToRelConverter.Blackboard.getInitializerExpressionFactory ( )
inline

Definition at line 4500 of file SqlToRelConverter.java.

4500  {
4502  }
final InitializerExpressionFactory initializerExpressionFactory
RexBuilder org.apache.calcite.sql2rel.SqlToRelConverter.Blackboard.getRexBuilder ( )
inline

Definition at line 4486 of file SqlToRelConverter.java.

4486  {
4487  return rexBuilder;
4488  }
RelDataTypeField org.apache.calcite.sql2rel.SqlToRelConverter.Blackboard.getRootField ( RexInputRef  inputRef)
inlinepackage

Definition at line 4185 of file SqlToRelConverter.java.

4185  {
4186  if (inputs == null) {
4187  return null;
4188  }
4189  int fieldOffset = inputRef.getIndex();
4190  for (RelNode input : inputs) {
4191  RelDataType rowType = input.getRowType();
4192  if (rowType == null) {
4193  // TODO: remove this once leastRestrictive
4194  // is correctly implemented
4195  return null;
4196  }
4197  if (fieldOffset < rowType.getFieldCount()) {
4198  return rowType.getFieldList().get(fieldOffset);
4199  }
4200  fieldOffset -= rowType.getFieldCount();
4201  }
4202  throw new AssertionError();
4203  }
SubQuery org.apache.calcite.sql2rel.SqlToRelConverter.Blackboard.getSubQuery ( SqlNode  expr)
inlinepackage

Definition at line 4231 of file SqlToRelConverter.java.

4231  {
4232  for (SubQuery subQuery : subQueryList) {
4233  if (expr.equalsDeep(subQuery.node, Litmus.IGNORE)) {
4234  return subQuery;
4235  }
4236  }
4237 
4238  return null;
4239  }
RexRangeRef org.apache.calcite.sql2rel.SqlToRelConverter.Blackboard.getSubQueryExpr ( SqlCall  call)
inline

Definition at line 4490 of file SqlToRelConverter.java.

References assert().

4490  {
4491  final SubQuery subQuery = getSubQuery(call);
4492  assert subQuery != null;
4493  return (RexRangeRef) subQuery.expr;
4494  }
int64_t const int32_t sz assert(dest)

+ Here is the call graph for this function:

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

Definition at line 3946 of file SqlToRelConverter.java.

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

3946  {
3947  try {
3948  if (null == scope) {
3949  return null;
3950  }
3951  return scope.getNode();
3952  } catch (Exception e) {
3953  return null;
3954  }
3955  }

+ Here is the caller graph for this function:

RelDataTypeFactory org.apache.calcite.sql2rel.SqlToRelConverter.Blackboard.getTypeFactory ( )
inline

Definition at line 4496 of file SqlToRelConverter.java.

4496  {
4497  return typeFactory;
4498  }
SqlValidator org.apache.calcite.sql2rel.SqlToRelConverter.Blackboard.getValidator ( )
inline

Definition at line 4504 of file SqlToRelConverter.java.

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

4504  {
4505  return validator;
4506  }

+ Here is the caller graph for this function:

boolean org.apache.calcite.sql2rel.SqlToRelConverter.Blackboard.isConvertedSubq ( RexNode  rex)
inlineprivate

Determines whether a RexNode corresponds to a sub-query that's been converted to a constant.

Parameters
rexthe expression to be examined
Returns
true if the expression is a dynamic parameter, a literal, or a literal that is being cast

Definition at line 4460 of file SqlToRelConverter.java.

4460  {
4461  if ((rex instanceof RexLiteral) || (rex instanceof RexDynamicParam)) {
4462  return true;
4463  }
4464  if (rex instanceof RexCall) {
4465  RexCall call = (RexCall) rex;
4466  if (call.getOperator() == SqlStdOperatorTable.CAST) {
4467  RexNode operand = call.getOperands().get(0);
4468  if (operand instanceof RexLiteral) {
4469  return true;
4470  }
4471  }
4472  }
4473  return false;
4474  }
RexNode org.apache.calcite.sql2rel.SqlToRelConverter.Blackboard.lookup ( int  offset,
LookupContext  lookupContext 
)
inlinepackage

Creates an expression with which to reference the expression whose offset in its from-list is

offset

.

Definition at line 4180 of file SqlToRelConverter.java.

4180  {
4181  Pair<RelNode, Integer> pair = lookupContext.findRel(offset);
4182  return rexBuilder.makeRangeReference(pair.left.getRowType(), pair.right, false);
4183  }
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 4102 of file SqlToRelConverter.java.

References field(), Integer, and Experimental.String.

4102  {
4103  if (nameToNodeMap != null && qualified.prefixLength == 1) {
4104  RexNode node = nameToNodeMap.get(qualified.identifier.names.get(0));
4105  if (node == null) {
4106  throw new AssertionError("Unknown identifier '" + qualified.identifier
4107  + "' encountered while expanding expression");
4108  }
4109  return Pair.of(node, null);
4110  }
4111  final SqlNameMatcher nameMatcher =
4112  scope.getValidator().getCatalogReader().nameMatcher();
4113  final SqlValidatorScope.ResolvedImpl resolved =
4114  new SqlValidatorScope.ResolvedImpl();
4115  scope.resolve(qualified.prefix(), nameMatcher, false, resolved);
4116  if (!(resolved.count() == 1)) {
4117  return null;
4118  }
4119  final SqlValidatorScope.Resolve resolve = resolved.only();
4120  final RelDataType rowType = resolve.rowType();
4121 
4122  // Found in current query's from list. Find which from item.
4123  // We assume that the order of the from clause items has been
4124  // preserved.
4125  final SqlValidatorScope ancestorScope = resolve.scope;
4126  boolean isParent = ancestorScope != scope;
4127  if ((inputs != null) && !isParent) {
4128  final LookupContext rels =
4129  new LookupContext(this, inputs, systemFieldList.size());
4130  final RexNode node = lookup(resolve.path.steps().get(0).i, rels);
4131  if (node == null) {
4132  return null;
4133  } else {
4134  final Map<String, Integer> fieldOffsets = new HashMap<>();
4135  for (RelDataTypeField f : resolve.rowType().getFieldList()) {
4136  if (!fieldOffsets.containsKey(f.getName())) {
4137  fieldOffsets.put(f.getName(), f.getIndex());
4138  }
4139  }
4140  final Map<String, Integer> map = ImmutableMap.copyOf(fieldOffsets);
4141  return Pair.of(node, map);
4142  }
4143  } else {
4144  // We're referencing a relational expression which has not been
4145  // converted yet. This occurs when from items are correlated,
4146  // e.g. "select from emp as emp join emp.getDepts() as dept".
4147  // Create a temporary expression.
4148  DeferredLookup lookup =
4149  new DeferredLookup(this, qualified.identifier.names.get(0));
4150  final CorrelationId correlId = cluster.createCorrel();
4151  mapCorrelToDeferred.put(correlId, lookup);
4152  if (resolve.path.steps().get(0).i < 0) {
4153  return Pair.of(rexBuilder.makeCorrel(rowType, correlId), null);
4154  } else {
4155  final RelDataTypeFactory.Builder builder = typeFactory.builder();
4156  final ListScope ancestorScope1 = (ListScope) resolve.scope;
4157  final ImmutableMap.Builder<String, Integer> fields = ImmutableMap.builder();
4158  int i = 0;
4159  int offset = 0;
4160  for (SqlValidatorNamespace c : ancestorScope1.getChildren()) {
4161  builder.addAll(c.getRowType().getFieldList());
4162  if (i == resolve.path.steps().get(0).i) {
4163  for (RelDataTypeField field : c.getRowType().getFieldList()) {
4164  fields.put(field.getName(), field.getIndex() + offset);
4165  }
4166  }
4167  ++i;
4168  offset += c.getRowType().getFieldCount();
4169  }
4170  final RexNode c = rexBuilder.makeCorrel(builder.uniquify().build(), correlId);
4171  return Pair.of(c, fields.build());
4172  }
4173  }
4174  }
const rapidjson::Value & field(const rapidjson::Value &obj, const char field[]) noexcept
Definition: JsonAccessors.h:31
RexNode lookup(int offset, LookupContext lookupContext)

+ Here is the call graph for this function:

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

Definition at line 3961 of file SqlToRelConverter.java.

3961  {
3962  return register(rel, joinType, null);
3963  }
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 3974 of file SqlToRelConverter.java.

References assert(), join(), and Experimental.String.

3974  {
3975  assert joinType != null;
3976  if (root == null) {
3977  assert leftKeys == null;
3978  setRoot(rel, false);
3979  return rexBuilder.makeRangeReference(root.getRowType(), 0, false);
3980  }
3981 
3982  final RexNode joinCond;
3983  final int origLeftInputCount = root.getRowType().getFieldCount();
3984  if (leftKeys != null) {
3985  List<RexNode> newLeftInputExprs = new ArrayList<>();
3986  for (int i = 0; i < origLeftInputCount; i++) {
3987  newLeftInputExprs.add(rexBuilder.makeInputRef(root, i));
3988  }
3989 
3990  final List<Integer> leftJoinKeys = new ArrayList<>();
3991  for (RexNode leftKey : leftKeys) {
3992  int index = newLeftInputExprs.indexOf(leftKey);
3993  if (index < 0 || joinType == JoinRelType.LEFT) {
3994  index = newLeftInputExprs.size();
3995  newLeftInputExprs.add(leftKey);
3996  }
3997  leftJoinKeys.add(index);
3998  }
3999 
4000  RelNode newLeftInput = relBuilder.push(root).project(newLeftInputExprs).build();
4001 
4002  // maintain the group by mapping in the new LogicalProject
4003  if (mapRootRelToFieldProjection.containsKey(root)) {
4004  mapRootRelToFieldProjection.put(
4005  newLeftInput, mapRootRelToFieldProjection.get(root));
4006  }
4007 
4008  setRoot(newLeftInput, false);
4009 
4010  // right fields appear after the LHS fields.
4011  final int rightOffset = root.getRowType().getFieldCount()
4012  - newLeftInput.getRowType().getFieldCount();
4013  final List<Integer> rightKeys =
4014  Util.range(rightOffset, rightOffset + leftKeys.size());
4015 
4016  joinCond = RelOptUtil.createEquiJoinCondition(
4017  newLeftInput, leftJoinKeys, rel, rightKeys, rexBuilder);
4018  } else {
4019  joinCond = rexBuilder.makeLiteral(true);
4020  }
4021 
4022  int leftFieldCount = root.getRowType().getFieldCount();
4023  final RelNode join = createJoin(this, root, rel, joinCond, joinType);
4024 
4025  setRoot(join, false);
4026 
4027  if (leftKeys != null && joinType == JoinRelType.LEFT) {
4028  final int leftKeyCount = leftKeys.size();
4029  int rightFieldLength = rel.getRowType().getFieldCount();
4030  assert leftKeyCount == rightFieldLength - 1;
4031 
4032  final int rexRangeRefLength = leftKeyCount + rightFieldLength;
4033  RelDataType returnType = typeFactory.createStructType(
4034  new AbstractList<Map.Entry<String, RelDataType>>() {
4035  public Map.Entry<String, RelDataType> get(int index) {
4036  return join.getRowType().getFieldList().get(
4037  origLeftInputCount + index);
4038  }
4039 
4040  public int size() {
4041  return rexRangeRefLength;
4042  }
4043  });
4044 
4045  return rexBuilder.makeRangeReference(returnType, origLeftInputCount, false);
4046  } else {
4047  return rexBuilder.makeRangeReference(
4048  rel.getRowType(), leftFieldCount, joinType.generatesNullsOnRight());
4049  }
4050  }
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.registerSubQuery ( SqlNode  node,
RelOptUtil.Logic  logic 
)
inlinepackage

Definition at line 4222 of file SqlToRelConverter.java.

4222  {
4223  for (SubQuery subQuery : subQueryList) {
4224  if (node.equalsDeep(subQuery.node, Litmus.IGNORE)) {
4225  return;
4226  }
4227  }
4228  subQueryList.add(new SubQuery(node, logic));
4229  }
ImmutableList<RelNode> org.apache.calcite.sql2rel.SqlToRelConverter.Blackboard.retrieveCursors ( )
inlinepackage

Definition at line 4241 of file SqlToRelConverter.java.

4241  {
4242  try {
4243  return ImmutableList.copyOf(cursors);
4244  } finally {
4245  cursors.clear();
4246  }
4247  }
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 4090 of file SqlToRelConverter.java.

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

Definition at line 3957 of file SqlToRelConverter.java.

3957  {
3958  this.isPatternVarRef = isVarRef;
3959  }
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 4063 of file SqlToRelConverter.java.

4063  {
4064  setRoot(Collections.singletonList(root), root, root instanceof LogicalJoin);
4065  if (leaf) {
4066  leaves.add(root);
4067  }
4068  this.columnMonotonicities.clear();
4069  }
void org.apache.calcite.sql2rel.SqlToRelConverter.Blackboard.setRoot ( List< RelNode >  inputs,
RelNode  root,
boolean  hasSystemFields 
)
inlineprivate

Definition at line 4071 of file SqlToRelConverter.java.

4071  {
4072  this.inputs = inputs;
4073  this.root = root;
4074  this.systemFieldList.clear();
4075  if (hasSystemFields) {
4076  this.systemFieldList.addAll(getSystemFields());
4077  }
4078  }
void org.apache.calcite.sql2rel.SqlToRelConverter.Blackboard.setRoot ( List< RelNode >  inputs)
inlinepackage

Definition at line 4092 of file SqlToRelConverter.java.

4092  {
4093  setRoot(inputs, null, false);
4094  }
RexNode org.apache.calcite.sql2rel.SqlToRelConverter.Blackboard.visit ( SqlLiteral  literal)
inline

Definition at line 4516 of file SqlToRelConverter.java.

4516  {
4517  return exprConverter.convertLiteral(this, literal);
4518  }
RexNode org.apache.calcite.sql2rel.SqlToRelConverter.Blackboard.visit ( SqlCall  call)
inline

Definition at line 4520 of file SqlToRelConverter.java.

4520  {
4521  if (agg != null) {
4522  final SqlOperator op = call.getOperator();
4523  if (window == null
4524  && (op.isAggregator() || op.getKind() == SqlKind.FILTER
4525  || op.getKind() == SqlKind.WITHIN_GROUP)) {
4526  return agg.lookupAggregates(call);
4527  }
4528  }
4529  return exprConverter.convertCall(
4530  this, new SqlCallBinding(validator, scope, call).permutedCall());
4531  }
RexNode org.apache.calcite.sql2rel.SqlToRelConverter.Blackboard.visit ( SqlNodeList  nodeList)
inline

Definition at line 4533 of file SqlToRelConverter.java.

4533  {
4534  throw new UnsupportedOperationException();
4535  }
RexNode org.apache.calcite.sql2rel.SqlToRelConverter.Blackboard.visit ( SqlIdentifier  id)
inline

Definition at line 4537 of file SqlToRelConverter.java.

4537  {
4538  return convertIdentifier(this, id);
4539  }
void convertIdentifier(Blackboard bb, SqlIdentifier id, SqlNodeList extendedColumns)
RexNode org.apache.calcite.sql2rel.SqlToRelConverter.Blackboard.visit ( SqlDataTypeSpec  type)
inline

Definition at line 4541 of file SqlToRelConverter.java.

4541  {
4542  throw new UnsupportedOperationException();
4543  }
RexNode org.apache.calcite.sql2rel.SqlToRelConverter.Blackboard.visit ( SqlDynamicParam  param)
inline

Definition at line 4545 of file SqlToRelConverter.java.

4545  {
4546  return convertDynamicParam(param);
4547  }
RexDynamicParam convertDynamicParam(final SqlDynamicParam dynamicParam)
RexNode org.apache.calcite.sql2rel.SqlToRelConverter.Blackboard.visit ( SqlIntervalQualifier  intervalQualifier)
inline

Definition at line 4549 of file SqlToRelConverter.java.

4549  {
4550  return convertInterval(intervalQualifier);
4551  }
RexNode convertInterval(SqlIntervalQualifier intervalQualifier)

Member Data Documentation

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

Workspace for building aggregates.

Definition at line 3904 of file SqlToRelConverter.java.

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

Definition at line 3920 of file SqlToRelConverter.java.

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

Definition at line 3893 of file SqlToRelConverter.java.

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

Definition at line 3925 of file SqlToRelConverter.java.

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

Definition at line 3888 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 3889 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 3917 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 3886 of file SqlToRelConverter.java.

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

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

Definition at line 3899 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 3922 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 3910 of file SqlToRelConverter.java.


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