You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hudi.apache.org by "rangareddy (via GitHub)" <gi...@apache.org> on 2025/12/15 05:35:13 UTC

Re: [I] Support bucket index for spark bulk_insert [hudi]

rangareddy commented on issue #15736:
URL: https://github.com/apache/hudi/issues/15736#issuecomment-3653258419

   I created a sample code to test this scenario. The data insertion was successful, but querying the table returned empty results.
   
   ```python
   table_name = "orders_bucket_bulk"
   base_path = f"file:///tmp/{table_name}"
   
   # Define the data schema
   data = [
       (1, "user-1", 100.0, "2024-01-01"),
       (2, "user-2", 200.0, "2024-01-01"),
       (3, "user-3", 300.0, "2024-01-02")
   ]
   columns = ["order_id", "customer_id", "amount", "order_date"]
   
   df = spark.createDataFrame(data, columns)
   df.printSchema()
   df.show()
   
   hudi_options = {
       "hoodie.table.name": table_name,
       "hoodie.datasource.write.table.name": table_name,
       "hoodie.datasource.write.recordkey.field": "order_id",
       "hoodie.datasource.write.partitionpath.field": "order_date",
       "hoodie.table.type": "MERGE_ON_READ",
       # Use bulk_insert operation
       "hoodie.datasource.write.operation": "bulk_insert",
       # Bucket index configuration
       "hoodie.index.type": "BUCKET",
       "hoodie.bucket.index.engine": "SIMPLE",
       "hoodie.bucket.index.hash.field": "order_id",
       "hoodie.bucket.index.num.buckets": "8"
   }
   
   df.write.format("hudi").options(**hudi_options).mode("overwrite").save(base_path)
   
   result_df = spark.read.format("hudi").load(base_path)
   result_df.show(truncate=False)
   
   +-------------------+--------------------+------------------+----------------------+-----------------+--------+-----------+------+----------+
   |_hoodie_commit_time|_hoodie_commit_seqno|_hoodie_record_key|_hoodie_partition_path|_hoodie_file_name|order_id|customer_id|amount|order_date|
   +-------------------+--------------------+------------------+----------------------+-----------------+--------+-----------+------+----------+
   +-------------------+--------------------+------------------+----------------------+-----------------+--------+-----------+------+----------+
   ```


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@hudi.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org