diff --git a/flow/connectors/clickhouse/normalize.go b/flow/connectors/clickhouse/normalize.go index fcd510fb11..5f6344e372 100644 --- a/flow/connectors/clickhouse/normalize.go +++ b/flow/connectors/clickhouse/normalize.go @@ -133,11 +133,15 @@ func generateCreateTableSQLForNormalizedTable( } if colType == qvalue.QValueKindNumeric { - precision, scale := datatypes.GetNumericTypeForWarehouse(column.TypeModifier, datatypes.ClickHouseNumericCompatibility{}) - if column.Nullable { - stmtBuilder.WriteString(fmt.Sprintf("`%s` Nullable(DECIMAL(%d, %d)), ", dstColName, precision, scale)) + if clickhouseType != "" && clickhouseType != "Decimal128(9)" { + stmtBuilder.WriteString(fmt.Sprintf("`%s` %s, ", dstColName, clickhouseType)) } else { - stmtBuilder.WriteString(fmt.Sprintf("`%s` DECIMAL(%d, %d), ", dstColName, precision, scale)) + precision, scale := datatypes.GetNumericTypeForWarehouse(column.TypeModifier, datatypes.ClickHouseNumericCompatibility{}) + if column.Nullable { + stmtBuilder.WriteString(fmt.Sprintf("`%s` Nullable(DECIMAL(%d, %d)), ", dstColName, precision, scale)) + } else { + stmtBuilder.WriteString(fmt.Sprintf("`%s` DECIMAL(%d, %d), ", dstColName, precision, scale)) + } } } else if tableSchema.NullableEnabled && column.Nullable && !colType.IsArray() { stmtBuilder.WriteString(fmt.Sprintf("`%s` Nullable(%s), ", dstColName, clickhouseType)) diff --git a/ui/app/mirrors/create/cdc/columnbox.tsx b/ui/app/mirrors/create/cdc/columnbox.tsx index de5bee3008..8bff96d66d 100644 --- a/ui/app/mirrors/create/cdc/columnbox.tsx +++ b/ui/app/mirrors/create/cdc/columnbox.tsx @@ -1,25 +1,29 @@ 'use client'; import { TableMapRow } from '@/app/dto/MirrorsDTO'; +import { Button } from '@/lib/Button'; import { Checkbox } from '@/lib/Checkbox'; +import { Icon } from '@/lib/Icon'; import { Label } from '@/lib/Label'; import { RowWithCheckbox } from '@/lib/Layout'; import { TextField } from '@/lib/TextField'; -import { Dispatch, SetStateAction } from 'react'; +import { Divider } from '@tremor/react'; +import { Dispatch, SetStateAction, useState } from 'react'; interface ColumnProps { - columns: string[]; + column: string; tableRow: TableMapRow; rows: TableMapRow[]; setRows: Dispatch>; - showOrdering: boolean; + showColumnSettings: boolean; } export default function ColumnBox({ - columns, + column, tableRow, rows, setRows, - showOrdering, + showColumnSettings, }: ColumnProps) { + const [show, setShow] = useState(false); const handleColumnExclusion = (column: string, include: boolean) => { const source = tableRow.source; const currRows = [...rows]; @@ -65,35 +69,119 @@ export default function ColumnBox({ } }; - return columns.map((column) => { - const [columnName, columnType, isPkeyStr] = column.split(':'); - const isPkey = isPkeyStr === 'true'; - return ( - { + const source = tableRow.source; + const currRows = [...rows]; + const rowIndex = currRows.findIndex((row) => row.source === source); + if (rowIndex !== -1) { + const sourceRow = currRows[rowIndex]; + const columns = [...sourceRow.columns]; + const colIndex = columns.findIndex((col) => col.sourceName === column); + if (colIndex !== -1) { + columns[colIndex] = { + ...columns[colIndex], + destinationType: type, + }; + } else { + columns.push({ + sourceName: column, + destinationName: '', + destinationType: type, + ordering: 0, + }); + } + currRows[rowIndex] = { + ...sourceRow, + columns, + }; + setRows(currRows); + } + }; + + const [columnName, columnType, isPkeyStr] = column?.split(':'); + const isPkey = isPkeyStr === 'true'; + return ( +
+
+ + {columnName} +

+ {columnType} +

+ + } + action={ + + handleColumnExclusion(columnName, state) + } + /> + } + /> + {showColumnSettings && ( + + )} +
+ {show && showColumnSettings && ( +
+ {!isPkey && ( +
- {columnType} -

- {showOrdering && !isPkey && ( +
+

Ordering

+
col.sourceName === columnName) ?.ordering ?? 0 @@ -102,20 +190,43 @@ export default function ColumnBox({ handleColumnOrdering(columnName, +e.target.value) } /> - )} - - } - action={ - - handleColumnExclusion(columnName, state) - } - /> - } - /> - ); - }); +
+ )} + +
+
+

+ Custom column type +

+
+ + col.sourceName === columnName) + ?.destinationType ?? '' + } + onChange={(e: React.ChangeEvent) => + handleColumnTypeChange(columnName, e.target.value) + } + /> +
+ +
+ )} +
+ ); } diff --git a/ui/app/mirrors/create/cdc/schemabox.tsx b/ui/app/mirrors/create/cdc/schemabox.tsx index 18fe14405f..1c8a0a0ef4 100644 --- a/ui/app/mirrors/create/cdc/schemabox.tsx +++ b/ui/app/mirrors/create/cdc/schemabox.tsx @@ -377,16 +377,22 @@ export default function SchemaBox({ Columns {columns ? ( - + columns.map( + (column) => + column != '' && ( + + ) + ) ) : columnsLoading ? ( ) : (