I have a very simple task of updating contents of a control file in Palantir Foundry. I need to read the contents of the file, perform a check and then write back to the same file. However, if I provide the same file as Input and Output in the transform, I get the following error -
Cyclic dependency exists in the code for the following Foundry datasets:...
Is there a workaround for this?
Updated question with more details and code snippet as per suggestion below
I have a requirement to append the contents of a transaction file to an incremental snapshot file, and this process is supposed to run once daily. However, if the process runs more than once in a day (inadvertently or restarting after a failure etc), I need to ensure that the same records are not appended again. So, I am trying to use the following piece of code (as advised in the documentation).
@incremental()
@transform(
inp=Input("<path>/daily_trans_file"),
op=Output("<path>/hist_snapshot_file")
)
def my_compute_function(inp, op):
# Calculates today's date and adds it to the daily transactional data
proc_date = (datetime.today()).strftime("%Y-%m-%d")
inp_df = inp.dataframe()
inp_df = inp_df.withColumn("Processed_Date", lit(proc_date))
# Appends the above dataframe to the end of the op file if it is not already present
op.write_dataframe(
inp_df.subtract(
op.dataframe('previous', schema=inp_df.schema)))
However, there seems to be some problem with this. The file just retains the data that was originally there and does not append any new data. Not sure why the subtract is not working as it should have been. I checked the documentation example and there is no need to set any other mode in this case.