OmniSciDB  a5dc49c757
 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 6576 of file SqlValidatorImpl.java.

Constructor & Destructor Documentation

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

Definition at line 6581 of file SqlValidatorImpl.java.

References 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().

6581  {
6582  switch (from.getKind()) {
6583  case JOIN:
6584  final SqlJoin join = (SqlJoin) from;
6585  final Permute left = new Permute(join.getLeft(), offset);
6586  final int fieldCount =
6587  getValidatedNodeType(join.getLeft()).getFieldList().size();
6588  final Permute right =
6589  new Permute(join.getRight(), offset + fieldCount);
6590  final List<String> names = usingNames(join);
6591  final List<ImmutableIntList> sources = new ArrayList<>();
6592  final Set<ImmutableIntList> sourceSet = new HashSet<>();
6593  final RelDataTypeFactory.Builder b = typeFactory.builder();
6594  if (names != null) {
6595  for (String name : names) {
6596  final RelDataTypeField f = left.field(name);
6597  final ImmutableIntList source = left.sources.get(f.getIndex());
6598  sourceSet.add(source);
6599  final RelDataTypeField f2 = right.field(name);
6600  final ImmutableIntList source2 = right.sources.get(f2.getIndex());
6601  sourceSet.add(source2);
6602  sources.add(source.appendAll(source2));
6603  final boolean nullable =
6604  (f.getType().isNullable()
6605  || join.getJoinType().generatesNullsOnLeft())
6606  && (f2.getType().isNullable()
6607  || join.getJoinType().generatesNullsOnRight());
6608  b.add(f).nullable(nullable);
6609  }
6610  }
6611  for (RelDataTypeField f : left.rowType.getFieldList()) {
6612  final ImmutableIntList source = left.sources.get(f.getIndex());
6613  if (sourceSet.add(source)) {
6614  sources.add(source);
6615  b.add(f);
6616  }
6617  }
6618  for (RelDataTypeField f : right.rowType.getFieldList()) {
6619  final ImmutableIntList source = right.sources.get(f.getIndex());
6620  if (sourceSet.add(source)) {
6621  sources.add(source);
6622  b.add(f);
6623  }
6624  }
6625  rowType = b.build();
6626  this.sources = ImmutableList.copyOf(sources);
6627  this.trivial = left.trivial
6628  && right.trivial
6629  && (names == null || names.isEmpty());
6630  break;
6631 
6632  default:
6633  rowType = getValidatedNodeType(from);
6634  this.sources = Functions.generate(rowType.getFieldCount(),
6635  i -> ImmutableIntList.of(offset + i));
6636  this.trivial = true;
6637  }
6638  }
std::string join(T const &container, std::string const &delim)
torch::Tensor f(torch::Tensor x, torch::Tensor W_target, torch::Tensor b_target)
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 6640 of file SqlValidatorImpl.java.

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

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

6640  {
6641  return catalogReader.nameMatcher().field(rowType, name);
6642  }
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 6645 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.

6646  {
6647  if (trivial) {
6648  return;
6649  }
6650 
6651  final List<SqlNode> oldSelectItems = ImmutableList.copyOf(selectItems);
6652  selectItems.clear();
6653  final List<Map.Entry<String, RelDataType>> oldFields =
6654  ImmutableList.copyOf(fields);
6655  fields.clear();
6656  for (ImmutableIntList source : sources) {
6657  final int p0 = source.get(0);
6658  Map.Entry<String, RelDataType> field = oldFields.get(p0);
6659  final String name = field.getKey();
6660  RelDataType type = field.getValue();
6661  SqlNode selectItem = oldSelectItems.get(p0);
6662  for (int p1 : Util.skip(source)) {
6663  final Map.Entry<String, RelDataType> field1 = oldFields.get(p1);
6664  final SqlNode selectItem1 = oldSelectItems.get(p1);
6665  final RelDataType type1 = field1.getValue();
6666  // output is nullable only if both inputs are
6667  final boolean nullable = type.isNullable() && type1.isNullable();
6668  final RelDataType type2 =
6669  SqlTypeUtil.leastRestrictiveForComparison(typeFactory, type,
6670  type1);
6671  selectItem =
6672  SqlStdOperatorTable.AS.createCall(SqlParserPos.ZERO,
6673  SqlStdOperatorTable.COALESCE.createCall(SqlParserPos.ZERO,
6674  maybeCast(selectItem, type, type2),
6675  maybeCast(selectItem1, type1, type2)),
6676  new SqlIdentifier(name, SqlParserPos.ZERO));
6677  type = typeFactory.createTypeWithNullability(type2, nullable);
6678  }
6679  fields.add(Pair.of(name, type));
6680  selectItems.add(selectItem);
6681  }
6682  }
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: