Skip to content

Commit

Permalink
Quote watermark table in QRep UI (#723)
Browse files Browse the repository at this point in the history
Co-authored-by: Kaushik Iska <[email protected]>
  • Loading branch information
Amogh-Bharadwaj and iskakaushik authored Nov 27, 2023
1 parent c8afa19 commit 91f7687
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 8 deletions.
13 changes: 12 additions & 1 deletion ui/app/mirrors/create/handlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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;
}
Expand Down
33 changes: 26 additions & 7 deletions ui/app/mirrors/create/qrep/qrep.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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 }));
Expand Down Expand Up @@ -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<HTMLInputElement>) =>
Expand Down

0 comments on commit 91f7687

Please sign in to comment.