Posts

Showing posts from July, 2023

Define variable in scenario

 If you want to declare variables in dataiku in scenario and access them in project. There is sequence in dataiku to declare variable. (1) Define variable :- Where you can build logic or condition to create variable       Example                   v1=100 (2) Set project variable steps:  Assign v1 to another variable v2.       example :                 v2-v1 (3) Execute and check v2 will automatically define Global variables.            If you want to take already define variable in Global variable and take as parameter in "Define variable"  var1  ----> variables["dt_param"] (4)  If you have specific date and you want to get other date bases on on your given date in scenario then "Go to - Define Variable " create variable and use below code var1-> inc(asDate(variables["dt_param"],'yyyy-MM-dd'),toNumber(co...

Last month date of previous month

Case 1  If  you have any date and you want to calculate last month date of previous month in data dataiku function then use "inc" and "datePart" function. inc(dt,toNumber(concat('-',datePart(dt,'Day'))),'day')  Example : Parameter date - 2023-06-26 Result :-  2023-05-31 Case 2 If you have specific date and you want to get  last month date of  previous months or 2 previous month data then use below code inc(inc(asDate("2023-06-26","yyyy-MM-dd"),toNumber(concat('-',datePart(asDate("2023-06-26","yyyy-MM-dd"),'Day'))),'day'),-1,'months') Example : Parameter date - 2023-06-26 Result :-  2023-04-30

Exponential Value parsing in SQL

 If you have exponential value in you column and and you want to concert into number or string then please use below function. Cast the value in double ( in some sql  double is not supported then please try with float) but if the  length  is higher like Bigint or Long Int the use double. Use format_number function  to convert exponential value to normal number. with precision. Cast again to convert into string to remove precision value. Use replace function to remove comma(',')  between string .     Problem: col -  5.498342022637685E15 Solution: SELECT  replace(cast(format_number(cast(col_name as double),0) as string),',','') as alias   from table_name    Result :- 5498342022637680

Dataiku and Dremio date difference

In dataiku you have applied to_date function to convert string to date datatype in SparkSQL and when query same dataset in dremio then you will difference of 1 day. Example -  In dataiku      SELECT  offer_date  FROM temp      Result :      2023-05-18T00:00:00.000Z Dremio :     SELECT  offer_date  FROM temp Result :      2023-05-17 08:00:00.000 Now you will find the difference of  1 day and 8 hours (sometime 16 hours)  between Dataiku and Dremio. Solutions:       This difference is due to time difference. In Dataiku we have  correct date to correct it Dremio please use TO_TIMESTAMP function to get correct date. Example : select TO_TIMESTAMP(offer_date, 'yyyy-mm-dd' ) as offer_date from temp