OmniSciDB  c1a53651b2
 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 5783 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 5790 of file SqlValidatorImpl.java.

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

5790  {
5791  return literal.createSqlType(typeFactory);
5792  }
RelDataType org.apache.calcite.sql.validate.SqlValidatorImpl.DeriveTypeVisitor.visit ( SqlCall  call)
inline

Definition at line 5794 of file SqlValidatorImpl.java.

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

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

Definition at line 5799 of file SqlValidatorImpl.java.

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

Definition at line 5807 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.

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

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

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

+ 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 5905 of file SqlValidatorImpl.java.

5905  {
5906  return typeFactory.createSqlIntervalType(intervalQualifier);
5907  }

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: