OmniSciDB  c1a53651b2
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
org.apache.calcite.sql.validate.SqlValidatorImpl.Permute Class Reference
+ Collaboration diagram for org.apache.calcite.sql.validate.SqlValidatorImpl.Permute:

Public Member Functions

void permute (List< SqlNode > selectItems, List< Map.Entry< String, RelDataType >> fields)
 

Package Functions

 Permute (SqlNode from, int offset)
 

Package Attributes

final List< ImmutableIntList > sources
 
final RelDataType rowType
 
final boolean trivial
 

Private Member Functions

RelDataTypeField field (String name)
 

Detailed Description

Permutation of fields in NATURAL JOIN or USING.

Definition at line 6565 of file SqlValidatorImpl.java.

Constructor & Destructor Documentation

org.apache.calcite.sql.validate.SqlValidatorImpl.Permute.Permute ( SqlNode  from,
int  offset 
)
inlinepackage

Definition at line 6570 of file SqlValidatorImpl.java.

References anonymous_namespace{Utm.h}.f, org.apache.calcite.sql.validate.SqlValidatorImpl.getValidatedNodeType(), join(), setup.name, org.apache.calcite.sql.validate.SqlValidatorImpl.Permute.rowType, org.apache.calcite.sql.validate.SqlValidatorImpl.Permute.sources, and org.apache.calcite.sql.validate.SqlValidatorImpl.usingNames().

6570  {
6571  switch (from.getKind()) {
6572  case JOIN:
6573  final SqlJoin join = (SqlJoin) from;
6574  final Permute left = new Permute(join.getLeft(), offset);
6575  final int fieldCount =
6576  getValidatedNodeType(join.getLeft()).getFieldList().size();
6577  final Permute right =
6578  new Permute(join.getRight(), offset + fieldCount);
6579  final List<String> names = usingNames(join);
6580  final List<ImmutableIntList> sources = new ArrayList<>();
6581  final Set<ImmutableIntList> sourceSet = new HashSet<>();
6582  final RelDataTypeFactory.Builder b = typeFactory.builder();
6583  if (names != null) {
6584  for (String name : names) {
6585  final RelDataTypeField f = left.field(name);
6586  final ImmutableIntList source = left.sources.get(f.getIndex());
6587  sourceSet.add(source);
6588  final RelDataTypeField f2 = right.field(name);
6589  final ImmutableIntList source2 = right.sources.get(f2.getIndex());
6590  sourceSet.add(source2);
6591  sources.add(source.appendAll(source2));
6592  final boolean nullable =
6593  (f.getType().isNullable()
6594  || join.getJoinType().generatesNullsOnLeft())
6595  && (f2.getType().isNullable()
6596  || join.getJoinType().generatesNullsOnRight());
6597  b.add(f).nullable(nullable);
6598  }
6599  }
6600  for (RelDataTypeField f : left.rowType.getFieldList()) {
6601  final ImmutableIntList source = left.sources.get(f.getIndex());
6602  if (sourceSet.add(source)) {
6603  sources.add(source);
6604  b.add(f);
6605  }
6606  }
6607  for (RelDataTypeField f : right.rowType.getFieldList()) {
6608  final ImmutableIntList source = right.sources.get(f.getIndex());
6609  if (sourceSet.add(source)) {
6610  sources.add(source);
6611  b.add(f);
6612  }
6613  }
6614  rowType = b.build();
6615  this.sources = ImmutableList.copyOf(sources);
6616  this.trivial = left.trivial
6617  && right.trivial
6618  && (names == null || names.isEmpty());
6619  break;
6620 
6621  default:
6622  rowType = getValidatedNodeType(from);
6623  this.sources = Functions.generate(rowType.getFieldCount(),
6624  i -> ImmutableIntList.of(offset + i));
6625  this.trivial = true;
6626  }
6627  }
std::string join(T const &container, std::string const &delim)
constexpr double f
Definition: Utm.h:31
string name
Definition: setup.in.py:72

+ Here is the call graph for this function:

Member Function Documentation

RelDataTypeField org.apache.calcite.sql.validate.SqlValidatorImpl.Permute.field ( String  name)
inlineprivate

Definition at line 6629 of file SqlValidatorImpl.java.

References org.apache.calcite.sql.validate.SqlValidatorImpl.Permute.rowType.

Referenced by org.apache.calcite.sql.validate.SqlValidatorImpl.Permute.permute().

6629  {
6630  return catalogReader.nameMatcher().field(rowType, name);
6631  }
string name
Definition: setup.in.py:72

+ Here is the caller graph for this function:

void org.apache.calcite.sql.validate.SqlValidatorImpl.Permute.permute ( List< SqlNode >  selectItems,
List< Map.Entry< String, RelDataType >>  fields 
)
inline

Moves fields according to the permutation.

Definition at line 6634 of file SqlValidatorImpl.java.

References org.apache.calcite.sql.validate.SqlValidatorImpl.Permute.field(), org.apache.calcite.sql.validate.SqlValidatorImpl.maybeCast(), setup.name, org.apache.calcite.sql.validate.SqlValidatorImpl.Permute.sources, org.apache.calcite.sql.validate.SqlValidatorImpl.Permute.trivial, run_benchmark_import.type, and org.apache.calcite.sql.validate.SqlValidatorImpl.typeFactory.

6635  {
6636  if (trivial) {
6637  return;
6638  }
6639 
6640  final List<SqlNode> oldSelectItems = ImmutableList.copyOf(selectItems);
6641  selectItems.clear();
6642  final List<Map.Entry<String, RelDataType>> oldFields =
6643  ImmutableList.copyOf(fields);
6644  fields.clear();
6645  for (ImmutableIntList source : sources) {
6646  final int p0 = source.get(0);
6647  Map.Entry<String, RelDataType> field = oldFields.get(p0);
6648  final String name = field.getKey();
6649  RelDataType type = field.getValue();
6650  SqlNode selectItem = oldSelectItems.get(p0);
6651  for (int p1 : Util.skip(source)) {
6652  final Map.Entry<String, RelDataType> field1 = oldFields.get(p1);
6653  final SqlNode selectItem1 = oldSelectItems.get(p1);
6654  final RelDataType type1 = field1.getValue();
6655  // output is nullable only if both inputs are
6656  final boolean nullable = type.isNullable() && type1.isNullable();
6657  final RelDataType type2 =
6658  SqlTypeUtil.leastRestrictiveForComparison(typeFactory, type,
6659  type1);
6660  selectItem =
6661  SqlStdOperatorTable.AS.createCall(SqlParserPos.ZERO,
6662  SqlStdOperatorTable.COALESCE.createCall(SqlParserPos.ZERO,
6663  maybeCast(selectItem, type, type2),
6664  maybeCast(selectItem1, type1, type2)),
6665  new SqlIdentifier(name, SqlParserPos.ZERO));
6666  type = typeFactory.createTypeWithNullability(type2, nullable);
6667  }
6668  fields.add(Pair.of(name, type));
6669  selectItems.add(selectItem);
6670  }
6671  }
SqlNode maybeCast(SqlNode node, RelDataType currentType, RelDataType desiredType)
string name
Definition: setup.in.py:72

+ Here is the call graph for this function:

Member Data Documentation

final RelDataType org.apache.calcite.sql.validate.SqlValidatorImpl.Permute.rowType
package
final List<ImmutableIntList> org.apache.calcite.sql.validate.SqlValidatorImpl.Permute.sources
package
final boolean org.apache.calcite.sql.validate.SqlValidatorImpl.Permute.trivial
package

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