From 91f7687d84b72b74f15fb8c09e4b00d664c65f18 Mon Sep 17 00:00:00 2001 From: Amogh Bharadwaj Date: Mon, 27 Nov 2023 23:18:35 +0530 Subject: [PATCH] Quote watermark table in QRep UI (#723) Co-authored-by: Kaushik Iska --- ui/app/mirrors/create/handlers.ts | 13 +++++++++++- ui/app/mirrors/create/qrep/qrep.tsx | 33 +++++++++++++++++++++++------ 2 files changed, 38 insertions(+), 8 deletions(-) diff --git a/ui/app/mirrors/create/handlers.ts b/ui/app/mirrors/create/handlers.ts index 3f90b37297..f65ecc8fd8 100644 --- a/ui/app/mirrors/create/handlers.ts +++ b/ui/app/mirrors/create/handlers.ts @@ -187,6 +187,15 @@ export const handleCreateCDC = async ( setLoading(false); }; +const quotedWatermarkTable = (watermarkTable: string): string => { + if (watermarkTable.includes('.')) { + const [schema, table] = watermarkTable.split('.'); + return `"${schema}"."${table}"`; + } else { + return `"${watermarkTable}"`; + } +}; + export const handleCreateQRep = async ( flowJobName: string, query: string, @@ -210,7 +219,9 @@ export const handleCreateQRep = async ( if (xmin == true) { config.watermarkColumn = 'xmin'; - config.query = `SELECT * FROM ${config.watermarkTable} WHERE xmin::text::bigint BETWEEN {{.start}} AND {{.end}}`; + config.query = `SELECT * FROM ${quotedWatermarkTable( + config.watermarkTable + )} WHERE xmin::text::bigint BETWEEN {{.start}} AND {{.end}}`; query = config.query; config.initialCopyOnly = false; } diff --git a/ui/app/mirrors/create/qrep/qrep.tsx b/ui/app/mirrors/create/qrep/qrep.tsx index 993e7bc1aa..6b5b7b4b35 100644 --- a/ui/app/mirrors/create/qrep/qrep.tsx +++ b/ui/app/mirrors/create/qrep/qrep.tsx @@ -114,7 +114,17 @@ export default function QRepConfigForm({ ) => { if (val) { if (setting.label === 'Table') { - setter((curr) => ({ ...curr, destinationTableIdentifier: val })); + if (mirrorConfig.destinationPeer?.type === DBType.BIGQUERY) { + setter((curr) => ({ + ...curr, + destinationTableIdentifier: val.split('.')[1], + })); + } else { + setter((curr) => ({ + ...curr, + destinationTableIdentifier: val, + })); + } loadColumnOptions(val); } handleChange(val, setting); @@ -127,6 +137,20 @@ export default function QRepConfigForm({ ); }, [mirrorConfig.sourcePeer]); + useEffect(() => { + if (mirrorConfig.destinationPeer?.type === DBType.BIGQUERY) { + setter((curr) => ({ + ...curr, + destinationTableIdentifier: mirrorConfig.watermarkTable?.split('.')[1], + })); + } else { + setter((curr) => ({ + ...curr, + destinationTableIdentifier: mirrorConfig.watermarkTable, + })); + } + }, [mirrorConfig.destinationPeer, mirrorConfig.watermarkTable, setter]); + useEffect(() => { // set defaults setter((curr) => ({ ...curr, ...blankQRepSetting })); @@ -255,12 +279,7 @@ export default function QRepConfigForm({ type={setting.type} defaultValue={ setting.label === 'Destination Table Name' - ? mirrorConfig.destinationPeer?.type === - DBType.BIGQUERY - ? mirrorConfig.destinationTableIdentifier?.split( - '.' - )[1] - : mirrorConfig.destinationTableIdentifier + ? mirrorConfig.destinationTableIdentifier : setting.default } onChange={(e: React.ChangeEvent) =>