Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
logging.debug("Reading table_schema_file: " + table_schema_file)
create_table_sql = table_schema.read().replace("\n", " ")
create_table_sql = create_table_sql.replace(
"##TAB##", import_table_name
)
create_table_sql = create_table_sql.replace(
"##FRAGMENT_SIZE##", args.fragment_size
)
except FileNotFoundError:
logging.exception("Could not find table_schema_file.")
exit(1)
try:
logging.debug("Creating import table...")
res = con.execute(create_table_sql)
logging.debug("Import table created.")
except (pymapd.exceptions.ProgrammingError, pymapd.exceptions.Error):
logging.exception("Error running table creation")
exit(1)
# Run the import query
if import_query_template_file:
try:
with open(import_query_template_file, "r") as import_query_template:
logging.debug(
"Reading import_query_template_file: " + import_query_template_file
)
import_query = import_query_template.read().replace("\n", " ")
import_query = import_query.replace(
"##TAB##", import_table_name
)
import_query = import_query.replace(
Returns:
con(class): Connection class
False(bool): The connection failed. Exception should be logged.
"""
try:
logging.debug("Connecting to mapd db...")
con = pymapd.connect(
user=kwargs["db_user"],
password=kwargs["db_passwd"],
host=kwargs["db_server"],
port=kwargs["db_port"],
dbname=kwargs["db_name"],
)
logging.info("Succesfully connected to mapd db")
return con
except (pymapd.exceptions.OperationalError, pymapd.exceptions.Error):
logging.exception("Error connecting to database.")
return False
logging.debug("Executing create destination table query")
dest_con.execute(create_table_sql)
logging.debug("Destination table created.")
except (pymapd.exceptions.ProgrammingError, pymapd.exceptions.Error):
logging.exception("Error running destination table creation")
return False
logging.info("Loading results into destination db")
try:
dest_con.load_table_columnar(
kwargs["table"],
results_df,
preserve_index=False,
chunk_size_bytes=0,
col_names_from_schema=True,
)
except (pymapd.exceptions.ProgrammingError, pymapd.exceptions.Error):
logging.exception("Error loading results into destination db")
dest_con.close()
return False
dest_con.close()
return True
Returns:
con(class): Connection class
False(bool): The connection failed. Exception should be logged.
"""
try:
logging.debug("Connecting to mapd db...")
con = pymapd.connect(
user=kwargs["db_user"],
password=kwargs["db_passwd"],
host=kwargs["db_server"],
port=kwargs["db_port"],
dbname=kwargs["db_name"],
)
logging.info("Succesfully connected to mapd db")
return con
except (pymapd.exceptions.OperationalError, pymapd.exceptions.Error):
logging.exception("Error connecting to database.")
return False