OmniSciDB  0fdbebe030
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
com.mapd.utility.SQLImporter Class Reference
+ Collaboration diagram for com.mapd.utility.SQLImporter:

Static Public Member Functions

static void main (String[] args)
 

Protected Attributes

String session = null
 
MapD.Client client = null
 

Package Functions

void doWork (String[] args)
 
void executeQuery ()
 

Package Attributes

Db_vendor_types vendor_types = null
 

Static Package Attributes

static final Logger LOGGER = LoggerFactory.getLogger(SQLImporter.class)
 

Private Member Functions

void run_init (Connection conn)
 
void help (Options options)
 
void checkMapDTable (Connection otherdb_conn, ResultSetMetaData md) throws SQLException
 
void verifyColumnSignaturesMatch (Connection otherdb_conn, List< TColumnType > dstColumns, ResultSetMetaData srcColumns) throws SQLException
 
void createMapDTable (Connection otherdb_conn, ResultSetMetaData metaData)
 
void createMapDConnection ()
 
List< TColumnType > getColumnInfo (String tName)
 
boolean tableExists (String tName)
 
void executeMapDCommand (String sql)
 
String getColType (int cType, int precision, int scale)
 
TColumn setupBinaryColumn (int i, ResultSetMetaData md, int bufferSize) throws SQLException
 
void setColValue (ResultSet rs, TColumn col, int columnType, int colNum, int scale, String colTypeName) throws SQLException
 
void resetBinaryColumn (int i, ResultSetMetaData md, int bufferSize, TColumn col) throws SQLException
 

Private Attributes

CommandLine cmd = null
 
DateTimeUtils dateTimeUtils
 

Detailed Description

Definition at line 300 of file SQLImporter.java.

Member Function Documentation

void com.mapd.utility.SQLImporter.checkMapDTable ( Connection  otherdb_conn,
ResultSetMetaData  md 
) throws SQLException
inlineprivate

Definition at line 492 of file SQLImporter.java.

References com.mapd.utility.SQLImporter.cmd, com.mapd.utility.SQLImporter.createMapDConnection(), com.mapd.utility.SQLImporter.createMapDTable(), com.mapd.utility.SQLImporter.executeMapDCommand(), com.mapd.utility.SQLImporter.getColumnInfo(), com.mapd.utility.SQLImporter.tableExists(), and com.mapd.utility.SQLImporter.verifyColumnSignaturesMatch().

Referenced by com.mapd.utility.SQLImporter.executeQuery().

493  {
495  String tName = cmd.getOptionValue("targetTable");
496 
497  if (tableExists(tName)) {
498  // check if we want to truncate
499  if (cmd.hasOption("truncate")) {
500  executeMapDCommand("Drop table " + tName);
501  createMapDTable(otherdb_conn, md);
502  } else {
503  List<TColumnType> columnInfo = getColumnInfo(tName);
504  verifyColumnSignaturesMatch(otherdb_conn, columnInfo, md);
505  }
506  } else {
507  createMapDTable(otherdb_conn, md);
508  }
509  }
List< TColumnType > getColumnInfo(String tName)
void createMapDTable(Connection otherdb_conn, ResultSetMetaData metaData)
void verifyColumnSignaturesMatch(Connection otherdb_conn, List< TColumnType > dstColumns, ResultSetMetaData srcColumns)
boolean tableExists(String tName)
void executeMapDCommand(String sql)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void com.mapd.utility.SQLImporter.createMapDConnection ( )
inlineprivate

Definition at line 667 of file SQLImporter.java.

References com.mapd.utility.SQLImporter.client, com.mapd.utility.SQLImporter.cmd, and com.mapd.utility.SQLImporter.session.

Referenced by com.mapd.utility.SQLImporter.checkMapDTable().

667  {
668  TTransport transport = null;
669  TProtocol protocol = new TBinaryProtocol(transport);
670  int port = Integer.valueOf(cmd.getOptionValue("port", "6274"));
671  String server = cmd.getOptionValue("server", "localhost");
672  try {
673  // Uses default certificate stores.
674  boolean load_trust_store = cmd.hasOption("https");
675  SockTransportProperties skT = null;
676  if (cmd.hasOption("https")) {
677  skT = SockTransportProperties.getEncryptedClientDefaultTrustStore(
678  !cmd.hasOption("insecure"));
679  transport = skT.openHttpsClientTransport(server, port);
680  transport.open();
681  protocol = new TJSONProtocol(transport);
682  } else if (cmd.hasOption("http")) {
683  skT = SockTransportProperties.getUnencryptedClient();
684  transport = skT.openHttpClientTransport(server, port);
685  protocol = new TJSONProtocol(transport);
686  } else {
687  skT = SockTransportProperties.getUnencryptedClient();
688  transport = skT.openClientTransport(server, port);
689  transport.open();
690  protocol = new TBinaryProtocol(transport);
691  }
692 
693  client = new MapD.Client(protocol);
694  // This if will be useless until PKI signon
695  if (cmd.hasOption("user")) {
696  session = client.connect(cmd.getOptionValue("user", "admin"),
697  cmd.getOptionValue("passwd", "HyperInteractive"),
698  cmd.getOptionValue("database", "omnisci"));
699  }
700  LOGGER.debug("Connected session is " + session);
701 
702  } catch (TTransportException ex) {
703  LOGGER.error("Connection failed - " + ex.toString());
704  exit(1);
705  } catch (TMapDException ex) {
706  LOGGER.error("Connection failed - " + ex.toString());
707  exit(2);
708  } catch (TException ex) {
709  LOGGER.error("Connection failed - " + ex.toString());
710  exit(3);
711  } catch (Exception ex) {
712  LOGGER.error("General exception - " + ex.toString());
713  exit(4);
714  }
715  }

+ Here is the caller graph for this function:

void com.mapd.utility.SQLImporter.createMapDTable ( Connection  otherdb_conn,
ResultSetMetaData  metaData 
)
inlineprivate

Definition at line 625 of file SQLImporter.java.

References File_Namespace.append(), com.mapd.utility.SQLImporter.cmd, com.mapd.utility.SQLImporter.executeMapDCommand(), com.mapd.utility.SQLImporter.getColType(), Integer, and run_benchmark_import.type.

Referenced by com.mapd.utility.SQLImporter.checkMapDTable().

625  {
626  StringBuilder sb = new StringBuilder();
627  sb.append("Create table ").append(cmd.getOptionValue("targetTable")).append("(");
628 
629  // Now iterate the metadata
630  try {
631  for (int i = 1; i <= metaData.getColumnCount(); i++) {
632  if (i > 1) {
633  sb.append(",");
634  }
635  LOGGER.debug("Column name is " + metaData.getColumnName(i));
636  LOGGER.debug("Column type is " + metaData.getColumnTypeName(i));
637  LOGGER.debug("Column type is " + metaData.getColumnType(i));
638 
639  sb.append(metaData.getColumnName(i)).append(" ");
640  int col_type = metaData.getColumnType(i);
641  if (col_type == java.sql.Types.OTHER) {
642  Db_vendor_types.GisType type =
643  vendor_types.find_gis_type(otherdb_conn, metaData, i);
644  sb.append(Db_vendor_types.gis_type_to_str(type));
645  } else {
646  sb.append(getColType(metaData.getColumnType(i),
647  metaData.getPrecision(i),
648  metaData.getScale(i)));
649  }
650  }
651  sb.append(")");
652 
653  if (Integer.valueOf(cmd.getOptionValue("fragmentSize", "0")) > 0) {
654  sb.append(" with (fragment_size = ");
655  sb.append(cmd.getOptionValue("fragmentSize", "0"));
656  sb.append(")");
657  }
658 
659  } catch (SQLException ex) {
660  LOGGER.error("Error processing the metadata - " + ex.toString());
661  exit(1);
662  }
663 
664  executeMapDCommand(sb.toString());
665  }
String getColType(int cType, int precision, int scale)
size_t append(FILE *f, const size_t size, int8_t *buf)
Appends the specified number of bytes to the end of the file f from buf.
Definition: File.cpp:135
void executeMapDCommand(String sql)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void com.mapd.utility.SQLImporter.doWork ( String[]  args)
inlinepackage

Definition at line 316 of file SQLImporter.java.

References run_benchmark_import.args, com.mapd.utility.SQLImporter.cmd, and com.mapd.utility.SQLImporter.executeQuery().

316  {
317  // create Options object
318 
319  SQLImporter_args s_args = new SQLImporter_args();
320 
321  try {
322  cmd = s_args.parse(args);
323  } catch (ParseException ex) {
324  LOGGER.error(ex.getLocalizedMessage());
325  s_args.printHelpMessage();
326  exit(0);
327  }
328  executeQuery();
329  }

+ Here is the call graph for this function:

void com.mapd.utility.SQLImporter.executeMapDCommand ( String  sql)
inlineprivate

Definition at line 752 of file SQLImporter.java.

References com.mapd.utility.SQLImporter.session.

Referenced by com.mapd.utility.SQLImporter.checkMapDTable(), and com.mapd.utility.SQLImporter.createMapDTable().

752  {
753  LOGGER.info(" run comamnd :" + sql);
754 
755  try {
756  TQueryResult sqlResult = client.sql_execute(session, sql + ";", true, null, -1, -1);
757  } catch (TMapDException ex) {
758  LOGGER.error("SQL Execute failed - " + ex.toString());
759  exit(1);
760  } catch (TException ex) {
761  LOGGER.error("SQL Execute failed - " + ex.toString());
762  exit(1);
763  }
764  }

+ Here is the caller graph for this function:

void com.mapd.utility.SQLImporter.executeQuery ( )
inlinepackage

Definition at line 331 of file SQLImporter.java.

References com.mapd.utility.SQLImporter.checkMapDTable(), com.mapd.utility.SQLImporter.cmd, com.mapd.utility.SQLImporter.resetBinaryColumn(), com.mapd.utility.SQLImporter.run_init(), com.mapd.utility.SQLImporter.session, com.mapd.utility.SQLImporter.setColValue(), com.mapd.utility.SQLImporter.setupBinaryColumn(), and com.mapd.utility.SQLImporter.vendor_types.

Referenced by com.mapd.utility.SQLImporter.doWork().

331  {
332  Connection conn = null;
333  Statement stmt = null;
334 
335  long totalTime = 0;
336 
337  try {
338  // Open a connection
339  LOGGER.info("Connecting to database url :" + cmd.getOptionValue("jdbcConnect"));
340  conn = DriverManager.getConnection(cmd.getOptionValue("jdbcConnect"),
341  cmd.getOptionValue("sourceUser"),
342  cmd.getOptionValue("sourcePasswd"));
343  vendor_types = Db_vendor_types.Db_vendor_factory(cmd.getOptionValue("jdbcConnect"));
344  long startTime = System.currentTimeMillis();
345 
346  // run init file script on targe DB if present
347  if (cmd.hasOption("initializeFile")) {
348  run_init(conn);
349  }
350 
351  // set autocommit off to allow postgress to not load all results
352  try {
353  conn.setAutoCommit(false);
354  } catch (SQLException se) {
355  LOGGER.warn(
356  "SQLException when attempting to setAutoCommit to false, jdbc driver probably doesnt support it. Error is "
357  + se.toString());
358  }
359 
360  // Execute a query
361  stmt = conn.createStatement();
362 
363  int bufferSize = Integer.valueOf(cmd.getOptionValue("bufferSize", "10000"));
364  // set the jdbc fetch buffer size to reduce the amount of records being moved to
365  // java from postgress
366  stmt.setFetchSize(bufferSize);
367  long timer;
368 
369  ResultSet rs = stmt.executeQuery(cmd.getOptionValue("sqlStmt"));
370 
371  // check if table already exists and is compatible in OmniSci with the query
372  // metadata
373  ResultSetMetaData md = rs.getMetaData();
374  checkMapDTable(conn, md);
375 
376  timer = System.currentTimeMillis();
377 
378  long resultCount = 0;
379  int bufferCount = 0;
380  long total = 0;
381 
382  List<TColumn> cols = new ArrayList(md.getColumnCount());
383  for (int i = 1; i <= md.getColumnCount(); i++) {
384  TColumn col = setupBinaryColumn(i, md, bufferSize);
385  cols.add(col);
386  }
387 
388  // read data from old DB
389  while (rs.next()) {
390  for (int i = 1; i <= md.getColumnCount(); i++) {
391  setColValue(rs,
392  cols.get(i - 1),
393  md.getColumnType(i),
394  i,
395  md.getScale(i),
396  md.getColumnTypeName(i));
397  }
398  resultCount++;
399  bufferCount++;
400  if (bufferCount == bufferSize) {
401  bufferCount = 0;
402  // send the buffer to mapD
403  client.load_table_binary_columnar(
404  session, cmd.getOptionValue("targetTable"), cols); // old
405  // recreate columnar store for use
406  for (int i = 1; i <= md.getColumnCount(); i++) {
407  resetBinaryColumn(i, md, bufferSize, cols.get(i - 1));
408  }
409 
410  if (resultCount % 100000 == 0) {
411  LOGGER.info("Imported " + resultCount + " records");
412  }
413  }
414  }
415  if (bufferCount > 0) {
416  // send the LAST buffer to mapD
417  client.load_table_binary_columnar(
418  session, cmd.getOptionValue("targetTable"), cols);
419  bufferCount = 0;
420  }
421  LOGGER.info("result set count is " + resultCount + " read time is "
422  + (System.currentTimeMillis() - timer) + "ms");
423 
424  // Clean-up environment
425  rs.close();
426  stmt.close();
427 
428  totalTime = System.currentTimeMillis() - startTime;
429  conn.close();
430  } catch (SQLException se) {
431  LOGGER.error("SQLException - " + se.toString());
432  se.printStackTrace();
433  } catch (TMapDException ex) {
434  LOGGER.error("TMapDException - " + ex.toString());
435  ex.printStackTrace();
436  } catch (TException ex) {
437  LOGGER.error("TException failed - " + ex.toString());
438  ex.printStackTrace();
439  } finally {
440  // finally block used to close resources
441  try {
442  if (stmt != null) {
443  stmt.close();
444  }
445  } catch (SQLException se2) {
446  } // nothing we can do
447  try {
448  if (conn != null) {
449  conn.close();
450  }
451  } catch (SQLException se) {
452  LOGGER.error("SQlException in close - " + se.toString());
453  se.printStackTrace();
454  } // end finally try
455  } // end try
456  }
void resetBinaryColumn(int i, ResultSetMetaData md, int bufferSize, TColumn col)
void checkMapDTable(Connection otherdb_conn, ResultSetMetaData md)
void setColValue(ResultSet rs, TColumn col, int columnType, int colNum, int scale, String colTypeName)
TColumn setupBinaryColumn(int i, ResultSetMetaData md, int bufferSize)
void run_init(Connection conn)

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

String com.mapd.utility.SQLImporter.getColType ( int  cType,
int  precision,
int  scale 
)
inlineprivate

Definition at line 766 of file SQLImporter.java.

Referenced by com.mapd.utility.SQLImporter.createMapDTable().

766  {
767  // Note - if cType is OTHER a earlier call will have been made
768  // to try and work out the db vendors specific type.
769  if (precision > 19) {
770  precision = 19;
771  }
772  if (scale > 19) {
773  scale = 18;
774  }
775  switch (cType) {
776  case java.sql.Types.TINYINT:
777  return ("TINYINT");
778  case java.sql.Types.SMALLINT:
779  return ("SMALLINT");
780  case java.sql.Types.INTEGER:
781  return ("INTEGER");
782  case java.sql.Types.BIGINT:
783  return ("BIGINT");
784  case java.sql.Types.FLOAT:
785  return ("FLOAT");
786  case java.sql.Types.DECIMAL:
787  return ("DECIMAL(" + precision + "," + scale + ")");
788  case java.sql.Types.DOUBLE:
789  return ("DOUBLE");
790  case java.sql.Types.REAL:
791  return ("REAL");
792  case java.sql.Types.NUMERIC:
793  return ("NUMERIC(" + precision + "," + scale + ")");
794  case java.sql.Types.TIME:
795  return ("TIME");
796  case java.sql.Types.TIMESTAMP:
797  return ("TIMESTAMP");
798  case java.sql.Types.DATE:
799  return ("DATE");
800  case java.sql.Types.BOOLEAN:
801  case java.sql.Types
802  .BIT: // deal with postgress treating boolean as bit... this will bite me
803  return ("BOOLEAN");
804  case java.sql.Types.NVARCHAR:
805  case java.sql.Types.VARCHAR:
806  case java.sql.Types.NCHAR:
807  case java.sql.Types.CHAR:
808  case java.sql.Types.LONGVARCHAR:
809  case java.sql.Types.LONGNVARCHAR:
810  return ("TEXT ENCODING DICT");
811  default:
812  throw new AssertionError("Column type " + cType + " not Supported");
813  }
814  }

+ Here is the caller graph for this function:

List<TColumnType> com.mapd.utility.SQLImporter.getColumnInfo ( String  tName)
inlineprivate

Definition at line 717 of file SQLImporter.java.

References com.mapd.utility.SQLImporter.session.

Referenced by com.mapd.utility.SQLImporter.checkMapDTable().

717  {
718  LOGGER.debug("Getting columns for " + tName);
719  List<TColumnType> row_descriptor = null;
720  try {
721  TTableDetails table_details = client.get_table_details(session, tName);
722  row_descriptor = table_details.row_desc;
723  } catch (TMapDException ex) {
724  LOGGER.error("column check failed - " + ex.toString());
725  exit(3);
726  } catch (TException ex) {
727  LOGGER.error("column check failed - " + ex.toString());
728  exit(3);
729  }
730  return row_descriptor;
731  }

+ Here is the caller graph for this function:

void com.mapd.utility.SQLImporter.help ( Options  options)
inlineprivate

Definition at line 485 of file SQLImporter.java.

485  {
486  // automatically generate the help statement
487  HelpFormatter formatter = new HelpFormatter();
488  formatter.setOptionComparator(null); // get options in the order they are created
489  formatter.printHelp("SQLImporter", options);
490  }
static void com.mapd.utility.SQLImporter.main ( String[]  args)
inlinestatic

Definition at line 311 of file SQLImporter.java.

References run_benchmark_import.args.

311  {
312  SQLImporter sq = new SQLImporter();
313  sq.doWork(args);
314  }
void com.mapd.utility.SQLImporter.resetBinaryColumn ( int  i,
ResultSetMetaData  md,
int  bufferSize,
TColumn  col 
) throws SQLException
inlineprivate

Definition at line 987 of file SQLImporter.java.

Referenced by com.mapd.utility.SQLImporter.executeQuery().

988  {
989  col.nulls.clear();
990 
991  switch (md.getColumnType(i)) {
992  case java.sql.Types.TINYINT:
993  case java.sql.Types.SMALLINT:
994  case java.sql.Types.INTEGER:
995  case java.sql.Types.BIGINT:
996  case java.sql.Types.TIME:
997  case java.sql.Types.TIMESTAMP:
998  case java.sql.Types
999  .BIT: // deal with postgress treating boolean as bit... this will bite me
1000  case java.sql.Types.BOOLEAN:
1001  case java.sql.Types.DATE:
1002  case java.sql.Types.DECIMAL:
1003  case java.sql.Types.NUMERIC:
1004  col.data.int_col.clear();
1005  break;
1006 
1007  case java.sql.Types.FLOAT:
1008  case java.sql.Types.DOUBLE:
1009  case java.sql.Types.REAL:
1010  col.data.real_col.clear();
1011  break;
1012 
1013  case java.sql.Types.NVARCHAR:
1014  case java.sql.Types.VARCHAR:
1015  case java.sql.Types.NCHAR:
1016  case java.sql.Types.CHAR:
1017  case java.sql.Types.LONGVARCHAR:
1018  case java.sql.Types.LONGNVARCHAR:
1019  case java.sql.Types.OTHER:
1020  col.data.str_col.clear();
1021  break;
1022  default:
1023  throw new AssertionError("Column type " + md.getColumnType(i) + " not Supported");
1024  }
1025  }

+ Here is the caller graph for this function:

void com.mapd.utility.SQLImporter.run_init ( Connection  conn)
inlineprivate

Definition at line 458 of file SQLImporter.java.

References com.mapd.utility.SQLImporter.cmd.

Referenced by com.mapd.utility.SQLImporter.executeQuery().

458  {
459  // attempt to open file
460  String line = "";
461  try {
462  BufferedReader reader =
463  new BufferedReader(new FileReader(cmd.getOptionValue("initializeFile")));
464  Statement stmt = conn.createStatement();
465  while ((line = reader.readLine()) != null) {
466  if (line.isEmpty()) {
467  continue;
468  }
469  LOGGER.info("Running : " + line);
470  stmt.execute(line);
471  }
472  stmt.close();
473  reader.close();
474  } catch (IOException e) {
475  LOGGER.error("Exception occurred trying to read initialize file: "
476  + cmd.getOptionValue("initFile"));
477  exit(1);
478  } catch (SQLException e) {
479  LOGGER.error(
480  "Exception occurred trying to execute initialize file entry : " + line);
481  exit(1);
482  }
483  }

+ Here is the caller graph for this function:

void com.mapd.utility.SQLImporter.setColValue ( ResultSet  rs,
TColumn  col,
int  columnType,
int  colNum,
int  scale,
String  colTypeName 
) throws SQLException
inlineprivate

Definition at line 862 of file SQLImporter.java.

References Double.

Referenced by com.mapd.utility.SQLImporter.executeQuery().

867  {
868  switch (columnType) {
869  case java.sql.Types
870  .BIT: // deal with postgress treating boolean as bit... this will bite me
871  case java.sql.Types.BOOLEAN:
872  Boolean b = rs.getBoolean(colNum);
873  if (rs.wasNull()) {
874  col.nulls.add(Boolean.TRUE);
875  col.data.int_col.add(0L);
876  } else {
877  col.nulls.add(Boolean.FALSE);
878  col.data.int_col.add(b ? 1L : 0L);
879  }
880  break;
881 
882  case java.sql.Types.DECIMAL:
883  case java.sql.Types.NUMERIC:
884  BigDecimal bd = rs.getBigDecimal(colNum);
885  if (rs.wasNull()) {
886  col.nulls.add(Boolean.TRUE);
887  col.data.int_col.add(0L);
888  } else {
889  col.nulls.add(Boolean.FALSE);
890  col.data.int_col.add(bd.multiply(new BigDecimal(pow(10L, scale))).longValue());
891  }
892  break;
893 
894  case java.sql.Types.TINYINT:
895  case java.sql.Types.SMALLINT:
896  case java.sql.Types.INTEGER:
897  case java.sql.Types.BIGINT:
898  Long l = rs.getLong(colNum);
899  if (rs.wasNull()) {
900  col.nulls.add(Boolean.TRUE);
901  col.data.int_col.add(new Long(0));
902  } else {
903  col.nulls.add(Boolean.FALSE);
904  col.data.int_col.add(l);
905  }
906  break;
907 
908  case java.sql.Types.TIME:
909  Time t = rs.getTime(colNum);
910  if (rs.wasNull()) {
911  col.nulls.add(Boolean.TRUE);
912  col.data.int_col.add(0L);
913 
914  } else {
915  col.data.int_col.add(dateTimeUtils.getSecondsFromMilliseconds(t.getTime()));
916  col.nulls.add(Boolean.FALSE);
917  }
918 
919  break;
920  case java.sql.Types.TIMESTAMP:
921  Timestamp ts = rs.getTimestamp(colNum);
922  if (rs.wasNull()) {
923  col.nulls.add(Boolean.TRUE);
924  col.data.int_col.add(0L);
925 
926  } else {
927  col.data.int_col.add(dateTimeUtils.getSecondsFromMilliseconds(ts.getTime()));
928  col.nulls.add(Boolean.FALSE);
929  }
930 
931  break;
932  case java.sql.Types.DATE:
933  Date d = rs.getDate(colNum);
934  if (rs.wasNull()) {
935  col.nulls.add(Boolean.TRUE);
936  col.data.int_col.add(0L);
937 
938  } else {
939  col.data.int_col.add(dateTimeUtils.getSecondsFromMilliseconds(d.getTime()));
940  col.nulls.add(Boolean.FALSE);
941  }
942  break;
943  case java.sql.Types.FLOAT:
944  case java.sql.Types.DOUBLE:
945  case java.sql.Types.REAL:
946  Double db = rs.getDouble(colNum);
947  if (rs.wasNull()) {
948  col.nulls.add(Boolean.TRUE);
949  col.data.real_col.add(new Double(0));
950 
951  } else {
952  col.nulls.add(Boolean.FALSE);
953  col.data.real_col.add(db);
954  }
955  break;
956 
957  case java.sql.Types.NVARCHAR:
958  case java.sql.Types.VARCHAR:
959  case java.sql.Types.NCHAR:
960  case java.sql.Types.CHAR:
961  case java.sql.Types.LONGVARCHAR:
962  case java.sql.Types.LONGNVARCHAR:
963  String strVal = rs.getString(colNum);
964  if (rs.wasNull()) {
965  col.nulls.add(Boolean.TRUE);
966  col.data.str_col.add("");
967 
968  } else {
969  col.data.str_col.add(strVal);
970  col.nulls.add(Boolean.FALSE);
971  }
972  break;
973  case java.sql.Types.OTHER:
974  if (rs.wasNull()) {
975  col.nulls.add(Boolean.TRUE);
976  col.data.str_col.add("");
977  } else {
978  col.data.str_col.add(vendor_types.get_wkt(rs, colNum, colTypeName));
979  col.nulls.add(Boolean.FALSE);
980  }
981  break;
982  default:
983  throw new AssertionError("Column type " + columnType + " not Supported");
984  }
985  }

+ Here is the caller graph for this function:

TColumn com.mapd.utility.SQLImporter.setupBinaryColumn ( int  i,
ResultSetMetaData  md,
int  bufferSize 
) throws SQLException
inlineprivate

Definition at line 816 of file SQLImporter.java.

Referenced by com.mapd.utility.SQLImporter.executeQuery().

817  {
818  TColumn col = new TColumn();
819 
820  col.nulls = new ArrayList<Boolean>(bufferSize);
821 
822  col.data = new TColumnData();
823 
824  switch (md.getColumnType(i)) {
825  case java.sql.Types.TINYINT:
826  case java.sql.Types.SMALLINT:
827  case java.sql.Types.INTEGER:
828  case java.sql.Types.BIGINT:
829  case java.sql.Types.TIME:
830  case java.sql.Types.TIMESTAMP:
831  case java.sql.Types
832  .BIT: // deal with postgress treating boolean as bit... this will bite me
833  case java.sql.Types.BOOLEAN:
834  case java.sql.Types.DATE:
835  case java.sql.Types.DECIMAL:
836  case java.sql.Types.NUMERIC:
837  col.data.int_col = new ArrayList<Long>(bufferSize);
838  break;
839 
840  case java.sql.Types.FLOAT:
841  case java.sql.Types.DOUBLE:
842  case java.sql.Types.REAL:
843  col.data.real_col = new ArrayList<Double>(bufferSize);
844  break;
845 
846  case java.sql.Types.NVARCHAR:
847  case java.sql.Types.VARCHAR:
848  case java.sql.Types.NCHAR:
849  case java.sql.Types.CHAR:
850  case java.sql.Types.LONGVARCHAR:
851  case java.sql.Types.LONGNVARCHAR:
852  case java.sql.Types.OTHER:
853  col.data.str_col = new ArrayList<String>(bufferSize);
854  break;
855 
856  default:
857  throw new AssertionError("Column type " + md.getColumnType(i) + " not Supported");
858  }
859  return col;
860  }

+ Here is the caller graph for this function:

boolean com.mapd.utility.SQLImporter.tableExists ( String  tName)
inlineprivate

Definition at line 733 of file SQLImporter.java.

References com.mapd.utility.SQLImporter.session.

Referenced by com.mapd.utility.SQLImporter.checkMapDTable().

733  {
734  LOGGER.debug("Check for table " + tName);
735  try {
736  List<String> recv_get_tables = client.get_tables(session);
737  for (String s : recv_get_tables) {
738  if (s.equals(tName)) {
739  return true;
740  }
741  }
742  } catch (TMapDException ex) {
743  LOGGER.error("Table check failed - " + ex.toString());
744  exit(3);
745  } catch (TException ex) {
746  LOGGER.error("Table check failed - " + ex.toString());
747  exit(3);
748  }
749  return false;
750  }

+ Here is the caller graph for this function:

void com.mapd.utility.SQLImporter.verifyColumnSignaturesMatch ( Connection  otherdb_conn,
List< TColumnType >  dstColumns,
ResultSetMetaData  srcColumns 
) throws SQLException
inlineprivate

Definition at line 511 of file SQLImporter.java.

Referenced by com.mapd.utility.SQLImporter.checkMapDTable().

513  {
514  if (srcColumns.getColumnCount() != dstColumns.size()) {
515  LOGGER.error("Table sizes do not match: Destination " + dstColumns.size()
516  + " versus Source " + srcColumns.getColumnCount());
517  exit(1);
518  }
519  for (int i = 1; i <= dstColumns.size(); ++i) {
520  if (!dstColumns.get(i - 1).getCol_name().equalsIgnoreCase(
521  srcColumns.getColumnName(i))) {
522  LOGGER.error(
523  "Destination table does not have matching column in same order for column number"
524  + i + " destination column name is " + dstColumns.get(i - 1).col_name
525  + " versus Select " + srcColumns.getColumnName(i));
526  exit(1);
527  }
528  TDatumType dstType = dstColumns.get(i - 1).getCol_type().getType();
529  int dstPrecision = dstColumns.get(i - 1).getCol_type().getPrecision();
530  int dstScale = dstColumns.get(i - 1).getCol_type().getScale();
531  int srcType = srcColumns.getColumnType(i);
532  int srcPrecision = srcColumns.getPrecision(i);
533  int srcScale = srcColumns.getScale(i);
534 
535  boolean match = false;
536  switch (srcType) {
537  case java.sql.Types.TINYINT:
538  match |= dstType == TDatumType.TINYINT;
539  // NOTE: it's okay to import smaller type to a bigger one,
540  // so we just fall through and try to match the next type.
541  // But the order of case statements is important here!
542  case java.sql.Types.SMALLINT:
543  match |= dstType == TDatumType.SMALLINT;
544  case java.sql.Types.INTEGER:
545  match |= dstType == TDatumType.INT;
546  case java.sql.Types.BIGINT:
547  match |= dstType == TDatumType.BIGINT;
548  break;
549  case java.sql.Types.DECIMAL:
550  case java.sql.Types.NUMERIC:
551  match = dstType == TDatumType.DECIMAL && dstPrecision == srcPrecision
552  && dstScale == srcScale;
553  break;
554  case java.sql.Types.FLOAT:
555  case java.sql.Types.REAL:
556  match |= dstType == TDatumType.FLOAT;
557  // Fall through and try double
558  case java.sql.Types.DOUBLE:
559  match |= dstType == TDatumType.DOUBLE;
560  break;
561  case java.sql.Types.TIME:
562  match = dstType == TDatumType.TIME;
563  break;
564  case java.sql.Types.TIMESTAMP:
565  match = dstType == TDatumType.TIMESTAMP;
566  break;
567  case java.sql.Types.DATE:
568  match = dstType == TDatumType.DATE;
569  break;
570  case java.sql.Types.BOOLEAN:
571  case java.sql.Types
572  .BIT: // deal with postgres treating boolean as bit... this will bite me
573  match = dstType == TDatumType.BOOL;
574  break;
575  case java.sql.Types.NVARCHAR:
576  case java.sql.Types.VARCHAR:
577  case java.sql.Types.NCHAR:
578  case java.sql.Types.CHAR:
579  case java.sql.Types.LONGVARCHAR:
580  case java.sql.Types.LONGNVARCHAR:
581  match = dstType == TDatumType.STR;
582  break;
583  case java.sql.Types.OTHER:
584  // NOTE: I ignore subtypes (geography vs geopetry vs none) here just because it
585  // makes no difference for OmniSciDB at the moment
586  Db_vendor_types.GisType gisType =
587  vendor_types.find_gis_type(otherdb_conn, srcColumns, i);
588  if (gisType.srid != dstScale) {
589  match = false;
590  break;
591  }
592  switch (dstType) {
593  case POINT:
594  match = gisType.type.equalsIgnoreCase("POINT");
595  break;
596  case LINESTRING:
597  match = gisType.type.equalsIgnoreCase("LINESTRING");
598  break;
599  case POLYGON:
600  match = gisType.type.equalsIgnoreCase("POLYGON");
601  break;
602  case MULTIPOLYGON:
603  match = gisType.type.equalsIgnoreCase("MULTIPOLYGON");
604  break;
605  default:
606  LOGGER.error("Column type " + JDBCType.valueOf(srcType).getName()
607  + " not Supported");
608  exit(1);
609  }
610  break;
611  default:
612  LOGGER.error("Column type " + JDBCType.valueOf(srcType).getName()
613  + " not Supported");
614  exit(1);
615  }
616  if (!match) {
617  LOGGER.error("Source and destination types for column "
618  + srcColumns.getColumnName(i)
619  + " do not match. Please make sure that type, precision and scale are exactly the same");
620  exit(1);
621  }
622  }
623  }

+ Here is the caller graph for this function:

Member Data Documentation

MapD.Client com.mapd.utility.SQLImporter.client = null
protected

Definition at line 302 of file SQLImporter.java.

Referenced by com.mapd.utility.SQLImporter.createMapDConnection().

DateTimeUtils com.mapd.utility.SQLImporter.dateTimeUtils
private
Initial value:
= (milliseconds) -> {
return milliseconds / 1000;
}

Definition at line 305 of file SQLImporter.java.

final Logger com.mapd.utility.SQLImporter.LOGGER = LoggerFactory.getLogger(SQLImporter.class)
staticpackage

Definition at line 304 of file SQLImporter.java.

Db_vendor_types com.mapd.utility.SQLImporter.vendor_types = null
package

Definition at line 309 of file SQLImporter.java.

Referenced by com.mapd.utility.SQLImporter.executeQuery().


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