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

Public Member Functions

RelDataType visit (SqlLiteral literal)
 
RelDataType visit (SqlCall call)
 
RelDataType visit (SqlNodeList nodeList)
 
RelDataType visit (SqlIdentifier id)
 
RelDataType visit (SqlDataTypeSpec dataType)
 
RelDataType visit (SqlDynamicParam param)
 
RelDataType visit (SqlIntervalQualifier intervalQualifier)
 

Package Functions

 DeriveTypeVisitor (SqlValidatorScope scope)
 

Private Attributes

final SqlValidatorScope scope
 

Detailed Description

Visitor which derives the type of a given SqlNode.

Each method must return the derived type. This visitor is basically a single-use dispatcher; the visit is never recursive.

Definition at line 5786 of file SqlValidatorImpl.java.

Constructor & Destructor Documentation

org.apache.calcite.sql.validate.SqlValidatorImpl.DeriveTypeVisitor.DeriveTypeVisitor ( SqlValidatorScope  scope)
inlinepackage

Member Function Documentation

RelDataType org.apache.calcite.sql.validate.SqlValidatorImpl.DeriveTypeVisitor.visit ( SqlLiteral  literal)
inline

Definition at line 5793 of file SqlValidatorImpl.java.

References org.apache.calcite.sql.validate.SqlValidatorImpl.typeFactory.

5793  {
5794  return literal.createSqlType(typeFactory);
5795  }
RelDataType org.apache.calcite.sql.validate.SqlValidatorImpl.DeriveTypeVisitor.visit ( SqlCall  call)
inline

Definition at line 5797 of file SqlValidatorImpl.java.

References org.apache.calcite.sql.validate.SqlValidatorImpl.DeriveTypeVisitor.scope, and this.

5797  {
5798  final SqlOperator operator = call.getOperator();
5799  return operator.deriveType(SqlValidatorImpl.this, scope, call);
5800  }
this
Definition: Execute.cpp:281
RelDataType org.apache.calcite.sql.validate.SqlValidatorImpl.DeriveTypeVisitor.visit ( SqlNodeList  nodeList)
inline

Definition at line 5802 of file SqlValidatorImpl.java.

5802  {
5803  // Operand is of a type that we can't derive a type for. If the
5804  // operand is of a peculiar type, such as a SqlNodeList, then you
5805  // should override the operator's validateCall() method so that it
5806  // doesn't try to validate that operand as an expression.
5807  throw Util.needToImplement(nodeList);
5808  }
RelDataType org.apache.calcite.sql.validate.SqlValidatorImpl.DeriveTypeVisitor.visit ( SqlIdentifier  id)
inline

Definition at line 5810 of file SqlValidatorImpl.java.

References field(), org.apache.calcite.sql.validate.SqlValidatorImpl.getTypeFactory(), org.apache.calcite.sql.validate.SqlValidatorImpl.makeNullaryCall(), setup.name, org.apache.calcite.sql.validate.SqlValidatorImpl.newValidationError(), org.apache.calcite.sql.validate.SqlValidatorImpl.DeriveTypeVisitor.scope, and run_benchmark_import.type.

5810  {
5811  // First check for builtin functions which don't have parentheses,
5812  // like "LOCALTIME".
5813  final SqlCall call = makeNullaryCall(id);
5814  if (call != null) {
5815  return call.getOperator().validateOperands(
5816  SqlValidatorImpl.this,
5817  scope,
5818  call);
5819  }
5820 
5821  RelDataType type = null;
5822  if (!(scope instanceof EmptyScope)) {
5823  id = scope.fullyQualify(id).identifier;
5824  }
5825 
5826  // Resolve the longest prefix of id that we can
5827  int i;
5828  for (i = id.names.size() - 1; i > 0; i--) {
5829  // REVIEW jvs 9-June-2005: The name resolution rules used
5830  // here are supposed to match SQL:2003 Part 2 Section 6.6
5831  // (identifier chain), but we don't currently have enough
5832  // information to get everything right. In particular,
5833  // routine parameters are currently looked up via resolve;
5834  // we could do a better job if they were looked up via
5835  // resolveColumn.
5836 
5837  final SqlNameMatcher nameMatcher = catalogReader.nameMatcher();
5838  final SqlValidatorScope.ResolvedImpl resolved =
5839  new SqlValidatorScope.ResolvedImpl();
5840  scope.resolve(id.names.subList(0, i), nameMatcher, false, resolved);
5841  if (resolved.count() == 1) {
5842  // There's a namespace with the name we seek.
5843  final SqlValidatorScope.Resolve resolve = resolved.only();
5844  type = resolve.rowType();
5845  for (SqlValidatorScope.Step p : Util.skip(resolve.path.steps())) {
5846  type = type.getFieldList().get(p.i).getType();
5847  }
5848  break;
5849  }
5850  }
5851 
5852  // Give precedence to namespace found, unless there
5853  // are no more identifier components.
5854  if (type == null || id.names.size() == 1) {
5855  // See if there's a column with the name we seek in
5856  // precisely one of the namespaces in this scope.
5857  RelDataType colType = scope.resolveColumn(id.names.get(0), id);
5858  if (colType != null) {
5859  type = colType;
5860  }
5861  ++i;
5862  }
5863 
5864  if (type == null) {
5865  final SqlIdentifier last = id.getComponent(i - 1, i);
5866  throw newValidationError(last,
5867  RESOURCE.unknownIdentifier(last.toString()));
5868  }
5869 
5870  // Resolve rest of identifier
5871  for (; i < id.names.size(); i++) {
5872  String name = id.names.get(i);
5873  final RelDataTypeField field;
5874  if (name.equals("")) {
5875  // The wildcard "*" is represented as an empty name. It never
5876  // resolves to a field.
5877  name = "*";
5878  field = null;
5879  } else {
5880  final SqlNameMatcher nameMatcher = catalogReader.nameMatcher();
5881  field = nameMatcher.field(type, name);
5882  }
5883  if (field == null) {
5884  throw newValidationError(id.getComponent(i),
5885  RESOURCE.unknownField(name));
5886  }
5887  type = field.getType();
5888  }
5889  type =
5890  SqlTypeUtil.addCharsetAndCollation(
5891  type,
5892  getTypeFactory());
5893  return type;
5894  }
SqlValidatorImpl(SqlOperatorTable opTab, SqlValidatorCatalogReader catalogReader, RelDataTypeFactory typeFactory, Config config)
CalciteContextException newValidationError(SqlNode node, Resources.ExInst< SqlValidatorException > e)
const rapidjson::Value & field(const rapidjson::Value &obj, const char field[]) noexcept
Definition: JsonAccessors.h:33
string name
Definition: setup.in.py:72

+ Here is the call graph for this function:

RelDataType org.apache.calcite.sql.validate.SqlValidatorImpl.DeriveTypeVisitor.visit ( SqlDataTypeSpec  dataType)
inline

Definition at line 5896 of file SqlValidatorImpl.java.

References this, and org.apache.calcite.sql.validate.SqlValidatorImpl.validateDataType().

5896  {
5897  // Q. How can a data type have a type?
5898  // A. When it appears in an expression. (Say as the 2nd arg to the
5899  // CAST operator.)
5900  validateDataType(dataType);
5901  return dataType.deriveType(SqlValidatorImpl.this);
5902  }
this
Definition: Execute.cpp:281

+ Here is the call graph for this function:

RelDataType org.apache.calcite.sql.validate.SqlValidatorImpl.DeriveTypeVisitor.visit ( SqlDynamicParam  param)
inline
RelDataType org.apache.calcite.sql.validate.SqlValidatorImpl.DeriveTypeVisitor.visit ( SqlIntervalQualifier  intervalQualifier)
inline

Definition at line 5908 of file SqlValidatorImpl.java.

5908  {
5909  return typeFactory.createSqlIntervalType(intervalQualifier);
5910  }

Member Data Documentation

final SqlValidatorScope org.apache.calcite.sql.validate.SqlValidatorImpl.DeriveTypeVisitor.scope
private

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