Skip to content

Commit 2320318

Browse files
committed
fix: make ExtDestGeCopy EXECUTE clause sh-compatible
The EXECUTE clause for CREATE EXTERNAL WEB TABLE in the ExtDestGeCopy strategy used bash-specific array syntax (`SEGMENTS=(...)` and `"${SEGMENTS[@]}"`) to determine if a segment should run cbcopy_helper. This caused a `sh: 1: Syntax error: "(" unexpected` error when the database, which often uses `sh`, tried to execute the command. This commit refactors the shell script within the EXECUTE clause: - Replaces bash array initialization with a space-separated string variable `SRC_SEG_IDS_STR`. - Uses a `sh`-compatible `for` loop to iterate over `SRC_SEG_IDS_STR`. - Employs standard string comparison `[ "$cur_id" = "$GP_SEGMENT_ID" ]` to check for matching segment IDs. This change ensures the external table command is compatible with `sh` and prevents the previously observed syntax error, allowing data copy to proceed correctly when the ExtDestGeCopy strategy is used.
1 parent 7005ef2 commit 2320318

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

copy/copy_command.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,7 @@ func (edgc *ExtDestGeCopy) CopyFrom(conn *dbconn.DBConn, ctx context.Context, ta
353353
extTabName := "cbcopy_ext_" + strings.Replace(uuid.NewV4().String(), "-", "", -1)
354354
ids := edgc.FormAllSegsIds()
355355

356-
query := fmt.Sprintf(`CREATE EXTERNAL WEB TEMP TABLE %v (like %v.%v) EXECUTE 'MATCHED=0; SEGMENTS=(%v); for i in "${SEGMENTS[@]}"; do [ $i = "$GP_SEGMENT_ID" ] && MATCHED=1; done; [ $MATCHED != 1 ] && exit 0 || cbcopy_helper %v --listen --seg-id $GP_SEGMENT_ID --cmd-id %s --data-port-range %v' FORMAT 'csv'`,
356+
query := fmt.Sprintf(`CREATE EXTERNAL WEB TEMP TABLE %v (like %v.%v) EXECUTE 'MATCHED="0"; SRC_SEG_IDS_STR="%v"; for cur_id in $SRC_SEG_IDS_STR; do if [ "$cur_id" = "$GP_SEGMENT_ID" ]; then MATCHED="1"; break; fi; done; [ "$MATCHED" != "1" ] && exit 0 || cbcopy_helper %v --listen --seg-id $GP_SEGMENT_ID --cmd-id %s --data-port-range %v' FORMAT 'csv'`,
357357
extTabName, table.Schema, table.Name, ids, edgc.CompArg, cmdId, dataPortRange)
358358

359359
if err := edgc.CommitBegin(conn); err != nil {

0 commit comments

Comments
 (0)