OmniSciDB  a5dc49c757
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
org.apache.calcite.sql2rel.StandardConvertletTable Class Reference
+ Inheritance diagram for org.apache.calcite.sql2rel.StandardConvertletTable:
+ Collaboration diagram for org.apache.calcite.sql2rel.StandardConvertletTable:

Classes

class  AvgVarianceConvertlet
 
class  FloorCeilConvertlet
 
class  GreatestConvertlet
 
class  RegrCovarianceConvertlet
 
class  TimestampAddConvertlet
 
class  TimestampDiffConvertlet
 
class  TrimConvertlet
 

Public Member Functions

RexNode convertCase (SqlRexContext cx, SqlCase call)
 
RexNode convertMultiset (SqlRexContext cx, SqlMultisetValueConstructor op, SqlCall call)
 
RexNode convertArray (SqlRexContext cx, SqlArrayValueConstructor op, SqlCall call)
 
RexNode convertMap (SqlRexContext cx, SqlMapValueConstructor op, SqlCall call)
 
RexNode convertMultisetQuery (SqlRexContext cx, SqlMultisetQueryConstructor op, SqlCall call)
 
RexNode convertJdbc (SqlRexContext cx, SqlJdbcFunctionCall op, SqlCall call)
 
RexNode convertExtract (SqlRexContext cx, SqlExtractFunction op, SqlCall call)
 
RexNode convertDatetimeMinus (SqlRexContext cx, SqlDatetimeSubtractionOperator op, SqlCall call)
 
RexNode convertFunction (SqlRexContext cx, SqlFunction fun, SqlCall call)
 
RexNode convertWindowFunction (SqlRexContext cx, SqlWindowTableFunction fun, SqlCall call)
 
RexNode convertJsonValueFunction (SqlRexContext cx, SqlJsonValueFunction fun, SqlCall call)
 
RexNode convertSequenceValue (SqlRexContext cx, SqlSequenceValueOperator fun, SqlCall call)
 
RexNode convertAggregateFunction (SqlRexContext cx, SqlAggFunction fun, SqlCall call)
 
RexNode convertCall (SqlRexContext cx, SqlCall call)
 
RexNode convertBetween (SqlRexContext cx, SqlBetweenOperator op, SqlCall call)
 
RexNode convertLiteralChain (SqlRexContext cx, SqlLiteralChainOperator op, SqlCall call)
 
RexNode convertRow (SqlRexContext cx, SqlRowOperator op, SqlCall call)
 
RexNode convertOverlaps (SqlRexContext cx, SqlOverlapsOperator op, SqlCall call)
 
RexNode castToValidatedType (SqlRexContext cx, SqlCall call, RexNode value)
 

Static Public Member Functions

static RexNode castToValidatedType (SqlNode node, RexNode e, SqlValidator validator, RexBuilder rexBuilder)
 

Static Public Attributes

static final
StandardConvertletTable 
INSTANCE = new StandardConvertletTable()
 

Protected Member Functions

RexNode convertCast (SqlRexContext cx, final SqlCall call)
 
RexNode convertTryCast (SqlRexContext cx, final SqlCall call)
 
RexNode convertFloorCeil (SqlRexContext cx, SqlCall call)
 

Private Member Functions

 StandardConvertletTable ()
 
RexNode or (RexBuilder rexBuilder, RexNode a0, RexNode a1)
 
RexNode eq (RexBuilder rexBuilder, RexNode a0, RexNode a1)
 
RexNode ge (RexBuilder rexBuilder, RexNode a0, RexNode a1)
 
RexNode le (RexBuilder rexBuilder, RexNode a0, RexNode a1)
 
RexNode and (RexBuilder rexBuilder, RexNode a0, RexNode a1)
 
RexNode plus (RexBuilder rexBuilder, RexNode a0, RexNode a1)
 
RexNode minus (RexBuilder rexBuilder, RexNode a0, RexNode a1)
 
RexNode case_ (RexBuilder rexBuilder, RexNode...args)
 
SqlCall plus (SqlParserPos pos, SqlNode a0, SqlNode a1)
 
RexNode mod (RexBuilder rexBuilder, RelDataType resType, RexNode res, BigDecimal val)
 
RexNode convertCall (SqlRexContext cx, SqlOperator op, List< SqlNode > operands)
 
List< Integer > elseArgs (int count)
 
RexNode convertPlus (SqlRexContext cx, SqlCall call)
 
RexNode convertIsDistinctFrom (SqlRexContext cx, SqlCall call, boolean neg)
 
Pair< RexNode, RexNode > convertOverlapsOperand (SqlRexContext cx, SqlParserPos pos, SqlNode operand)
 

Static Private Member Functions

static RexNode convertInterval (SqlRexContext cx, SqlCall call)
 
static RexNode divideInt (RexBuilder rexBuilder, RexNode a0, RexNode a1)
 
static RexNode multiply (RexBuilder rexBuilder, RexNode a0, RexNode a1)
 
static RexNode divide (RexBuilder rexBuilder, RexNode res, BigDecimal val)
 
static RexNode makeConstructorCall (SqlRexContext cx, SqlFunction constructor, List< RexNode > exprs)
 
static List< RexNode > convertExpressionList (SqlRexContext cx, List< SqlNode > nodes, SqlOperandTypeChecker.Consistency consistency)
 
static RelDataType consistentType (SqlRexContext cx, SqlOperandTypeChecker.Consistency consistency, List< RelDataType > types)
 

Detailed Description

Standard implementation of SqlRexConvertletTable.

Definition at line 95 of file StandardConvertletTable.java.

Constructor & Destructor Documentation

org.apache.calcite.sql2rel.StandardConvertletTable.StandardConvertletTable ( )
inlineprivate

Definition at line 101 of file StandardConvertletTable.java.

References org.apache.calcite.sql2rel.StandardConvertletTable.convertCall(), org.apache.calcite.sql2rel.StandardConvertletTable.convertDatetimeMinus(), org.apache.calcite.sql2rel.StandardConvertletTable.convertIsDistinctFrom(), and com.mapd.calcite.parser.HeavyDBSqlOperatorTable.TRY_CAST.

101  {
102  super();
103 
104  // Register aliases (operators which have a different name but
105  // identical behavior to other operators).
106  addAlias(SqlStdOperatorTable.CHARACTER_LENGTH, SqlStdOperatorTable.CHAR_LENGTH);
107  addAlias(SqlStdOperatorTable.IS_UNKNOWN, SqlStdOperatorTable.IS_NULL);
108  addAlias(SqlStdOperatorTable.IS_NOT_UNKNOWN, SqlStdOperatorTable.IS_NOT_NULL);
109  addAlias(SqlStdOperatorTable.PERCENT_REMAINDER, SqlStdOperatorTable.MOD);
110 
111  // Register convertlets for specific objects.
112  registerOp(SqlStdOperatorTable.CAST, this::convertCast);
113  registerOp(SqlLibraryOperators.INFIX_CAST, this::convertCast);
114 
115  // HEAVY.AI new
116  registerOp(HeavyDBSqlOperatorTable.TRY_CAST, this::convertTryCast);
117  // end HEAVY.AI new
118 
119  registerOp(SqlStdOperatorTable.IS_DISTINCT_FROM,
120  (cx, call) -> convertIsDistinctFrom(cx, call, false));
121  registerOp(SqlStdOperatorTable.IS_NOT_DISTINCT_FROM,
122  (cx, call) -> convertIsDistinctFrom(cx, call, true));
123 
124  registerOp(SqlStdOperatorTable.PLUS, this::convertPlus);
125 
126  registerOp(SqlStdOperatorTable.MINUS, (cx, call) -> {
127  final RexCall e = (RexCall) StandardConvertletTable.this.convertCall(
128  cx, call.getOperator(), call.getOperandList());
129  switch (e.getOperands().get(0).getType().getSqlTypeName()) {
130  case DATE:
131  case TIME:
132  case TIMESTAMP:
133  return convertDatetimeMinus(cx, SqlStdOperatorTable.MINUS_DATE, call);
134  default:
135  return e;
136  }
137  });
138 
139  registerOp(
140  SqlLibraryOperators.LTRIM, new TrimConvertlet(SqlTrimFunction.Flag.LEADING));
141  registerOp(
142  SqlLibraryOperators.RTRIM, new TrimConvertlet(SqlTrimFunction.Flag.TRAILING));
143 
144  registerOp(SqlLibraryOperators.GREATEST, new GreatestConvertlet());
145  registerOp(SqlLibraryOperators.LEAST, new GreatestConvertlet());
146 
147  registerOp(SqlLibraryOperators.NVL, (cx, call) -> {
148  final RexBuilder rexBuilder = cx.getRexBuilder();
149  final RexNode operand0 = cx.convertExpression(call.getOperandList().get(0));
150  final RexNode operand1 = cx.convertExpression(call.getOperandList().get(1));
151  final RelDataType type = cx.getValidator().getValidatedNodeType(call);
152  return rexBuilder.makeCall(type,
153  SqlStdOperatorTable.CASE,
154  ImmutableList.of(
155  rexBuilder.makeCall(SqlStdOperatorTable.IS_NOT_NULL, operand0),
156  rexBuilder.makeCast(type, operand0),
157  rexBuilder.makeCast(type, operand1)));
158  });
159 
160  registerOp(SqlLibraryOperators.DECODE, (cx, call) -> {
161  final RexBuilder rexBuilder = cx.getRexBuilder();
162  final List<RexNode> operands = convertExpressionList(
163  cx, call.getOperandList(), SqlOperandTypeChecker.Consistency.NONE);
164  final RelDataType type = cx.getValidator().getValidatedNodeType(call);
165  final List<RexNode> exprs = new ArrayList<>();
166  for (int i = 1; i < operands.size() - 1; i += 2) {
167  exprs.add(RelOptUtil.isDistinctFrom(
168  rexBuilder, operands.get(0), operands.get(i), true));
169  exprs.add(operands.get(i + 1));
170  }
171  if (operands.size() % 2 == 0) {
172  exprs.add(Util.last(operands));
173  } else {
174  exprs.add(rexBuilder.makeNullLiteral(type));
175  }
176  return rexBuilder.makeCall(type, SqlStdOperatorTable.CASE, exprs);
177  });
178 
179  // Expand "x NOT LIKE y" into "NOT (x LIKE y)"
180  registerOp(SqlStdOperatorTable.NOT_LIKE,
181  (cx, call)
182  -> cx.convertExpression(
183  SqlStdOperatorTable.NOT.createCall(SqlParserPos.ZERO,
184  SqlStdOperatorTable.LIKE.createCall(
185  SqlParserPos.ZERO, call.getOperandList()))));
186 
187  // Expand "x NOT SIMILAR y" into "NOT (x SIMILAR y)"
188  registerOp(SqlStdOperatorTable.NOT_SIMILAR_TO,
189  (cx, call)
190  -> cx.convertExpression(
191  SqlStdOperatorTable.NOT.createCall(SqlParserPos.ZERO,
192  SqlStdOperatorTable.SIMILAR_TO.createCall(
193  SqlParserPos.ZERO, call.getOperandList()))));
194 
195  // Unary "+" has no effect, so expand "+ x" into "x".
196  registerOp(SqlStdOperatorTable.UNARY_PLUS,
197  (cx, call) -> cx.convertExpression(call.operand(0)));
198 
199  // "DOT"
200  registerOp(SqlStdOperatorTable.DOT,
201  (cx, call)
202  -> cx.getRexBuilder().makeFieldAccess(
203  cx.convertExpression(call.operand(0)),
204  call.operand(1).toString(),
205  false));
206  // "AS" has no effect, so expand "x AS id" into "x".
207  registerOp(
208  SqlStdOperatorTable.AS, (cx, call) -> cx.convertExpression(call.operand(0)));
209  // "SQRT(x)" is equivalent to "POWER(x, .5)"
210  registerOp(SqlStdOperatorTable.SQRT,
211  (cx, call)
212  -> cx.convertExpression(SqlStdOperatorTable.POWER.createCall(
213  SqlParserPos.ZERO,
214  call.operand(0),
215  SqlLiteral.createExactNumeric("0.5", SqlParserPos.ZERO))));
216 
217  // REVIEW jvs 24-Apr-2006: This only seems to be working from within a
218  // windowed agg. I have added an optimizer rule
219  // org.apache.calcite.rel.rules.AggregateReduceFunctionsRule which handles
220  // other cases post-translation. The reason I did that was to defer the
221  // implementation decision; e.g. we may want to push it down to a foreign
222  // server directly rather than decomposed; decomposition is easier than
223  // recognition.
224 
225  // Convert "avg(<expr>)" to "cast(sum(<expr>) / count(<expr>) as
226  // <type>)". We don't need to handle the empty set specially, because
227  // the SUM is already supposed to come out as NULL in cases where the
228  // COUNT is zero, so the null check should take place first and prevent
229  // division by zero. We need the cast because SUM and COUNT may use
230  // different types, say BIGINT.
231  //
232  // Similarly STDDEV_POP and STDDEV_SAMP, VAR_POP and VAR_SAMP.
233  registerOp(SqlStdOperatorTable.AVG, new AvgVarianceConvertlet(SqlKind.AVG));
234  registerOp(SqlStdOperatorTable.STDDEV_POP,
235  new AvgVarianceConvertlet(SqlKind.STDDEV_POP));
236  registerOp(SqlStdOperatorTable.STDDEV_SAMP,
237  new AvgVarianceConvertlet(SqlKind.STDDEV_SAMP));
238  registerOp(
239  SqlStdOperatorTable.STDDEV, new AvgVarianceConvertlet(SqlKind.STDDEV_SAMP));
240  registerOp(SqlStdOperatorTable.VAR_POP, new AvgVarianceConvertlet(SqlKind.VAR_POP));
241  registerOp(SqlStdOperatorTable.VAR_SAMP, new AvgVarianceConvertlet(SqlKind.VAR_SAMP));
242  registerOp(SqlStdOperatorTable.VARIANCE, new AvgVarianceConvertlet(SqlKind.VAR_SAMP));
243  registerOp(SqlStdOperatorTable.COVAR_POP,
244  new RegrCovarianceConvertlet(SqlKind.COVAR_POP));
245  registerOp(SqlStdOperatorTable.COVAR_SAMP,
246  new RegrCovarianceConvertlet(SqlKind.COVAR_SAMP));
247  registerOp(
248  SqlStdOperatorTable.REGR_SXX, new RegrCovarianceConvertlet(SqlKind.REGR_SXX));
249  registerOp(
250  SqlStdOperatorTable.REGR_SYY, new RegrCovarianceConvertlet(SqlKind.REGR_SYY));
251 
252  final SqlRexConvertlet floorCeilConvertlet = new FloorCeilConvertlet();
253  registerOp(SqlStdOperatorTable.FLOOR, floorCeilConvertlet);
254  registerOp(SqlStdOperatorTable.CEIL, floorCeilConvertlet);
255 
256  registerOp(SqlStdOperatorTable.TIMESTAMP_ADD, new TimestampAddConvertlet());
257  registerOp(SqlStdOperatorTable.TIMESTAMP_DIFF, new TimestampDiffConvertlet());
258 
259  registerOp(SqlStdOperatorTable.INTERVAL, StandardConvertletTable::convertInterval);
260 
261  // Convert "element(<expr>)" to "$element_slice(<expr>)", if the
262  // expression is a multiset of scalars.
263  if (false) {
264  registerOp(SqlStdOperatorTable.ELEMENT, (cx, call) -> {
265  assert call.operandCount() == 1;
266  final SqlNode operand = call.operand(0);
267  final RelDataType type = cx.getValidator().getValidatedNodeType(operand);
268  if (!type.getComponentType().isStruct()) {
269  return cx.convertExpression(SqlStdOperatorTable.ELEMENT_SLICE.createCall(
270  SqlParserPos.ZERO, operand));
271  }
272 
273  // fallback on default behavior
274  return StandardConvertletTable.this.convertCall(cx, call);
275  });
276  }
277 
278  // Convert "$element_slice(<expr>)" to "element(<expr>).field#0"
279  if (false) {
280  registerOp(SqlStdOperatorTable.ELEMENT_SLICE, (cx, call) -> {
281  assert call.operandCount() == 1;
282  final SqlNode operand = call.operand(0);
283  final RexNode expr = cx.convertExpression(
284  SqlStdOperatorTable.ELEMENT.createCall(SqlParserPos.ZERO, operand));
285  return cx.getRexBuilder().makeFieldAccess(expr, 0);
286  });
287  }
288  }
static RexNode convertInterval(SqlRexContext cx, SqlCall call)
static List< RexNode > convertExpressionList(SqlRexContext cx, List< SqlNode > nodes, SqlOperandTypeChecker.Consistency consistency)
std::string toString(const Executor::ExtModuleKinds &kind)
Definition: Execute.h:1703
RexNode convertIsDistinctFrom(SqlRexContext cx, SqlCall call, boolean neg)
RexNode convertDatetimeMinus(SqlRexContext cx, SqlDatetimeSubtractionOperator op, SqlCall call)

+ Here is the call graph for this function:

Member Function Documentation

RexNode org.apache.calcite.sql2rel.StandardConvertletTable.and ( RexBuilder  rexBuilder,
RexNode  a0,
RexNode  a1 
)
inlineprivate

Definition at line 323 of file StandardConvertletTable.java.

323  {
324  return rexBuilder.makeCall(SqlStdOperatorTable.AND, a0, a1);
325  }
RexNode org.apache.calcite.sql2rel.StandardConvertletTable.case_ ( RexBuilder  rexBuilder,
RexNode...  args 
)
inlineprivate

Definition at line 343 of file StandardConvertletTable.java.

References run_benchmark_import.args.

343  {
344  return rexBuilder.makeCall(SqlStdOperatorTable.CASE, args);
345  }
RexNode org.apache.calcite.sql2rel.StandardConvertletTable.castToValidatedType ( SqlRexContext  cx,
SqlCall  call,
RexNode  value 
)
inline

Casts a RexNode value to the validated type of a SqlCall. If the value was already of the validated type, then the value is returned without an additional cast.

Definition at line 1021 of file StandardConvertletTable.java.

1021  {
1022  return castToValidatedType(call, value, cx.getValidator(), cx.getRexBuilder());
1023  }
RexNode castToValidatedType(SqlRexContext cx, SqlCall call, RexNode value)
static RexNode org.apache.calcite.sql2rel.StandardConvertletTable.castToValidatedType ( SqlNode  node,
RexNode  e,
SqlValidator  validator,
RexBuilder  rexBuilder 
)
inlinestatic

Casts a RexNode value to the validated type of a SqlCall. If the value was already of the validated type, then the value is returned without an additional cast.

Definition at line 1030 of file StandardConvertletTable.java.

References run_benchmark_import.type.

1031  {
1032  final RelDataType type = validator.getValidatedNodeType(node);
1033  if (e.getType() == type) {
1034  return e;
1035  }
1036  return rexBuilder.makeCast(type, e);
1037  }
static RelDataType org.apache.calcite.sql2rel.StandardConvertletTable.consistentType ( SqlRexContext  cx,
SqlOperandTypeChecker.Consistency  consistency,
List< RelDataType >  types 
)
inlinestaticprivate

Definition at line 787 of file StandardConvertletTable.java.

References run_benchmark_import.type.

789  {
790  switch (consistency) {
791  case COMPARE:
792  if (SqlTypeUtil.areSameFamily(types)) {
793  // All arguments are of same family. No need for explicit casts.
794  return null;
795  }
796  final List<RelDataType> nonCharacterTypes = new ArrayList<>();
797  for (RelDataType type : types) {
798  if (type.getFamily() != SqlTypeFamily.CHARACTER) {
799  nonCharacterTypes.add(type);
800  }
801  }
802  if (!nonCharacterTypes.isEmpty()) {
803  final int typeCount = types.size();
804  types = nonCharacterTypes;
805  if (nonCharacterTypes.size() < typeCount) {
806  final RelDataTypeFamily family = nonCharacterTypes.get(0).getFamily();
807  if (family instanceof SqlTypeFamily) {
808  // The character arguments might be larger than the numeric
809  // argument. Give ourselves some headroom.
810  switch ((SqlTypeFamily) family) {
811  case INTEGER:
812  case NUMERIC:
813  nonCharacterTypes.add(
814  cx.getTypeFactory().createSqlType(SqlTypeName.BIGINT));
815  }
816  }
817  }
818  }
819  // fall through
820  case LEAST_RESTRICTIVE:
821  return cx.getTypeFactory().leastRestrictive(types);
822  default:
823  return null;
824  }
825  }
RexNode org.apache.calcite.sql2rel.StandardConvertletTable.convertAggregateFunction ( SqlRexContext  cx,
SqlAggFunction  fun,
SqlCall  call 
)
inline

Definition at line 667 of file StandardConvertletTable.java.

668  {
669  final List<SqlNode> operands = call.getOperandList();
670  final List<RexNode> exprs;
671  if (call.isCountStar()) {
672  exprs = ImmutableList.of();
673  } else {
674  exprs = convertExpressionList(cx, operands, SqlOperandTypeChecker.Consistency.NONE);
675  }
676  RelDataType returnType = cx.getValidator().getValidatedNodeTypeIfKnown(call);
677  final int groupCount = cx.getGroupCount();
678  if (returnType == null) {
679  RexCallBinding binding =
680  new RexCallBinding(cx.getTypeFactory(), fun, exprs, ImmutableList.of()) {
681  @Override
682  public int getGroupCount() {
683  return groupCount;
684  }
685  };
686  returnType = fun.inferReturnType(binding);
687  }
688  return cx.getRexBuilder().makeCall(returnType, fun, exprs);
689  }
static List< RexNode > convertExpressionList(SqlRexContext cx, List< SqlNode > nodes, SqlOperandTypeChecker.Consistency consistency)
RexNode org.apache.calcite.sql2rel.StandardConvertletTable.convertArray ( SqlRexContext  cx,
SqlArrayValueConstructor  op,
SqlCall  call 
)
inline

Definition at line 414 of file StandardConvertletTable.java.

415  {
416  return convertCall(cx, call);
417  }
RexNode convertCall(SqlRexContext cx, SqlCall call)
RexNode org.apache.calcite.sql2rel.StandardConvertletTable.convertBetween ( SqlRexContext  cx,
SqlBetweenOperator  op,
SqlCall  call 
)
inline

Converts a BETWEEN expression.

Called automatically via reflection.

Definition at line 874 of file StandardConvertletTable.java.

References run_benchmark_import.res.

874  {
875  final List<RexNode> list = convertExpressionList(
876  cx, call.getOperandList(), op.getOperandTypeChecker().getConsistency());
877  final RexNode x = list.get(SqlBetweenOperator.VALUE_OPERAND);
878  final RexNode y = list.get(SqlBetweenOperator.LOWER_OPERAND);
879  final RexNode z = list.get(SqlBetweenOperator.UPPER_OPERAND);
880 
881  final RexBuilder rexBuilder = cx.getRexBuilder();
882  RexNode ge1 = ge(rexBuilder, x, y);
883  RexNode le1 = le(rexBuilder, x, z);
884  RexNode and1 = and(rexBuilder, ge1, le1);
885 
886  RexNode res;
887  final SqlBetweenOperator.Flag symmetric = op.flag;
888  switch (symmetric) {
889  case ASYMMETRIC:
890  res = and1;
891  break;
892  case SYMMETRIC:
893  RexNode ge2 = ge(rexBuilder, x, z);
894  RexNode le2 = le(rexBuilder, x, y);
895  RexNode and2 = and(rexBuilder, ge2, le2);
896  res = or(rexBuilder, and1, and2);
897  break;
898  default:
899  throw Util.unexpected(symmetric);
900  }
901  final SqlBetweenOperator betweenOp = (SqlBetweenOperator) call.getOperator();
902  if (betweenOp.isNegated()) {
903  res = rexBuilder.makeCall(SqlStdOperatorTable.NOT, res);
904  }
905  return res;
906  }
RexNode ge(RexBuilder rexBuilder, RexNode a0, RexNode a1)
RexNode or(RexBuilder rexBuilder, RexNode a0, RexNode a1)
RexNode and(RexBuilder rexBuilder, RexNode a0, RexNode a1)
static List< RexNode > convertExpressionList(SqlRexContext cx, List< SqlNode > nodes, SqlOperandTypeChecker.Consistency consistency)
RexNode le(RexBuilder rexBuilder, RexNode a0, RexNode a1)
RexNode org.apache.calcite.sql2rel.StandardConvertletTable.convertCall ( SqlRexContext  cx,
SqlCall  call 
)
inline

Converts a call to an operator into a RexCall to the same operator.

Called automatically via reflection.

Parameters
cxContext
callCall
Returns
Rex call

Definition at line 733 of file StandardConvertletTable.java.

Referenced by org.apache.calcite.sql2rel.StandardConvertletTable.StandardConvertletTable().

733  {
734  return convertCall(cx, call.getOperator(), call.getOperandList());
735  }
RexNode convertCall(SqlRexContext cx, SqlCall call)

+ Here is the caller graph for this function:

RexNode org.apache.calcite.sql2rel.StandardConvertletTable.convertCall ( SqlRexContext  cx,
SqlOperator  op,
List< SqlNode >  operands 
)
inlineprivate

Converts a SqlCall to a RexCall with a perhaps different operator.

Definition at line 741 of file StandardConvertletTable.java.

References org.apache.calcite.sql.SqlOperator.getOperandTypeChecker(), and run_benchmark_import.type.

741  {
742  final RexBuilder rexBuilder = cx.getRexBuilder();
743  final SqlOperandTypeChecker.Consistency consistency =
744  op.getOperandTypeChecker() == null
745  ? SqlOperandTypeChecker.Consistency.NONE
746  : op.getOperandTypeChecker().getConsistency();
747  final List<RexNode> exprs = convertExpressionList(cx, operands, consistency);
748  RelDataType type = rexBuilder.deriveReturnType(op, exprs);
749  return rexBuilder.makeCall(type, op, RexUtil.flatten(exprs, op));
750  }
static List< RexNode > convertExpressionList(SqlRexContext cx, List< SqlNode > nodes, SqlOperandTypeChecker.Consistency consistency)

+ Here is the call graph for this function:

RexNode org.apache.calcite.sql2rel.StandardConvertletTable.convertCase ( SqlRexContext  cx,
SqlCase  call 
)
inline

Converts a CASE expression.

Definition at line 356 of file StandardConvertletTable.java.

References run_benchmark_import.type.

356  {
357  SqlNodeList whenList = call.getWhenOperands();
358  SqlNodeList thenList = call.getThenOperands();
359  assert whenList.size() == thenList.size();
360 
361  RexBuilder rexBuilder = cx.getRexBuilder();
362  final List<RexNode> exprList = new ArrayList<>();
363  final RelDataTypeFactory typeFactory = rexBuilder.getTypeFactory();
364  final RexLiteral unknownLiteral =
365  rexBuilder.makeNullLiteral(typeFactory.createSqlType(SqlTypeName.BOOLEAN));
366  final RexLiteral nullLiteral =
367  rexBuilder.makeNullLiteral(typeFactory.createSqlType(SqlTypeName.NULL));
368  for (int i = 0; i < whenList.size(); i++) {
369  if (SqlUtil.isNullLiteral(whenList.get(i), false)) {
370  exprList.add(unknownLiteral);
371  } else {
372  exprList.add(cx.convertExpression(whenList.get(i)));
373  }
374  if (SqlUtil.isNullLiteral(thenList.get(i), false)) {
375  exprList.add(nullLiteral);
376  } else {
377  exprList.add(cx.convertExpression(thenList.get(i)));
378  }
379  }
380  if (SqlUtil.isNullLiteral(call.getElseOperand(), false)) {
381  exprList.add(nullLiteral);
382  } else {
383  exprList.add(cx.convertExpression(call.getElseOperand()));
384  }
385 
386  RelDataType type = rexBuilder.deriveReturnType(call.getOperator(), exprList);
387  for (int i : elseArgs(exprList.size())) {
388  exprList.set(i, rexBuilder.ensureType(type, exprList.get(i), false));
389  }
390  return rexBuilder.makeCall(type, SqlStdOperatorTable.CASE, exprList);
391  }
RexNode org.apache.calcite.sql2rel.StandardConvertletTable.convertCast ( SqlRexContext  cx,
final SqlCall  call 
)
inlineprotected

Definition at line 450 of file StandardConvertletTable.java.

References run_benchmark_import.type.

450  {
451  RelDataTypeFactory typeFactory = cx.getTypeFactory();
452  assert call.getKind() == SqlKind.CAST;
453  final SqlNode left = call.operand(0);
454  final SqlNode right = call.operand(1);
455  if (right instanceof SqlIntervalQualifier) {
456  final SqlIntervalQualifier intervalQualifier = (SqlIntervalQualifier) right;
457  if (left instanceof SqlIntervalLiteral) {
458  RexLiteral sourceInterval = (RexLiteral) cx.convertExpression(left);
459  BigDecimal sourceValue = (BigDecimal) sourceInterval.getValue();
460  RexLiteral castedInterval =
461  cx.getRexBuilder().makeIntervalLiteral(sourceValue, intervalQualifier);
462  return castToValidatedType(cx, call, castedInterval);
463  } else if (left instanceof SqlNumericLiteral) {
464  RexLiteral sourceInterval = (RexLiteral) cx.convertExpression(left);
465  BigDecimal sourceValue = (BigDecimal) sourceInterval.getValue();
466  final BigDecimal multiplier = intervalQualifier.getUnit().multiplier;
467  sourceValue = sourceValue.multiply(multiplier);
468  RexLiteral castedInterval =
469  cx.getRexBuilder().makeIntervalLiteral(sourceValue, intervalQualifier);
470  return castToValidatedType(cx, call, castedInterval);
471  }
472  return castToValidatedType(cx, call, cx.convertExpression(left));
473  }
474  SqlDataTypeSpec dataType = (SqlDataTypeSpec) right;
475  RelDataType type = dataType.deriveType(cx.getValidator());
476  if (type == null) {
477  type = cx.getValidator().getValidatedNodeType(dataType.getTypeName());
478  }
479  RexNode arg = cx.convertExpression(left);
480  if (arg.getType().isNullable()) {
481  type = typeFactory.createTypeWithNullability(type, true);
482  }
483  if (SqlUtil.isNullLiteral(left, false)) {
484  final SqlValidatorImpl validator = (SqlValidatorImpl) cx.getValidator();
485  validator.setValidatedNodeType(left, type);
486  return cx.convertExpression(left);
487  }
488  if (null != dataType.getCollectionsTypeName()) {
489  final RelDataType argComponentType = arg.getType().getComponentType();
490  final RelDataType componentType = type.getComponentType();
491  if (argComponentType.isStruct() && !componentType.isStruct()) {
492  RelDataType tt = typeFactory.builder()
493  .add(argComponentType.getFieldList().get(0).getName(),
494  componentType)
495  .build();
496  tt = typeFactory.createTypeWithNullability(tt, componentType.isNullable());
497  boolean isn = type.isNullable();
498  type = typeFactory.createMultisetType(tt, -1);
499  type = typeFactory.createTypeWithNullability(type, isn);
500  }
501  }
502  return cx.getRexBuilder().makeCast(type, arg);
503  }
RexNode castToValidatedType(SqlRexContext cx, SqlCall call, RexNode value)
RexNode org.apache.calcite.sql2rel.StandardConvertletTable.convertDatetimeMinus ( SqlRexContext  cx,
SqlDatetimeSubtractionOperator  op,
SqlCall  call 
)
inline

Definition at line 599 of file StandardConvertletTable.java.

Referenced by org.apache.calcite.sql2rel.StandardConvertletTable.StandardConvertletTable().

600  {
601  // Rewrite datetime minus
602  final RexBuilder rexBuilder = cx.getRexBuilder();
603  final List<SqlNode> operands = call.getOperandList();
604  final List<RexNode> exprs =
605  convertExpressionList(cx, operands, SqlOperandTypeChecker.Consistency.NONE);
606 
607  final RelDataType resType = cx.getValidator().getValidatedNodeType(call);
608  return rexBuilder.makeCall(resType, op, exprs.subList(0, 2));
609  }
static List< RexNode > convertExpressionList(SqlRexContext cx, List< SqlNode > nodes, SqlOperandTypeChecker.Consistency consistency)

+ Here is the caller graph for this function:

static List<RexNode> org.apache.calcite.sql2rel.StandardConvertletTable.convertExpressionList ( SqlRexContext  cx,
List< SqlNode >  nodes,
SqlOperandTypeChecker.Consistency  consistency 
)
inlinestaticprivate

Definition at line 767 of file StandardConvertletTable.java.

References run_benchmark_import.type.

769  {
770  final List<RexNode> exprs = new ArrayList<>();
771  for (SqlNode node : nodes) {
772  exprs.add(cx.convertExpression(node));
773  }
774  if (exprs.size() > 1) {
775  final RelDataType type = consistentType(cx, consistency, RexUtil.types(exprs));
776  if (type != null) {
777  final List<RexNode> oldExprs = Lists.newArrayList(exprs);
778  exprs.clear();
779  for (RexNode expr : oldExprs) {
780  exprs.add(cx.getRexBuilder().ensureType(type, expr, true));
781  }
782  }
783  }
784  return exprs;
785  }
static RelDataType consistentType(SqlRexContext cx, SqlOperandTypeChecker.Consistency consistency, List< RelDataType > types)
RexNode org.apache.calcite.sql2rel.StandardConvertletTable.convertExtract ( SqlRexContext  cx,
SqlExtractFunction  op,
SqlCall  call 
)
inline

Converts a call to the

EXTRACT

function.

Called automatically via reflection.

Definition at line 568 of file StandardConvertletTable.java.

568  {
569  return convertFunction(cx, (SqlFunction) call.getOperator(), call);
570  }
RexNode convertFunction(SqlRexContext cx, SqlFunction fun, SqlCall call)
RexNode org.apache.calcite.sql2rel.StandardConvertletTable.convertFloorCeil ( SqlRexContext  cx,
SqlCall  call 
)
inlineprotected

Definition at line 531 of file StandardConvertletTable.java.

531  {
532  final boolean floor = call.getKind() == SqlKind.FLOOR;
533  // Rewrite floor, ceil of interval
534  if (call.operandCount() == 1 && call.operand(0) instanceof SqlIntervalLiteral) {
535  final SqlIntervalLiteral literal = call.operand(0);
536  SqlIntervalLiteral.IntervalValue interval =
537  literal.getValueAs(SqlIntervalLiteral.IntervalValue.class);
538  BigDecimal val = interval.getIntervalQualifier().getStartUnit().multiplier;
539  RexNode rexInterval = cx.convertExpression(literal);
540 
541  final RexBuilder rexBuilder = cx.getRexBuilder();
542  RexNode zero = rexBuilder.makeExactLiteral(BigDecimal.valueOf(0));
543  RexNode cond = ge(rexBuilder, rexInterval, zero);
544 
545  RexNode pad = rexBuilder.makeExactLiteral(val.subtract(BigDecimal.ONE));
546  RexNode cast = rexBuilder.makeReinterpretCast(
547  rexInterval.getType(), pad, rexBuilder.makeLiteral(false));
548  RexNode sum = floor ? minus(rexBuilder, rexInterval, cast)
549  : plus(rexBuilder, rexInterval, cast);
550 
551  RexNode kase = floor ? case_(rexBuilder, rexInterval, cond, sum)
552  : case_(rexBuilder, sum, cond, rexInterval);
553 
554  RexNode factor = rexBuilder.makeExactLiteral(val);
555  RexNode div = divideInt(rexBuilder, kase, factor);
556  return multiply(rexBuilder, div, factor);
557  }
558 
559  // normal floor, ceil function
560  return convertFunction(cx, (SqlFunction) call.getOperator(), call);
561  }
RexNode ge(RexBuilder rexBuilder, RexNode a0, RexNode a1)
RexNode plus(RexBuilder rexBuilder, RexNode a0, RexNode a1)
static RexNode multiply(RexBuilder rexBuilder, RexNode a0, RexNode a1)
RexNode convertFunction(SqlRexContext cx, SqlFunction fun, SqlCall call)
static RexNode divideInt(RexBuilder rexBuilder, RexNode a0, RexNode a1)
RexNode minus(RexBuilder rexBuilder, RexNode a0, RexNode a1)
RexNode case_(RexBuilder rexBuilder, RexNode...args)
RexNode org.apache.calcite.sql2rel.StandardConvertletTable.convertFunction ( SqlRexContext  cx,
SqlFunction  fun,
SqlCall  call 
)
inline

Definition at line 611 of file StandardConvertletTable.java.

611  {
612  final List<SqlNode> operands = call.getOperandList();
613  final List<RexNode> exprs =
614  convertExpressionList(cx, operands, SqlOperandTypeChecker.Consistency.NONE);
615  if (fun.getFunctionType() == SqlFunctionCategory.USER_DEFINED_CONSTRUCTOR) {
616  return makeConstructorCall(cx, fun, exprs);
617  }
618  RelDataType returnType = cx.getValidator().getValidatedNodeTypeIfKnown(call);
619  if (returnType == null) {
620  returnType = cx.getRexBuilder().deriveReturnType(fun, exprs);
621  }
622  return cx.getRexBuilder().makeCall(returnType, fun, exprs);
623  }
static List< RexNode > convertExpressionList(SqlRexContext cx, List< SqlNode > nodes, SqlOperandTypeChecker.Consistency consistency)
static RexNode makeConstructorCall(SqlRexContext cx, SqlFunction constructor, List< RexNode > exprs)
static RexNode org.apache.calcite.sql2rel.StandardConvertletTable.convertInterval ( SqlRexContext  cx,
SqlCall  call 
)
inlinestaticprivate

Converts an interval expression to a numeric multiplied by an interval literal.

Definition at line 294 of file StandardConvertletTable.java.

References anonymous_namespace{Utm.h}.n.

294  {
295  // "INTERVAL n HOUR" becomes "n * INTERVAL '1' HOUR"
296  final SqlNode n = call.operand(0);
297  final SqlIntervalQualifier intervalQualifier = call.operand(1);
298  final SqlIntervalLiteral literal = SqlLiteral.createInterval(
299  1, "1", intervalQualifier, call.getParserPosition());
300  final SqlCall multiply =
301  SqlStdOperatorTable.MULTIPLY.createCall(call.getParserPosition(), n, literal);
302  return cx.convertExpression(multiply);
303  }
static RexNode multiply(RexBuilder rexBuilder, RexNode a0, RexNode a1)
constexpr double n
Definition: Utm.h:38
RexNode org.apache.calcite.sql2rel.StandardConvertletTable.convertIsDistinctFrom ( SqlRexContext  cx,
SqlCall  call,
boolean  neg 
)
inlineprivate

Definition at line 863 of file StandardConvertletTable.java.

Referenced by org.apache.calcite.sql2rel.StandardConvertletTable.StandardConvertletTable().

863  {
864  RexNode op0 = cx.convertExpression(call.operand(0));
865  RexNode op1 = cx.convertExpression(call.operand(1));
866  return RelOptUtil.isDistinctFrom(cx.getRexBuilder(), op0, op1, neg);
867  }

+ Here is the caller graph for this function:

RexNode org.apache.calcite.sql2rel.StandardConvertletTable.convertJdbc ( SqlRexContext  cx,
SqlJdbcFunctionCall  op,
SqlCall  call 
)
inline

Definition at line 443 of file StandardConvertletTable.java.

443  {
444  // Yuck!! The function definition contains arguments!
445  // TODO: adopt a more conventional definition/instance structure
446  final SqlCall convertedCall = op.getLookupCall();
447  return cx.convertExpression(convertedCall);
448  }
RexNode org.apache.calcite.sql2rel.StandardConvertletTable.convertJsonValueFunction ( SqlRexContext  cx,
SqlJsonValueFunction  fun,
SqlCall  call 
)
inline

Definition at line 638 of file StandardConvertletTable.java.

639  {
640  // For Expression with explicit return type:
641  // i.e. json_value('{"foo":"bar"}', 'lax $.foo', returning varchar(2000))
642  // use the specified type as the return type.
643  List<SqlNode> operands = call.getOperandList();
644  boolean hasExplicitReturningType = SqlJsonValueFunction.hasExplicitTypeSpec(
645  operands.toArray(SqlNode.EMPTY_ARRAY));
646  if (hasExplicitReturningType) {
647  operands = SqlJsonValueFunction.removeTypeSpecOperands(call);
648  }
649  final List<RexNode> exprs =
650  convertExpressionList(cx, operands, SqlOperandTypeChecker.Consistency.NONE);
651  RelDataType returnType = cx.getValidator().getValidatedNodeTypeIfKnown(call);
652  return cx.getRexBuilder().makeCall(returnType, fun, exprs);
653  }
static List< RexNode > convertExpressionList(SqlRexContext cx, List< SqlNode > nodes, SqlOperandTypeChecker.Consistency consistency)
RexNode org.apache.calcite.sql2rel.StandardConvertletTable.convertLiteralChain ( SqlRexContext  cx,
SqlLiteralChainOperator  op,
SqlCall  call 
)
inline

Converts a LiteralChain expression: that is, concatenates the operands immediately, to produce a single literal string.

Called automatically via reflection.

Definition at line 914 of file StandardConvertletTable.java.

915  {
916  Util.discard(cx);
917 
918  SqlLiteral sum = SqlLiteralChainOperator.concatenateOperands(call);
919  return cx.convertLiteral(sum);
920  }
RexNode org.apache.calcite.sql2rel.StandardConvertletTable.convertMap ( SqlRexContext  cx,
SqlMapValueConstructor  op,
SqlCall  call 
)
inline

Definition at line 419 of file StandardConvertletTable.java.

419  {
420  return convertCall(cx, call);
421  }
RexNode convertCall(SqlRexContext cx, SqlCall call)
RexNode org.apache.calcite.sql2rel.StandardConvertletTable.convertMultiset ( SqlRexContext  cx,
SqlMultisetValueConstructor  op,
SqlCall  call 
)
inline

Definition at line 393 of file StandardConvertletTable.java.

394  {
395  final RelDataType originalType = cx.getValidator().getValidatedNodeType(call);
396  RexRangeRef rr = cx.getSubQueryExpr(call);
397  assert rr != null;
398  RelDataType msType = rr.getType().getFieldList().get(0).getType();
399  RexNode expr = cx.getRexBuilder().makeInputRef(msType, rr.getOffset());
400  assert msType.getComponentType().isStruct();
401  if (!originalType.getComponentType().isStruct()) {
402  // If the type is not a struct, the multiset operator will have
403  // wrapped the type as a record. Add a call to the $SLICE operator
404  // to compensate. For example,
405  // if '<ms>' has type 'RECORD (INTEGER x) MULTISET',
406  // then '$SLICE(<ms>) has type 'INTEGER MULTISET'.
407  // This will be removed as the expression is translated.
408  expr = cx.getRexBuilder().makeCall(
409  originalType, SqlStdOperatorTable.SLICE, ImmutableList.of(expr));
410  }
411  return expr;
412  }
RexNode org.apache.calcite.sql2rel.StandardConvertletTable.convertMultisetQuery ( SqlRexContext  cx,
SqlMultisetQueryConstructor  op,
SqlCall  call 
)
inline

Definition at line 423 of file StandardConvertletTable.java.

424  {
425  final RelDataType originalType = cx.getValidator().getValidatedNodeType(call);
426  RexRangeRef rr = cx.getSubQueryExpr(call);
427  assert rr != null;
428  RelDataType msType = rr.getType().getFieldList().get(0).getType();
429  RexNode expr = cx.getRexBuilder().makeInputRef(msType, rr.getOffset());
430  assert msType.getComponentType().isStruct();
431  if (!originalType.getComponentType().isStruct()) {
432  // If the type is not a struct, the multiset operator will have
433  // wrapped the type as a record. Add a call to the $SLICE operator
434  // to compensate. For example,
435  // if '<ms>' has type 'RECORD (INTEGER x) MULTISET',
436  // then '$SLICE(<ms>) has type 'INTEGER MULTISET'.
437  // This will be removed as the expression is translated.
438  expr = cx.getRexBuilder().makeCall(SqlStdOperatorTable.SLICE, expr);
439  }
440  return expr;
441  }
RexNode org.apache.calcite.sql2rel.StandardConvertletTable.convertOverlaps ( SqlRexContext  cx,
SqlOverlapsOperator  op,
SqlCall  call 
)
inline

Converts a call to OVERLAPS.

Called automatically via reflection.

Definition at line 947 of file StandardConvertletTable.java.

947  {
948  // for intervals [t0, t1] overlaps [t2, t3], we can find if the
949  // intervals overlaps by: ~(t1 < t2 or t3 < t0)
950  assert call.getOperandList().size() == 2;
951 
952  final Pair<RexNode, RexNode> left =
953  convertOverlapsOperand(cx, call.getParserPosition(), call.operand(0));
954  final RexNode r0 = left.left;
955  final RexNode r1 = left.right;
956  final Pair<RexNode, RexNode> right =
957  convertOverlapsOperand(cx, call.getParserPosition(), call.operand(1));
958  final RexNode r2 = right.left;
959  final RexNode r3 = right.right;
960 
961  // Sort end points into start and end, such that (s0 <= e0) and (s1 <= e1).
962  final RexBuilder rexBuilder = cx.getRexBuilder();
963  RexNode leftSwap = le(rexBuilder, r0, r1);
964  final RexNode s0 = case_(rexBuilder, leftSwap, r0, r1);
965  final RexNode e0 = case_(rexBuilder, leftSwap, r1, r0);
966  RexNode rightSwap = le(rexBuilder, r2, r3);
967  final RexNode s1 = case_(rexBuilder, rightSwap, r2, r3);
968  final RexNode e1 = case_(rexBuilder, rightSwap, r3, r2);
969  // (e0 >= s1) AND (e1 >= s0)
970  switch (op.kind) {
971  case OVERLAPS:
972  return and(rexBuilder, ge(rexBuilder, e0, s1), ge(rexBuilder, e1, s0));
973  case CONTAINS:
974  return and(rexBuilder, le(rexBuilder, s0, s1), ge(rexBuilder, e0, e1));
975  case PERIOD_EQUALS:
976  return and(rexBuilder, eq(rexBuilder, s0, s1), eq(rexBuilder, e0, e1));
977  case PRECEDES:
978  return le(rexBuilder, e0, s1);
979  case IMMEDIATELY_PRECEDES:
980  return eq(rexBuilder, e0, s1);
981  case SUCCEEDS:
982  return ge(rexBuilder, s0, e1);
983  case IMMEDIATELY_SUCCEEDS:
984  return eq(rexBuilder, s0, e1);
985  default:
986  throw new AssertionError(op);
987  }
988  }
RexNode ge(RexBuilder rexBuilder, RexNode a0, RexNode a1)
RexNode eq(RexBuilder rexBuilder, RexNode a0, RexNode a1)
Pair< RexNode, RexNode > convertOverlapsOperand(SqlRexContext cx, SqlParserPos pos, SqlNode operand)
RexNode and(RexBuilder rexBuilder, RexNode a0, RexNode a1)
RexNode le(RexBuilder rexBuilder, RexNode a0, RexNode a1)
RexNode case_(RexBuilder rexBuilder, RexNode...args)
Pair<RexNode, RexNode> org.apache.calcite.sql2rel.StandardConvertletTable.convertOverlapsOperand ( SqlRexContext  cx,
SqlParserPos  pos,
SqlNode  operand 
)
inlineprivate

Definition at line 990 of file StandardConvertletTable.java.

991  {
992  final SqlNode a0;
993  final SqlNode a1;
994  switch (operand.getKind()) {
995  case ROW:
996  a0 = ((SqlCall) operand).operand(0);
997  final SqlNode a10 = ((SqlCall) operand).operand(1);
998  final RelDataType t1 = cx.getValidator().getValidatedNodeType(a10);
999  if (SqlTypeUtil.isInterval(t1)) {
1000  // make t1 = t0 + t1 when t1 is an interval.
1001  a1 = plus(pos, a0, a10);
1002  } else {
1003  a1 = a10;
1004  }
1005  break;
1006  default:
1007  a0 = operand;
1008  a1 = operand;
1009  }
1010 
1011  final RexNode r0 = cx.convertExpression(a0);
1012  final RexNode r1 = cx.convertExpression(a1);
1013  return Pair.of(r0, r1);
1014  }
RexNode plus(RexBuilder rexBuilder, RexNode a0, RexNode a1)
RexNode org.apache.calcite.sql2rel.StandardConvertletTable.convertPlus ( SqlRexContext  cx,
SqlCall  call 
)
inlineprivate

Definition at line 827 of file StandardConvertletTable.java.

827  {
828  final RexNode rex = convertCall(cx, call);
829  switch (rex.getType().getSqlTypeName()) {
830  case DATE:
831  case TIME:
832  case TIMESTAMP:
833  // Use special "+" operator for datetime + interval.
834  // Re-order operands, if necessary, so that interval is second.
835  final RexBuilder rexBuilder = cx.getRexBuilder();
836  List<RexNode> operands = ((RexCall) rex).getOperands();
837  if (operands.size() == 2) {
838  final SqlTypeName sqlTypeName = operands.get(0).getType().getSqlTypeName();
839  switch (sqlTypeName) {
840  case INTERVAL_YEAR:
841  case INTERVAL_YEAR_MONTH:
842  case INTERVAL_MONTH:
843  case INTERVAL_DAY:
844  case INTERVAL_DAY_HOUR:
845  case INTERVAL_DAY_MINUTE:
846  case INTERVAL_DAY_SECOND:
847  case INTERVAL_HOUR:
848  case INTERVAL_HOUR_MINUTE:
849  case INTERVAL_HOUR_SECOND:
850  case INTERVAL_MINUTE:
851  case INTERVAL_MINUTE_SECOND:
852  case INTERVAL_SECOND:
853  operands = ImmutableList.of(operands.get(1), operands.get(0));
854  }
855  }
856  return rexBuilder.makeCall(
857  rex.getType(), SqlStdOperatorTable.DATETIME_PLUS, operands);
858  default:
859  return rex;
860  }
861  }
RexNode convertCall(SqlRexContext cx, SqlCall call)
RexNode org.apache.calcite.sql2rel.StandardConvertletTable.convertRow ( SqlRexContext  cx,
SqlRowOperator  op,
SqlCall  call 
)
inline

Converts a ROW.

Called automatically via reflection.

Definition at line 927 of file StandardConvertletTable.java.

References run_benchmark_import.type.

927  {
928  if (cx.getValidator().getValidatedNodeType(call).getSqlTypeName()
929  != SqlTypeName.COLUMN_LIST) {
930  return convertCall(cx, call);
931  }
932  final RexBuilder rexBuilder = cx.getRexBuilder();
933  final List<RexNode> columns = new ArrayList<>();
934  for (SqlNode operand : call.getOperandList()) {
935  columns.add(rexBuilder.makeLiteral(((SqlIdentifier) operand).getSimple()));
936  }
937  final RelDataType type =
938  rexBuilder.deriveReturnType(SqlStdOperatorTable.COLUMN_LIST, columns);
939  return rexBuilder.makeCall(type, SqlStdOperatorTable.COLUMN_LIST, columns);
940  }
RexNode convertCall(SqlRexContext cx, SqlCall call)
RexNode org.apache.calcite.sql2rel.StandardConvertletTable.convertSequenceValue ( SqlRexContext  cx,
SqlSequenceValueOperator  fun,
SqlCall  call 
)
inline

Definition at line 655 of file StandardConvertletTable.java.

656  {
657  final List<SqlNode> operands = call.getOperandList();
658  assert operands.size() == 1;
659  assert operands.get(0) instanceof SqlIdentifier;
660  final SqlIdentifier id = (SqlIdentifier) operands.get(0);
661  final String key = Util.listToString(id.names);
662  RelDataType returnType = cx.getValidator().getValidatedNodeType(call);
663  return cx.getRexBuilder().makeCall(
664  returnType, fun, ImmutableList.of(cx.getRexBuilder().makeLiteral(key)));
665  }
RexNode org.apache.calcite.sql2rel.StandardConvertletTable.convertTryCast ( SqlRexContext  cx,
final SqlCall  call 
)
inlineprotected

Definition at line 506 of file StandardConvertletTable.java.

References com.mapd.calcite.parser.HeavyDBSqlOperatorTable.TRY_CAST, and run_benchmark_import.type.

506  {
507  RelDataTypeFactory typeFactory = cx.getTypeFactory();
508  // assert call.getKind() == SqlKind.CAST;
509  final SqlNode left = call.operand(0);
510  final SqlNode right = call.operand(1);
511 
512  SqlDataTypeSpec dataType = (SqlDataTypeSpec) right;
513  RelDataType type = dataType.deriveType(cx.getValidator());
514  if (type == null) {
515  type = cx.getValidator().getValidatedNodeType(dataType.getTypeName());
516  }
517  RexNode arg = cx.convertExpression(left);
518  if (arg.getType().isNullable()) {
519  type = typeFactory.createTypeWithNullability(type, true);
520  }
521  if (SqlUtil.isNullLiteral(left, false)) {
522  final SqlValidatorImpl validator = (SqlValidatorImpl) cx.getValidator();
523  validator.setValidatedNodeType(left, type);
524  return cx.convertExpression(left);
525  }
526  return cx.getRexBuilder().makeCall(
527  type, HeavyDBSqlOperatorTable.TRY_CAST, ImmutableList.of(arg));
528  }
RexNode org.apache.calcite.sql2rel.StandardConvertletTable.convertWindowFunction ( SqlRexContext  cx,
SqlWindowTableFunction  fun,
SqlCall  call 
)
inline

Definition at line 625 of file StandardConvertletTable.java.

626  {
627  // The first operand of window function is actually a query, skip that.
628  final List<SqlNode> operands = Util.skip(call.getOperandList(), 1);
629  final List<RexNode> exprs =
630  convertExpressionList(cx, operands, SqlOperandTypeChecker.Consistency.NONE);
631  RelDataType returnType = cx.getValidator().getValidatedNodeTypeIfKnown(call);
632  if (returnType == null) {
633  returnType = cx.getRexBuilder().deriveReturnType(fun, exprs);
634  }
635  return cx.getRexBuilder().makeCall(returnType, fun, exprs);
636  }
static List< RexNode > convertExpressionList(SqlRexContext cx, List< SqlNode > nodes, SqlOperandTypeChecker.Consistency consistency)
static RexNode org.apache.calcite.sql2rel.StandardConvertletTable.divide ( RexBuilder  rexBuilder,
RexNode  res,
BigDecimal  val 
)
inlinestaticprivate

Definition at line 581 of file StandardConvertletTable.java.

References run_benchmark_import.res.

581  {
582  if (val.equals(BigDecimal.ONE)) {
583  return res;
584  }
585  // If val is between 0 and 1, rather than divide by val, multiply by its
586  // reciprocal. For example, rather than divide by 0.001 multiply by 1000.
587  if (val.compareTo(BigDecimal.ONE) < 0 && val.signum() == 1) {
588  try {
589  final BigDecimal reciprocal =
590  BigDecimal.ONE.divide(val, RoundingMode.UNNECESSARY);
591  return multiply(rexBuilder, res, rexBuilder.makeExactLiteral(reciprocal));
592  } catch (ArithmeticException e) {
593  // ignore - reciprocal is not an integer
594  }
595  }
596  return divideInt(rexBuilder, res, rexBuilder.makeExactLiteral(val));
597  }
static RexNode multiply(RexBuilder rexBuilder, RexNode a0, RexNode a1)
static RexNode divideInt(RexBuilder rexBuilder, RexNode a0, RexNode a1)
static RexNode org.apache.calcite.sql2rel.StandardConvertletTable.divideInt ( RexBuilder  rexBuilder,
RexNode  a0,
RexNode  a1 
)
inlinestaticprivate

Definition at line 327 of file StandardConvertletTable.java.

327  {
328  return rexBuilder.makeCall(SqlStdOperatorTable.DIVIDE_INTEGER, a0, a1);
329  }
List<Integer> org.apache.calcite.sql2rel.StandardConvertletTable.elseArgs ( int  count)
inlineprivate

Definition at line 752 of file StandardConvertletTable.java.

752  {
753  // If list is odd, e.g. [0, 1, 2, 3, 4] we get [1, 3, 4]
754  // If list is even, e.g. [0, 1, 2, 3, 4, 5] we get [2, 4, 5]
755  final List<Integer> list = new ArrayList<>();
756  for (int i = count % 2;;) {
757  list.add(i);
758  i += 2;
759  if (i >= count) {
760  list.add(i - 1);
761  break;
762  }
763  }
764  return list;
765  }
RexNode org.apache.calcite.sql2rel.StandardConvertletTable.eq ( RexBuilder  rexBuilder,
RexNode  a0,
RexNode  a1 
)
inlineprivate

Definition at line 311 of file StandardConvertletTable.java.

311  {
312  return rexBuilder.makeCall(SqlStdOperatorTable.EQUALS, a0, a1);
313  }
RexNode org.apache.calcite.sql2rel.StandardConvertletTable.ge ( RexBuilder  rexBuilder,
RexNode  a0,
RexNode  a1 
)
inlineprivate

Definition at line 315 of file StandardConvertletTable.java.

315  {
316  return rexBuilder.makeCall(SqlStdOperatorTable.GREATER_THAN_OR_EQUAL, a0, a1);
317  }
RexNode org.apache.calcite.sql2rel.StandardConvertletTable.le ( RexBuilder  rexBuilder,
RexNode  a0,
RexNode  a1 
)
inlineprivate

Definition at line 319 of file StandardConvertletTable.java.

319  {
320  return rexBuilder.makeCall(SqlStdOperatorTable.LESS_THAN_OR_EQUAL, a0, a1);
321  }
static RexNode org.apache.calcite.sql2rel.StandardConvertletTable.makeConstructorCall ( SqlRexContext  cx,
SqlFunction  constructor,
List< RexNode >  exprs 
)
inlinestaticprivate

Definition at line 691 of file StandardConvertletTable.java.

References anonymous_namespace{Utm.h}.n, and run_benchmark_import.type.

692  {
693  final RexBuilder rexBuilder = cx.getRexBuilder();
694  RelDataType type = rexBuilder.deriveReturnType(constructor, exprs);
695 
696  int n = type.getFieldCount();
697  ImmutableList.Builder<RexNode> initializationExprs = ImmutableList.builder();
698  final InitializerContext initializerContext = new InitializerContext() {
699  public RexBuilder getRexBuilder() {
700  return rexBuilder;
701  }
702 
703  public SqlNode validateExpression(RelDataType rowType, SqlNode expr) {
704  throw new UnsupportedOperationException();
705  }
706 
707  public RexNode convertExpression(SqlNode e) {
708  throw new UnsupportedOperationException();
709  }
710  };
711  for (int i = 0; i < n; ++i) {
712  initializationExprs.add(
713  cx.getInitializerExpressionFactory().newAttributeInitializer(
714  type, constructor, i, exprs, initializerContext));
715  }
716 
717  List<RexNode> defaultCasts = RexUtil.generateCastExpressions(
718  rexBuilder, type, initializationExprs.build());
719 
720  return rexBuilder.makeNewInvocation(type, defaultCasts);
721  }
constexpr double n
Definition: Utm.h:38
RexNode org.apache.calcite.sql2rel.StandardConvertletTable.minus ( RexBuilder  rexBuilder,
RexNode  a0,
RexNode  a1 
)
inlineprivate

Definition at line 335 of file StandardConvertletTable.java.

335  {
336  return rexBuilder.makeCall(SqlStdOperatorTable.MINUS, a0, a1);
337  }
RexNode org.apache.calcite.sql2rel.StandardConvertletTable.mod ( RexBuilder  rexBuilder,
RelDataType  resType,
RexNode  res,
BigDecimal  val 
)
inlineprivate

Definition at line 572 of file StandardConvertletTable.java.

References run_benchmark_import.res.

573  {
574  if (val.equals(BigDecimal.ONE)) {
575  return res;
576  }
577  return rexBuilder.makeCall(
578  SqlStdOperatorTable.MOD, res, rexBuilder.makeExactLiteral(val, resType));
579  }
static RexNode org.apache.calcite.sql2rel.StandardConvertletTable.multiply ( RexBuilder  rexBuilder,
RexNode  a0,
RexNode  a1 
)
inlinestaticprivate

Definition at line 339 of file StandardConvertletTable.java.

339  {
340  return rexBuilder.makeCall(SqlStdOperatorTable.MULTIPLY, a0, a1);
341  }
RexNode org.apache.calcite.sql2rel.StandardConvertletTable.or ( RexBuilder  rexBuilder,
RexNode  a0,
RexNode  a1 
)
inlineprivate

Definition at line 307 of file StandardConvertletTable.java.

307  {
308  return rexBuilder.makeCall(SqlStdOperatorTable.OR, a0, a1);
309  }
RexNode org.apache.calcite.sql2rel.StandardConvertletTable.plus ( RexBuilder  rexBuilder,
RexNode  a0,
RexNode  a1 
)
inlineprivate

Definition at line 331 of file StandardConvertletTable.java.

331  {
332  return rexBuilder.makeCall(SqlStdOperatorTable.PLUS, a0, a1);
333  }
SqlCall org.apache.calcite.sql2rel.StandardConvertletTable.plus ( SqlParserPos  pos,
SqlNode  a0,
SqlNode  a1 
)
inlineprivate

Definition at line 349 of file StandardConvertletTable.java.

349  {
350  return SqlStdOperatorTable.PLUS.createCall(pos, a0, a1);
351  }

Member Data Documentation

final StandardConvertletTable org.apache.calcite.sql2rel.StandardConvertletTable.INSTANCE = new StandardConvertletTable()
static

Singleton instance.

Definition at line 97 of file StandardConvertletTable.java.


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