generate_tfl
Generate a Tableau Prep data flow (.tfl/.tflx) file from a declarative flow definition.
Args: flow_name: Display name for the flow in Tableau Prep. connection: Connection settings. Must include a "type" key: For type="database": Required keys: host. Conditionally required: username (required for mysql/postgres, optional for sqlserver with sspi authentication), dbname (required for mysql/postgres, often empty at connection-level for sqlserver). Optional keys: port (default depends on db_class), db_class ("mysql"|"sqlserver"|"postgres"|"adb_mysql", default "mysql"), authentication ("sspi"|"sqlserver"|"", default ""), schema (e.g. "dbo" for SQL Server input_table nodes). For type="file": No additional keys needed at this level. File connections are created automatically from input_excel/input_csv nodes. nodes: Ordered list of node definitions. Each node is a dict with a "type" key and a "name" key (used to reference this node from downstream nodes). Additional keys depend on the node type:
- input_sql: sql (str)
- input_table: table (str)
- input_excel: filename, sheet (str), fields? (list)
- input_csv: filename, fields? (list), separator?, locale?, charset?, contains_headers?
- input_csv_union: file_names (list of str), fields? (list), separator?, locale?, charset?, contains_headers?
- join: left, right (node names), left_col, right_col, join_type?
- union: parents (list of node names)
- filter: parent (node name), expression (str)
- value_filter: parent, field, values (list), exclude? (bool)
- calculation: parent, column_name, formula
- aggregate: parent, group_by (list), aggregations? (list of {field, function, output_name?})
- keep_only: parent, columns (list)
- remove_columns: parent, columns (list)
- rename: parent, renames ({old: new})
- pivot: parent, pivot_column, aggregate_column, new_columns, group_by?, aggregation?
- unpivot: parent, columns_to_unpivot, name_column?, value_column?
- quick_calc: parent, column_name, calc_type (lowercase|uppercase|titlecase|trim_spaces|remove_extra_spaces|remove_all_spaces|remove_letters|remove_punctuation)
- change_type: parent, fields ({column: target_type})
- duplicate_column: parent, source_column, new_column_name?
- output_server: parent, datasource_name, project_name?, server_url? output_path: File path for the generated flow file. Use .tfl extension for standard flows. Use .tflx extension for packaged flows with embedded data files. data_files: Optional dict mapping filenames to list of absolute source file paths. Required when output_path ends with .tflx. Example: {"orders.xlsx": ["C:/data/orders.xlsx"]}
Returns: A summary string with the output file path and node count.