TODAY() Function in Foundry Fusion Sheets

310 Views Asked by At

I am pretty new to Fusion Sheets and want to prepare some data. As it seems, there is no TODAY() function existing as far as I could tell. So I was thinking of creating a custom function in order to do so. But the documentation is not giving any guidance of which kind of coding language to be used. Or at least I did not find anything.

I would be very thankful if any of you could give a hint on how to get the today date or how to write a custom function.

Thanks again!

1

There are 1 best solutions below

0
On

One way to do this would be to create a dataset built on a schedule each day that just returns the current date, e.g.:

from pyspark.sql import types as T
from transforms.api import transform_df, Output
from datetime import datetime


@transform_df(Output("/path/to/your/today/dataset"))
def compute(ctx):
    return ctx.spark_session.createDataFrame(
        [[datetime.now()]],
        T.StructType([T.StructField("today", T.DateType())])
    )

Then you can import this in Fusion by adding it to the index and using the lookup function:

=lookup('/path/to/your/today/dataset', 'today')