OmniSciDB  c07336695a
MapDView.java
Go to the documentation of this file.
1 /*
2  * Copyright 2017 MapD Technologies, Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 package com.mapd.calcite.parser;
17 
19 
21 import com.mapd.thrift.server.TTableDetails;
22 
23 import org.apache.calcite.plan.RelOptTable;
25 import org.apache.calcite.rel.RelNode;
26 import org.apache.calcite.rel.RelRoot;
27 import org.apache.calcite.rel.type.RelDataType;
28 import org.apache.calcite.rel.type.RelDataTypeFactory;
29 import org.apache.calcite.schema.Schema;
30 import org.apache.calcite.schema.TranslatableTable;
31 import org.apache.calcite.sql.parser.SqlParseException;
32 import org.apache.calcite.tools.RelConversionException;
33 import org.apache.calcite.tools.ValidationException;
34 import org.slf4j.Logger;
35 import org.slf4j.LoggerFactory;
36 
37 import java.util.ArrayList;
38 
39 public class MapDView extends MapDTable implements TranslatableTable {
40  final static Logger MAPDLOGGER = LoggerFactory.getLogger(MapDView.class);
41  private final String viewSql;
43  private RelRoot viewRelRoot;
44 
45  public MapDView(String view_sql, TTableDetails ri, MapDParser mp) {
46  super(ri);
47  this.viewSql = view_sql;
48  try {
49  MapDParserOptions parserOptions = new MapDParserOptions();
50  viewRelRoot = mp.queryToSqlNode(viewSql, parserOptions);
51  accessObjects = mp.captureIdentifiers(viewSql, parserOptions.isLegacySyntax());
52  } catch (SqlParseException e) {
53  MAPDLOGGER.error("error parsing view SQL: " + view_sql, e);
54  } catch (ValidationException ex) {
55  MAPDLOGGER.error("error validating view SQL: " + view_sql, ex);
56  } catch (RelConversionException ex) {
57  MAPDLOGGER.error("error doing Rel Conversion view SQL: " + view_sql, ex);
58  }
59  }
60 
61  public String toString() {
62  return "View SQL: " + viewSql + "\n"
63  + "Accessed Objects\n" + accessObjects;
64  }
65 
67  return accessObjects;
68  }
69 
71  return viewSql;
72  }
73 
74  @Override
75  public Schema.TableType getJdbcTableType() {
76  return Schema.TableType.VIEW;
77  }
78 
79  @Override
80  public RelNode toRel(RelOptTable.ToRelContext context, RelOptTable relOptTable) {
81  return viewRelRoot.rel;
82  }
83 
84  @Override
85  public RelDataType getRowType(RelDataTypeFactory rdtf) {
86  return viewRelRoot.validatedRowType;
87  }
88 }
RelDataType getRowType(RelDataTypeFactory rdtf)
Definition: MapDView.java:85
RelNode toRel(RelOptTable.ToRelContext context, RelOptTable relOptTable)
Definition: MapDView.java:80
SqlIdentifierCapturer getAccessedObjects()
Definition: MapDView.java:66
static final Logger MAPDLOGGER
Definition: MapDView.java:40
SqlIdentifierCapturer captureIdentifiers(String sql, boolean legacy_syntax)
SqlIdentifierCapturer accessObjects
Definition: MapDView.java:42
Schema.TableType getJdbcTableType()
Definition: MapDView.java:75
MapDView(String view_sql, TTableDetails ri, MapDParser mp)
Definition: MapDView.java:45
RelRoot queryToSqlNode(final String sql, final MapDParserOptions parserOptions)
static final ThreadLocal< MapDParser > CURRENT_PARSER
Definition: MapDParser.java:90