chrthomsen / pygrametl

Official repository for pygrametl - ETL programming in Python
http://pygrametl.org
BSD 2-Clause "Simplified" License
289 stars 41 forks source link

Added missing BulkFactTable attributes #49

Closed fromm1990 closed 2 years ago

fromm1990 commented 2 years ago

This should fix issue #48 The following should be able to run after applying this fix.

import sqlite3

from pygrametl import ConnectionWrapper, parallel
from pygrametl.tables import BulkFactTable, DecoupledFactTable, FactTablePartitioner

connection = sqlite3.connect(":memory:")
cursor = connection.execute("CREATE TABLE test_table(ra INT, rb INT, ma INT, mb INT)")
connection.commit()
cursor.close()

def bulkloader(name: str, attributes, fieldsep, rowsep, nullval, filehandle):
    pass

cw = ConnectionWrapper(connection)
scw = parallel.shareconnectionwrapper(cw, userfuncs=[bulkloader])

fact = DecoupledFactTable(
    BulkFactTable(
        name="test_table",
        keyrefs=["ra", "rb"],
        measures=["ma", "mb"],
        bulkloader=scw.copy().bulkloader,
        usefilename=True
    ),
    returnvalues=False,
)

partitioner = FactTablePartitioner(parts=[fact])

print("START")
for i in range(3000):
    print(i)
    partitioner.insert({"ra": i, "rb": i % 2, "ma": 1, "mb": 2})
scw.commit()
scw.close()
print("END")