OmniSciDB  29e35f4d58
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

◆ MetaConnect()

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.calcite.parser.MapDUser.getDB(), 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  }
final SockTransportProperties sock_transport_properties
+ Here is the call graph for this function:

Member Function Documentation

◆ connectToDBCatalog()

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

Definition at line 121 of file MetaConnect.java.

References com.mapd.metadata.MetaConnect.db, and Experimental.String.

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  }
static final Logger MAPDLOGGER
+ Here is the caller graph for this function:

◆ disconnectFromDBCatalog()

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

Definition at line 143 of file MetaConnect.java.

References Experimental.String.

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  }
static final Logger MAPDLOGGER
+ Here is the caller graph for this function:

◆ get_physical_cols()

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:

◆ get_table_detail_JSON()

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

Definition at line 444 of file MetaConnect.java.

References com.mapd.metadata.MetaConnect.get_physical_cols(), com.mapd.metadata.MetaConnect.is_geometry(), Experimental.String, and com.mapd.metadata.MetaConnect.typeToThrift().

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

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

◆ get_table_detail_SQL()

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.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(), Experimental.String, 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 
410  if (skip_physical_cols <= 0) skip_physical_cols = get_physical_cols(colType);
411  if (is_geometry(colType) || skip_physical_cols-- <= 0) td.addToRow_desc(tct);
412  }
413  } catch (Exception e) {
414  String err = "error trying to read from mapd_columns, error was " + e.getMessage();
415  MAPDLOGGER.error(err);
416  throw new RuntimeException(err);
417  } finally {
418  if (rs != null) {
419  try {
420  rs.close();
421  } catch (SQLException ex) {
422  String err = "Could not close resultset, error was " + ex.getMessage();
423  MAPDLOGGER.error(err);
424  throw new RuntimeException(err);
425  }
426  }
427  if (stmt != null) {
428  try {
429  stmt.close();
430  } catch (SQLException ex) {
431  String err = "Could not close stmt, error was " + ex.getMessage();
432  MAPDLOGGER.error(err);
433  throw new RuntimeException(err);
434  }
435  }
436  }
437  if (isView(tableName)) {
438  td.setView_sqlIsSet(true);
439  td.setView_sql(getViewSqlViaSql(id));
440  }
441  return td;
442  }
static final int get_physical_cols(int type)
static final boolean is_geometry(int type)
String getViewSqlViaSql(int tableId)
static final Logger MAPDLOGGER
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:

◆ get_table_details()

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(), com.mapd.calcite.parser.MapDUser.getSession(), and com.mapd.common.SockTransportProperties.openClientTransport().

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 =
299  if (!transport.isOpen()) transport.open();
300  protocol = new TBinaryProtocol(transport);
301 
302  MapD.Client client = new MapD.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 (TMapDException 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  }
TTransport openClientTransport(String server_host, int port)
static final Logger MAPDLOGGER
final SockTransportProperties sock_transport_properties
TTableDetails get_table_detail_SQL(String tableName)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getTable()

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(), and com.mapd.metadata.MetaConnect.getViewSql().

Referenced by com.mapd.calcite.parser.MapDSchema.getTable().

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  }
static volatile Map< List< String >, Table > MAPD_TABLE_DETAILS
String getViewSql(String tableName)
TTableDetails get_table_details(String tableName)
static final Logger MAPDLOGGER
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getTableId()

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

Definition at line 544 of file MetaConnect.java.

References Experimental.String.

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

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

◆ getTables()

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.calcite.parser.MapDUser.getSession(), com.mapd.metadata.MetaConnect.getTables_SQL(), com.mapd.common.SockTransportProperties.openClientTransport(), and Experimental.String.

Referenced by com.mapd.calcite.parser.MapDSchema.getTableNames().

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 =
195  if (!transport.isOpen()) transport.open();
196  protocol = new TBinaryProtocol(transport);
197 
198  MapD.Client client = new MapD.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 (TMapDException 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  }
TTransport openClientTransport(String server_host, int port)
static final Logger MAPDLOGGER
final SockTransportProperties sock_transport_properties
static volatile Map< String, Set< String > > MAPD_DATABASE_TO_TABLES
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getTables_SQL()

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.disconnectFromDBCatalog(), and Experimental.String.

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  }
static final Logger MAPDLOGGER
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getViewSql()

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

Definition at line 612 of file MetaConnect.java.

References com.mapd.metadata.MetaConnect.connectToDBCatalog(), com.mapd.metadata.MetaConnect.disconnectFromDBCatalog(), com.mapd.calcite.parser.MapDUser.getSession(), com.mapd.metadata.MetaConnect.getTableId(), com.mapd.metadata.MetaConnect.getViewSqlViaSql(), com.mapd.common.SockTransportProperties.openClientTransport(), and Experimental.String.

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

612  {
613  String sqlText;
614  if (mapdPort == -1) {
615  // use sql
617  sqlText = getViewSqlViaSql(getTableId(tableName));
619  } else {
620  // use thrift direct to local server
621  try {
622  TProtocol protocol = null;
623 
624  TTransport transport =
626  if (!transport.isOpen()) transport.open();
627  protocol = new TBinaryProtocol(transport);
628 
629  MapD.Client client = new MapD.Client(protocol);
630 
631  TTableDetails td = client.get_table_details(currentUser.getSession(), tableName);
632 
633  transport.close();
634 
635  sqlText = td.getView_sql();
636 
637  } catch (TTransportException ex) {
638  MAPDLOGGER.error(ex.toString());
639  throw new RuntimeException(ex.toString());
640  } catch (TMapDException ex) {
641  MAPDLOGGER.error(ex.toString());
642  throw new RuntimeException(ex.toString());
643  } catch (TException ex) {
644  MAPDLOGGER.error(ex.toString());
645  throw new RuntimeException(ex.toString());
646  }
647  }
648  /* return string without the sqlite's trailing semicolon */
649  if (sqlText.charAt(sqlText.length() - 1) == ';') {
650  return (sqlText.substring(0, sqlText.length() - 1));
651  } else {
652  return (sqlText);
653  }
654  }
TTransport openClientTransport(String server_host, int port)
String getViewSqlViaSql(int tableId)
static final Logger MAPDLOGGER
final SockTransportProperties sock_transport_properties
int getTableId(String tableName)
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ getViewSqlViaSql()

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

Definition at line 657 of file MetaConnect.java.

References Experimental.String.

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

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

◆ is_geometry()

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.KMULTIPOLYGON.

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:

◆ isView()

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

Definition at line 588 of file MetaConnect.java.

References Experimental.String.

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

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

◆ typeToThrift()

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

Definition at line 686 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().

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

◆ updateMetaData()

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

Definition at line 732 of file MetaConnect.java.

Referenced by com.mapd.calcite.parser.MapDSchema.updateMetaData().

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

Member Data Documentation

◆ catConn

Connection com.mapd.metadata.MetaConnect.catConn
private

Definition at line 72 of file MetaConnect.java.

◆ currentUser

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

Definition at line 70 of file MetaConnect.java.

◆ dataDir

final String com.mapd.metadata.MetaConnect.dataDir
private

Definition at line 68 of file MetaConnect.java.

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

◆ db

final String com.mapd.metadata.MetaConnect.db
private

Definition at line 69 of file MetaConnect.java.

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

◆ KARRAY

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

Definition at line 89 of file MetaConnect.java.

◆ KBIGINT

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

Definition at line 86 of file MetaConnect.java.

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

◆ KBOOLEAN

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

Definition at line 75 of file MetaConnect.java.

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

◆ KCHAR

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

Definition at line 76 of file MetaConnect.java.

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

◆ KDATE

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

Definition at line 88 of file MetaConnect.java.

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

◆ KDECIMAL

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

Definition at line 79 of file MetaConnect.java.

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

◆ KDOUBLE

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

Definition at line 83 of file MetaConnect.java.

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

◆ KFLOAT

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

Definition at line 82 of file MetaConnect.java.

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

◆ KINT

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

Definition at line 80 of file MetaConnect.java.

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

◆ KINTERVAL_DAY_TIME

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().

◆ KINTERVAL_YEAR_MONTH

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().

◆ KLINESTRING

final int com.mapd.metadata.MetaConnect.KLINESTRING = 19
staticprivate

◆ KMULTIPOLYGON

final int com.mapd.metadata.MetaConnect.KMULTIPOLYGON = 21
staticprivate

◆ KNUMERIC

final int com.mapd.metadata.MetaConnect.KNUMERIC = 4
staticprivate

Definition at line 78 of file MetaConnect.java.

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

◆ KPOINT

final int com.mapd.metadata.MetaConnect.KPOINT = 18
staticprivate

◆ KPOLYGON

final int com.mapd.metadata.MetaConnect.KPOLYGON = 20
staticprivate

◆ KSMALLINT

final int com.mapd.metadata.MetaConnect.KSMALLINT = 7
staticprivate

Definition at line 81 of file MetaConnect.java.

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

◆ KTEXT

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

Definition at line 87 of file MetaConnect.java.

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

◆ KTIME

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

Definition at line 84 of file MetaConnect.java.

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

◆ KTIMESTAMP

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

Definition at line 85 of file MetaConnect.java.

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

◆ KTINYINT

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

Definition at line 96 of file MetaConnect.java.

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

◆ KVARCHAR

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

Definition at line 77 of file MetaConnect.java.

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

◆ MAPD_DATABASE_TO_TABLES

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.

◆ MAPD_TABLE_DETAILS

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.

◆ MAPDLOGGER

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

Definition at line 67 of file MetaConnect.java.

◆ mapdPort

final int com.mapd.metadata.MetaConnect.mapdPort
private

Definition at line 71 of file MetaConnect.java.

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

◆ parser

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

Definition at line 73 of file MetaConnect.java.

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

◆ sock_transport_properties

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: