python - pygrametl KeyError when loading data from one to another table -
i experimenting pygrametl, trying data 1 table in database (source) table in destination database.
the source table has following schema:
create table `sdata` ( `id` int(11) not null auto_increment, `fname` varchar(255) default null, `descr` varchar(255) default null, primary key (`id`) ) engine=innodb auto_increment=4 default charset=utf8 comment=' ';
the destination table uses following schema:
create table `dtable` ( `id` int(11) not null auto_increment, `dname` varchar(255) default null, `ddescr` varchar(255) default null, primary key (`id`) ) engine=innodb default charset=utf8;
in python have following code:
import pygrametl pygrametl.datasources import sqlsource, csvsource pygrametl.tables import dimension, facttable, slowlychangingdimension import pymysql sourcedatabase = pymysql.connect(host='localhost', user='root', password='pass', database='source') destdatabase = pymysql.connect(host='localhost', user='root', password='pass', database='dest') dw_conn_wrapper = pygrametl.connectionwrapper(connection=destdatabase) sql = "select fname, descr sdata" name_mapping = 'fname', 'descr' source = sqlsource(connection=sourcedatabase, query=sql, names=name_mapping) destdimension = dimension( name='dtable', key='id', attributes=['dname', 'ddescr']) row in source: print(row) destdimension.insert(row) dw_conn_wrapper.commit() dw_conn_wrapper.close() sourcedatabase.close()
the error getting following:
traceback (most recent call last): file ".\testex.py", line 35, in sourcedimension.insert(row) file "python\python36-32\lib\site-packages\pygrametl\tables.py", line 357, in insert self.targetconnection.execute(self.insertsql, row, namemapping) file "python\python36-32\lib\site-packages\pygrametl__init__.py", line 663, in execute self.__cursor.execute(stmt, arguments) file "python\python36-32\lib\site-packages\pymysql\cursors.py", line 164, in execute query = self.mogrify(query, args) file "python\python36-32\lib\site-packages\pymysql\cursors.py", line 143, in mogrify query = query % self._escape_args(args, conn) keyerror: 'dname'
Comments
Post a Comment