( nodeId: string, textValue: string, inputData: DBTablesNodeData, config?: unknown, )
| 815 | } |
| 816 | |
| 817 | async function executeGroupByColumnsNode( |
| 818 | nodeId: string, |
| 819 | textValue: string, |
| 820 | inputData: DBTablesNodeData, |
| 821 | config?: unknown, |
| 822 | ): Promise<NodeExecutionResult> { |
| 823 | console.log(`GroupByColumns Node ${nodeId}: Processing with textValue:`, textValue); |
| 824 | console.log(`GroupByColumns Node ${nodeId}: Input data:`, inputData); |
| 825 | |
| 826 | if (!inputData || inputData.type !== "TableSelection") { |
| 827 | return { success: false, error: "Invalid input: Expected TableSelection data" }; |
| 828 | } |
| 829 | |
| 830 | // Parse the column selections from textValue |
| 831 | const parsed = getNodeConfig<{ column1?: string; column2?: string; onlyForMultiple?: boolean }>(config, textValue); |
| 832 | if (!parsed) { |
| 833 | return { |
| 834 | success: false, |
| 835 | error: "Invalid column configuration. Expected JSON with column1 and column2 fields.", |
| 836 | }; |
| 837 | } |
| 838 | const column1 = parsed.column1 || ""; |
| 839 | const column2 = parsed.column2 || ""; |
| 840 | const onlyForMultiple = parsed.onlyForMultiple || false; |
| 841 | |
| 842 | if (!column1 || column1.trim() === "" || !column2 || column2.trim() === "") { |
| 843 | return { |
| 844 | success: false, |
| 845 | error: `Both column1 and column2 must be selected. Received: column1="${column1}", column2="${column2}"`, |
| 846 | }; |
| 847 | } |
| 848 | |
| 849 | // Process each table |
| 850 | const groupedData = new Map<string, string[]>(); |
| 851 | |
| 852 | for (const tableData of inputData.tables) { |
| 853 | if ( |
| 854 | !tableData.table.tableSchema || |
| 855 | !tableData.table.schemaFields || |
| 856 | tableData.table.schemaFields.length === 0 |
| 857 | ) { |
| 858 | console.log(`Missing table data, skipping ${tableData.name}!`); |
| 859 | continue; |
| 860 | } |
| 861 | |
| 862 | const rows = getRowsForPackedFile(tableData.table); |
| 863 | |
| 864 | // Find the column indices |
| 865 | const column1Index = getColumnIndexForPackedFile(tableData.table, column1); |
| 866 | const column2Index = getColumnIndexForPackedFile(tableData.table, column2); |
| 867 | |
| 868 | if (column1Index === -1 || column2Index === -1) { |
| 869 | console.warn( |
| 870 | `Columns ${column1} or ${column2} not found in table ${tableData.name}. Skipping this table.`, |
| 871 | ); |
| 872 | continue; |
| 873 | } |
| 874 |
no test coverage detected