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

Public Member Functions

 HeavyDBRelJsonReader (RelOptCluster cluster, RelOptSchema relOptSchema, Schema schema)
 
RelNode read (String s) throws IOException
 

Private Member Functions

void readRels (List< Map< String, Object >> jsonRels)
 
void readRel (final Map< String, Object > jsonRel)
 
AggregateCall toAggCall (RelInput relInput, Map< String, Object > jsonAggCall)
 
RelNode lookupInput (String jsonInput)
 

Private Attributes

final RelOptCluster cluster
 
final RelOptSchema relOptSchema
 
final HeavyDBRelJson relJson = new HeavyDBRelJson(null)
 
final Map< String, RelNode > relMap = new LinkedHashMap<>()
 
RelNode lastRel
 

Static Private Attributes

static final TypeReference
< LinkedHashMap< String,
Object > > 
TYPE_REF
 

Detailed Description

Reads a JSON plan and converts it back to a tree of relational expressions.

See Also
org.apache.calcite.rel.RelInput

Definition at line 61 of file HeavyDBRelJsonReader.java.

Constructor & Destructor Documentation

org.apache.calcite.rel.externalize.HeavyDBRelJsonReader.HeavyDBRelJsonReader ( RelOptCluster  cluster,
RelOptSchema  relOptSchema,
Schema  schema 
)
inline

Member Function Documentation

RelNode org.apache.calcite.rel.externalize.HeavyDBRelJsonReader.lookupInput ( String  jsonInput)
inlineprivate

Definition at line 311 of file HeavyDBRelJsonReader.java.

Referenced by org.apache.calcite.rel.externalize.HeavyDBRelJsonReader.readRel().

311  {
312  RelNode node = relMap.get(jsonInput);
313  if (node == null) {
314  throw new RuntimeException(
315  "unknown id " + jsonInput + " for relational expression");
316  }
317  return node;
318  }

+ Here is the caller graph for this function:

RelNode org.apache.calcite.rel.externalize.HeavyDBRelJsonReader.read ( String  s) throws IOException
inline

Definition at line 78 of file HeavyDBRelJsonReader.java.

References org.apache.calcite.rel.externalize.HeavyDBRelJsonReader.lastRel, org.apache.calcite.rel.externalize.HeavyDBRelJsonReader.readRels(), and org.apache.calcite.rel.externalize.HeavyDBRelJsonReader.TYPE_REF.

78  {
79  lastRel = null;
80  final ObjectMapper mapper = new ObjectMapper();
81  Map<String, Object> o =
82  mapper.configure(DeserializationFeature.USE_BIG_DECIMAL_FOR_FLOATS, true)
83  .readValue(s, TYPE_REF);
84  @SuppressWarnings("unchecked")
85  final List<Map<String, Object>> rels = (List) o.get("rels");
86  readRels(rels);
87  return lastRel;
88  }
static final TypeReference< LinkedHashMap< String, Object > > TYPE_REF
void readRels(List< Map< String, Object >> jsonRels)

+ Here is the call graph for this function:

void org.apache.calcite.rel.externalize.HeavyDBRelJsonReader.readRel ( final Map< String, Object >  jsonRel)
inlineprivate

Definition at line 96 of file HeavyDBRelJsonReader.java.

References org.apache.calcite.rel.externalize.HeavyDBRelJsonReader.cluster, org.apache.calcite.rel.externalize.HeavyDBRelJsonReader.lastRel, org.apache.calcite.rel.externalize.HeavyDBRelJsonReader.lookupInput(), org.apache.calcite.rel.externalize.HeavyDBRelJsonReader.relJson, org.apache.calcite.rel.externalize.HeavyDBRelJsonReader.relOptSchema, org.apache.calcite.rel.externalize.HeavyDBRelJsonReader.toAggCall(), org.apache.calcite.rel.externalize.HeavyDBRelJson.toRex(), and run_benchmark_import.type.

Referenced by org.apache.calcite.rel.externalize.HeavyDBRelJsonReader.readRels().

96  {
97  String id = (String) jsonRel.get("id");
98  String type = (String) jsonRel.get("relOp");
99  Constructor constructor = null;
100  if (!type.equalsIgnoreCase("EnumerableTableScan")) {
101  constructor = relJson.getConstructor(type);
102  }
103  RelInput input = new RelInput() {
104  public RelOptCluster getCluster() {
105  return cluster;
106  }
107 
108  public RelTraitSet getTraitSet() {
109  return cluster.traitSetOf(Convention.NONE);
110  }
111 
112  public RelOptTable getTable(String table) {
113  final List<String> list = getStringList(table);
114  return relOptSchema.getTableForMember(list);
115  }
116 
117  public RelNode getInput() {
118  final List<RelNode> inputs = getInputs();
119  assert inputs.size() == 1;
120  return inputs.get(0);
121  }
122 
123  public List<RelNode> getInputs() {
124  final List<String> jsonInputs = getStringList("inputs");
125  if (jsonInputs == null) {
126  return ImmutableList.of(lastRel);
127  }
128  final List<RelNode> inputs = new ArrayList<>();
129  for (String jsonInput : jsonInputs) {
130  inputs.add(lookupInput(jsonInput));
131  }
132  return inputs;
133  }
134 
135  public RexNode getExpression(String tag) {
136  return relJson.toRex(this, jsonRel.get(tag));
137  }
138 
139  public ImmutableBitSet getBitSet(String tag) {
140  return ImmutableBitSet.of(getIntegerList(tag));
141  }
142 
143  public List<ImmutableBitSet> getBitSetList(String tag) {
144  List<List<Integer>> list = getIntegerListList(tag);
145  if (list == null) {
146  return null;
147  }
148  final ImmutableList.Builder<ImmutableBitSet> builder = ImmutableList.builder();
149  for (List<Integer> integers : list) {
150  builder.add(ImmutableBitSet.of(integers));
151  }
152  return builder.build();
153  }
154 
155  public List<String> getStringList(String tag) {
156  // noinspection unchecked
157  return (List<String>) jsonRel.get(tag);
158  }
159 
160  public List<Integer> getIntegerList(String tag) {
161  // noinspection unchecked
162  return (List<Integer>) jsonRel.get(tag);
163  }
164 
165  public List<List<Integer>> getIntegerListList(String tag) {
166  // noinspection unchecked
167  return (List<List<Integer>>) jsonRel.get(tag);
168  }
169 
170  public List<AggregateCall> getAggregateCalls(String tag) {
171  @SuppressWarnings("unchecked")
172  final List<Map<String, Object>> jsonAggs = (List) jsonRel.get(tag);
173  final List<AggregateCall> inputs = new ArrayList<>();
174  for (Map<String, Object> jsonAggCall : jsonAggs) {
175  inputs.add(toAggCall(this, jsonAggCall));
176  }
177  return inputs;
178  }
179 
180  public Object get(String tag) {
181  return jsonRel.get(tag);
182  }
183 
184  public String getString(String tag) {
185  return (String) jsonRel.get(tag);
186  }
187 
188  public float getFloat(String tag) {
189  return ((Number) jsonRel.get(tag)).floatValue();
190  }
191 
192  public boolean getBoolean(String tag, boolean default_) {
193  final Boolean b = (Boolean) jsonRel.get(tag);
194  return b != null ? b : default_;
195  }
196 
197  public <E extends Enum<E>> E getEnum(String tag, Class<E> enumClass) {
198  return Util.enumVal(enumClass, getString(tag).toUpperCase(Locale.ROOT));
199  }
200 
201  public List<RexNode> getExpressionList(String tag) {
202  @SuppressWarnings("unchecked")
203  final List<Object> jsonNodes = (List) jsonRel.get(tag);
204  final List<RexNode> nodes = new ArrayList<>();
205  for (Object jsonNode : jsonNodes) {
206  nodes.add(relJson.toRex(this, jsonNode));
207  }
208  return nodes;
209  }
210 
211  public RelDataType getRowType(String tag) {
212  final Object o = jsonRel.get(tag);
213  return relJson.toType(cluster.getTypeFactory(), o);
214  }
215 
216  public RelDataType getRowType(String expressionsTag, String fieldsTag) {
217  final List<RexNode> expressionList = getExpressionList(expressionsTag);
218  @SuppressWarnings("unchecked")
219  final List<String> names = (List<String>) get(fieldsTag);
220  return cluster.getTypeFactory().createStructType(
221  new AbstractList<Map.Entry<String, RelDataType>>() {
222  @Override
223  public Map.Entry<String, RelDataType> get(int index) {
224  return Pair.of(names.get(index), expressionList.get(index).getType());
225  }
226 
227  @Override
228  public int size() {
229  return names.size();
230  }
231  });
232  }
233 
234  public RelCollation getCollation() {
235  // noinspection unchecked
236  return relJson.toCollation((List) get("collation"));
237  }
238 
239  public RelDistribution getDistribution() {
240  return relJson.toDistribution(get("distribution"));
241  }
242 
243  public ImmutableList<ImmutableList<RexLiteral>> getTuples(String tag) {
244  // noinspection unchecked
245  final List<List> jsonTuples = (List) get(tag);
246  final ImmutableList.Builder<ImmutableList<RexLiteral>> builder =
247  ImmutableList.builder();
248  for (List jsonTuple : jsonTuples) {
249  builder.add(getTuple(jsonTuple));
250  }
251  return builder.build();
252  }
253 
254  public ImmutableList<RexLiteral> getTuple(List jsonTuple) {
255  final ImmutableList.Builder<RexLiteral> builder = ImmutableList.builder();
256  for (Object jsonValue : jsonTuple) {
257  builder.add((RexLiteral) relJson.toRex(this, jsonValue));
258  }
259  return builder.build();
260  }
261  };
262  try {
263  RelNode rel;
264 
265  if (!type.equalsIgnoreCase("EnumerableTableScan")) {
266  rel = (RelNode) constructor.newInstance(input);
267  } else {
268  Objects.requireNonNull(cluster);
269  Objects.requireNonNull(relOptSchema);
270  Objects.requireNonNull(jsonRel);
271  Objects.requireNonNull(jsonRel.get("table"));
272  Objects.requireNonNull(
273  relOptSchema.getTableForMember((List<String>) jsonRel.get("table")));
274  rel = EnumerableTableScan.create(cluster,
275  relOptSchema.getTableForMember((List<String>) jsonRel.get("table")));
276  }
277  relMap.put(id, rel);
278  lastRel = rel;
279  } catch (InstantiationException | IllegalAccessException e) {
280  throw new RuntimeException(e);
281  } catch (InvocationTargetException e) {
282  final Throwable e2 = e.getCause();
283  if (e2 instanceof RuntimeException) {
284  throw(RuntimeException) e2;
285  }
286  throw new RuntimeException(e2);
287  }
288  }
RexNode toRex(RelInput relInput, Object o)
AggregateCall toAggCall(RelInput relInput, Map< String, Object > jsonAggCall)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void org.apache.calcite.rel.externalize.HeavyDBRelJsonReader.readRels ( List< Map< String, Object >>  jsonRels)
inlineprivate

Definition at line 90 of file HeavyDBRelJsonReader.java.

References org.apache.calcite.rel.externalize.HeavyDBRelJsonReader.readRel().

Referenced by org.apache.calcite.rel.externalize.HeavyDBRelJsonReader.read().

90  {
91  for (Map<String, Object> jsonRel : jsonRels) {
92  readRel(jsonRel);
93  }
94  }
void readRel(final Map< String, Object > jsonRel)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

AggregateCall org.apache.calcite.rel.externalize.HeavyDBRelJsonReader.toAggCall ( RelInput  relInput,
Map< String, Object >  jsonAggCall 
)
inlineprivate

Definition at line 290 of file HeavyDBRelJsonReader.java.

References Integer, setup.name, and run_benchmark_import.type.

Referenced by org.apache.calcite.rel.externalize.HeavyDBRelJsonReader.readRel().

290  {
291  final SqlAggFunction aggregation =
292  relJson.toAggregation(relInput, (String) jsonAggCall.get("agg"));
293  final Boolean distinct = (Boolean) jsonAggCall.get("distinct");
294  @SuppressWarnings("unchecked")
295  final List<Integer> operands = (List<Integer>) jsonAggCall.get("operands");
296  final Integer filterOperand = (Integer) jsonAggCall.get("filter");
297  final RelDataType type =
298  relJson.toType(cluster.getTypeFactory(), jsonAggCall.get("type"));
299  final String name = (String) jsonAggCall.get("name");
300  return AggregateCall.create(aggregation,
301  distinct,
302  false,
303  false,
304  operands,
305  filterOperand == null ? -1 : filterOperand,
306  RelCollations.EMPTY,
307  type,
308  name);
309  }
std::pair< FILE *, std::string > create(const std::string &basePath, const int fileId, const size_t pageSize, const size_t numPages)
Definition: File.cpp:55
bool g_enable_watchdog false
Definition: Execute.cpp:80
string name
Definition: setup.in.py:72

+ Here is the caller graph for this function:

Member Data Documentation

final RelOptCluster org.apache.calcite.rel.externalize.HeavyDBRelJsonReader.cluster
private
RelNode org.apache.calcite.rel.externalize.HeavyDBRelJsonReader.lastRel
private
final HeavyDBRelJson org.apache.calcite.rel.externalize.HeavyDBRelJsonReader.relJson = new HeavyDBRelJson(null)
private
final Map<String, RelNode> org.apache.calcite.rel.externalize.HeavyDBRelJsonReader.relMap = new LinkedHashMap<>()
private

Definition at line 68 of file HeavyDBRelJsonReader.java.

final RelOptSchema org.apache.calcite.rel.externalize.HeavyDBRelJsonReader.relOptSchema
private
final TypeReference<LinkedHashMap<String, Object> > org.apache.calcite.rel.externalize.HeavyDBRelJsonReader.TYPE_REF
staticprivate
Initial value:
=
new TypeReference<LinkedHashMap<String, Object>>() {}

Definition at line 62 of file HeavyDBRelJsonReader.java.

Referenced by org.apache.calcite.rel.externalize.HeavyDBRelJsonReader.read().


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