OmniSciDB  04ee39c94c
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

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

Constructor & Destructor Documentation

◆ Blackboard()

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

Member Function Documentation

◆ convertExpression()

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

Definition at line 4205 of file SqlToRelConverter.java.

References ALL, org.apache.calcite.sql2rel.SqlToRelConverter.RexAccessShuttle.builder, org.apache.calcite.sql2rel.SqlToRelConverter.config, org.apache.calcite.sql2rel.SqlToRelConverter.convertExpression(), org.apache.calcite.sql2rel.SqlToRelConverter.convertExtendedExpression(), org.apache.calcite.sql2rel.SqlToRelConverter.convertOver(), org.apache.calcite.sql2rel.SqlToRelConverter.convertQueryRecursive(), org.apache.calcite.sql2rel.SqlToRelConverter.SubQuery.expr, org.apache.calcite.sql2rel.SqlToRelConverter.negate(), anonymous_namespace{UpdateMetadataTest.cpp}.query, org.apache.calcite.sql2rel.SqlToRelConverter.rexBuilder, and org.apache.calcite.sql2rel.SqlToRelConverter.validator.

Referenced by org.apache.calcite.sql2rel.SqlToRelConverter.AggConverter.addGroupExpr(), org.apache.calcite.sql2rel.SqlToRelConverter.convertCollectionTable(), org.apache.calcite.sql2rel.SqlToRelConverter.convertExpression(), org.apache.calcite.sql2rel.SqlToRelConverter.convertFrom(), org.apache.calcite.sql2rel.SqlToRelConverter.convertIdentifier(), org.apache.calcite.sql2rel.SqlToRelConverter.convertInToOr(), org.apache.calcite.sql2rel.SqlToRelConverter.convertJoinCondition(), org.apache.calcite.sql2rel.SqlToRelConverter.convertMatchRecognize(), org.apache.calcite.sql2rel.SqlToRelConverter.convertOver(), org.apache.calcite.sql2rel.SqlToRelConverter.convertSelectList(), org.apache.calcite.sql2rel.SqlToRelConverter.convertUpdate(), org.apache.calcite.sql2rel.SqlToRelConverter.convertValuesImpl(), org.apache.calcite.sql2rel.SqlToRelConverter.convertWhere(), org.apache.calcite.sql2rel.SqlToRelConverter.createAggImpl(), org.apache.calcite.sql2rel.SqlToRelConverter.snapshotTemporalTable(), org.apache.calcite.sql2rel.SqlToRelConverter.substituteSubQuery(), and org.apache.calcite.sql2rel.SqlToRelConverter.AggConverter.translateAgg().

4205  {
4206  // If we're in aggregation mode and this is an expression in the
4207  // GROUP BY clause, return a reference to the field.
4208  if (agg != null) {
4209  final SqlNode expandedGroupExpr = validator.expand(expr, scope);
4210  final int ref = agg.lookupGroupExpr(expandedGroupExpr);
4211  if (ref >= 0) {
4212  return rexBuilder.makeInputRef(root, ref);
4213  }
4214  if (expr instanceof SqlCall) {
4215  final RexNode rex = agg.lookupAggregates((SqlCall) expr);
4216  if (rex != null) {
4217  return rex;
4218  }
4219  }
4220  }
4221 
4222  // Allow the derived class chance to override the standard
4223  // behavior for special kinds of expressions.
4224  RexNode rex = convertExtendedExpression(expr, this);
4225  if (rex != null) {
4226  return rex;
4227  }
4228 
4229  // Sub-queries and OVER expressions are not like ordinary
4230  // expressions.
4231  final SqlKind kind = expr.getKind();
4232  final SubQuery subQuery;
4233  if (!config.isExpand()) {
4234  final SqlCall call;
4235  final SqlNode query;
4236  final RelRoot root;
4237  switch (kind) {
4238  case IN:
4239  case NOT_IN:
4240  case SOME:
4241  case ALL:
4242  call = (SqlCall) expr;
4243  query = call.operand(1);
4244  if (!(query instanceof SqlNodeList)) {
4245  root = convertQueryRecursive(query, false, null);
4246  final SqlNode operand = call.operand(0);
4247  List<SqlNode> nodes;
4248  switch (operand.getKind()) {
4249  case ROW:
4250  nodes = ((SqlCall) operand).getOperandList();
4251  break;
4252  default:
4253  nodes = ImmutableList.of(operand);
4254  }
4255  final ImmutableList.Builder<RexNode> builder = ImmutableList.builder();
4256  for (SqlNode node : nodes) {
4257  builder.add(convertExpression(node));
4258  }
4259  final ImmutableList<RexNode> list = builder.build();
4260  switch (kind) {
4261  case IN:
4262  return RexSubQuery.in(root.rel, list);
4263  case NOT_IN:
4264  return rexBuilder.makeCall(
4265  SqlStdOperatorTable.NOT, RexSubQuery.in(root.rel, list));
4266  case SOME:
4267  return RexSubQuery.some(
4268  root.rel, list, (SqlQuantifyOperator) call.getOperator());
4269  case ALL:
4270  return rexBuilder.makeCall(SqlStdOperatorTable.NOT,
4271  RexSubQuery.some(root.rel,
4272  list,
4273  negate((SqlQuantifyOperator) call.getOperator())));
4274  default:
4275  throw new AssertionError(kind);
4276  }
4277  }
4278  break;
4279 
4280  case EXISTS:
4281  call = (SqlCall) expr;
4282  query = Iterables.getOnlyElement(call.getOperandList());
4283  root = convertQueryRecursive(query, false, null);
4284  RelNode rel = root.rel;
4285  while (rel instanceof Project
4286  || rel instanceof Sort && ((Sort) rel).fetch == null
4287  && ((Sort) rel).offset == null) {
4288  rel = ((SingleRel) rel).getInput();
4289  }
4290  return RexSubQuery.exists(rel);
4291 
4292  case SCALAR_QUERY:
4293  call = (SqlCall) expr;
4294  query = Iterables.getOnlyElement(call.getOperandList());
4295  root = convertQueryRecursive(query, false, null);
4296  return RexSubQuery.scalar(root.rel);
4297  }
4298  }
4299 
4300  switch (kind) {
4301  case SOME:
4302  case ALL:
4303  if (config.isExpand()) {
4304  throw new RuntimeException(kind + " is only supported if expand = false");
4305  }
4306  // fall through
4307  case CURSOR:
4308  case IN:
4309  case NOT_IN:
4310  subQuery = Objects.requireNonNull(getSubQuery(expr));
4311  rex = Objects.requireNonNull(subQuery.expr);
4312  return StandardConvertletTable.castToValidatedType(
4313  expr, rex, validator, rexBuilder);
4314 
4315  case SELECT:
4316  case EXISTS:
4317  case SCALAR_QUERY:
4318  subQuery = getSubQuery(expr);
4319  assert subQuery != null;
4320  rex = subQuery.expr;
4321  assert rex != null : "rex != null";
4322 
4323  if (((kind == SqlKind.SCALAR_QUERY) || (kind == SqlKind.EXISTS))
4324  && isConvertedSubq(rex)) {
4325  // scalar sub-query or EXISTS has been converted to a
4326  // constant
4327  return rex;
4328  }
4329 
4330  // The indicator column is the last field of the sub-query.
4331  RexNode fieldAccess =
4332  rexBuilder.makeFieldAccess(rex, rex.getType().getFieldCount() - 1);
4333 
4334  // The indicator column will be nullable if it comes from
4335  // the null-generating side of the join. For EXISTS, add an
4336  // "IS TRUE" check so that the result is "BOOLEAN NOT NULL".
4337  if (fieldAccess.getType().isNullable() && kind == SqlKind.EXISTS) {
4338  fieldAccess =
4339  rexBuilder.makeCall(SqlStdOperatorTable.IS_NOT_NULL, fieldAccess);
4340  }
4341  return fieldAccess;
4342 
4343  case OVER:
4344  return convertOver(this, expr);
4345 
4346  default:
4347  // fall through
4348  }
4349 
4350  // Apply standard conversions.
4351  rex = expr.accept(this);
4352  return Objects.requireNonNull(rex);
4353  }
SqlQuantifyOperator negate(SqlQuantifyOperator operator)
const std::vector< std::shared_ptr< TestColumnDescriptor > > ALL
RelRoot convertQueryRecursive(SqlNode query, boolean top, RelDataType targetRowType)
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:

◆ convertInterval()

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

Definition at line 4466 of file SqlToRelConverter.java.

References org.apache.calcite.sql2rel.SqlToRelConverter.exprConverter.

4466  {
4467  return exprConverter.convertInterval(this, intervalQualifier);
4468  }

◆ convertLiteral()

RexNode org.apache.calcite.sql2rel.SqlToRelConverter.Blackboard.convertLiteral ( SqlLiteral  literal)
inline

Definition at line 4462 of file SqlToRelConverter.java.

References org.apache.calcite.sql2rel.SqlToRelConverter.exprConverter.

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

4462  {
4463  return exprConverter.convertLiteral(this, literal);
4464  }
+ Here is the caller graph for this function:

◆ convertSortExpression()

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

References org.apache.calcite.sql2rel.SqlToRelConverter.convertExpression(), org.apache.calcite.sql2rel.SqlToRelConverter.desc(), FIRST, LAST, and org.apache.calcite.sql2rel.SqlToRelConverter.validator.

Referenced by org.apache.calcite.sql2rel.SqlToRelConverter.convertOver(), and org.apache.calcite.sql2rel.SqlToRelConverter.AggConverter.translateAgg().

4361  {
4362  switch (expr.getKind()) {
4363  case DESCENDING:
4364  return convertSortExpression(((SqlCall) expr).operand(0),
4365  RelFieldCollation.Direction.DESCENDING,
4366  nullDirection);
4367  case NULLS_LAST:
4368  return convertSortExpression(((SqlCall) expr).operand(0),
4369  direction,
4370  RelFieldCollation.NullDirection.LAST);
4371  case NULLS_FIRST:
4372  return convertSortExpression(((SqlCall) expr).operand(0),
4373  direction,
4374  RelFieldCollation.NullDirection.FIRST);
4375  default:
4376  final Set<SqlKind> flags = EnumSet.noneOf(SqlKind.class);
4377  switch (direction) {
4378  case DESCENDING:
4379  flags.add(SqlKind.DESCENDING);
4380  }
4381  switch (nullDirection) {
4382  case UNSPECIFIED:
4383  final RelFieldCollation.NullDirection nullDefaultDirection =
4384  validator.getDefaultNullCollation().last(desc(direction))
4385  ? RelFieldCollation.NullDirection.LAST
4386  : RelFieldCollation.NullDirection.FIRST;
4387  if (nullDefaultDirection != direction.defaultNullDirection()) {
4388  SqlKind nullDirectionSqlKind =
4389  validator.getDefaultNullCollation().last(desc(direction))
4390  ? SqlKind.NULLS_LAST
4391  : SqlKind.NULLS_FIRST;
4392  flags.add(nullDirectionSqlKind);
4393  }
4394  break;
4395  case FIRST:
4396  flags.add(SqlKind.NULLS_FIRST);
4397  break;
4398  case LAST:
4399  flags.add(SqlKind.NULLS_LAST);
4400  break;
4401  }
4402  return new RexFieldCollation(convertExpression(expr), flags);
4403  }
4404  }
RexFieldCollation convertSortExpression(SqlNode expr, RelFieldCollation.Direction direction, RelFieldCollation.NullDirection nullDirection)
static boolean desc(RelFieldCollation.Direction direction)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ flatten()

void org.apache.calcite.sql2rel.SqlToRelConverter.Blackboard.flatten ( List< RelNode >  rels,
int  systemFieldCount,
int []  start,
List< Pair< RelNode, Integer >>  relOffsetList 
)
inline

Definition at line 4161 of file SqlToRelConverter.java.

References org.apache.calcite.sql2rel.SqlToRelConverter.leaves.

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

4164  {
4165  for (RelNode rel : rels) {
4166  if (leaves.contains(rel) || rel instanceof LogicalMatch) {
4167  relOffsetList.add(Pair.of(rel, start[0]));
4168  start[0] += rel.getRowType().getFieldCount();
4169  } else {
4170  if (rel instanceof LogicalJoin || rel instanceof LogicalAggregate) {
4171  start[0] += systemFieldCount;
4172  }
4173  flatten(rel.getInputs(), systemFieldCount, start, relOffsetList);
4174  }
4175  }
4176  }
void flatten(List< RelNode > rels, int systemFieldCount, int[] start, List< Pair< RelNode, Integer >> relOffsetList)
+ Here is the caller graph for this function:

◆ getColumnMonotonicities()

List<SqlMonotonicity> org.apache.calcite.sql2rel.SqlToRelConverter.Blackboard.getColumnMonotonicities ( )
inline

Definition at line 4507 of file SqlToRelConverter.java.

4507  {
4508  return columnMonotonicities;
4509  }

◆ getGroupCount()

int org.apache.calcite.sql2rel.SqlToRelConverter.Blackboard.getGroupCount ( )
inline

Definition at line 4430 of file SqlToRelConverter.java.

4430  {
4431  if (agg != null) {
4432  return agg.groupExprs.size();
4433  }
4434  if (window != null) {
4435  return window.isAlwaysNonEmpty() ? 1 : 0;
4436  }
4437  return -1;
4438  }

◆ getInitializerExpressionFactory()

InitializerExpressionFactory org.apache.calcite.sql2rel.SqlToRelConverter.Blackboard.getInitializerExpressionFactory ( )
inline

Definition at line 4454 of file SqlToRelConverter.java.

4454  {
4456  }
final InitializerExpressionFactory initializerExpressionFactory

◆ getRexBuilder()

RexBuilder org.apache.calcite.sql2rel.SqlToRelConverter.Blackboard.getRexBuilder ( )
inline

Definition at line 4440 of file SqlToRelConverter.java.

References org.apache.calcite.sql2rel.SqlToRelConverter.rexBuilder.

4440  {
4441  return rexBuilder;
4442  }

◆ getRootField()

RelDataTypeField org.apache.calcite.sql2rel.SqlToRelConverter.Blackboard.getRootField ( RexInputRef  inputRef)
inlinepackage

Definition at line 4141 of file SqlToRelConverter.java.

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

4141  {
4142  if (inputs == null) {
4143  return null;
4144  }
4145  int fieldOffset = inputRef.getIndex();
4146  for (RelNode input : inputs) {
4147  RelDataType rowType = input.getRowType();
4148  if (rowType == null) {
4149  // TODO: remove this once leastRestrictive
4150  // is correctly implemented
4151  return null;
4152  }
4153  if (fieldOffset < rowType.getFieldCount()) {
4154  return rowType.getFieldList().get(fieldOffset);
4155  }
4156  fieldOffset -= rowType.getFieldCount();
4157  }
4158  throw new AssertionError();
4159  }
+ Here is the caller graph for this function:

◆ getSubQuery()

SubQuery org.apache.calcite.sql2rel.SqlToRelConverter.Blackboard.getSubQuery ( SqlNode  expr)
inlinepackage

Definition at line 4187 of file SqlToRelConverter.java.

4187  {
4188  for (SubQuery subQuery : subQueryList) {
4189  if (expr.equalsDeep(subQuery.node, Litmus.IGNORE)) {
4190  return subQuery;
4191  }
4192  }
4193 
4194  return null;
4195  }

◆ getSubQueryExpr()

RexRangeRef org.apache.calcite.sql2rel.SqlToRelConverter.Blackboard.getSubQueryExpr ( SqlCall  call)
inline

Definition at line 4444 of file SqlToRelConverter.java.

References org.apache.calcite.sql2rel.SqlToRelConverter.SubQuery.expr.

4444  {
4445  final SubQuery subQuery = getSubQuery(call);
4446  assert subQuery != null;
4447  return (RexRangeRef) subQuery.expr;
4448  }

◆ getTypeFactory()

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

Definition at line 4450 of file SqlToRelConverter.java.

References org.apache.calcite.sql2rel.SqlToRelConverter.typeFactory.

4450  {
4451  return typeFactory;
4452  }

◆ getValidator()

SqlValidator org.apache.calcite.sql2rel.SqlToRelConverter.Blackboard.getValidator ( )
inline

Definition at line 4458 of file SqlToRelConverter.java.

References org.apache.calcite.sql2rel.SqlToRelConverter.validator.

Referenced by org.apache.calcite.sql2rel.SqlToRelConverter.AggConverter.AggConverter(), org.apache.calcite.sql2rel.SqlToRelConverter.convertIdentifier(), and org.apache.calcite.sql2rel.SqlToRelConverter.getCorrelationUse().

4458  {
4459  return validator;
4460  }
+ Here is the caller graph for this function:

◆ isConvertedSubq()

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

4414  {
4415  if ((rex instanceof RexLiteral) || (rex instanceof RexDynamicParam)) {
4416  return true;
4417  }
4418  if (rex instanceof RexCall) {
4419  RexCall call = (RexCall) rex;
4420  if (call.getOperator() == SqlStdOperatorTable.CAST) {
4421  RexNode operand = call.getOperands().get(0);
4422  if (operand instanceof RexLiteral) {
4423  return true;
4424  }
4425  }
4426  }
4427  return false;
4428  }

◆ lookup()

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

References org.apache.calcite.sql2rel.SqlToRelConverter.LookupContext.findRel(), and org.apache.calcite.sql2rel.SqlToRelConverter.rexBuilder.

4136  {
4137  Pair<RelNode, Integer> pair = lookupContext.findRel(offset);
4138  return rexBuilder.makeRangeReference(pair.left.getRowType(), pair.right, false);
4139  }
+ Here is the call graph for this function:

◆ lookupExp()

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

References org.apache.calcite.sql2rel.SqlToRelConverter.RexAccessShuttle.builder, anonymous_namespace{ExecuteTest.cpp}.c(), org.apache.calcite.sql2rel.SqlToRelConverter.cluster, field(), Integer, org.apache.calcite.sql2rel.SqlToRelConverter.mapCorrelToDeferred, org.apache.calcite.sql2rel.SqlToRelConverter.rexBuilder, Experimental.String, and org.apache.calcite.sql2rel.SqlToRelConverter.typeFactory.

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

4058  {
4059  if (nameToNodeMap != null && qualified.prefixLength == 1) {
4060  RexNode node = nameToNodeMap.get(qualified.identifier.names.get(0));
4061  if (node == null) {
4062  throw new AssertionError("Unknown identifier '" + qualified.identifier
4063  + "' encountered while expanding expression");
4064  }
4065  return Pair.of(node, null);
4066  }
4067  final SqlNameMatcher nameMatcher =
4068  scope.getValidator().getCatalogReader().nameMatcher();
4069  final SqlValidatorScope.ResolvedImpl resolved =
4070  new SqlValidatorScope.ResolvedImpl();
4071  scope.resolve(qualified.prefix(), nameMatcher, false, resolved);
4072  if (!(resolved.count() == 1)) {
4073  return null;
4074  }
4075  final SqlValidatorScope.Resolve resolve = resolved.only();
4076  final RelDataType rowType = resolve.rowType();
4077 
4078  // Found in current query's from list. Find which from item.
4079  // We assume that the order of the from clause items has been
4080  // preserved.
4081  final SqlValidatorScope ancestorScope = resolve.scope;
4082  boolean isParent = ancestorScope != scope;
4083  if ((inputs != null) && !isParent) {
4084  final LookupContext rels =
4085  new LookupContext(this, inputs, systemFieldList.size());
4086  final RexNode node = lookup(resolve.path.steps().get(0).i, rels);
4087  if (node == null) {
4088  return null;
4089  } else {
4090  final Map<String, Integer> fieldOffsets = new HashMap<>();
4091  for (RelDataTypeField f : resolve.rowType().getFieldList()) {
4092  if (!fieldOffsets.containsKey(f.getName())) {
4093  fieldOffsets.put(f.getName(), f.getIndex());
4094  }
4095  }
4096  final Map<String, Integer> map = ImmutableMap.copyOf(fieldOffsets);
4097  return Pair.of(node, map);
4098  }
4099  } else {
4100  // We're referencing a relational expression which has not been
4101  // converted yet. This occurs when from items are correlated,
4102  // e.g. "select from emp as emp join emp.getDepts() as dept".
4103  // Create a temporary expression.
4104  DeferredLookup lookup =
4105  new DeferredLookup(this, qualified.identifier.names.get(0));
4106  final CorrelationId correlId = cluster.createCorrel();
4107  mapCorrelToDeferred.put(correlId, lookup);
4108  if (resolve.path.steps().get(0).i < 0) {
4109  return Pair.of(rexBuilder.makeCorrel(rowType, correlId), null);
4110  } else {
4111  final RelDataTypeFactory.Builder builder = typeFactory.builder();
4112  final ListScope ancestorScope1 = (ListScope) resolve.scope;
4113  final ImmutableMap.Builder<String, Integer> fields = ImmutableMap.builder();
4114  int i = 0;
4115  int offset = 0;
4116  for (SqlValidatorNamespace c : ancestorScope1.getChildren()) {
4117  builder.addAll(c.getRowType().getFieldList());
4118  if (i == resolve.path.steps().get(0).i) {
4119  for (RelDataTypeField field : c.getRowType().getFieldList()) {
4120  fields.put(field.getName(), field.getIndex() + offset);
4121  }
4122  }
4123  ++i;
4124  offset += c.getRowType().getFieldCount();
4125  }
4126  final RexNode c = rexBuilder.makeCorrel(builder.uniquify().build(), correlId);
4127  return Pair.of(c, fields.build());
4128  }
4129  }
4130  }
void c(const std::string &query_string, const ExecutorDeviceType device_type)
const rapidjson::Value & field(const rapidjson::Value &obj, const char field[]) noexcept
Definition: JsonAccessors.h:31
final Map< CorrelationId, DeferredLookup > mapCorrelToDeferred
RexNode lookup(int offset, LookupContext lookupContext)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ register() [1/2]

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

Definition at line 3914 of file SqlToRelConverter.java.

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

3914  {
3915  return register(rel, joinType, null);
3916  }
+ Here is the caller graph for this function:

◆ register() [2/2]

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

References org.apache.calcite.sql2rel.SqlToRelConverter.createJoin(), join(), org.apache.calcite.sql2rel.SqlToRelConverter.relBuilder, org.apache.calcite.sql2rel.SqlToRelConverter.rexBuilder, Experimental.String, and org.apache.calcite.sql2rel.SqlToRelConverter.typeFactory.

3928  {
3929  assert joinType != null;
3930  if (root == null) {
3931  assert leftKeys == null;
3932  setRoot(rel, false);
3933  return rexBuilder.makeRangeReference(root.getRowType(), 0, false);
3934  }
3935 
3936  final RexNode joinCond;
3937  final int origLeftInputCount = root.getRowType().getFieldCount();
3938  if (leftKeys != null) {
3939  List<RexNode> newLeftInputExprs = new ArrayList<>();
3940  for (int i = 0; i < origLeftInputCount; i++) {
3941  newLeftInputExprs.add(rexBuilder.makeInputRef(root, i));
3942  }
3943 
3944  final List<Integer> leftJoinKeys = new ArrayList<>();
3945  for (RexNode leftKey : leftKeys) {
3946  int index = newLeftInputExprs.indexOf(leftKey);
3947  if (index < 0 || joinType == JoinRelType.LEFT) {
3948  index = newLeftInputExprs.size();
3949  newLeftInputExprs.add(leftKey);
3950  }
3951  leftJoinKeys.add(index);
3952  }
3953 
3954  RelNode newLeftInput = relBuilder.push(root).project(newLeftInputExprs).build();
3955 
3956  // maintain the group by mapping in the new LogicalProject
3957  if (mapRootRelToFieldProjection.containsKey(root)) {
3959  newLeftInput, mapRootRelToFieldProjection.get(root));
3960  }
3961 
3962  setRoot(newLeftInput, false);
3963 
3964  // right fields appear after the LHS fields.
3965  final int rightOffset = root.getRowType().getFieldCount()
3966  - newLeftInput.getRowType().getFieldCount();
3967  final List<Integer> rightKeys =
3968  Util.range(rightOffset, rightOffset + leftKeys.size());
3969 
3970  joinCond = RelOptUtil.createEquiJoinCondition(
3971  newLeftInput, leftJoinKeys, rel, rightKeys, rexBuilder);
3972  } else {
3973  joinCond = rexBuilder.makeLiteral(true);
3974  }
3975 
3976  int leftFieldCount = root.getRowType().getFieldCount();
3977  final RelNode join = createJoin(this, root, rel, joinCond, joinType);
3978 
3979  setRoot(join, false);
3980 
3981  if (leftKeys != null && joinType == JoinRelType.LEFT) {
3982  final int leftKeyCount = leftKeys.size();
3983  int rightFieldLength = rel.getRowType().getFieldCount();
3984  assert leftKeyCount == rightFieldLength - 1;
3985 
3986  final int rexRangeRefLength = leftKeyCount + rightFieldLength;
3987  RelDataType returnType = typeFactory.createStructType(
3988  new AbstractList<Map.Entry<String, RelDataType>>() {
3989  public Map.Entry<String, RelDataType> get(int index) {
3990  return join.getRowType().getFieldList().get(
3991  origLeftInputCount + index);
3992  }
3993 
3994  public int size() {
3995  return rexRangeRefLength;
3996  }
3997  });
3998 
3999  return rexBuilder.makeRangeReference(returnType, origLeftInputCount, false);
4000  } else {
4001  return rexBuilder.makeRangeReference(
4002  rel.getRowType(), leftFieldCount, joinType.generatesNullsOnRight());
4003  }
4004  }
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:

◆ registerSubQuery()

void org.apache.calcite.sql2rel.SqlToRelConverter.Blackboard.registerSubQuery ( SqlNode  node,
RelOptUtil.Logic  logic 
)
inlinepackage

Definition at line 4178 of file SqlToRelConverter.java.

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

4178  {
4179  for (SubQuery subQuery : subQueryList) {
4180  if (node.equalsDeep(subQuery.node, Litmus.IGNORE)) {
4181  return;
4182  }
4183  }
4184  subQueryList.add(new SubQuery(node, logic));
4185  }
+ Here is the caller graph for this function:

◆ retrieveCursors()

ImmutableList<RelNode> org.apache.calcite.sql2rel.SqlToRelConverter.Blackboard.retrieveCursors ( )
inlinepackage

Definition at line 4197 of file SqlToRelConverter.java.

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

4197  {
4198  try {
4199  return ImmutableList.copyOf(cursors);
4200  } finally {
4201  cursors.clear();
4202  }
4203  }
+ Here is the caller graph for this function:

◆ setDataset()

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

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

4045 {}
+ Here is the caller graph for this function:

◆ setPatternVarRef()

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

Definition at line 3910 of file SqlToRelConverter.java.

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

3910  {
3911  this.isPatternVarRef = isVarRef;
3912  }
+ Here is the caller graph for this function:

◆ setRoot() [1/3]

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

References org.apache.calcite.sql2rel.SqlToRelConverter.leaves.

Referenced by org.apache.calcite.sql2rel.SqlToRelConverter.convertCollectionTable(), org.apache.calcite.sql2rel.SqlToRelConverter.convertFrom(), org.apache.calcite.sql2rel.SqlToRelConverter.convertIdentifier(), org.apache.calcite.sql2rel.SqlToRelConverter.convertJoinCondition(), org.apache.calcite.sql2rel.SqlToRelConverter.convertMatchRecognize(), org.apache.calcite.sql2rel.SqlToRelConverter.convertOrder(), org.apache.calcite.sql2rel.SqlToRelConverter.convertSelectImpl(), org.apache.calcite.sql2rel.SqlToRelConverter.convertSelectList(), org.apache.calcite.sql2rel.SqlToRelConverter.convertValuesImpl(), org.apache.calcite.sql2rel.SqlToRelConverter.convertWhere(), org.apache.calcite.sql2rel.SqlToRelConverter.createAggImpl(), org.apache.calcite.sql2rel.SqlToRelConverter.distinctify(), org.apache.calcite.sql2rel.SqlToRelConverter.snapshotTemporalTable(), and org.apache.calcite.sql2rel.SqlToRelConverter.substituteSubQuery().

4018  {
4019  setRoot(Collections.singletonList(root), root, root instanceof LogicalJoin);
4020  if (leaf) {
4021  leaves.add(root);
4022  }
4023  this.columnMonotonicities.clear();
4024  }
+ Here is the caller graph for this function:

◆ setRoot() [2/3]

void org.apache.calcite.sql2rel.SqlToRelConverter.Blackboard.setRoot ( List< RelNode >  inputs,
RelNode  root,
boolean  hasSystemFields 
)
inlineprivate

Definition at line 4026 of file SqlToRelConverter.java.

References org.apache.calcite.sql2rel.SqlToRelConverter.getSystemFields().

4026  {
4027  this.inputs = inputs;
4028  this.root = root;
4029  this.systemFieldList.clear();
4030  if (hasSystemFields) {
4031  this.systemFieldList.addAll(getSystemFields());
4032  }
4033  }
+ Here is the call graph for this function:

◆ setRoot() [3/3]

void org.apache.calcite.sql2rel.SqlToRelConverter.Blackboard.setRoot ( List< RelNode >  inputs)
inlinepackage

Definition at line 4047 of file SqlToRelConverter.java.

4047  {
4048  setRoot(inputs, null, false);
4049  }

◆ visit() [1/7]

RexNode org.apache.calcite.sql2rel.SqlToRelConverter.Blackboard.visit ( SqlLiteral  literal)
inline

Definition at line 4470 of file SqlToRelConverter.java.

References org.apache.calcite.sql2rel.SqlToRelConverter.exprConverter.

4470  {
4471  return exprConverter.convertLiteral(this, literal);
4472  }

◆ visit() [2/7]

RexNode org.apache.calcite.sql2rel.SqlToRelConverter.Blackboard.visit ( SqlCall  call)
inline

Definition at line 4474 of file SqlToRelConverter.java.

References org.apache.calcite.sql2rel.SqlToRelConverter.exprConverter, and org.apache.calcite.sql2rel.SqlToRelConverter.validator.

4474  {
4475  if (agg != null) {
4476  final SqlOperator op = call.getOperator();
4477  if (window == null
4478  && (op.isAggregator() || op.getKind() == SqlKind.FILTER
4479  || op.getKind() == SqlKind.WITHIN_GROUP)) {
4480  return agg.lookupAggregates(call);
4481  }
4482  }
4483  return exprConverter.convertCall(
4484  this, new SqlCallBinding(validator, scope, call).permutedCall());
4485  }

◆ visit() [3/7]

RexNode org.apache.calcite.sql2rel.SqlToRelConverter.Blackboard.visit ( SqlNodeList  nodeList)
inline

Definition at line 4487 of file SqlToRelConverter.java.

4487  {
4488  throw new UnsupportedOperationException();
4489  }

◆ visit() [4/7]

RexNode org.apache.calcite.sql2rel.SqlToRelConverter.Blackboard.visit ( SqlIdentifier  id)
inline

Definition at line 4491 of file SqlToRelConverter.java.

References org.apache.calcite.sql2rel.SqlToRelConverter.convertIdentifier().

4491  {
4492  return convertIdentifier(this, id);
4493  }
void convertIdentifier(Blackboard bb, SqlIdentifier id, SqlNodeList extendedColumns)
+ Here is the call graph for this function:

◆ visit() [5/7]

RexNode org.apache.calcite.sql2rel.SqlToRelConverter.Blackboard.visit ( SqlDataTypeSpec  type)
inline

Definition at line 4495 of file SqlToRelConverter.java.

4495  {
4496  throw new UnsupportedOperationException();
4497  }

◆ visit() [6/7]

RexNode org.apache.calcite.sql2rel.SqlToRelConverter.Blackboard.visit ( SqlDynamicParam  param)
inline

Definition at line 4499 of file SqlToRelConverter.java.

References org.apache.calcite.sql2rel.SqlToRelConverter.convertDynamicParam().

4499  {
4500  return convertDynamicParam(param);
4501  }
RexDynamicParam convertDynamicParam(final SqlDynamicParam dynamicParam)
+ Here is the call graph for this function:

◆ visit() [7/7]

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

Definition at line 4503 of file SqlToRelConverter.java.

4503  {
4504  return convertInterval(intervalQualifier);
4505  }
RexNode convertInterval(SqlIntervalQualifier intervalQualifier)

Member Data Documentation

◆ agg

◆ columnMonotonicities

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

◆ cursors

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

◆ initializerExpressionFactory

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

Definition at line 3889 of file SqlToRelConverter.java.

◆ inputs

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

Definition at line 3852 of file SqlToRelConverter.java.

◆ isPatternVarRef

boolean org.apache.calcite.sql2rel.SqlToRelConverter.Blackboard.isPatternVarRef = false
private

◆ mapCorrelateToRex

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

◆ mapRootRelToFieldProjection

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

Referenced by org.apache.calcite.sql2rel.SqlToRelConverter.createAggImpl(), and org.apache.calcite.sql2rel.SqlToRelConverter.getCorrelationUse().

◆ nameToNodeMap

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

◆ root

◆ scope

◆ subQueryList

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

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

◆ systemFieldList

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

Definition at line 3886 of file SqlToRelConverter.java.

◆ top

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

◆ window

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

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


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