OmniSciDB  8a228a1076
org.apache.calcite.rel.externalize.MapDRelJsonWriter Class Reference
+ Inheritance diagram for org.apache.calcite.rel.externalize.MapDRelJsonWriter:
+ Collaboration diagram for org.apache.calcite.rel.externalize.MapDRelJsonWriter:

Public Member Functions

 MapDRelJsonWriter ()
 
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 MapDRelJson 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 51 of file MapDRelJsonWriter.java.

Constructor & Destructor Documentation

◆ MapDRelJsonWriter()

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

Definition at line 63 of file MapDRelJsonWriter.java.

63  {
64  jsonBuilder = new EscapedStringJsonBuilder();
65  relList = jsonBuilder.list();
66  relJson = new MapDRelJson(jsonBuilder);
67  }

Member Function Documentation

◆ asJsonMap()

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

Definition at line 246 of file MapDRelJsonWriter.java.

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

246  {
247  final Map<String, Object> map = jsonBuilder.map();
248  map.put("rels", relList);
249  return map;
250  }
+ Here is the caller graph for this function:

◆ asString()

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

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

Definition at line 242 of file MapDRelJsonWriter.java.

Referenced by com.mapd.calcite.parser.MapDSerializer.toString().

242  {
243  return jsonBuilder.toJsonString(asJsonMap());
244  }
+ Here is the caller graph for this function:

◆ deliverHints()

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

Definition at line 130 of file MapDRelJsonWriter.java.

130  {
131  if (rel instanceof LogicalTableScan) {
132  LogicalTableScan node = (LogicalTableScan) rel;
133  if (!node.getHints().isEmpty()) {
134  return true;
135  } else {
136  return false;
137  }
138  } else if (rel instanceof LogicalAggregate) {
139  LogicalAggregate node = (LogicalAggregate) rel;
140  if (!node.getHints().isEmpty()) {
141  return true;
142  } else {
143  return false;
144  }
145  } else if (rel instanceof LogicalJoin) {
146  LogicalJoin node = (LogicalJoin) rel;
147  if (!node.getHints().isEmpty()) {
148  return true;
149  } else {
150  return false;
151  }
152  } else if (rel instanceof LogicalProject) {
153  LogicalProject node = (LogicalProject) rel;
154  if (!node.getHints().isEmpty()) {
155  return true;
156  } else {
157  return false;
158  }
159  } else if (rel instanceof LogicalCalc) {
160  LogicalCalc node = (LogicalCalc) rel;
161  if (!node.getHints().isEmpty()) {
162  return true;
163  } else {
164  return false;
165  }
166  }
167  return false;
168  }

◆ done()

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

Definition at line 227 of file MapDRelJsonWriter.java.

227  {
228  final List<Pair<String, Object>> valuesCopy = ImmutableList.copyOf(values);
229  values.clear();
230  explain_(node, valuesCopy);
231  return this;
232  }
void explain_(RelNode rel, List< Pair< String, Object >> values)

◆ explain()

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

Definition at line 191 of file MapDRelJsonWriter.java.

191  {
192  explain_(rel, valueList);
193  }
void explain_(RelNode rel, List< Pair< String, Object >> values)

◆ explain_()

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

Definition at line 71 of file MapDRelJsonWriter.java.

References org.apache.calcite.rel.externalize.MapDRelJson.classToTypeName().

71  {
72  final Map<String, Object> map = jsonBuilder.map();
73 
74  map.put("id", null); // ensure that id is the first attribute
75  map.put("relOp", relJson.classToTypeName(rel.getClass()));
76  if (rel instanceof TableScan) {
77  RelDataType row_type = ((TableScan) rel).getTable().getRowType();
78  List<String> field_names = row_type.getFieldNames();
79  map.put("fieldNames", field_names);
80  }
81  if (rel instanceof LogicalAggregate) {
82  map.put("fields", rel.getRowType().getFieldNames());
83  }
84  if (rel instanceof LogicalTableModify) {
85  // FIX-ME: What goes here?
86  }
87 
88  // handle hints
89  if (deliverHints(rel)) {
90  map.put("hints", explainHints(rel));
91  }
92 
93  for (Pair<String, Object> value : values) {
94  if (value.right instanceof RelNode) {
95  continue;
96  }
97  put(map, value.left, value.right);
98  }
99  // omit 'inputs: ["3"]' if "3" is the preceding rel
100  final List<Object> list = explainInputs(rel.getInputs());
101  if (list.size() != 1 || !list.get(0).equals(previousId)) {
102  map.put("inputs", list);
103  }
104 
105  final String id = Integer.toString(relIdMap.size());
106  relIdMap.put(rel, id);
107  map.put("id", id);
108 
109  relList.add(map);
110  previousId = id;
111  }
List< Object > explainInputs(List< RelNode > inputs)
String classToTypeName(Class<? extends RelNode > class_)
void put(Map< String, Object > map, String name, Object value)
+ Here is the call graph for this function:

◆ explainHints()

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

Definition at line 170 of file MapDRelJsonWriter.java.

170  {
171  List<String> explained = new ArrayList<>();
172  if (rel instanceof LogicalTableScan) {
173  LogicalTableScan node = (LogicalTableScan) rel;
174  node.getHints().stream().forEach(s -> explained.add(s.toString().toLowerCase()));
175  } else if (rel instanceof LogicalAggregate) {
176  LogicalAggregate node = (LogicalAggregate) rel;
177  node.getHints().stream().forEach(s -> explained.add(s.toString().toLowerCase()));
178  } else if (rel instanceof LogicalJoin) {
179  LogicalJoin node = (LogicalJoin) rel;
180  node.getHints().stream().forEach(s -> explained.add(s.toString().toLowerCase()));
181  } else if (rel instanceof LogicalProject) {
182  LogicalProject node = (LogicalProject) rel;
183  node.getHints().stream().forEach(s -> explained.add(s.toString().toLowerCase()));
184  } else if (rel instanceof LogicalCalc) {
185  LogicalCalc node = (LogicalCalc) rel;
186  node.getHints().stream().forEach(s -> explained.add(s.toString().toLowerCase()));
187  }
188  return explained.stream().collect(Collectors.joining("|"));
189  }

◆ explainInputs()

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

Definition at line 117 of file MapDRelJsonWriter.java.

117  {
118  final List<Object> list = jsonBuilder.list();
119  for (RelNode input : inputs) {
120  String id = relIdMap.get(input);
121  if (id == null) {
122  input.explain(this);
123  id = previousId;
124  }
125  list.add(id);
126  }
127  return list;
128  }

◆ getDetailLevel()

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

Definition at line 195 of file MapDRelJsonWriter.java.

195  {
196  return SqlExplainLevel.ALL_ATTRIBUTES;
197  }

◆ getList()

List<Object> org.apache.calcite.rel.externalize.MapDRelJsonWriter.getList ( List< Pair< String, Object >>  values,
String  tag 
)
inlineprivate

Definition at line 208 of file MapDRelJsonWriter.java.

208  {
209  for (Pair<String, Object> value : values) {
210  if (value.left.equals(tag)) {
211  // noinspection unchecked
212  return (List<Object>) value.right;
213  }
214  }
215  final List<Object> list = new ArrayList<Object>();
216  values.add(Pair.of(tag, (Object) list));
217  return list;
218  }

◆ input()

RelWriter org.apache.calcite.rel.externalize.MapDRelJsonWriter.input ( String  term,
RelNode  input 
)
inline

Definition at line 199 of file MapDRelJsonWriter.java.

199  {
200  return this;
201  }

◆ item()

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

Definition at line 203 of file MapDRelJsonWriter.java.

203  {
204  values.add(Pair.of(term, value));
205  return this;
206  }

◆ itemIf()

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

Definition at line 220 of file MapDRelJsonWriter.java.

220  {
221  if (condition) {
222  item(term, value);
223  }
224  return this;
225  }

◆ nest()

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

Definition at line 234 of file MapDRelJsonWriter.java.

234  {
235  return true;
236  }

◆ put()

void org.apache.calcite.rel.externalize.MapDRelJsonWriter.put ( Map< String, Object >  map,
String  name,
Object  value 
)
inlineprivate

Definition at line 113 of file MapDRelJsonWriter.java.

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

113  {
114  map.put(name, relJson.toJson(value));
115  }
+ Here is the call graph for this function:

Member Data Documentation

◆ jsonBuilder

final EscapedStringJsonBuilder org.apache.calcite.rel.externalize.MapDRelJsonWriter.jsonBuilder
private

Definition at line 54 of file MapDRelJsonWriter.java.

◆ previousId

String org.apache.calcite.rel.externalize.MapDRelJsonWriter.previousId
private

Definition at line 59 of file MapDRelJsonWriter.java.

◆ relIdMap

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

Definition at line 56 of file MapDRelJsonWriter.java.

◆ relJson

final MapDRelJson org.apache.calcite.rel.externalize.MapDRelJsonWriter.relJson
private

Definition at line 55 of file MapDRelJsonWriter.java.

◆ relList

final List<Object> org.apache.calcite.rel.externalize.MapDRelJsonWriter.relList
private

Definition at line 57 of file MapDRelJsonWriter.java.

◆ values

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

Definition at line 58 of file MapDRelJsonWriter.java.


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