Apperently it doesn't have items() method. By how then?
I am trying to send Row to database with the code:
def write_row(table_name, cur, row): data = [] for key, value in row.items(): data.append((key, value)) data = zip(*data) columns = ", ".join(data[0]) values = data[1] questionmarks = ", ".join(["?"] * len(columns)) query = f"INSERT INTO {table_name} ({columns}) VALUES ({questionmarks})" cur.execute(query, values) def write_data_frame(df, epoch1): conn = mariadb.connect(**config["mariadb"]) cur = conn.cursor() table_name = "pysparktest" rows = df.collect() for row in rows: write_row(table_name, cur, row) conn.commit() It swears
AttributeError: items What if rows are nested?
root |-- track: struct (nullable = true) | |-- name: string (nullable = true) | |-- version: string (nullable = true) |-- car: struct (nullable = true) | |-- name: string (nullable = true) | |-- version: string (nullable = true) |-- cnt: long (nullable = false) |-- minBestLapTime: double (nullable = true)
row.asDict().items()?