OmniSciDB  467d548b97
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
com.mapd.metadata.MetaConnect Class Reference
+ Collaboration diagram for com.mapd.metadata.MetaConnect:

Public Member Functions

 MetaConnect (int mapdPort, String dataDir, MapDUser currentMapDUser, MapDParser parser, SockTransportProperties skT)
 
Table getTable (String tableName)
 
Set< String > getTables ()
 
TTableDetails get_table_details (String tableName)
 
void updateMetaData (String schema, String table)
 

Static Public Member Functions

static final int get_physical_cols (int type)
 
static final boolean is_geometry (int type)
 

Static Package Attributes

static final Logger MAPDLOGGER = LoggerFactory.getLogger(MetaConnect.class)
 

Private Member Functions

void connectToDBCatalog ()
 
void disconnectFromDBCatalog ()
 
Set< String > getTables_SQL ()
 
TTableDetails get_table_detail_SQL (String tableName)
 
TTableDetails get_table_detail_JSON (String tableName) throws IOException, RuntimeException
 
int getTableId (String tableName)
 
boolean isView (String tableName)
 
String getViewSql (String tableName)
 
String getViewSqlViaSql (int tableId)
 
TDatumType typeToThrift (int type)
 

Private Attributes

final String dataDir
 
final String db
 
final MapDUser currentUser
 
final int mapdPort
 
Connection catConn
 
final MapDParser parser
 
final SockTransportProperties sock_transport_properties
 

Static Private Attributes

static final int KBOOLEAN = 1
 
static final int KCHAR = 2
 
static final int KVARCHAR = 3
 
static final int KNUMERIC = 4
 
static final int KDECIMAL = 5
 
static final int KINT = 6
 
static final int KSMALLINT = 7
 
static final int KFLOAT = 8
 
static final int KDOUBLE = 9
 
static final int KTIME = 10
 
static final int KTIMESTAMP = 11
 
static final int KBIGINT = 12
 
static final int KTEXT = 13
 
static final int KDATE = 14
 
static final int KARRAY = 15
 
static final int KINTERVAL_DAY_TIME = 16
 
static final int KINTERVAL_YEAR_MONTH = 17
 
static final int KPOINT = 18
 
static final int KLINESTRING = 19
 
static final int KPOLYGON = 20
 
static final int KMULTIPOLYGON = 21
 
static final int KTINYINT = 22
 
static volatile Map< String,
Set< String > > 
MAPD_DATABASE_TO_TABLES
 
static volatile Map< List
< String >, Table > 
MAPD_TABLE_DETAILS
 

Detailed Description

Author
michael

Definition at line 66 of file MetaConnect.java.

Constructor & Destructor Documentation

com.mapd.metadata.MetaConnect.MetaConnect ( int  mapdPort,
String  dataDir,
MapDUser  currentMapDUser,
MapDParser  parser,
SockTransportProperties  skT 
)
inline

Definition at line 104 of file MetaConnect.java.

References com.mapd.metadata.MetaConnect.dataDir, com.mapd.metadata.MetaConnect.mapdPort, and com.mapd.metadata.MetaConnect.parser.

108  {
109  this.dataDir = dataDir;
110  if (currentMapDUser != null) {
111  this.db = currentMapDUser.getDB();
112  } else {
113  this.db = null;
114  }
115  this.currentUser = currentMapDUser;
116  this.mapdPort = mapdPort;
117  this.parser = parser;
118  this.sock_transport_properties = skT;
119  }

Member Function Documentation

void com.mapd.metadata.MetaConnect.connectToDBCatalog ( )
inlineprivate

Definition at line 121 of file MetaConnect.java.

References com.mapd.metadata.MetaConnect.catConn, com.mapd.metadata.MetaConnect.dataDir, and com.mapd.metadata.MetaConnect.db.

Referenced by com.mapd.metadata.MetaConnect.get_table_details(), com.mapd.metadata.MetaConnect.getTables(), com.mapd.metadata.MetaConnect.getTables_SQL(), and com.mapd.metadata.MetaConnect.getViewSql().

121  {
122  try {
123  // try {
124  Class.forName("org.sqlite.JDBC");
125  } catch (ClassNotFoundException ex) {
126  String err = "Could not find class for metadata connection; DB: '" + db
127  + "' data dir '" + dataDir + "', error was " + ex.getMessage();
128  MAPDLOGGER.error(err);
129  throw new RuntimeException(err);
130  }
131  String connectURL = "jdbc:sqlite:" + dataDir + "/mapd_catalogs/" + db;
132  try {
133  catConn = DriverManager.getConnection(connectURL);
134  } catch (SQLException ex) {
135  String err = "Could not establish a connection for metadata; DB: '" + db
136  + "' data dir '" + dataDir + "', error was " + ex.getMessage();
137  MAPDLOGGER.error(err);
138  throw new RuntimeException(err);
139  }
140  MAPDLOGGER.debug("Opened database successfully");
141  }

+ Here is the caller graph for this function:

void com.mapd.metadata.MetaConnect.disconnectFromDBCatalog ( )
inlineprivate

Definition at line 143 of file MetaConnect.java.

References com.mapd.metadata.MetaConnect.dataDir, and com.mapd.metadata.MetaConnect.db.

Referenced by com.mapd.metadata.MetaConnect.get_table_details(), com.mapd.metadata.MetaConnect.getTables(), com.mapd.metadata.MetaConnect.getTables_SQL(), and com.mapd.metadata.MetaConnect.getViewSql().

143  {
144  try {
145  catConn.close();
146  } catch (SQLException ex) {
147  String err = "Could not disconnect for metadata; DB: '" + db + "' data dir '"
148  + dataDir + "', error was " + ex.getMessage();
149  MAPDLOGGER.error(err);
150  throw new RuntimeException(err);
151  }
152  }

+ Here is the caller graph for this function:

static final int com.mapd.metadata.MetaConnect.get_physical_cols ( int  type)
inlinestatic

Definition at line 323 of file MetaConnect.java.

References com.mapd.metadata.MetaConnect.KLINESTRING, com.mapd.metadata.MetaConnect.KMULTIPOLYGON, com.mapd.metadata.MetaConnect.KPOINT, and com.mapd.metadata.MetaConnect.KPOLYGON.

Referenced by com.mapd.metadata.MetaConnect.get_table_detail_JSON(), and com.mapd.metadata.MetaConnect.get_table_detail_SQL().

323  {
324  switch (type) {
325  case KPOINT:
326  return 1; // coords
327  case KLINESTRING:
328  return 2; // coords, bounds
329  case KPOLYGON:
330  return 4; // coords, ring_sizes, bounds, render_group
331  case KMULTIPOLYGON:
332  return 5; // coords, ring_sizes, poly_rings, bounds, render_group
333  default:
334  break;
335  }
336  return 0;
337  }
static final int KMULTIPOLYGON
static final int KLINESTRING

+ Here is the caller graph for this function:

TTableDetails com.mapd.metadata.MetaConnect.get_table_detail_JSON ( String  tableName) throws IOException, RuntimeException
inlineprivate

Definition at line 445 of file MetaConnect.java.

References assert(), com.mapd.metadata.MetaConnect.dataDir, com.mapd.metadata.MetaConnect.db, com.mapd.metadata.MetaConnect.get_physical_cols(), com.mapd.metadata.MetaConnect.is_geometry(), com.mapd.metadata.MetaConnect.KARRAY, and com.mapd.metadata.MetaConnect.typeToThrift().

Referenced by com.mapd.metadata.MetaConnect.get_table_detail_SQL().

446  {
447  TTableDetails td = new TTableDetails();
448  td.getRow_descIterator();
449 
450  // open table json file
451  final String filePath = dataDir + "/mapd_catalogs/" + db + "_temp_tables.json";
452  MAPDLOGGER.debug("Opening temp table file at " + filePath);
453 
454  String tempTablesJsonStr;
455  try {
456  File tempTablesFile = new File(filePath);
457  FileInputStream tempTablesStream = new FileInputStream(tempTablesFile);
458  byte[] data = new byte[(int) tempTablesFile.length()];
459  tempTablesStream.read(data);
460  tempTablesStream.close();
461 
462  tempTablesJsonStr = new String(data, "UTF-8");
463  } catch (java.io.FileNotFoundException e) {
464  throw new RuntimeException("Failed to read temporary tables file.");
465  }
466 
467  Gson gson = new Gson();
468  JsonObject fileParentObject = gson.fromJson(tempTablesJsonStr, JsonObject.class);
469  if (fileParentObject == null) {
470  throw new IOException("Malformed temporary tables file.");
471  }
472 
473  JsonObject tableObject = fileParentObject.getAsJsonObject(tableName);
474  if (tableObject == null) {
475  throw new RuntimeException(
476  "Failed to find table " + tableName + " in temporary tables file.");
477  }
478 
479  String jsonTableName = tableObject.get("name").getAsString();
480  assert (tableName == jsonTableName);
481  int id = tableObject.get("id").getAsInt();
482  MAPDLOGGER.debug("table id is " + id);
483  MAPDLOGGER.debug("table name is " + tableName);
484 
485  JsonArray jsonColumns = tableObject.getAsJsonArray("columns");
486  assert (jsonColumns != null);
487 
488  int skip_physical_cols = 0;
489  for (JsonElement columnElement : jsonColumns) {
490  JsonObject columnObject = columnElement.getAsJsonObject();
491 
492  String colName = columnObject.get("name").getAsString();
493  MAPDLOGGER.debug("name = " + colName);
494  int colType = columnObject.get("coltype").getAsInt();
495  MAPDLOGGER.debug("coltype = " + colType);
496  int colSubType = columnObject.get("colsubtype").getAsInt();
497  MAPDLOGGER.debug("colsubtype = " + colSubType);
498  int colDim = columnObject.get("coldim").getAsInt();
499  MAPDLOGGER.debug("coldim = " + colDim);
500  int colScale = columnObject.get("colscale").getAsInt();
501  MAPDLOGGER.debug("colscale = " + colScale);
502  boolean isNotNull = columnObject.get("is_notnull").getAsBoolean();
503  MAPDLOGGER.debug("is_notnull = " + isNotNull);
504  boolean isSystemCol = columnObject.get("is_systemcol").getAsBoolean();
505  MAPDLOGGER.debug("is_systemcol = " + isSystemCol);
506  boolean isVirtualCol = columnObject.get("is_virtualcol").getAsBoolean();
507  MAPDLOGGER.debug("is_vitrualcol = " + isVirtualCol);
508  boolean isDeletedCol = columnObject.get("is_deletedcol").getAsBoolean();
509  MAPDLOGGER.debug("is_deletedcol = " + isDeletedCol);
510  MAPDLOGGER.debug("");
511 
512  if (isDeletedCol) {
513  MAPDLOGGER.debug("Skipping delete column.");
514  continue;
515  }
516 
517  TColumnType tct = new TColumnType();
518  TTypeInfo tti = new TTypeInfo();
519  TDatumType tdt;
520 
521  if (colType == KARRAY) {
522  tti.is_array = true;
523  tdt = typeToThrift(colSubType);
524  } else {
525  tti.is_array = false;
526  tdt = typeToThrift(colType);
527  }
528 
529  tti.nullable = !isNotNull;
530  tti.encoding = TEncodingType.NONE;
531  tti.type = tdt;
532  tti.scale = colScale;
533  tti.precision = colDim;
534 
535  tct.col_name = colName;
536  tct.col_type = tti;
537  tct.is_system = isSystemCol;
538 
539  if (skip_physical_cols <= 0) skip_physical_cols = get_physical_cols(colType);
540  if (is_geometry(colType) || skip_physical_cols-- <= 0) td.addToRow_desc(tct);
541  }
542 
543  return td;
544  }
static final int get_physical_cols(int type)
static final boolean is_geometry(int type)
int64_t const int32_t sz assert(dest)
TDatumType typeToThrift(int type)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

TTableDetails com.mapd.metadata.MetaConnect.get_table_detail_SQL ( String  tableName)
inlineprivate

Definition at line 344 of file MetaConnect.java.

References com.mapd.metadata.MetaConnect.db, com.mapd.metadata.MetaConnect.get_physical_cols(), com.mapd.metadata.MetaConnect.get_table_detail_JSON(), com.mapd.metadata.MetaConnect.getTableId(), com.mapd.metadata.MetaConnect.getViewSqlViaSql(), com.mapd.metadata.MetaConnect.is_geometry(), com.mapd.metadata.MetaConnect.isView(), com.mapd.metadata.MetaConnect.KARRAY, and com.mapd.metadata.MetaConnect.typeToThrift().

Referenced by com.mapd.metadata.MetaConnect.get_table_details().

344  {
345  TTableDetails td = new TTableDetails();
346  td.getRow_descIterator();
347  int id = getTableId(tableName);
348  if (id == -1) {
349  try {
350  return get_table_detail_JSON(tableName);
351  } catch (Exception e) {
352  String err = "Table '" + tableName + "' does not exist for DB '" + db + "'";
353  MAPDLOGGER.error(err);
354  throw new RuntimeException(err);
355  }
356  }
357 
358  // read data from table
359  Statement stmt = null;
360  ResultSet rs = null;
361  try {
362  stmt = catConn.createStatement();
363  MAPDLOGGER.debug("table id is " + id);
364  MAPDLOGGER.debug("table name is " + tableName);
365  String query = String.format(
366  "SELECT * FROM mapd_columns where tableid = %d and not is_deletedcol order by columnid;",
367  id);
368  MAPDLOGGER.debug(query);
369  rs = stmt.executeQuery(query);
370  int skip_physical_cols = 0;
371  while (rs.next()) {
372  String colName = rs.getString("name");
373  MAPDLOGGER.debug("name = " + colName);
374  int colType = rs.getInt("coltype");
375  MAPDLOGGER.debug("coltype = " + colType);
376  int colSubType = rs.getInt("colsubtype");
377  MAPDLOGGER.debug("colsubtype = " + colSubType);
378  int colDim = rs.getInt("coldim");
379  MAPDLOGGER.debug("coldim = " + colDim);
380  int colScale = rs.getInt("colscale");
381  MAPDLOGGER.debug("colscale = " + colScale);
382  boolean isNotNull = rs.getBoolean("is_notnull");
383  MAPDLOGGER.debug("is_notnull = " + isNotNull);
384  boolean isSystemCol = rs.getBoolean("is_systemcol");
385  MAPDLOGGER.debug("is_systemcol = " + isSystemCol);
386  boolean isVirtualCol = rs.getBoolean("is_virtualcol");
387  MAPDLOGGER.debug("is_vitrualcol = " + isVirtualCol);
388  MAPDLOGGER.debug("");
389  TColumnType tct = new TColumnType();
390  TTypeInfo tti = new TTypeInfo();
391  TDatumType tdt;
392 
393  if (colType == KARRAY) {
394  tti.is_array = true;
395  tdt = typeToThrift(colSubType);
396  } else {
397  tti.is_array = false;
398  tdt = typeToThrift(colType);
399  }
400 
401  tti.nullable = !isNotNull;
402  tti.encoding = TEncodingType.NONE;
403  tti.type = tdt;
404  tti.scale = colScale;
405  tti.precision = colDim;
406 
407  tct.col_name = colName;
408  tct.col_type = tti;
409  tct.is_system = isSystemCol;
410 
411  if (skip_physical_cols <= 0) skip_physical_cols = get_physical_cols(colType);
412  if (is_geometry(colType) || skip_physical_cols-- <= 0) td.addToRow_desc(tct);
413  }
414  } catch (Exception e) {
415  String err = "error trying to read from mapd_columns, error was " + e.getMessage();
416  MAPDLOGGER.error(err);
417  throw new RuntimeException(err);
418  } finally {
419  if (rs != null) {
420  try {
421  rs.close();
422  } catch (SQLException ex) {
423  String err = "Could not close resultset, error was " + ex.getMessage();
424  MAPDLOGGER.error(err);
425  throw new RuntimeException(err);
426  }
427  }
428  if (stmt != null) {
429  try {
430  stmt.close();
431  } catch (SQLException ex) {
432  String err = "Could not close stmt, error was " + ex.getMessage();
433  MAPDLOGGER.error(err);
434  throw new RuntimeException(err);
435  }
436  }
437  }
438  if (isView(tableName)) {
439  td.setView_sqlIsSet(true);
440  td.setView_sql(getViewSqlViaSql(id));
441  }
442  return td;
443  }
static final int get_physical_cols(int type)
static final boolean is_geometry(int type)
String getViewSqlViaSql(int tableId)
TDatumType typeToThrift(int type)
int getTableId(String tableName)
TTableDetails get_table_detail_JSON(String tableName)
boolean isView(String tableName)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

TTableDetails com.mapd.metadata.MetaConnect.get_table_details ( String  tableName)
inline

Definition at line 285 of file MetaConnect.java.

References com.mapd.metadata.MetaConnect.connectToDBCatalog(), com.mapd.metadata.MetaConnect.disconnectFromDBCatalog(), com.mapd.metadata.MetaConnect.get_table_detail_SQL(), and com.mapd.metadata.MetaConnect.mapdPort.

Referenced by com.mapd.metadata.MetaConnect.getTable().

285  {
286  if (mapdPort == -1) {
287  // use sql
289  TTableDetails td = get_table_detail_SQL(tableName);
291  return td;
292  }
293  // use thrift direct to local server
294  try {
295  TProtocol protocol = null;
296 
297  TTransport transport =
298  sock_transport_properties.openClientTransport("localhost", mapdPort);
299  if (!transport.isOpen()) transport.open();
300  protocol = new TBinaryProtocol(transport);
301 
302  OmniSci.Client client = new OmniSci.Client(protocol);
303 
304  TTableDetails td =
305  client.get_internal_table_details(currentUser.getSession(), tableName);
306 
307  transport.close();
308 
309  return td;
310 
311  } catch (TTransportException ex) {
312  MAPDLOGGER.error(ex.toString());
313  throw new RuntimeException(ex.toString());
314  } catch (TOmniSciException ex) {
315  MAPDLOGGER.error(ex.toString());
316  throw new RuntimeException(ex.toString());
317  } catch (TException ex) {
318  MAPDLOGGER.error(ex.toString());
319  throw new RuntimeException(ex.toString());
320  }
321  }
TTableDetails get_table_detail_SQL(String tableName)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Table com.mapd.metadata.MetaConnect.getTable ( String  tableName)
inline

Definition at line 154 of file MetaConnect.java.

References com.mapd.metadata.MetaConnect.get_table_details(), com.mapd.metadata.MetaConnect.getViewSql(), and com.mapd.metadata.MetaConnect.parser.

154  {
155  List<String> dbTable = ImmutableList.of(db.toUpperCase(), tableName.toUpperCase());
156  Table cTable = MAPD_TABLE_DETAILS.get(dbTable);
157  if (cTable != null) {
158  return cTable;
159  }
160 
161  TTableDetails td = get_table_details(tableName);
162 
163  if (td.getView_sql() == null || td.getView_sql().isEmpty()) {
164  MAPDLOGGER.debug("Processing a table");
165  Table rTable = new MapDTable(td);
166  MAPD_TABLE_DETAILS.putIfAbsent(dbTable, rTable);
167  return rTable;
168  } else {
169  MAPDLOGGER.debug("Processing a view");
170  Table rTable = new MapDView(getViewSql(tableName), td, parser);
171  MAPD_TABLE_DETAILS.putIfAbsent(dbTable, rTable);
172  return rTable;
173  }
174  }
String getViewSql(String tableName)
TTableDetails get_table_details(String tableName)

+ Here is the call graph for this function:

int com.mapd.metadata.MetaConnect.getTableId ( String  tableName)
inlineprivate

Definition at line 546 of file MetaConnect.java.

References com.mapd.metadata.MetaConnect.dataDir, and com.mapd.metadata.MetaConnect.db.

Referenced by com.mapd.metadata.MetaConnect.get_table_detail_SQL(), and com.mapd.metadata.MetaConnect.getViewSql().

546  {
547  Statement stmt = null;
548  ResultSet rs = null;
549  int tableId = -1;
550  try {
551  stmt = catConn.createStatement();
552  rs = stmt.executeQuery(String.format(
553  "SELECT tableid FROM mapd_tables where name = '%s' COLLATE NOCASE;",
554  tableName));
555  while (rs.next()) {
556  tableId = rs.getInt("tableid");
557  MAPDLOGGER.debug("tableId = " + tableId);
558  MAPDLOGGER.debug("");
559  }
560  rs.close();
561  stmt.close();
562  } catch (Exception e) {
563  String err = "Error trying to read from metadata table mapd_tables;DB: " + db
564  + " data dir " + dataDir + ", error was " + e.getMessage();
565  MAPDLOGGER.error(err);
566  throw new RuntimeException(err);
567  } finally {
568  if (rs != null) {
569  try {
570  rs.close();
571  } catch (SQLException ex) {
572  String err = "Could not close resultset, error was " + ex.getMessage();
573  MAPDLOGGER.error(err);
574  throw new RuntimeException(err);
575  }
576  }
577  if (stmt != null) {
578  try {
579  stmt.close();
580  } catch (SQLException ex) {
581  String err = "Could not close stmt, error was " + ex.getMessage();
582  MAPDLOGGER.error(err);
583  throw new RuntimeException(err);
584  }
585  }
586  }
587  return (tableId);
588  }

+ Here is the caller graph for this function:

Set<String> com.mapd.metadata.MetaConnect.getTables ( )
inline

Definition at line 176 of file MetaConnect.java.

References com.mapd.metadata.MetaConnect.connectToDBCatalog(), com.mapd.metadata.MetaConnect.disconnectFromDBCatalog(), com.mapd.metadata.MetaConnect.getTables_SQL(), and com.mapd.metadata.MetaConnect.mapdPort.

176  {
177  Set<String> mSet = MAPD_DATABASE_TO_TABLES.get(db.toUpperCase());
178  if (mSet != null) {
179  return mSet;
180  }
181 
182  if (mapdPort == -1) {
183  // use sql
185  Set<String> ts = getTables_SQL();
187  MAPD_DATABASE_TO_TABLES.putIfAbsent(db.toUpperCase(), ts);
188  return ts;
189  }
190  // use thrift direct to local server
191  try {
192  TProtocol protocol = null;
193  TTransport transport =
194  sock_transport_properties.openClientTransport("localhost", mapdPort);
195  if (!transport.isOpen()) transport.open();
196  protocol = new TBinaryProtocol(transport);
197 
198  OmniSci.Client client = new OmniSci.Client(protocol);
199 
200  List<String> tablesList = client.get_tables(currentUser.getSession());
201  Set<String> ts = new HashSet<String>(tablesList.size());
202  for (String tableName : tablesList) {
203  ts.add(tableName);
204  }
205 
206  transport.close();
207  MAPD_DATABASE_TO_TABLES.putIfAbsent(db.toUpperCase(), ts);
208  return ts;
209 
210  } catch (TTransportException ex) {
211  MAPDLOGGER.error("TTransportException on port [" + mapdPort + "]");
212  MAPDLOGGER.error(ex.toString());
213  throw new RuntimeException(ex.toString());
214  } catch (TOmniSciException ex) {
215  MAPDLOGGER.error(ex.toString());
216  throw new RuntimeException(ex.toString());
217  } catch (TException ex) {
218  MAPDLOGGER.error(ex.toString());
219  throw new RuntimeException(ex.toString());
220  }
221  }

+ Here is the call graph for this function:

Set<String> com.mapd.metadata.MetaConnect.getTables_SQL ( )
inlineprivate

Definition at line 223 of file MetaConnect.java.

References com.mapd.metadata.MetaConnect.connectToDBCatalog(), com.mapd.metadata.MetaConnect.dataDir, com.mapd.metadata.MetaConnect.db, and com.mapd.metadata.MetaConnect.disconnectFromDBCatalog().

Referenced by com.mapd.metadata.MetaConnect.getTables().

223  {
225  Set<String> tableSet = new HashSet<String>();
226  Statement stmt = null;
227  ResultSet rs = null;
228  String sqlText = "";
229  try {
230  stmt = catConn.createStatement();
231 
232  // get the tables
233  rs = stmt.executeQuery("SELECT name FROM mapd_tables ");
234  while (rs.next()) {
235  tableSet.add(rs.getString("name"));
236  /*--*/
237  MAPDLOGGER.debug("Object name = " + rs.getString("name"));
238  }
239  rs.close();
240  stmt.close();
241 
242  } catch (Exception e) {
243  String err = "error trying to get all the tables, error was " + e.getMessage();
244  MAPDLOGGER.error(err);
245  throw new RuntimeException(err);
246  }
248 
249  try {
250  // open temp table json file
251  final String filePath = dataDir + "/mapd_catalogs/" + db + "_temp_tables.json";
252  MAPDLOGGER.debug("Opening temp table file at " + filePath);
253  String tempTablesJsonStr;
254  try {
255  File tempTablesFile = new File(filePath);
256  FileInputStream tempTablesStream = new FileInputStream(tempTablesFile);
257  byte[] data = new byte[(int) tempTablesFile.length()];
258  tempTablesStream.read(data);
259  tempTablesStream.close();
260 
261  tempTablesJsonStr = new String(data, "UTF-8");
262  } catch (java.io.FileNotFoundException e) {
263  return tableSet;
264  }
265 
266  Gson gson = new Gson();
267  JsonObject fileParentObject = gson.fromJson(tempTablesJsonStr, JsonObject.class);
268  for (Entry<String, JsonElement> member : fileParentObject.entrySet()) {
269  String tableName = member.getKey();
270  tableSet.add(tableName);
271  /*--*/
272  MAPDLOGGER.debug("Temp table object name = " + tableName);
273  }
274 
275  } catch (Exception e) {
276  String err = "error trying to load temporary tables from json file, error was "
277  + e.getMessage();
278  MAPDLOGGER.error(err);
279  throw new RuntimeException(err);
280  }
281 
282  return tableSet;
283  }

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

String com.mapd.metadata.MetaConnect.getViewSql ( String  tableName)
inlineprivate

Definition at line 614 of file MetaConnect.java.

References com.mapd.metadata.MetaConnect.connectToDBCatalog(), com.mapd.metadata.MetaConnect.disconnectFromDBCatalog(), com.mapd.metadata.MetaConnect.getTableId(), com.mapd.metadata.MetaConnect.getViewSqlViaSql(), and com.mapd.metadata.MetaConnect.mapdPort.

Referenced by com.mapd.metadata.MetaConnect.getTable().

614  {
615  String sqlText;
616  if (mapdPort == -1) {
617  // use sql
619  sqlText = getViewSqlViaSql(getTableId(tableName));
621  } else {
622  // use thrift direct to local server
623  try {
624  TProtocol protocol = null;
625 
626  TTransport transport =
627  sock_transport_properties.openClientTransport("localhost", mapdPort);
628  if (!transport.isOpen()) transport.open();
629  protocol = new TBinaryProtocol(transport);
630 
631  OmniSci.Client client = new OmniSci.Client(protocol);
632 
633  TTableDetails td = client.get_table_details(currentUser.getSession(), tableName);
634 
635  transport.close();
636 
637  sqlText = td.getView_sql();
638 
639  } catch (TTransportException ex) {
640  MAPDLOGGER.error(ex.toString());
641  throw new RuntimeException(ex.toString());
642  } catch (TOmniSciException ex) {
643  MAPDLOGGER.error(ex.toString());
644  throw new RuntimeException(ex.toString());
645  } catch (TException ex) {
646  MAPDLOGGER.error(ex.toString());
647  throw new RuntimeException(ex.toString());
648  }
649  }
650  /* return string without the sqlite's trailing semicolon */
651  if (sqlText.charAt(sqlText.length() - 1) == ';') {
652  return (sqlText.substring(0, sqlText.length() - 1));
653  } else {
654  return (sqlText);
655  }
656  }
String getViewSqlViaSql(int tableId)
int getTableId(String tableName)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

String com.mapd.metadata.MetaConnect.getViewSqlViaSql ( int  tableId)
inlineprivate

Definition at line 659 of file MetaConnect.java.

Referenced by com.mapd.metadata.MetaConnect.get_table_detail_SQL(), and com.mapd.metadata.MetaConnect.getViewSql().

659  {
660  Statement stmt;
661  ResultSet rs;
662  String sqlText = "";
663  try {
664  stmt = catConn.createStatement();
665  rs = stmt.executeQuery(String.format(
666  "SELECT sql FROM mapd_views where tableid = '%s' COLLATE NOCASE;",
667  tableId));
668  while (rs.next()) {
669  sqlText = rs.getString("sql");
670  MAPDLOGGER.debug("View definition = " + sqlText);
671  MAPDLOGGER.debug("");
672  }
673  rs.close();
674  stmt.close();
675  } catch (Exception e) {
676  String err = "error trying to read from mapd_views, error was " + e.getMessage();
677  MAPDLOGGER.error(err);
678  throw new RuntimeException(err);
679  }
680  if (sqlText == null || sqlText.length() == 0) {
681  String err = "No view text found";
682  MAPDLOGGER.error(err);
683  throw new RuntimeException(err);
684  }
685  return sqlText;
686  }

+ Here is the caller graph for this function:

static final boolean com.mapd.metadata.MetaConnect.is_geometry ( int  type)
inlinestatic

Definition at line 339 of file MetaConnect.java.

References com.mapd.metadata.MetaConnect.KLINESTRING, com.mapd.metadata.MetaConnect.KMULTIPOLYGON, com.mapd.metadata.MetaConnect.KPOINT, and com.mapd.metadata.MetaConnect.KPOLYGON.

Referenced by com.mapd.metadata.MetaConnect.get_table_detail_JSON(), and com.mapd.metadata.MetaConnect.get_table_detail_SQL().

339  {
340  return type == KPOINT || type == KLINESTRING || type == KPOLYGON
341  || type == KMULTIPOLYGON;
342  }
static final int KMULTIPOLYGON
static final int KLINESTRING

+ Here is the caller graph for this function:

boolean com.mapd.metadata.MetaConnect.isView ( String  tableName)
inlineprivate

Definition at line 590 of file MetaConnect.java.

Referenced by com.mapd.metadata.MetaConnect.get_table_detail_SQL().

590  {
591  Statement stmt;
592  ResultSet rs;
593  int viewFlag = 0;
594  try {
595  stmt = catConn.createStatement();
596  rs = stmt.executeQuery(String.format(
597  "SELECT isview FROM mapd_tables where name = '%s' COLLATE NOCASE;",
598  tableName));
599  while (rs.next()) {
600  viewFlag = rs.getInt("isview");
601  MAPDLOGGER.debug("viewFlag = " + viewFlag);
602  MAPDLOGGER.debug("");
603  }
604  rs.close();
605  stmt.close();
606  } catch (Exception e) {
607  String err = "error trying to read from mapd_views, error was " + e.getMessage();
608  MAPDLOGGER.error(err);
609  throw new RuntimeException(err);
610  }
611  return (viewFlag == 1);
612  }

+ Here is the caller graph for this function:

TDatumType com.mapd.metadata.MetaConnect.typeToThrift ( int  type)
inlineprivate

Definition at line 688 of file MetaConnect.java.

References com.mapd.metadata.MetaConnect.KBIGINT, com.mapd.metadata.MetaConnect.KBOOLEAN, com.mapd.metadata.MetaConnect.KCHAR, com.mapd.metadata.MetaConnect.KDATE, com.mapd.metadata.MetaConnect.KDECIMAL, com.mapd.metadata.MetaConnect.KDOUBLE, com.mapd.metadata.MetaConnect.KFLOAT, com.mapd.metadata.MetaConnect.KINT, com.mapd.metadata.MetaConnect.KINTERVAL_DAY_TIME, com.mapd.metadata.MetaConnect.KINTERVAL_YEAR_MONTH, com.mapd.metadata.MetaConnect.KLINESTRING, com.mapd.metadata.MetaConnect.KMULTIPOLYGON, com.mapd.metadata.MetaConnect.KNUMERIC, com.mapd.metadata.MetaConnect.KPOINT, com.mapd.metadata.MetaConnect.KPOLYGON, com.mapd.metadata.MetaConnect.KSMALLINT, com.mapd.metadata.MetaConnect.KTEXT, com.mapd.metadata.MetaConnect.KTIME, com.mapd.metadata.MetaConnect.KTIMESTAMP, com.mapd.metadata.MetaConnect.KTINYINT, and com.mapd.metadata.MetaConnect.KVARCHAR.

Referenced by com.mapd.metadata.MetaConnect.get_table_detail_JSON(), and com.mapd.metadata.MetaConnect.get_table_detail_SQL().

688  {
689  switch (type) {
690  case KBOOLEAN:
691  return TDatumType.BOOL;
692  case KTINYINT:
693  return TDatumType.TINYINT;
694  case KSMALLINT:
695  return TDatumType.SMALLINT;
696  case KINT:
697  return TDatumType.INT;
698  case KBIGINT:
699  return TDatumType.BIGINT;
700  case KFLOAT:
701  return TDatumType.FLOAT;
702  case KNUMERIC:
703  case KDECIMAL:
704  return TDatumType.DECIMAL;
705  case KDOUBLE:
706  return TDatumType.DOUBLE;
707  case KTEXT:
708  case KVARCHAR:
709  case KCHAR:
710  return TDatumType.STR;
711  case KTIME:
712  return TDatumType.TIME;
713  case KTIMESTAMP:
714  return TDatumType.TIMESTAMP;
715  case KDATE:
716  return TDatumType.DATE;
717  case KINTERVAL_DAY_TIME:
718  return TDatumType.INTERVAL_DAY_TIME;
720  return TDatumType.INTERVAL_YEAR_MONTH;
721  case KPOINT:
722  return TDatumType.POINT;
723  case KLINESTRING:
724  return TDatumType.LINESTRING;
725  case KPOLYGON:
726  return TDatumType.POLYGON;
727  case KMULTIPOLYGON:
728  return TDatumType.MULTIPOLYGON;
729  default:
730  return null;
731  }
732  }
static final int KMULTIPOLYGON
static final int KINTERVAL_YEAR_MONTH
static final int KLINESTRING
static final int KINTERVAL_DAY_TIME

+ Here is the caller graph for this function:

void com.mapd.metadata.MetaConnect.updateMetaData ( String  schema,
String  table 
)
inline

Definition at line 734 of file MetaConnect.java.

References all.

734  {
735  // Check if table is specified, if not we are dropping an entire DB so need to
736  // remove all
737  // tables for that DB
738  if (table.equals("")) {
739  // Drop db and all tables
740  // iterate through all and remove matching schema
741  Set<List<String>> all = new HashSet<>(MAPD_TABLE_DETAILS.keySet());
742  for (List<String> keys : all) {
743  if (keys.get(0).equals(schema.toUpperCase())) {
744  MAPDLOGGER.debug("removing schema " + keys.get(0) + " table " + keys.get(1));
745  MAPD_TABLE_DETAILS.remove(keys);
746  }
747  }
748  } else {
749  MAPDLOGGER.debug("removing schema " + schema.toUpperCase() + " table "
750  + table.toUpperCase());
751  MAPD_TABLE_DETAILS.remove(
752  ImmutableList.of(schema.toUpperCase(), table.toUpperCase()));
753  }
754  // Invalidate views
755  Set<List<String>> all = new HashSet<>(MAPD_TABLE_DETAILS.keySet());
756  for (List<String> keys : all) {
757  if (keys.get(0).equals(schema.toUpperCase())) {
758  Table ttable = MAPD_TABLE_DETAILS.get(keys);
759  if (ttable instanceof MapDView) {
760  MAPDLOGGER.debug(
761  "removing view in schema " + keys.get(0) + " view " + keys.get(1));
762  MAPD_TABLE_DETAILS.remove(keys);
763  }
764  }
765  }
766  // now remove schema
767  MAPDLOGGER.debug("removing schema " + schema.toUpperCase());
768  MAPD_DATABASE_TO_TABLES.remove(schema.toUpperCase());
769  }

Member Data Documentation

Connection com.mapd.metadata.MetaConnect.catConn
private

Definition at line 72 of file MetaConnect.java.

Referenced by com.mapd.metadata.MetaConnect.connectToDBCatalog().

final MapDUser com.mapd.metadata.MetaConnect.currentUser
private

Definition at line 70 of file MetaConnect.java.

final int com.mapd.metadata.MetaConnect.KARRAY = 15
staticprivate
final int com.mapd.metadata.MetaConnect.KBIGINT = 12
staticprivate

Definition at line 86 of file MetaConnect.java.

Referenced by com.mapd.metadata.MetaConnect.typeToThrift().

final int com.mapd.metadata.MetaConnect.KBOOLEAN = 1
staticprivate

Definition at line 75 of file MetaConnect.java.

Referenced by com.mapd.metadata.MetaConnect.typeToThrift().

final int com.mapd.metadata.MetaConnect.KCHAR = 2
staticprivate

Definition at line 76 of file MetaConnect.java.

Referenced by com.mapd.metadata.MetaConnect.typeToThrift().

final int com.mapd.metadata.MetaConnect.KDATE = 14
staticprivate

Definition at line 88 of file MetaConnect.java.

Referenced by com.mapd.metadata.MetaConnect.typeToThrift().

final int com.mapd.metadata.MetaConnect.KDECIMAL = 5
staticprivate

Definition at line 79 of file MetaConnect.java.

Referenced by com.mapd.metadata.MetaConnect.typeToThrift().

final int com.mapd.metadata.MetaConnect.KDOUBLE = 9
staticprivate

Definition at line 83 of file MetaConnect.java.

Referenced by com.mapd.metadata.MetaConnect.typeToThrift().

final int com.mapd.metadata.MetaConnect.KFLOAT = 8
staticprivate

Definition at line 82 of file MetaConnect.java.

Referenced by com.mapd.metadata.MetaConnect.typeToThrift().

final int com.mapd.metadata.MetaConnect.KINT = 6
staticprivate

Definition at line 80 of file MetaConnect.java.

Referenced by com.mapd.metadata.MetaConnect.typeToThrift().

final int com.mapd.metadata.MetaConnect.KINTERVAL_DAY_TIME = 16
staticprivate

Definition at line 90 of file MetaConnect.java.

Referenced by com.mapd.metadata.MetaConnect.typeToThrift().

final int com.mapd.metadata.MetaConnect.KINTERVAL_YEAR_MONTH = 17
staticprivate

Definition at line 91 of file MetaConnect.java.

Referenced by com.mapd.metadata.MetaConnect.typeToThrift().

final int com.mapd.metadata.MetaConnect.KLINESTRING = 19
staticprivate
final int com.mapd.metadata.MetaConnect.KMULTIPOLYGON = 21
staticprivate
final int com.mapd.metadata.MetaConnect.KNUMERIC = 4
staticprivate

Definition at line 78 of file MetaConnect.java.

Referenced by com.mapd.metadata.MetaConnect.typeToThrift().

final int com.mapd.metadata.MetaConnect.KPOINT = 18
staticprivate
final int com.mapd.metadata.MetaConnect.KPOLYGON = 20
staticprivate
final int com.mapd.metadata.MetaConnect.KSMALLINT = 7
staticprivate

Definition at line 81 of file MetaConnect.java.

Referenced by com.mapd.metadata.MetaConnect.typeToThrift().

final int com.mapd.metadata.MetaConnect.KTEXT = 13
staticprivate

Definition at line 87 of file MetaConnect.java.

Referenced by com.mapd.metadata.MetaConnect.typeToThrift().

final int com.mapd.metadata.MetaConnect.KTIME = 10
staticprivate

Definition at line 84 of file MetaConnect.java.

Referenced by com.mapd.metadata.MetaConnect.typeToThrift().

final int com.mapd.metadata.MetaConnect.KTIMESTAMP = 11
staticprivate

Definition at line 85 of file MetaConnect.java.

Referenced by com.mapd.metadata.MetaConnect.typeToThrift().

final int com.mapd.metadata.MetaConnect.KTINYINT = 22
staticprivate

Definition at line 96 of file MetaConnect.java.

Referenced by com.mapd.metadata.MetaConnect.typeToThrift().

final int com.mapd.metadata.MetaConnect.KVARCHAR = 3
staticprivate

Definition at line 77 of file MetaConnect.java.

Referenced by com.mapd.metadata.MetaConnect.typeToThrift().

volatile Map<String, Set<String> > com.mapd.metadata.MetaConnect.MAPD_DATABASE_TO_TABLES
staticprivate
Initial value:
=
new ConcurrentHashMap<>()

Definition at line 98 of file MetaConnect.java.

volatile Map<List<String>, Table> com.mapd.metadata.MetaConnect.MAPD_TABLE_DETAILS
staticprivate
Initial value:
=
new ConcurrentHashMap<>()

Definition at line 100 of file MetaConnect.java.

final Logger com.mapd.metadata.MetaConnect.MAPDLOGGER = LoggerFactory.getLogger(MetaConnect.class)
staticpackage

Definition at line 67 of file MetaConnect.java.

final MapDParser com.mapd.metadata.MetaConnect.parser
private
final SockTransportProperties com.mapd.metadata.MetaConnect.sock_transport_properties
private

Definition at line 102 of file MetaConnect.java.


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