16 package com.mapd.utility;
18 import static java.lang.Math.pow;
19 import static java.lang.System.exit;
24 import org.apache.commons.cli.*;
25 import org.apache.thrift.TException;
26 import org.apache.thrift.protocol.TBinaryProtocol;
27 import org.apache.thrift.protocol.TJSONProtocol;
28 import org.apache.thrift.protocol.TProtocol;
29 import org.apache.thrift.transport.TSocket;
30 import org.apache.thrift.transport.TTransport;
31 import org.apache.thrift.transport.TTransportException;
32 import org.slf4j.Logger;
33 import org.slf4j.LoggerFactory;
35 import java.io.BufferedReader;
36 import java.io.FileReader;
37 import java.io.IOException;
38 import java.math.BigDecimal;
39 import java.security.KeyStore;
42 import java.util.ArrayList;
43 import java.util.List;
45 import ai.heavy.thrift.server.*;
57 StringBuffer sb =
new StringBuffer(
58 "Mutually exclusive options used. " + errMsg +
". Options provided [");
59 for (String s : strings) {
63 sb.setCharAt(sb.length() - 1,
']');
72 System.out.println(
"SQLImporter Version 4.6.0");
76 StringBuffer sb =
new StringBuffer(
"\nSQLImporter ");
79 sb.append(
"-u <userid> -p <password> [(--binary|--http|--https [--insecure])]\n");
80 sb.append(
"-s <omnisci server host> -db <omnisci db> --port <omnisci server port>\n");
85 "[-d <other database JDBC drive class>] -c <other database JDBC connection string>\n");
87 "-su <other database user> -sp <other database user password> -ss <other database sql statement>\n");
89 "-t <HEAVYAI target table> -b <transfer buffer size> -f <table fragment size>\n");
90 sb.append(
"[-tr] [-adtf] [-nprg] -i <init commands file>\n");
91 sb.append(
"\nSQLImporter -h | --help\n\n");
93 HelpFormatter formatter =
new HelpFormatter();
96 formatter.setOptionComparator(null);
98 formatter.printHelp(help_width, sb.toString(),
"",
options,
"");
102 options.addOption(
"r",
true,
"Row Load Limit");
105 options.addOption(Option.builder(
"h").desc(
"help message").longOpt(
"help").build());
107 Option.builder(
"u").hasArg().desc(
"HEAVYAI User").longOpt(
"user").build());
108 options.addOption(Option.builder(
"p")
110 .desc(
"HEAVYAI Password")
114 OptionGroup transport_grp =
new OptionGroup();
115 transport_grp.addOption(Option.builder()
116 .desc(
"use binary transport to connect to HEAVYAI ")
119 transport_grp.addOption(Option.builder()
120 .desc(
"use http transport to connect to HEAVYAI ")
123 transport_grp.addOption(Option.builder()
124 .desc(
"use https transport to connect to HEAVYAI ")
127 options.addOptionGroup(transport_grp);
130 options.addOption(Option.builder(
"s")
132 .desc(
"HEAVYAI Server")
135 options.addOption(Option.builder(
"db")
137 .desc(
"HEAVYAI Database")
141 Option.builder().hasArg().desc(
"HEAVYAI Port").longOpt(
"port").build());
144 options.addOption(Option.builder()
146 .desc(
"CA certificate trust store")
147 .longOpt(
"ca-trust-store")
149 options.addOption(Option.builder()
151 .desc(
"CA certificate trust store password")
152 .longOpt(
"ca-trust-store-passwd")
156 .desc(
"Insecure TLS - do not validate server HEAVYAI server credentials")
161 options.addOption(Option.builder(
"d")
163 .desc(
"JDBC driver class")
166 options.addOption(Option.builder(
"c")
168 .desc(
"JDBC Connection string")
169 .longOpt(
"jdbcConnect")
172 options.addOption(Option.builder(
"su")
175 .longOpt(
"sourceUser")
178 options.addOption(Option.builder(
"sp")
180 .desc(
"Source Password")
181 .longOpt(
"sourcePasswd")
184 options.addOption(Option.builder(
"ss")
186 .desc(
"SQL Select statement")
191 options.addOption(Option.builder(
"t")
193 .desc(
"HEAVYAI Target Table")
194 .longOpt(
"targetTable")
198 options.addOption(Option.builder(
"b")
200 .desc(
"transfer buffer size")
201 .longOpt(
"bufferSize")
203 options.addOption(Option.builder(
"f")
205 .desc(
"table fragment size")
206 .longOpt(
"fragmentSize")
209 options.addOption(Option.builder(
"tr")
210 .desc(
"Truncate table if it exists")
214 options.addOption(Option.builder(
"i")
216 .desc(
"File containing init command for DB")
217 .longOpt(
"initializeFile")
221 Option.builder(
"adtf")
222 .desc(
"Allow double to float conversion, note precision will be reduced")
223 .longOpt(
"AllowDoubleToFloat")
227 Option.builder(
"ain")
228 .desc(
"Allow conversion from bigger integer types to smaller. Overflow might occur, "
229 +
"use it only when casting is impossible")
230 .longOpt(
"AllowIntegerNarrowing")
233 options.addOption(Option.builder(
"nlj")
234 .desc(
"Omit JDBC connection string from logs.")
235 .longOpt(
"no-log-jdbc-connection-string")
240 option.setRequired(
true);
244 public CommandLine
parse(String[]
args)
throws ParseException {
245 CommandLineParser clp =
new DefaultParser() {
246 public CommandLine
parse(Options
options, String[] strings)
throws ParseException {
247 Options helpOptions =
new Options();
248 helpOptions.addOption(
249 Option.builder(
"h").desc(
"help message").longOpt(
"help").build());
251 CommandLine cmd = super.parse(helpOptions, strings);
252 }
catch (UnrecognizedOptionException uE) {
254 if (cmd.hasOption(
"help")) {
258 if (cmd.hasOption(
"version")) {
262 cmd = super.parse(
options, strings);
263 if (!cmd.hasOption(
"user") && !cmd.hasOption(
"client-cert")) {
264 throw new MissingArgumentException(
265 "Must supply either an HEAVYAI db user or a user certificate");
268 if (cmd.hasOption(
"user") || cmd.hasOption(
"passwd")) {
278 if (cmd.hasOption(
"client-cert") || cmd.hasOption(
"client-key")) {
284 if (options.getOption(
"user").isRequired()
285 && options.getOption(
"client-key").isRequired()) {
287 MutuallyExlusiveOptionsException.create(
288 "user/password can not be use with client-cert/client-key",
293 if (cmd.hasOption(
"http")
294 || cmd.hasOption(
"binary")
295 && (cmd.hasOption(
"client-cert")
296 || cmd.hasOption(
"client-key"))) {
298 "http|binary can not be use with ca-cert|client-cert|client-key",
303 if (cmd.hasOption(
"insecure") && !cmd.hasOption(
"https")) {
305 "insecure can only be use with https", strings);
312 public CommandLine
parse(Options options, String[] strings,
boolean b)
313 throws ParseException {
324 private CommandLine
cmd = null;
325 final static Logger
LOGGER = LoggerFactory.getLogger(SQLImporter.class);
327 return milliseconds / 1000;
344 }
catch (ParseException ex) {
345 LOGGER.error(ex.getLocalizedMessage());
346 s_args.printHelpMessage();
353 Connection
conn = null;
354 Statement stmt = null;
360 if (
cmd.hasOption(
"nlj")) {
361 LOGGER.info(
"Connecting to source database.");
363 LOGGER.info(
"Connecting to database url :" + cmd.getOptionValue(
"jdbcConnect"));
365 conn = DriverManager.getConnection(cmd.getOptionValue(
"jdbcConnect"),
366 cmd.getOptionValue(
"sourceUser"),
367 cmd.getOptionValue(
"sourcePasswd"));
368 vendor_types = Db_vendor_types.Db_vendor_factory(cmd.getOptionValue(
"jdbcConnect"));
369 long startTime = System.currentTimeMillis();
372 if (
cmd.hasOption(
"initializeFile")) {
378 conn.setAutoCommit(
false);
380 }
catch (SQLException se) {
382 "SQLException when attempting to setAutoCommit to false, jdbc driver probably doesnt support it. Error is "
387 stmt = conn.createStatement();
389 int bufferSize = Integer.valueOf(cmd.getOptionValue(
"bufferSize",
"10000"));
392 stmt.setFetchSize(bufferSize);
395 ResultSet rs = stmt.executeQuery(cmd.getOptionValue(
"sqlStmt"));
399 ResultSetMetaData md = rs.getMetaData();
402 timer = System.currentTimeMillis();
404 long resultCount = 0;
408 List<TColumn> cols =
new ArrayList(md.getColumnCount());
409 for (
int i = 1; i <= md.getColumnCount(); i++) {
416 for (
int i = 1; i <= md.getColumnCount(); i++) {
422 md.getColumnTypeName(i));
426 if (bufferCount == bufferSize) {
429 client.load_table_binary_columnar(
430 session, cmd.getOptionValue(
"targetTable"), cols, null);
432 for (
int i = 1; i <= md.getColumnCount(); i++) {
436 if (resultCount % 100000 == 0) {
437 LOGGER.info(
"Imported " + resultCount +
" records");
441 if (bufferCount > 0) {
443 client.load_table_binary_columnar(
444 session, cmd.getOptionValue(
"targetTable"), cols, null);
448 LOGGER.info(
"result set count is " + resultCount +
" read time is "
449 + (System.currentTimeMillis() - timer) +
"ms");
456 totalTime = System.currentTimeMillis() - startTime;
457 }
catch (SQLException se) {
458 LOGGER.error(
"SQLException - " + se.toString());
459 se.printStackTrace();
460 }
catch (TDBException ex) {
461 LOGGER.error(
"TDBException - " + ex.getError_msg());
462 ex.printStackTrace();
463 }
catch (TException ex) {
464 LOGGER.error(
"TException failed - " + ex.toString());
465 ex.printStackTrace();
472 }
catch (SQLException se2) {
478 }
catch (SQLException se) {
479 LOGGER.error(
"SQlException in close - " + se.toString());
480 se.printStackTrace();
486 }
catch (TDBException ex) {
487 LOGGER.error(
"TDBException - in finalization " + ex.getError_msg());
488 ex.printStackTrace();
489 }
catch (TException ex) {
490 LOGGER.error(
"TException - in finalization" + ex.toString());
491 ex.printStackTrace();
500 BufferedReader reader =
501 new BufferedReader(
new FileReader(
cmd.getOptionValue(
"initializeFile")));
502 Statement stmt = conn.createStatement();
503 while ((line = reader.readLine()) != null) {
504 if (line.isEmpty()) {
507 LOGGER.info(
"Running : " +
line);
512 }
catch (IOException e) {
513 LOGGER.error(
"Exception occurred trying to read initialize file: "
514 + cmd.getOptionValue(
"initFile"));
516 }
catch (SQLException e) {
518 "Exception occurred trying to execute initialize file entry : " +
line);
523 private void help(Options options) {
525 HelpFormatter formatter =
new HelpFormatter();
526 formatter.setOptionComparator(null);
527 formatter.printHelp(
"SQLImporter", options);
530 private void checkDBTable(Connection otherdb_conn, ResultSetMetaData md)
531 throws SQLException {
533 String tName = cmd.getOptionValue(
"targetTable");
537 if (
cmd.hasOption(
"truncate")) {
550 List<TColumnType> dstColumns,
551 ResultSetMetaData srcColumns)
throws SQLException {
552 if (srcColumns.getColumnCount() != dstColumns.size()) {
553 LOGGER.error(
"Table sizes do not match: Destination " + dstColumns.size()
554 +
" versus Source " + srcColumns.getColumnCount());
557 for (
int i = 1; i <= dstColumns.size(); ++i) {
558 if (!dstColumns.get(i - 1).getCol_name().equalsIgnoreCase(
559 srcColumns.getColumnName(i))) {
561 "Destination table does not have matching column in same order for column number "
562 + i +
" destination column name is " + dstColumns.get(i - 1).col_name
563 +
" versus target column " + srcColumns.getColumnName(i));
566 TDatumType dstType = dstColumns.get(i - 1).getCol_type().getType();
567 int dstPrecision = dstColumns.get(i - 1).getCol_type().getPrecision();
568 int dstScale = dstColumns.get(i - 1).getCol_type().getScale();
569 int srcType = srcColumns.getColumnType(i);
570 int srcPrecision = srcColumns.getPrecision(i);
571 int srcScale = srcColumns.getScale(i);
573 boolean match =
false;
575 case java.sql.Types.TINYINT:
576 match |= dstType == TDatumType.TINYINT;
580 case java.sql.Types.SMALLINT:
581 match |= dstType == TDatumType.SMALLINT;
582 case java.sql.Types.INTEGER:
583 match |= dstType == TDatumType.INT;
584 case java.sql.Types.BIGINT:
585 match |= dstType == TDatumType.BIGINT;
586 if (
cmd.hasOption(
"AllowIntegerNarrowing")) {
587 match |= dstType == TDatumType.TINYINT || dstType == TDatumType.SMALLINT
588 || dstType == TDatumType.INT;
591 case java.sql.Types.DECIMAL:
592 case java.sql.Types.NUMERIC:
593 match = dstType == TDatumType.DECIMAL && dstPrecision == srcPrecision
594 && dstScale == srcScale;
596 case java.sql.Types.FLOAT:
597 case java.sql.Types.REAL:
598 match |= dstType == TDatumType.FLOAT;
600 case java.sql.Types.DOUBLE:
601 match |= dstType == TDatumType.DOUBLE;
602 if (
cmd.hasOption(
"AllowDoubleToFloat")) {
603 match |= dstType == TDatumType.FLOAT;
606 case java.sql.Types.TIME:
607 match = dstType == TDatumType.TIME;
609 case java.sql.Types.TIMESTAMP:
610 match = dstType == TDatumType.TIMESTAMP;
612 case java.sql.Types.DATE:
613 match = dstType == TDatumType.DATE;
615 case java.sql.Types.BOOLEAN:
618 match = dstType == TDatumType.BOOL;
620 case java.sql.Types.NVARCHAR:
621 case java.sql.Types.VARCHAR:
622 case java.sql.Types.NCHAR:
623 case java.sql.Types.CHAR:
624 case java.sql.Types.LONGVARCHAR:
625 case java.sql.Types.LONGNVARCHAR:
626 match = (dstType == TDatumType.STR || dstType == TDatumType.POINT
627 || dstType == TDatumType.POLYGON || dstType == TDatumType.MULTIPOLYGON
628 || dstType == TDatumType.LINESTRING
629 || dstType == TDatumType.MULTILINESTRING
630 || dstType == TDatumType.MULTIPOINT);
632 case java.sql.Types.OTHER:
635 Db_vendor_types.GisType gisType =
636 vendor_types.find_gis_type(otherdb_conn, srcColumns, i);
637 if (gisType.srid != dstScale) {
643 match = gisType.type.equalsIgnoreCase(
"POINT");
646 match = gisType.type.equalsIgnoreCase(
"MULTIPOINT");
649 match = gisType.type.equalsIgnoreCase(
"LINESTRING");
651 case MULTILINESTRING:
652 match = gisType.type.equalsIgnoreCase(
"MULTILINESTRING");
655 match = gisType.type.equalsIgnoreCase(
"POLYGON");
658 match = gisType.type.equalsIgnoreCase(
"MULTIPOLYGON");
661 LOGGER.error(
"Column type " + JDBCType.valueOf(srcType).getName()
667 LOGGER.error(
"Column type " + JDBCType.valueOf(srcType).getName()
672 LOGGER.error(
"Source and destination types for column "
673 + srcColumns.getColumnName(i)
674 +
" do not match. Please make sure that type, precision and scale are exactly the same");
680 private void createDBTable(Connection otherdb_conn, ResultSetMetaData metaData) {
681 StringBuilder sb =
new StringBuilder();
682 sb.append(
"Create table ").
append(
cmd.getOptionValue(
"targetTable")).
append(
"(");
686 for (
int i = 1; i <= metaData.getColumnCount(); i++) {
690 LOGGER.debug(
"Column name is " + metaData.getColumnName(i));
691 LOGGER.debug(
"Column type is " + metaData.getColumnTypeName(i));
692 LOGGER.debug(
"Column type is " + metaData.getColumnType(i));
694 sb.append(metaData.getColumnName(i)).append(
" ");
695 int col_type = metaData.getColumnType(i);
696 if (col_type == java.sql.Types.OTHER) {
697 Db_vendor_types.GisType
type =
698 vendor_types.find_gis_type(otherdb_conn, metaData, i);
699 sb.append(Db_vendor_types.gis_type_to_str(
type));
701 sb.append(
getColType(metaData.getColumnType(i),
702 metaData.getPrecision(i),
703 metaData.getScale(i)));
708 if (
Integer.valueOf(
cmd.getOptionValue(
"fragmentSize",
"0")) > 0) {
709 sb.append(
" with (fragment_size = ");
710 sb.append(cmd.getOptionValue(
"fragmentSize",
"0"));
714 }
catch (SQLException ex) {
715 LOGGER.error(
"Error processing the metadata - " + ex.toString());
723 TTransport transport = null;
724 TProtocol protocol =
new TBinaryProtocol(transport);
725 int port = Integer.valueOf(cmd.getOptionValue(
"port",
"6274"));
726 String server = cmd.getOptionValue(
"server",
"localhost");
729 boolean load_trust_store = cmd.hasOption(
"https");
731 if (
cmd.hasOption(
"https")) {
732 skT = SockTransportProperties.getEncryptedClientDefaultTrustStore(
733 !cmd.hasOption(
"insecure"));
734 transport = skT.openHttpsClientTransport(server, port);
736 protocol =
new TJSONProtocol(transport);
737 }
else if (
cmd.hasOption(
"http")) {
738 skT = SockTransportProperties.getUnencryptedClient();
739 transport = skT.openHttpClientTransport(server, port);
740 protocol =
new TJSONProtocol(transport);
742 skT = SockTransportProperties.getUnencryptedClient();
743 transport = skT.openClientTransport(server, port);
745 protocol =
new TBinaryProtocol(transport);
748 client =
new Heavy.Client(protocol);
750 if (
cmd.hasOption(
"user")) {
751 session = client.connect(cmd.getOptionValue(
"user",
"admin"),
752 cmd.getOptionValue(
"passwd",
"HyperInteractive"),
753 cmd.getOptionValue(
"database",
"omnisci"));
755 LOGGER.debug(
"Connected session is " +
session);
757 }
catch (TTransportException ex) {
758 LOGGER.error(
"Connection failed - " + ex.toString());
760 }
catch (TDBException ex) {
761 LOGGER.error(
"Connection failed - " + ex.getError_msg());
763 }
catch (TException ex) {
764 LOGGER.error(
"Connection failed - " + ex.toString());
766 }
catch (Exception ex) {
767 LOGGER.error(
"General exception - " + ex.toString());
773 LOGGER.debug(
"Getting columns for " + tName);
774 List<TColumnType> row_descriptor = null;
776 TTableDetails table_details = client.get_table_details(
session, tName);
777 row_descriptor = table_details.row_desc;
778 }
catch (TDBException ex) {
779 LOGGER.error(
"column check failed - " + ex.getError_msg());
781 }
catch (TException ex) {
782 LOGGER.error(
"column check failed - " + ex.toString());
785 return row_descriptor;
789 LOGGER.debug(
"Check for table " + tName);
791 List<String> recv_get_tables = client.get_tables(
session);
792 for (String s : recv_get_tables) {
793 if (s.equals(tName)) {
797 }
catch (TDBException ex) {
798 LOGGER.error(
"Table check failed - " + ex.getError_msg());
800 }
catch (TException ex) {
801 LOGGER.error(
"Table check failed - " + ex.toString());
808 LOGGER.info(
"Run Command - " + sql);
811 TQueryResult sqlResult = client.sql_execute(
session, sql +
";",
true, null, -1, -1);
812 }
catch (TDBException ex) {
813 LOGGER.error(
"SQL Execute failed - " + ex.getError_msg());
815 }
catch (TException ex) {
816 LOGGER.error(
"SQL Execute failed - " + ex.toString());
821 private String
getColType(
int cType,
int precision,
int scale) {
824 if (precision > 19) {
831 case java.sql.Types.TINYINT:
833 case java.sql.Types.SMALLINT:
835 case java.sql.Types.INTEGER:
837 case java.sql.Types.BIGINT:
839 case java.sql.Types.FLOAT:
841 case java.sql.Types.DECIMAL:
842 return (
"DECIMAL(" + precision +
"," + scale +
")");
843 case java.sql.Types.DOUBLE:
845 case java.sql.Types.REAL:
847 case java.sql.Types.NUMERIC:
848 return (
"NUMERIC(" + precision +
"," + scale +
")");
849 case java.sql.Types.TIME:
851 case java.sql.Types.TIMESTAMP:
852 return (
"TIMESTAMP");
853 case java.sql.Types.DATE:
855 case java.sql.Types.BOOLEAN:
859 case java.sql.Types.NVARCHAR:
860 case java.sql.Types.VARCHAR:
861 case java.sql.Types.NCHAR:
862 case java.sql.Types.CHAR:
863 case java.sql.Types.LONGVARCHAR:
864 case java.sql.Types.LONGNVARCHAR:
865 return (
"TEXT ENCODING DICT");
867 throw new AssertionError(
"Column type " + cType +
" not Supported");
872 throws SQLException {
873 TColumn col =
new TColumn();
875 col.nulls =
new ArrayList<Boolean>(bufferSize);
877 col.data =
new TColumnData();
879 switch (md.getColumnType(i)) {
880 case java.sql.Types.TINYINT:
881 case java.sql.Types.SMALLINT:
882 case java.sql.Types.INTEGER:
883 case java.sql.Types.BIGINT:
884 case java.sql.Types.TIME:
885 case java.sql.Types.TIMESTAMP:
888 case java.sql.Types.BOOLEAN:
889 case java.sql.Types.DATE:
890 case java.sql.Types.DECIMAL:
891 case java.sql.Types.NUMERIC:
892 col.data.int_col =
new ArrayList<Long>(bufferSize);
895 case java.sql.Types.FLOAT:
896 case java.sql.Types.DOUBLE:
897 case java.sql.Types.REAL:
898 col.data.real_col =
new ArrayList<Double>(bufferSize);
901 case java.sql.Types.NVARCHAR:
902 case java.sql.Types.VARCHAR:
903 case java.sql.Types.NCHAR:
904 case java.sql.Types.CHAR:
905 case java.sql.Types.LONGVARCHAR:
906 case java.sql.Types.LONGNVARCHAR:
907 case java.sql.Types.OTHER:
908 col.data.str_col =
new ArrayList<String>(bufferSize);
912 throw new AssertionError(
"Column type " + md.getColumnType(i) +
" not Supported");
922 String colTypeName)
throws SQLException {
923 switch (columnType) {
926 case java.sql.Types.BOOLEAN:
927 Boolean b = rs.getBoolean(colNum);
929 col.nulls.add(Boolean.TRUE);
930 col.data.int_col.add(0L);
932 col.nulls.add(Boolean.FALSE);
933 col.data.int_col.add(b ? 1L : 0L);
937 case java.sql.Types.DECIMAL:
938 case java.sql.Types.NUMERIC:
939 BigDecimal bd = rs.getBigDecimal(colNum);
941 col.nulls.add(Boolean.TRUE);
942 col.data.int_col.add(0L);
944 col.nulls.add(Boolean.FALSE);
945 col.data.int_col.add(bd.multiply(
new BigDecimal(pow(10L, scale))).longValue());
949 case java.sql.Types.TINYINT:
950 case java.sql.Types.SMALLINT:
951 case java.sql.Types.INTEGER:
952 case java.sql.Types.BIGINT:
953 Long l = rs.getLong(colNum);
955 col.nulls.add(Boolean.TRUE);
956 col.data.int_col.add(
new Long(0));
958 col.nulls.add(Boolean.FALSE);
959 col.data.int_col.add(l);
963 case java.sql.Types.TIME:
964 Time t = rs.getTime(colNum);
966 col.nulls.add(Boolean.TRUE);
967 col.data.int_col.add(0L);
970 col.data.int_col.add(dateTimeUtils.getSecondsFromMilliseconds(t.getTime()));
971 col.nulls.add(Boolean.FALSE);
975 case java.sql.Types.TIMESTAMP:
976 Timestamp ts = rs.getTimestamp(colNum);
978 col.nulls.add(Boolean.TRUE);
979 col.data.int_col.add(0L);
982 col.data.int_col.add(dateTimeUtils.getSecondsFromMilliseconds(ts.getTime()));
983 col.nulls.add(Boolean.FALSE);
987 case java.sql.Types.DATE:
988 Date d = rs.getDate(colNum);
990 col.nulls.add(Boolean.TRUE);
991 col.data.int_col.add(0L);
994 col.data.int_col.add(dateTimeUtils.getSecondsFromMilliseconds(d.getTime()));
995 col.nulls.add(Boolean.FALSE);
998 case java.sql.Types.FLOAT:
999 case java.sql.Types.DOUBLE:
1000 case java.sql.Types.REAL:
1001 Double db = rs.getDouble(colNum);
1003 col.nulls.add(Boolean.TRUE);
1004 col.data.real_col.add(
new Double(0));
1007 col.nulls.add(Boolean.FALSE);
1008 col.data.real_col.add(db);
1012 case java.sql.Types.NVARCHAR:
1013 case java.sql.Types.VARCHAR:
1014 case java.sql.Types.NCHAR:
1015 case java.sql.Types.CHAR:
1016 case java.sql.Types.LONGVARCHAR:
1017 case java.sql.Types.LONGNVARCHAR:
1018 String strVal = rs.getString(colNum);
1020 col.nulls.add(Boolean.TRUE);
1021 col.data.str_col.add(
"");
1024 col.data.str_col.add(strVal);
1025 col.nulls.add(Boolean.FALSE);
1028 case java.sql.Types.OTHER:
1029 Object objVal = rs.getObject(colNum);
1031 col.nulls.add(Boolean.TRUE);
1032 col.data.str_col.add(
"");
1034 col.data.str_col.add(vendor_types.get_wkt(rs, colNum, colTypeName));
1035 col.nulls.add(Boolean.FALSE);
1039 throw new AssertionError(
"Column type " + columnType +
" not Supported");
1044 throws SQLException {
1047 switch (md.getColumnType(i)) {
1048 case java.sql.Types.TINYINT:
1049 case java.sql.Types.SMALLINT:
1050 case java.sql.Types.INTEGER:
1051 case java.sql.Types.BIGINT:
1052 case java.sql.Types.TIME:
1053 case java.sql.Types.TIMESTAMP:
1056 case java.sql.Types.BOOLEAN:
1057 case java.sql.Types.DATE:
1058 case java.sql.Types.DECIMAL:
1059 case java.sql.Types.NUMERIC:
1060 col.data.int_col.clear();
1063 case java.sql.Types.FLOAT:
1064 case java.sql.Types.DOUBLE:
1065 case java.sql.Types.REAL:
1066 col.data.real_col.clear();
1069 case java.sql.Types.NVARCHAR:
1070 case java.sql.Types.VARCHAR:
1071 case java.sql.Types.NCHAR:
1072 case java.sql.Types.CHAR:
1073 case java.sql.Types.LONGVARCHAR:
1074 case java.sql.Types.LONGNVARCHAR:
1075 case java.sql.Types.OTHER:
1076 col.data.str_col.clear();
1079 throw new AssertionError(
"Column type " + md.getColumnType(i) +
" not Supported");
void createDBTable(Connection otherdb_conn, ResultSetMetaData metaData)
void resetBinaryColumn(int i, ResultSetMetaData md, int bufferSize, TColumn col)
Option setOptionRequired(Option option)
size_t append(FILE *f, const size_t size, const int8_t *buf)
Appends the specified number of bytes to the end of the file f from buf.
String getColType(int cType, int precision, int scale)
void executeDBCommand(String sql)
abstract boolean isAutoCommitDisabledRequired()
void help(Options options)
static void main(String[] args)
void createDBConnection()
void doWork(String[] args)
void setColValue(ResultSet rs, TColumn col, int columnType, int colNum, int scale, String colTypeName)
List< TColumnType > getColumnInfo(String tName)
CommandLine parse(String[] args)
void checkDBTable(Connection otherdb_conn, ResultSetMetaData md)
void verifyColumnSignaturesMatch(Connection otherdb_conn, List< TColumnType > dstColumns, ResultSetMetaData srcColumns)
static final Logger LOGGER
boolean tableExists(String tName)
long getSecondsFromMilliseconds(long milliseconds)
DateTimeUtils dateTimeUtils
MutuallyExlusiveOptionsException(String message)
TColumn setupBinaryColumn(int i, ResultSetMetaData md, int bufferSize)
static MutuallyExlusiveOptionsException create(String errMsg, String[] strings)
Db_vendor_types vendor_types
void run_init(Connection conn)