OmniSciDB  c0231cc57d
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
org.apache.calcite.rel.externalize.HeavyDBRelJson Class Reference
+ Collaboration diagram for org.apache.calcite.rel.externalize.HeavyDBRelJson:

Public Member Functions

 HeavyDBRelJson (JsonBuilder jsonBuilder)
 
RelNode create (Map< String, Object > map)
 
Constructor getConstructor (String type)
 
Class typeNameToClass (String type)
 
String classToTypeName (Class<?extends RelNode > class_)
 
Object toJson (RelCollationImpl node)
 
Object toJson (RexFieldCollation node)
 
RelCollation toCollation (List< Map< String, Object >> jsonFieldCollations)
 
RelFieldCollation toFieldCollation (Map< String, Object > map)
 
RelDistribution toDistribution (Object o)
 
RelDataType toType (RelDataTypeFactory typeFactory, Object o)
 
Object toJson (AggregateCall node)
 

Static Public Attributes

static final List< String > PACKAGES
 

Package Functions

Object toJson (Object value)
 
RexNode toRex (RelInput relInput, Object o)
 
SqlOperator toOp (RelInput relInput, String name)
 
SqlAggFunction toAggregation (String agg)
 
SqlAggFunction toAggregation (RelInput relInput, String agg)
 

Private Member Functions

Object toJson (RelDataType node)
 
Object toJson (RelDataTypeField node)
 
Object toJson (CorrelationId node)
 
Object toJson (final RexWindowBound window_bound)
 
Object toJson (RexNode node)
 
List< RexNode > toRexList (RelInput relInput, List operands)
 
SqlOperator toOp (String op)
 
SqlOperator toOp (String op, Map< String, Object > map)
 
String toJson (SqlOperator operator)
 

Private Attributes

final Map< String, Constructor > constructorMap
 
final JsonBuilder jsonBuilder
 

Detailed Description

Utilities for converting org.apache.calcite.rel.RelNode into JSON format.

Definition at line 80 of file HeavyDBRelJson.java.

Constructor & Destructor Documentation

org.apache.calcite.rel.externalize.HeavyDBRelJson.HeavyDBRelJson ( JsonBuilder  jsonBuilder)
inline

Definition at line 92 of file HeavyDBRelJson.java.

References org.apache.calcite.rel.externalize.HeavyDBRelJson.jsonBuilder.

92  {
93  this.jsonBuilder = jsonBuilder;
94  }

Member Function Documentation

String org.apache.calcite.rel.externalize.HeavyDBRelJson.classToTypeName ( Class<?extends RelNode >  class_)
inline

Inverse of typeNameToClass.

Definition at line 152 of file HeavyDBRelJson.java.

References org.apache.calcite.rel.externalize.HeavyDBRelJson.PACKAGES.

152  {
153  final String canonicalName = class_.getName();
154  for (String package_ : PACKAGES) {
155  if (canonicalName.startsWith(package_)) {
156  String remaining = canonicalName.substring(package_.length());
157  if (remaining.indexOf('.') < 0 && remaining.indexOf('$') < 0) {
158  return remaining;
159  }
160  }
161  }
162  return canonicalName;
163  }
RelNode org.apache.calcite.rel.externalize.HeavyDBRelJson.create ( Map< String, Object >  map)
inline

Definition at line 96 of file HeavyDBRelJson.java.

References org.apache.calcite.rel.externalize.HeavyDBRelJson.getConstructor(), and run_benchmark_import.type.

96  {
97  String type = (String) map.get("type");
98  Constructor constructor = getConstructor(type);
99  try {
100  return (RelNode) constructor.newInstance(map);
101  } catch (InstantiationException e) {
102  throw new RuntimeException("while invoking constructor for type '" + type + "'", e);
103  } catch (IllegalAccessException e) {
104  throw new RuntimeException("while invoking constructor for type '" + type + "'", e);
105  } catch (InvocationTargetException e) {
106  throw new RuntimeException("while invoking constructor for type '" + type + "'", e);
107  } catch (ClassCastException e) {
108  throw new RuntimeException("while invoking constructor for type '" + type + "'", e);
109  }
110  }

+ Here is the call graph for this function:

Constructor org.apache.calcite.rel.externalize.HeavyDBRelJson.getConstructor ( String  type)
inline

Definition at line 112 of file HeavyDBRelJson.java.

References run_benchmark_import.type, and org.apache.calcite.rel.externalize.HeavyDBRelJson.typeNameToClass().

Referenced by org.apache.calcite.rel.externalize.HeavyDBRelJson.create().

112  {
113  Constructor constructor = constructorMap.get(type);
114  if (constructor == null) {
115  Class clazz = typeNameToClass(type);
116  try {
117  // noinspection unchecked
118  constructor = clazz.getConstructor(RelInput.class);
119  } catch (NoSuchMethodException e) {
120  throw new RuntimeException(
121  "class does not have required constructor, " + clazz + "(RelInput)");
122  }
123  constructorMap.put(type, constructor);
124  }
125  return constructor;
126  }

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

SqlAggFunction org.apache.calcite.rel.externalize.HeavyDBRelJson.toAggregation ( String  agg)
inlinepackage

Definition at line 575 of file HeavyDBRelJson.java.

References org.apache.calcite.rel.externalize.HeavyDBRelJson.toOp().

575  {
576  return (SqlAggFunction) toOp(agg);
577  }

+ Here is the call graph for this function:

SqlAggFunction org.apache.calcite.rel.externalize.HeavyDBRelJson.toAggregation ( RelInput  relInput,
String  agg 
)
inlinepackage

Definition at line 579 of file HeavyDBRelJson.java.

References org.apache.calcite.rel.externalize.HeavyDBRelJson.toOp().

579  {
580  return (SqlAggFunction) toOp(relInput, agg);
581  }

+ Here is the call graph for this function:

RelCollation org.apache.calcite.rel.externalize.HeavyDBRelJson.toCollation ( List< Map< String, Object >>  jsonFieldCollations)
inline

Definition at line 185 of file HeavyDBRelJson.java.

References org.apache.calcite.rel.externalize.HeavyDBRelJson.toFieldCollation().

185  {
186  final List<RelFieldCollation> fieldCollations = new ArrayList<RelFieldCollation>();
187  for (Map<String, Object> map : jsonFieldCollations) {
188  fieldCollations.add(toFieldCollation(map));
189  }
190  return RelCollations.of(fieldCollations);
191  }
RelFieldCollation toFieldCollation(Map< String, Object > map)

+ Here is the call graph for this function:

RelDistribution org.apache.calcite.rel.externalize.HeavyDBRelJson.toDistribution ( Object  o)
inline

Definition at line 202 of file HeavyDBRelJson.java.

202  {
203  return RelDistributions.ANY; // TODO:
204  }
RelFieldCollation org.apache.calcite.rel.externalize.HeavyDBRelJson.toFieldCollation ( Map< String, Object >  map)
inline

Definition at line 193 of file HeavyDBRelJson.java.

References field(), and Integer.

Referenced by org.apache.calcite.rel.externalize.HeavyDBRelJson.toCollation().

193  {
194  final Integer field = (Integer) map.get("field");
195  final RelFieldCollation.Direction direction = Util.enumVal(
196  RelFieldCollation.Direction.class, (String) map.get("direction"));
197  final RelFieldCollation.NullDirection nullDirection = Util.enumVal(
198  RelFieldCollation.NullDirection.class, (String) map.get("nulls"));
199  return new RelFieldCollation(field, direction, nullDirection);
200  }
const rapidjson::Value & field(const rapidjson::Value &obj, const char field[]) noexcept
Definition: JsonAccessors.h:31

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Object org.apache.calcite.rel.externalize.HeavyDBRelJson.toJson ( RelCollationImpl  node)
inline

Definition at line 165 of file HeavyDBRelJson.java.

References setup.name.

Referenced by org.apache.calcite.rel.externalize.HeavyDBRelJson.toJson().

165  {
166  final List<Object> list = new ArrayList<Object>();
167  for (RelFieldCollation fieldCollation : node.getFieldCollations()) {
168  final Map<String, Object> map = jsonBuilder.map();
169  map.put("field", fieldCollation.getFieldIndex());
170  map.put("direction", fieldCollation.getDirection().name());
171  map.put("nulls", fieldCollation.nullDirection.name());
172  list.add(map);
173  }
174  return list;
175  }
string name
Definition: setup.in.py:72

+ Here is the caller graph for this function:

Object org.apache.calcite.rel.externalize.HeavyDBRelJson.toJson ( RexFieldCollation  node)
inline

Definition at line 177 of file HeavyDBRelJson.java.

References setup.name, and org.apache.calcite.rel.externalize.HeavyDBRelJson.toJson().

177  {
178  final Map<String, Object> map = jsonBuilder.map();
179  map.put("field", toJson(node.left));
180  map.put("direction", node.getDirection().name());
181  map.put("nulls", node.getNullDirection().name());
182  return map;
183  }
string name
Definition: setup.in.py:72

+ Here is the call graph for this function:

Object org.apache.calcite.rel.externalize.HeavyDBRelJson.toJson ( AggregateCall  node)
inline

Definition at line 234 of file HeavyDBRelJson.java.

References org.apache.calcite.rel.externalize.HeavyDBRelJson.toJson().

234  {
235  final Map<String, Object> map = jsonBuilder.map();
236  map.put("agg", toJson(node.getAggregation()));
237  map.put("type", toJson(node.getType()));
238  map.put("distinct", node.isDistinct());
239  map.put("operands", node.getArgList());
240  return map;
241  }

+ Here is the call graph for this function:

Object org.apache.calcite.rel.externalize.HeavyDBRelJson.toJson ( Object  value)
inlinepackage

Definition at line 243 of file HeavyDBRelJson.java.

References Integer, and org.apache.calcite.rel.externalize.HeavyDBRelJson.toJson().

243  {
244  if (value == null || value instanceof Number || value instanceof String
245  || value instanceof Boolean) {
246  return value;
247  } else if (value instanceof RexNode) {
248  return toJson((RexNode) value);
249  } else if (value instanceof CorrelationId) {
250  return toJson((CorrelationId) value);
251  } else if (value instanceof List) {
252  final List<Object> list = jsonBuilder.list();
253  for (Object o : (List) value) {
254  list.add(toJson(o));
255  }
256  return list;
257  } else if (value instanceof ImmutableBitSet) {
258  final List<Object> list = jsonBuilder.list();
259  for (Integer integer : (ImmutableBitSet) value) {
260  list.add(toJson(integer));
261  }
262  return list;
263  } else if (value instanceof AggregateCall) {
264  return toJson((AggregateCall) value);
265  } else if (value instanceof RelCollationImpl) {
266  return toJson((RelCollationImpl) value);
267  } else if (value instanceof RexFieldCollation) {
268  return toJson((RexFieldCollation) value);
269  } else if (value instanceof RelDataType) {
270  return toJson((RelDataType) value);
271  } else if (value instanceof RelDataTypeField) {
272  return toJson((RelDataTypeField) value);
273  } else if (value instanceof JoinType) {
274  return value.toString();
275  } else if (value instanceof Operation) {
276  return value.toString();
277  } else {
278  throw new UnsupportedOperationException("type not serializable: " + value
279  + " (type " + value.getClass().getCanonicalName() + ")");
280  }
281  }
JoinType
Definition: sqldefs.h:156

+ Here is the call graph for this function:

Object org.apache.calcite.rel.externalize.HeavyDBRelJson.toJson ( RelDataType  node)
inlineprivate

Definition at line 283 of file HeavyDBRelJson.java.

References field(), setup.name, and org.apache.calcite.rel.externalize.HeavyDBRelJson.toJson().

283  {
284  if (node.isStruct()) {
285  final List<Object> list = jsonBuilder.list();
286  for (RelDataTypeField field : node.getFieldList()) {
287  list.add(toJson(field));
288  }
289  return list;
290  } else {
291  final Map<String, Object> map = jsonBuilder.map();
292  map.put("type", node.getSqlTypeName().name());
293  map.put("nullable", node.isNullable());
294  if (node.getSqlTypeName().allowsPrec()) {
295  map.put("precision", node.getPrecision());
296  }
297  if (node.getSqlTypeName().allowsScale()) {
298  map.put("scale", node.getScale());
299  }
300  return map;
301  }
302  }
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:

Object org.apache.calcite.rel.externalize.HeavyDBRelJson.toJson ( RelDataTypeField  node)
inlineprivate

Definition at line 304 of file HeavyDBRelJson.java.

References org.apache.calcite.rel.externalize.HeavyDBRelJson.toJson().

304  {
305  final Map<String, Object> map = (Map<String, Object>) toJson(node.getType());
306  map.put("name", node.getName());
307  return map;
308  }

+ Here is the call graph for this function:

Object org.apache.calcite.rel.externalize.HeavyDBRelJson.toJson ( CorrelationId  node)
inlineprivate

Definition at line 310 of file HeavyDBRelJson.java.

310  {
311  return node.getId();
312  }
Object org.apache.calcite.rel.externalize.HeavyDBRelJson.toJson ( final RexWindowBound  window_bound)
inlineprivate

Definition at line 314 of file HeavyDBRelJson.java.

References org.apache.calcite.rel.externalize.HeavyDBRelJson.toJson().

314  {
315  final Map<String, Object> map = jsonBuilder.map();
316  map.put("unbounded", toJson(window_bound.isUnbounded()));
317  map.put("preceding", toJson(window_bound.isPreceding()));
318  map.put("following", toJson(window_bound.isFollowing()));
319  map.put("is_current_row", toJson(window_bound.isCurrentRow()));
320  map.put("offset",
321  window_bound.getOffset() != null ? toJson(window_bound.getOffset()) : null);
322  map.put("order_key", toJson(window_bound.getOrderKey()));
323  return map;
324  }

+ Here is the call graph for this function:

Object org.apache.calcite.rel.externalize.HeavyDBRelJson.toJson ( RexNode  node)
inlineprivate

Definition at line 326 of file HeavyDBRelJson.java.

References gpu_enabled.lower_bound(), setup.name, org.apache.calcite.rel.externalize.HeavyDBRelJson.toJson(), and gpu_enabled.upper_bound().

326  {
327  final Map<String, Object> map;
328  switch (node.getKind()) {
329  case FIELD_ACCESS:
330  map = jsonBuilder.map();
331  final RexFieldAccess fieldAccess = (RexFieldAccess) node;
332  map.put("field", fieldAccess.getField().getName());
333  map.put("expr", toJson(fieldAccess.getReferenceExpr()));
334  return map;
335  case LITERAL:
336  final RexLiteral literal = (RexLiteral) node;
337  final Object value2 = literal.getValue2();
338  map = jsonBuilder.map();
339  if (value2 instanceof TimeUnitRange || value2 instanceof SqlTrimFunction.Flag) {
340  map.put("literal", value2.toString());
341  } else {
342  map.put("literal", value2);
343  }
344  map.put("type", literal.getTypeName().name());
345  map.put("target_type", literal.getType().getSqlTypeName().toString());
346  final Object value = literal.getValue();
347  if (value instanceof BigDecimal) {
348  map.put("scale", ((BigDecimal) value).scale());
349  map.put("precision", ((BigDecimal) value).precision());
350  } else {
351  map.put("scale", literal.getType().getScale());
352  map.put("precision", literal.getType().getPrecision());
353  }
354  map.put("type_scale", literal.getType().getScale());
355  map.put("type_precision", literal.getType().getPrecision());
356  return map;
357  case INPUT_REF:
358  map = jsonBuilder.map();
359  map.put("input", ((RexInputRef) node).getIndex());
360  return map;
361  case CORREL_VARIABLE:
362  map = jsonBuilder.map();
363  map.put("correl", ((RexCorrelVariable) node).getName());
364  map.put("type", toJson(node.getType()));
365  return map;
366  default:
367  if (node instanceof RexCall) {
368  final RexCall call = (RexCall) node;
369  map = jsonBuilder.map();
370  map.put("op", toJson(call.getOperator()));
371  final List<Object> list = jsonBuilder.list();
372  for (RexNode operand : call.getOperands()) {
373  list.add(toJson(operand));
374  }
375  map.put("operands", list);
376  map.put("type", toJson(node.getType()));
377  if (node instanceof RexSubQuery) {
378  final HeavyDBRelJsonWriter subqueryWriter = new HeavyDBRelJsonWriter();
379  ((RexSubQuery) node).rel.explain(subqueryWriter);
380  map.put("subquery", subqueryWriter.asJsonMap());
381  }
382  if (node instanceof RexOver) {
383  final RexWindow window = ((RexOver) node).getWindow();
384  final List<Object> partitionKeyList = jsonBuilder.list();
385  for (final RexNode partitionKey : window.partitionKeys) {
386  partitionKeyList.add(toJson(partitionKey));
387  }
388  map.put("partition_keys", partitionKeyList);
389  final List<Object> orderKeyList = jsonBuilder.list();
390  for (final RexFieldCollation orderKey : window.orderKeys) {
391  orderKeyList.add(toJson(orderKey));
392  }
393  map.put("order_keys", orderKeyList);
394  RexWindowBound lower_bound = window.getLowerBound();
395  RexWindowBound upper_bound = window.getUpperBound();
396  map.put("lower_bound", toJson(lower_bound));
397  map.put("upper_bound", toJson(upper_bound));
398  map.put("is_rows", toJson(window.isRows()));
399  }
400  if (call.getOperator() instanceof SqlFunction) {
401  switch (((SqlFunction) call.getOperator()).getFunctionType()) {
402  case USER_DEFINED_CONSTRUCTOR:
403  case USER_DEFINED_FUNCTION:
404  case USER_DEFINED_PROCEDURE:
405  case USER_DEFINED_SPECIFIC_FUNCTION:
406  map.put("class", call.getOperator().getClass().getName());
407  }
408  }
409  return map;
410  }
411  throw new UnsupportedOperationException("unknown rex " + node);
412  }
413  }
DEVICE auto upper_bound(ARGS &&...args)
Definition: gpu_enabled.h:123
DEVICE auto lower_bound(ARGS &&...args)
Definition: gpu_enabled.h:78
string name
Definition: setup.in.py:72

+ Here is the call graph for this function:

String org.apache.calcite.rel.externalize.HeavyDBRelJson.toJson ( SqlOperator  operator)
inlineprivate

Definition at line 583 of file HeavyDBRelJson.java.

583  {
584  // User-defined operators are not yet handled.
585  return operator.getName();
586  }
SqlOperator org.apache.calcite.rel.externalize.HeavyDBRelJson.toOp ( String  op)
inlineprivate

Definition at line 523 of file HeavyDBRelJson.java.

Referenced by org.apache.calcite.rel.externalize.HeavyDBRelJson.toAggregation(), and org.apache.calcite.rel.externalize.HeavyDBRelJson.toRex().

523  {
524  return toOp(op, new HashMap<>());
525  }

+ Here is the caller graph for this function:

SqlOperator org.apache.calcite.rel.externalize.HeavyDBRelJson.toOp ( String  op,
Map< String, Object >  map 
)
inlineprivate

Definition at line 527 of file HeavyDBRelJson.java.

527  {
528  // TODO: build a map, for more efficient lookup
529  // TODO: look up based on SqlKind
530  HeavyDBSqlOperatorTable operatorTable =
531  new HeavyDBSqlOperatorTable(SqlStdOperatorTable.instance());
532  operatorTable.addUDF(null);
533  final List<SqlOperator> operatorList = operatorTable.getOperatorList();
534  for (SqlOperator operator : operatorList) {
535  if (operator.getName().equals(op)) {
536  return operator;
537  }
538  }
539  String class_ = (String) map.get("class");
540  if (class_ != null) {
541  try {
542  return (SqlOperator) Class.forName(class_).newInstance();
543  } catch (InstantiationException e) {
544  throw new RuntimeException(e);
545  } catch (IllegalAccessException e) {
546  throw new RuntimeException(e);
547  } catch (ClassNotFoundException e) {
548  throw new RuntimeException(e);
549  }
550  }
551  throw new RuntimeException("Operator " + op + " does not supported");
552  }
SqlOperator org.apache.calcite.rel.externalize.HeavyDBRelJson.toOp ( RelInput  relInput,
String  name 
)
inlinepackage

Definition at line 554 of file HeavyDBRelJson.java.

References setup.name.

554  {
555  // in case different operator has the same kind, check with both name and kind.
556  String kind = name;
557  String syntax = "FUNCTION";
558  SqlKind sqlKind = SqlKind.valueOf(kind);
559  SqlSyntax sqlSyntax = SqlSyntax.valueOf(syntax);
560  HeavyDBSqlOperatorTable operatorTable =
561  new HeavyDBSqlOperatorTable(SqlStdOperatorTable.instance());
562  operatorTable.addUDF(null);
563  final List<SqlOperator> operators = operatorTable.getOperatorList();
564  List<String> names = new ArrayList<>();
565  for (SqlOperator operator : operators) {
566  names.add(operator.toString());
567  if (operator.getName().equals(name)) {
568  return operator;
569  }
570  }
571  throw new RuntimeException("Aggregation function with name " + name
572  + " not found, search in " + names.toString());
573  }
string name
Definition: setup.in.py:72
RexNode org.apache.calcite.rel.externalize.HeavyDBRelJson.toRex ( RelInput  relInput,
Object  o 
)
inlinepackage

Definition at line 415 of file HeavyDBRelJson.java.

References Double, field(), Float, Integer, org.apache.calcite.rel.externalize.HeavyDBRelJson.toOp(), org.apache.calcite.rel.externalize.HeavyDBRelJson.toRexList(), org.apache.calcite.rel.externalize.HeavyDBRelJson.toType(), and run_benchmark_import.type.

Referenced by org.apache.calcite.rel.externalize.HeavyDBRelJsonReader.readRel(), and org.apache.calcite.rel.externalize.HeavyDBRelJson.toRexList().

415  {
416  final RelOptCluster cluster = relInput.getCluster();
417  final RexBuilder rexBuilder = cluster.getRexBuilder();
418  if (o == null) {
419  return null;
420  } else if (o instanceof Map) {
421  Map map = (Map) o;
422  final String op = (String) map.get("op");
423  if (op != null) {
424  final List operands = (List) map.get("operands");
425  final Object jsonType = map.get("type");
426  final SqlOperator operator = toOp(op, map);
427  final List<RexNode> rexOperands = toRexList(relInput, operands);
428  RelDataType type;
429  if (jsonType != null) {
430  type = toType(cluster.getTypeFactory(), jsonType);
431  } else {
432  type = rexBuilder.deriveReturnType(operator, rexOperands);
433  }
434  return rexBuilder.makeCall(type, operator, rexOperands);
435  }
436  final Integer input = (Integer) map.get("input");
437  if (input != null) {
438  List<RelNode> inputNodes = relInput.getInputs();
439  int i = input;
440  for (RelNode inputNode : inputNodes) {
441  final RelDataType rowType = inputNode.getRowType();
442  if (i < rowType.getFieldCount()) {
443  final RelDataTypeField field = rowType.getFieldList().get(i);
444  return rexBuilder.makeInputRef(field.getType(), input);
445  }
446  i -= rowType.getFieldCount();
447  }
448  throw new RuntimeException("input field " + input + " is out of range");
449  }
450  final String field = (String) map.get("field");
451  if (field != null) {
452  final Object jsonExpr = map.get("expr");
453  final RexNode expr = toRex(relInput, jsonExpr);
454  return rexBuilder.makeFieldAccess(expr, field, true);
455  }
456  final String correl = (String) map.get("correl");
457  if (correl != null) {
458  final Object jsonType = map.get("type");
459  RelDataType type = toType(cluster.getTypeFactory(), jsonType);
460  return rexBuilder.makeCorrel(type, new CorrelationId(correl));
461  }
462  if (map.containsKey("literal")) {
463  final Object literal = map.get("literal");
464  final SqlTypeName sqlTypeName =
465  Util.enumVal(SqlTypeName.class, (String) map.get("type"));
466  if (literal == null) {
467  return rexBuilder.makeNullLiteral(
468  cluster.getTypeFactory().createSqlType(sqlTypeName));
469  }
470 
471  // HEAVY.AI serializes numeric literals differently, we need more data
472  // then the number. So, we need to have a special case for that.
473  if (literal instanceof Number) {
474  final SqlTypeName targetTypeName =
475  Util.enumVal(SqlTypeName.class, (String) map.get("target_type"));
476  final long scale = ((Number) map.get("scale")).longValue();
477  final long precision = ((Number) map.get("precision")).longValue();
478  final long typeScale = ((Number) map.get("type_scale")).longValue();
479  final long typePrecision = ((Number) map.get("type_precision")).longValue();
480  RelDataTypeFactory typeFactory = cluster.getTypeFactory();
481 
482  BigDecimal value =
483  BigDecimal.valueOf(((Number) literal).longValue(), (int) scale);
484 
485  if (typeScale != 0 && typeScale != -2147483648) {
486  return rexBuilder.makeLiteral(value,
487  typeFactory.createSqlType(
488  SqlTypeName.DECIMAL, (int) typePrecision, (int) typeScale),
489  false);
490  } else {
491  return rexBuilder.makeLiteral(
492  value, typeFactory.createSqlType(targetTypeName), false);
493  }
494  } else {
495  return toRex(relInput, literal);
496  }
497  }
498  throw new UnsupportedOperationException("cannot convert to rex " + o);
499  } else if (o instanceof Boolean) {
500  return rexBuilder.makeLiteral((Boolean) o);
501  } else if (o instanceof String) {
502  return rexBuilder.makeLiteral((String) o);
503  } else if (o instanceof Number) {
504  final Number number = (Number) o;
505  if (number instanceof Double || number instanceof Float) {
506  return rexBuilder.makeApproxLiteral(BigDecimal.valueOf(number.doubleValue()));
507  } else {
508  return rexBuilder.makeExactLiteral(BigDecimal.valueOf(number.longValue()));
509  }
510  } else {
511  throw new UnsupportedOperationException("cannot convert to rex " + o);
512  }
513  }
List< RexNode > toRexList(RelInput relInput, List operands)
const rapidjson::Value & field(const rapidjson::Value &obj, const char field[]) noexcept
Definition: JsonAccessors.h:31
RexNode toRex(RelInput relInput, Object o)
RelDataType toType(RelDataTypeFactory typeFactory, Object o)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

List<RexNode> org.apache.calcite.rel.externalize.HeavyDBRelJson.toRexList ( RelInput  relInput,
List  operands 
)
inlineprivate

Definition at line 515 of file HeavyDBRelJson.java.

References org.apache.calcite.rel.externalize.HeavyDBRelJson.toRex().

Referenced by org.apache.calcite.rel.externalize.HeavyDBRelJson.toRex().

515  {
516  final List<RexNode> list = new ArrayList<RexNode>();
517  for (Object operand : operands) {
518  list.add(toRex(relInput, operand));
519  }
520  return list;
521  }
RexNode toRex(RelInput relInput, Object o)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

RelDataType org.apache.calcite.rel.externalize.HeavyDBRelJson.toType ( RelDataTypeFactory  typeFactory,
Object  o 
)
inline

Definition at line 206 of file HeavyDBRelJson.java.

References Integer, and run_benchmark_import.type.

Referenced by org.apache.calcite.rel.externalize.HeavyDBRelJson.toRex().

206  {
207  if (o instanceof List) {
208  @SuppressWarnings("unchecked")
209  final List<Map<String, Object>> jsonList = (List<Map<String, Object>>) o;
210  final RelDataTypeFactory.Builder builder = typeFactory.builder();
211  for (Map<String, Object> jsonMap : jsonList) {
212  builder.add((String) jsonMap.get("name"), toType(typeFactory, jsonMap));
213  }
214  return builder.build();
215  } else {
216  final Map<String, Object> map = (Map<String, Object>) o;
217  final SqlTypeName sqlTypeName =
218  Util.enumVal(SqlTypeName.class, (String) map.get("type"));
219  final Integer precision = (Integer) map.get("precision");
220  final Integer scale = (Integer) map.get("scale");
221  final RelDataType type;
222  if (precision == null) {
223  type = typeFactory.createSqlType(sqlTypeName);
224  } else if (scale == null) {
225  type = typeFactory.createSqlType(sqlTypeName, precision);
226  } else {
227  type = typeFactory.createSqlType(sqlTypeName, precision, scale);
228  }
229  final boolean nullable = (Boolean) map.get("nullable");
230  return typeFactory.createTypeWithNullability(type, nullable);
231  }
232  }
RelDataType toType(RelDataTypeFactory typeFactory, Object o)

+ Here is the caller graph for this function:

Class org.apache.calcite.rel.externalize.HeavyDBRelJson.typeNameToClass ( String  type)
inline

Converts a type name to a class. E.g.

getClass("LogicalProject")

returns org.apache.calcite.rel.logical.LogicalProject.class.

Definition at line 132 of file HeavyDBRelJson.java.

References org.apache.calcite.rel.externalize.HeavyDBRelJson.PACKAGES, and run_benchmark_import.type.

Referenced by org.apache.calcite.rel.externalize.HeavyDBRelJson.getConstructor().

132  {
133  if (!type.contains(".")) {
134  for (String package_ : PACKAGES) {
135  try {
136  return Class.forName(package_ + type);
137  } catch (ClassNotFoundException e) {
138  // ignore
139  }
140  }
141  }
142  try {
143  return Class.forName(type);
144  } catch (ClassNotFoundException e) {
145  throw new RuntimeException("unknown type " + type);
146  }
147  }

+ Here is the caller graph for this function:

Member Data Documentation

final Map<String, Constructor> org.apache.calcite.rel.externalize.HeavyDBRelJson.constructorMap
private
Initial value:
=
new HashMap<String, Constructor>()

Definition at line 81 of file HeavyDBRelJson.java.

final JsonBuilder org.apache.calcite.rel.externalize.HeavyDBRelJson.jsonBuilder
private
final List<String> org.apache.calcite.rel.externalize.HeavyDBRelJson.PACKAGES
static
Initial value:
= ImmutableList.of("org.apache.calcite.rel.",
"org.apache.calcite.rel.core.",
"org.apache.calcite.rel.logical.",
"org.apache.calcite.adapter.jdbc.",
"org.apache.calcite.adapter.enumerable.",
"org.apache.calcite.adapter.jdbc.JdbcRules$")

Definition at line 85 of file HeavyDBRelJson.java.

Referenced by org.apache.calcite.rel.externalize.HeavyDBRelJson.classToTypeName(), and org.apache.calcite.rel.externalize.HeavyDBRelJson.typeNameToClass().


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