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

Public Member Functions

 HeavyDBRelJsonWriter ()
 
final void explain (RelNode rel, List< Pair< String, Object >> valueList)
 
SqlExplainLevel getDetailLevel ()
 
RelWriter input (String term, RelNode input)
 
RelWriter item (String term, Object value)
 
RelWriter itemIf (String term, Object value, boolean condition)
 
RelWriter done (RelNode node)
 
boolean nest ()
 
String asString ()
 
Map< String, Object > asJsonMap ()
 

Protected Member Functions

void explain_ (RelNode rel, List< Pair< String, Object >> values)
 

Private Member Functions

void put (Map< String, Object > map, String name, Object value)
 
List< Object > explainInputs (List< RelNode > inputs)
 
boolean deliverHints (RelNode rel)
 
String explainHints (RelNode rel)
 
List< Object > getList (List< Pair< String, Object >> values, String tag)
 

Private Attributes

final EscapedStringJsonBuilder jsonBuilder
 
final HeavyDBRelJson relJson
 
final Map< RelNode, String > relIdMap = new IdentityHashMap<RelNode, String>()
 
final List< Object > relList
 
final List< Pair< String,
Object > > 
values = new ArrayList<Pair<String, Object>>()
 
String previousId
 

Detailed Description

Callback for a relational expression to dump itself as JSON.

See Also
RelJsonReader

Definition at line 39 of file HeavyDBRelJsonWriter.java.

Constructor & Destructor Documentation

org.apache.calcite.rel.externalize.HeavyDBRelJsonWriter.HeavyDBRelJsonWriter ( )
inline

Member Function Documentation

Map<String, Object> org.apache.calcite.rel.externalize.HeavyDBRelJsonWriter.asJsonMap ( )
inline

Definition at line 234 of file HeavyDBRelJsonWriter.java.

References org.apache.calcite.rel.externalize.HeavyDBRelJsonWriter.relList.

Referenced by org.apache.calcite.rel.externalize.HeavyDBRelJsonWriter.asString().

234  {
235  final Map<String, Object> map = jsonBuilder.map();
236  map.put("rels", relList);
237  return map;
238  }

+ Here is the caller graph for this function:

String org.apache.calcite.rel.externalize.HeavyDBRelJsonWriter.asString ( )
inline

Returns a JSON string describing the relational expressions that were just explained.

Definition at line 230 of file HeavyDBRelJsonWriter.java.

References org.apache.calcite.rel.externalize.HeavyDBRelJsonWriter.asJsonMap().

230  {
231  return jsonBuilder.toJsonString(asJsonMap());
232  }

+ Here is the call graph for this function:

boolean org.apache.calcite.rel.externalize.HeavyDBRelJsonWriter.deliverHints ( RelNode  rel)
inlineprivate

Definition at line 118 of file HeavyDBRelJsonWriter.java.

Referenced by org.apache.calcite.rel.externalize.HeavyDBRelJsonWriter.explain_().

118  {
119  if (rel instanceof LogicalTableScan) {
120  LogicalTableScan node = (LogicalTableScan) rel;
121  if (!node.getHints().isEmpty()) {
122  return true;
123  } else {
124  return false;
125  }
126  } else if (rel instanceof LogicalAggregate) {
127  LogicalAggregate node = (LogicalAggregate) rel;
128  if (!node.getHints().isEmpty()) {
129  return true;
130  } else {
131  return false;
132  }
133  } else if (rel instanceof LogicalJoin) {
134  LogicalJoin node = (LogicalJoin) rel;
135  if (!node.getHints().isEmpty()) {
136  return true;
137  } else {
138  return false;
139  }
140  } else if (rel instanceof LogicalProject) {
141  LogicalProject node = (LogicalProject) rel;
142  if (!node.getHints().isEmpty()) {
143  return true;
144  } else {
145  return false;
146  }
147  } else if (rel instanceof LogicalCalc) {
148  LogicalCalc node = (LogicalCalc) rel;
149  if (!node.getHints().isEmpty()) {
150  return true;
151  } else {
152  return false;
153  }
154  }
155  return false;
156  }

+ Here is the caller graph for this function:

RelWriter org.apache.calcite.rel.externalize.HeavyDBRelJsonWriter.done ( RelNode  node)
inline

Definition at line 215 of file HeavyDBRelJsonWriter.java.

References org.apache.calcite.rel.externalize.HeavyDBRelJsonWriter.explain_(), and org.apache.calcite.rel.externalize.HeavyDBRelJsonWriter.values.

215  {
216  final List<Pair<String, Object>> valuesCopy = ImmutableList.copyOf(values);
217  values.clear();
218  explain_(node, valuesCopy);
219  return this;
220  }
void explain_(RelNode rel, List< Pair< String, Object >> values)

+ Here is the call graph for this function:

final void org.apache.calcite.rel.externalize.HeavyDBRelJsonWriter.explain ( RelNode  rel,
List< Pair< String, Object >>  valueList 
)
inline

Definition at line 179 of file HeavyDBRelJsonWriter.java.

References org.apache.calcite.rel.externalize.HeavyDBRelJsonWriter.explain_().

179  {
180  explain_(rel, valueList);
181  }
void explain_(RelNode rel, List< Pair< String, Object >> values)

+ Here is the call graph for this function:

void org.apache.calcite.rel.externalize.HeavyDBRelJsonWriter.explain_ ( RelNode  rel,
List< Pair< String, Object >>  values 
)
inlineprotected

Definition at line 59 of file HeavyDBRelJsonWriter.java.

References org.apache.calcite.rel.externalize.HeavyDBRelJsonWriter.deliverHints(), org.apache.calcite.rel.externalize.HeavyDBRelJsonWriter.explainHints(), org.apache.calcite.rel.externalize.HeavyDBRelJsonWriter.explainInputs(), org.apache.calcite.rel.externalize.HeavyDBRelJsonWriter.previousId, org.apache.calcite.rel.externalize.HeavyDBRelJsonWriter.put(), and org.apache.calcite.rel.externalize.HeavyDBRelJsonWriter.values.

Referenced by org.apache.calcite.rel.externalize.HeavyDBRelJsonWriter.done(), and org.apache.calcite.rel.externalize.HeavyDBRelJsonWriter.explain().

59  {
60  final Map<String, Object> map = jsonBuilder.map();
61 
62  map.put("id", null); // ensure that id is the first attribute
63  map.put("relOp", relJson.classToTypeName(rel.getClass()));
64  if (rel instanceof TableScan) {
65  RelDataType row_type = ((TableScan) rel).getTable().getRowType();
66  List<String> field_names = row_type.getFieldNames();
67  map.put("fieldNames", field_names);
68  }
69  if (rel instanceof LogicalAggregate) {
70  map.put("fields", rel.getRowType().getFieldNames());
71  }
72  if (rel instanceof LogicalTableModify) {
73  // FIX-ME: What goes here?
74  }
75 
76  // handle hints
77  if (deliverHints(rel)) {
78  map.put("hints", explainHints(rel));
79  }
80 
81  for (Pair<String, Object> value : values) {
82  if (value.right instanceof RelNode) {
83  continue;
84  }
85  put(map, value.left, value.right);
86  }
87  // omit 'inputs: ["3"]' if "3" is the preceding rel
88  final List<Object> list = explainInputs(rel.getInputs());
89  if (list.size() != 1 || !list.get(0).equals(previousId)) {
90  map.put("inputs", list);
91  }
92 
93  final String id = Integer.toString(relIdMap.size());
94  relIdMap.put(rel, id);
95  map.put("id", id);
96 
97  relList.add(map);
98  previousId = id;
99  }
void put(Map< String, Object > map, String name, Object value)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

String org.apache.calcite.rel.externalize.HeavyDBRelJsonWriter.explainHints ( RelNode  rel)
inlineprivate

Definition at line 158 of file HeavyDBRelJsonWriter.java.

Referenced by org.apache.calcite.rel.externalize.HeavyDBRelJsonWriter.explain_().

158  {
159  List<String> explained = new ArrayList<>();
160  if (rel instanceof LogicalTableScan) {
161  LogicalTableScan node = (LogicalTableScan) rel;
162  node.getHints().stream().forEach(s -> explained.add(s.toString().toLowerCase()));
163  } else if (rel instanceof LogicalAggregate) {
164  LogicalAggregate node = (LogicalAggregate) rel;
165  node.getHints().stream().forEach(s -> explained.add(s.toString().toLowerCase()));
166  } else if (rel instanceof LogicalJoin) {
167  LogicalJoin node = (LogicalJoin) rel;
168  node.getHints().stream().forEach(s -> explained.add(s.toString().toLowerCase()));
169  } else if (rel instanceof LogicalProject) {
170  LogicalProject node = (LogicalProject) rel;
171  node.getHints().stream().forEach(s -> explained.add(s.toString().toLowerCase()));
172  } else if (rel instanceof LogicalCalc) {
173  LogicalCalc node = (LogicalCalc) rel;
174  node.getHints().stream().forEach(s -> explained.add(s.toString().toLowerCase()));
175  }
176  return explained.stream().collect(Collectors.joining("|"));
177  }

+ Here is the caller graph for this function:

List<Object> org.apache.calcite.rel.externalize.HeavyDBRelJsonWriter.explainInputs ( List< RelNode >  inputs)
inlineprivate

Definition at line 105 of file HeavyDBRelJsonWriter.java.

References org.apache.calcite.rel.externalize.HeavyDBRelJsonWriter.input(), and org.apache.calcite.rel.externalize.HeavyDBRelJsonWriter.previousId.

Referenced by org.apache.calcite.rel.externalize.HeavyDBRelJsonWriter.explain_().

105  {
106  final List<Object> list = jsonBuilder.list();
107  for (RelNode input : inputs) {
108  String id = relIdMap.get(input);
109  if (id == null) {
110  input.explain(this);
111  id = previousId;
112  }
113  list.add(id);
114  }
115  return list;
116  }

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

SqlExplainLevel org.apache.calcite.rel.externalize.HeavyDBRelJsonWriter.getDetailLevel ( )
inline

Definition at line 183 of file HeavyDBRelJsonWriter.java.

183  {
184  return SqlExplainLevel.ALL_ATTRIBUTES;
185  }
List<Object> org.apache.calcite.rel.externalize.HeavyDBRelJsonWriter.getList ( List< Pair< String, Object >>  values,
String  tag 
)
inlineprivate

Definition at line 196 of file HeavyDBRelJsonWriter.java.

References org.apache.calcite.rel.externalize.HeavyDBRelJsonWriter.values.

196  {
197  for (Pair<String, Object> value : values) {
198  if (value.left.equals(tag)) {
199  // noinspection unchecked
200  return (List<Object>) value.right;
201  }
202  }
203  final List<Object> list = new ArrayList<Object>();
204  values.add(Pair.of(tag, (Object) list));
205  return list;
206  }
RelWriter org.apache.calcite.rel.externalize.HeavyDBRelJsonWriter.input ( String  term,
RelNode  input 
)
inline

Definition at line 187 of file HeavyDBRelJsonWriter.java.

Referenced by org.apache.calcite.rel.externalize.HeavyDBRelJsonWriter.explainInputs().

187  {
188  return this;
189  }

+ Here is the caller graph for this function:

RelWriter org.apache.calcite.rel.externalize.HeavyDBRelJsonWriter.item ( String  term,
Object  value 
)
inline

Definition at line 191 of file HeavyDBRelJsonWriter.java.

Referenced by org.apache.calcite.rel.externalize.HeavyDBRelJsonWriter.itemIf().

191  {
192  values.add(Pair.of(term, value));
193  return this;
194  }

+ Here is the caller graph for this function:

RelWriter org.apache.calcite.rel.externalize.HeavyDBRelJsonWriter.itemIf ( String  term,
Object  value,
boolean  condition 
)
inline

Definition at line 208 of file HeavyDBRelJsonWriter.java.

References org.apache.calcite.rel.externalize.HeavyDBRelJsonWriter.item().

208  {
209  if (condition) {
210  item(term, value);
211  }
212  return this;
213  }

+ Here is the call graph for this function:

boolean org.apache.calcite.rel.externalize.HeavyDBRelJsonWriter.nest ( )
inline

Definition at line 222 of file HeavyDBRelJsonWriter.java.

222  {
223  return true;
224  }
void org.apache.calcite.rel.externalize.HeavyDBRelJsonWriter.put ( Map< String, Object >  map,
String  name,
Object  value 
)
inlineprivate

Definition at line 101 of file HeavyDBRelJsonWriter.java.

References setup.name.

Referenced by org.apache.calcite.rel.externalize.HeavyDBRelJsonWriter.explain_().

101  {
102  map.put(name, relJson.toJson(value));
103  }
string name
Definition: setup.in.py:72

+ Here is the caller graph for this function:

Member Data Documentation

final EscapedStringJsonBuilder org.apache.calcite.rel.externalize.HeavyDBRelJsonWriter.jsonBuilder
private
String org.apache.calcite.rel.externalize.HeavyDBRelJsonWriter.previousId
private
final Map<RelNode, String> org.apache.calcite.rel.externalize.HeavyDBRelJsonWriter.relIdMap = new IdentityHashMap<RelNode, String>()
private

Definition at line 44 of file HeavyDBRelJsonWriter.java.

final HeavyDBRelJson org.apache.calcite.rel.externalize.HeavyDBRelJsonWriter.relJson
private
final List<Object> org.apache.calcite.rel.externalize.HeavyDBRelJsonWriter.relList
private
final List<Pair<String, Object> > org.apache.calcite.rel.externalize.HeavyDBRelJsonWriter.values = new ArrayList<Pair<String, Object>>()
private

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