I have weather data in json files. I'd like to import into a mariadb. The directory…
- User
I have weather data in json files. I'd like to import into a mariadb. The directory format is /YYYY_MM_DD//report.json . Can you help me import this into mariadb? Sample report.json file: { "temperature_F": 66.91309953674802, "humidity": 0.3792800598652316, "wind_speed_m/s": 1.251136434293354, "wind_direction": "WSW", "operator_name": "MonetaRuffolo", "sensor_name": "Curie_Ver1.3" }
- Assistant
- User
What are advantages or disadvantages of using commit for a batch size of 500?
- Assistant
Here’s a quick rundown of the trade‑offs when you group your INSERTs in transactions of ~500 rows before committing:
-
Throughput vs. Durability
• Pro: Fewer commits means fewer expensive fsyncs/round‑trips, so overall insert throughput goes up dramatically.
• Con: None of the 500 new rows is visible (or durable on disk) until you hit that 500‑row boundary and commit. • Risk: If the server crashes or you kill the script mid‑batch, you lose up to 499 rows rather than just the one you were on.
-
- User
If there are no commits mentioned in the script when does the data get committed?
- Assistant
In Python’s DB‐API (and in mysql‑connector-python by default), nothing is written permanently until you either:
- explicitly call
connection.commit(), or - you’ve turned on “autocommit” so that every statement is its own transaction.
In the example script I gave you we do two kinds of commits:
• Inside the loop:
python if count % BATCH_SIZE == 0: db.commit()
This flushes each batch of 500 rows.• After we’ve processed everything:
python db.commit()
This picks up any stragglers under 500.If you removed all calls to
db.commit()and leftautocommit=Falsein yourDB_CONFIG, then:• All of your inserts would accumulate in one big un‐committed transaction.
• When the script terminates (and the connection is closed), most MySQL/Python drivers will that open transaction by default. • Effectively—you’d end up with rows in the database. - explicitly call