Posts

Showing posts from May, 2023

Add new column with existing partition table

 Use Alter command to add new column with CASCADE. (1) alter table `db_name`.`table_name` add columns(flag string) CASCADE; (2)  Please assign database name to both source and target tables to sync metastore with DB. (3) Add column in schema with partition table. (4) Then execute below Hive recipe. insert overwrite table `db_name`.`emp_part1` partition(job) SELECT  `empno` ,`ename` ,`hiredate` ,`salary` ,`deptno` ,flag ,`job`   FROM `prd_tbl_uacolob_hk_nsen`.`Emp_3`

Automate to read files in scenario

 import os import dataiku import sys import time client = dataiku.api_client() project = client.get_project('project_id') try:          if len(os.listdir('/path/incoming'))==12:         scenario = project.get_scenario('Scenario_ID')         scenario.run_and_wait() except:     sys.exit(0)

Read sas file in python

Global Variables: {   "v_filename": "sas1234",   "v_file": "sas1234.sas7bdat",   "v_path": "/path_smptp/",   "v_file_date": "202301" }   Scenario (Python code) : import os import dataiku import sys import time import glob client = dataiku.api_client() project = client.get_project('MIGRATION') scenario = project.get_scenario("MIgration_FILES") os.chdir('/smtp_path') filepath='/smtp_path/' for file in (glob.glob('*.sas7bdat')):     #file='sas1234.sas7bdat'     filenm=file.split('.')[0]     partdt=filenm.split('_')[-1:][0]     filenm=filenm.replace('_'+partdt,'').strip()          project_variables = project.get_variables()     project_variables['standard']['v_filename']=filenm     project_variables['standard']['v_file']=file     project_variables['standard']['v_path']=filepath     p...

Remove special characters from column header of dataframe

 import dataiku import pandas as pd d_dataset=dataset("abc") d_df=d_dataset.get_dataframe() d_df.columns = d_df.columns .str.replace("[$_() ]".'') df_output=dataiku.Dataset("df_output") df_output=write_with_schema(df_output) Note:- Dataframe name should be same when you apply replace function as amrked in yellow.