Skip to content
This repository has been archived by the owner on Nov 19, 2021. It is now read-only.

Segmentation fault when work table present #88

Open
adamtwo opened this issue Nov 1, 2021 · 0 comments
Open

Segmentation fault when work table present #88

adamtwo opened this issue Nov 1, 2021 · 0 comments

Comments

@adamtwo
Copy link

adamtwo commented Nov 1, 2021

Giraffez core dumps with Segmentation fault error when giraffez.BulkLoad is called but a work table is present.

Steps to reproduce:

  1. Create a test database:
    CREATE DATABASE demo_db
    AS PERMANENT = 60e6,
        SPOOL = 60e6;
    
  2. Execute the following python script. You may have to edit td_connection to point to your Vantage database instance.
    The script drops table demo_db.test_table_wt and then creates it. It then runs giraffez.BulkLoad against demo_db.test_table. With this naming convention, the script pretends that the work table is always there.
    import giraffez
    
    td_connection = {
        "host": "localhost",
        "username": "dbc",
        "password": "dbc"
    }
    
    try:
        with giraffez.Cmd(**td_connection) as cmd:
            cmd.execute("DROP TABLE demo_db.test_table_wt")
    except Exception:
        pass
    
    
    create_ddl = "create multiset table demo_db.test_table_wt(\
        INDEX_ID         BIGINT)"
    
    with giraffez.Cmd(**td_connection) as cmd:
        cmd.execute(create_ddl)
        show_ddl = cmd.execute("SHOW TABLE demo_db.test_table_wt")
        print(list(show_ddl))
    
    
    f = open("/tmp/temp.csv", "w")
    f.write("1")
    f.close()
    
    with giraffez.BulkLoad(**td_connection, table="demo_db.test_table") as load:
        load.from_file(
            "/tmp/temp.csv",
            delimiter=","
        )
    
  3. Result:
    [Row({'request_text': 'CREATE MULTISET TABLE demo_db.test_table_wt ,FALLBACK ,\r     NO BEFORE JOURNAL,\r     NO AFTER JOURNAL,\r     CHECKSUM = DEFAULT,\r     DEFAULT MERGEBLOCKRATIO,\r     MAP = TD_MAP1\r     (\r      index_id BIGINT)\rPRIMARY INDEX ( index_id );'})]
    Segmentation fault (core dumped)
    

I've looked at the core dump. Backtrace points to giraffez/src/teradatapt.hpp:296 at if (err->Code == TD_SUCCESS):

PyObject* Exists(const char *tbl_name) {
    TeradataErr *err = NULL;
    PyObject *ret;
    ret = Py_False;
    Py_INCREF(ret);
    std::string query = "show table " + std::string(tbl_name);
    if ((err = this->ExecuteCommand(query, false)) != NULL) {
        if (err->Code != TD_ERROR_OBJECT_NOT_EXIST) {
            return NULL;
        }
        PyErr_Clear();
    }
    if (err->Code == TD_SUCCESS) { 
        // TODO: ref correct?
        ret = Py_True;
    }
    return ret;
}

When a work table exists ExecuteCommand() returns NULL. As a result, err object is also NULL. Line 296 then references memory address 0.

Many thanks to @acirtep for helping me identify the issue.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant