Forum Discussion

Jerome22's avatar
Jerome22
Resolver I
1 year ago
Solved

updating records using copy job?

Hi,

 

when Data copy will support updates and not just adding rows?

I have a lot of tables which can have updated records, so I want to update my destination not just adding new rows.

 

thanks.

  • Jerome22's avatar
    Jerome22
    1 year ago

    ok... unfortunately it's not supporting deletes.

    and the update appear to update all the rows matching the ID without option to select a hash or timestamp column.

     

    well... I'll still use SQL statements for now. still faster with more control than relying on external tools like the copy job.

     

11 Replies

  • smeetsh's avatar
    smeetsh
    Continued Contributor

    There is no option for warehouse for this yet, I did see an upsert (preview) button appear on a lakehouse though. The best way for now is to do it using SQL code, whwere you check for an existing record, which you than update (UPDATE TABLE, set column = etc etc ) and when a record does not exist you will do an insert

  • v-sdhruv's avatar
    v-sdhruv
    Community Support

    Hi Jerome22 ,
    Hope you were able to get some clarity on the issue. Let us know if need any help.
    If the response has addressed your query, kindly mark it as accepted solution so that the other members can find it easily.
    Thank you

  • v-sdhruv's avatar
    v-sdhruv
    Community Support

    Hi @Jerome22 ,
    Hope you were able to get some clarity on the issue. 
    If any of the responses has addressed your query, kindly mark it as accepted solution so that the other members can find it easily.
    Thank you

    • Jerome22's avatar
      Jerome22
      Resolver I

      ok... unfortunately it's not supporting deletes.

      and the update appear to update all the rows matching the ID without option to select a hash or timestamp column.

       

      well... I'll still use SQL statements for now. still faster with more control than relying on external tools like the copy job.

       

      • smeetsh's avatar
        smeetsh
        Continued Contributor

        What you could do is incorporate a where statement in the update statement, where you do something like 

        "WHERE hash in (select hash from TABLE) AND time_stamp_column > [your timestamp] 

         

        The above code is rough and probaly has some syntax errors, but I hope you understand the geste of the logic behind it 🙂

        Cheers

        Hans

  • Copy jobs in Data Factory means there is no need for updates. Overwrite where ever possible ( Data Lake and Data Lakehouse )  ( Apache Spark and Delta Lake ) or ( Merge in Microsoft Fabric or 

     

    Incremental Refresh with below code ( Append in Microsoft Fabric )

     

    ### Variables
    LakehouseName = "Demo"
    TableName = "DimTables"
    ColName = "Surrogate_Key_Demo"
    NumberOfRowsToRemove = "10"


    ### Remove Old rows
    Reload = spark.sql("SELECT Max({0})-{1} as ReLoadValue FROM {2}.{3}".format(ColName,NumberOfRowsToRemove,LakehouseName,TableName)).collect()
    Reload = Reload[0].ReLoadValue
    display(Reload)

    ## ColName should be integer at all times to work (Incremental Refresh)
     
    spark.sql("Delete from {0}.{1} where {2} > {3}".format(LakehouseName, TableName, ColName, Reload))
     
    so it means you should always use Notebooks. ( Concept of Data Lake and Data Lakehouse)

     

  • smeetsh's avatar
    smeetsh
    Continued Contributor

    We often do a clear out of tables or certain rows in tables, but we have a few datasets that are so large that is slows things down.
    This can de done with just pipeline activities (copy and script activity), notebooks are not always needed. I would only use a notebook when i need to do something with a lakehouse.

    • BhaveshPatel's avatar
      BhaveshPatel
      Super User

      smeetsh We always have Notebooks. No issues. Instead of Data Factory, Use Notebooks wherever we can. Databricks has implemented Delta Lake and then Microsoft follows Databricks. ( Delta Lake is based on Python and Scala ).

      • smeetsh's avatar
        smeetsh
        Continued Contributor

        I could be wrong here, but I don't think a notebook can write to a warehouse, which for us at least would be the issue and it may be as well for the topic starter