You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hudi.apache.org by GitBox <gi...@apache.org> on 2021/05/21 06:46:48 UTC

[GitHub] [hudi] calleo opened a new issue #2975: [SUPPORT]

calleo opened a new issue #2975:
URL: https://github.com/apache/hudi/issues/2975


   **Describe the problem you faced**
   
   I would like to read records from a Hudi table using the record key, to avoid having to scan the entire table. 
   
   I've read through the examples on how to query a Hudi table and the Spark Datasource mentions `read(keys)` but it's very unclear on how to apply this when using PySpark.
   
   What I am doing is reading data from a source table (non hudi), then transforming it and writing it to a target Hudi table. Sometimes this involves updating existing records in the target, but the merge logic is less than trivial. So the approach I am taking is:
   
   1. Read new rows from source => df1
   2. Read rows to be updated from target (this is where reading by record key would help) => df2
   3. Union df1 & df2, transform the data => transformed_df
   4. Upsert target using transformed_df
   
   **Expected behavior**
   
   Read from Hudi table using record keys.
   
   **Environment Description**
   
   * Hudi version : 0.5.3
   
   * Spark version : 2.4.3 (using AWS Glue 2.0, PySpark)
   
   * Hive version : AWS Glue Catalog
   
   * Hadoop version :
   
   * Storage (HDFS/S3/GCS..) :
   
   * Running on Docker? (yes/no) : 
   
   
   


-- 
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.

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



[GitHub] [hudi] n3nash commented on issue #2975: [SUPPORT] Read record using index

Posted by GitBox <gi...@apache.org>.
n3nash commented on issue #2975:
URL: https://github.com/apache/hudi/issues/2975#issuecomment-847407792


   @calleo Hudi allows you to write custom merge logic at a record level so you don't have to read the target table. Instead, you can just provide the input from the source non-hudi table, define your merge logic and let Hudi ensure to merge the incoming and on-disk data using the logic you have defined.
   
   One way to do this is to implement the [HoodieRecordPayload](https://github.com/apache/hudi/blob/master/hudi-common/src/main/java/org/apache/hudi/common/model/HoodieRecordPayload.java) in scala or java and combine it with the bundle hudi jars or drop this in with your spark classpath. 
   
   You will also need to set this as the custom merge logic class here -> https://github.com/apache/hudi/blob/master/hudi-client/hudi-client-common/src/main/java/org/apache/hudi/config/HoodieCompactionConfig.java#L100


-- 
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.

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



[GitHub] [hudi] n3nash commented on issue #2975: [SUPPORT] Read record using index

Posted by GitBox <gi...@apache.org>.
n3nash commented on issue #2975:
URL: https://github.com/apache/hudi/issues/2975#issuecomment-851718880


   This is being tracked in this JIRA -> https://issues.apache.org/jira/browse/HUDI-1936


-- 
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.

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



[GitHub] [hudi] n3nash closed issue #2975: [SUPPORT] Read record using index

Posted by GitBox <gi...@apache.org>.
n3nash closed issue #2975:
URL: https://github.com/apache/hudi/issues/2975


   


-- 
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.

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



[GitHub] [hudi] calleo commented on issue #2975: [SUPPORT] Read record using index

Posted by GitBox <gi...@apache.org>.
calleo commented on issue #2975:
URL: https://github.com/apache/hudi/issues/2975#issuecomment-860014912


   Will give this a try. Thanks all for helping out.


-- 
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.

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



[GitHub] [hudi] fanaticjo commented on issue #2975: [SUPPORT] Read record using index

Posted by GitBox <gi...@apache.org>.
fanaticjo commented on issue #2975:
URL: https://github.com/apache/hudi/issues/2975#issuecomment-850544149


   Hello @calleo   i am trying to make this as a generic release in version 0.9.0 , till the time being you can clone this git hub repo - https://github.com/fanaticjo/HudiJavaCustomUpsert/tree/master/src/main/java/com create a jar out of it and load this as a dependent jar with hudi and avro jar for your pysaprk . 
   
   In your pyspark code you can add this 2 options 
   "hoodie.update.keys": "admission_date,name",   #columns you want to update 
   "hoodie.datasource.write.payload.class": "com.hudiUpsert.hudiCustomUpsert",  #custom jar 
   
   Sample piece which is working for me 
   hudi_update_options_with_key = {
       'hoodie.table.name': "test",
       'hoodie.datasource.write.recordkey.field': 'id',
       'hoodie.datasource.write.partitionpath.field': 'dept',
       'hoodie.datasource.write.table.name': "test",
       "hoodie.index.type": "SIMPLE",
       "hoodie.update.keys": "admission_date,name",
       "hoodie.datasource.write.payload.class": "com.hudiUpsert.hudiCustomUpsert",
       'hoodie.datasource.write.operation': 'upsert',
       'hoodie.datasource.write.precombine.field': 'date',
       'hoodie.upsert.shuffle.parallelism': 2,
       'hoodie.insert.shuffle.parallelism': 2
   }
   
   df.write.format("org.apache.hudi").options(**hudi_update_options_with_key).mode("append").save(
       "/Users/biswajit/PycharmProjects/hudicustomupsert/output/")
   
   


-- 
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.

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



[GitHub] [hudi] n3nash commented on issue #2975: [SUPPORT] Read record using index

Posted by GitBox <gi...@apache.org>.
n3nash commented on issue #2975:
URL: https://github.com/apache/hudi/issues/2975#issuecomment-859317683


   Closing since JIRA is filed and no activity on this issue. Please re-open if further assistance is required


-- 
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.

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



[GitHub] [hudi] n3nash commented on issue #2975: [SUPPORT] Read record using index

Posted by GitBox <gi...@apache.org>.
n3nash commented on issue #2975:
URL: https://github.com/apache/hudi/issues/2975#issuecomment-847968028


   @fanaticjo Can you help @calleo since you recently implemented a custom recordpayload while using pyspark ?


-- 
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.

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