Skip to content
Permalink

Comparing changes

This is a direct comparison between two commits made in this repository or its related repositories. View the default comparison for this range or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: ydb-platform/ydbcp
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 3538e352298cee46c02c997077eae887e9de2ed8
Choose a base ref
..
head repository: ydb-platform/ydbcp
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 7cf7d0dc8b7f73f9da24e7ec728a3401e364fd88
Choose a head ref
Showing with 11 additions and 6 deletions.
  1. +7 −2 internal/connectors/db/yql/queries/write.go
  2. +2 −2 internal/connectors/db/yql/queries/write_test.go
  3. +2 −2 internal/connectors/db/yql/schema/fill_tables.yql
9 changes: 7 additions & 2 deletions internal/connectors/db/yql/queries/write.go
Original file line number Diff line number Diff line change
@@ -178,9 +178,14 @@ func (d *WriteTableQueryImpl) FormatQuery(ctx context.Context) (*FormatQueryResu
return nil, errors.New("No table")
}
declares := t.DeclareParameters()
paramNames := t.GetParamNames()
keyParam := fmt.Sprintf("%s = %s", t.upsertFields[0], paramNames[0])
updates := make([]string, 0)
for j := 1; j < len(t.upsertFields); j++ {
updates = append(updates, fmt.Sprintf("%s = %s", t.upsertFields[j], paramNames[j]))
}
queryStrings[i] = fmt.Sprintf(
"%s;\nUPSERT INTO %s (%s) VALUES (%s)", declares, t.tableName, strings.Join(t.upsertFields, ", "),
strings.Join(t.GetParamNames(), ", "),
"%s;\nUPDATE %s SET %s WHERE %s", declares, t.tableName, strings.Join(updates, ", "), keyParam,
)
for _, p := range t.tableQueryParams {
allParams = append(allParams, p)
4 changes: 2 additions & 2 deletions internal/connectors/db/yql/queries/write_test.go
Original file line number Diff line number Diff line change
@@ -13,11 +13,11 @@ func TestQueryBuilder_Write(t *testing.T) {
const (
queryString = `DECLARE $id_0 AS Uuid;
DECLARE $status_0 AS String;
UPSERT INTO Backups (id, status) VALUES ($id_0, $status_0);
UPDATE Backups SET status = $status_0 WHERE id = $id_0;
DECLARE $id_1 AS Uuid;
DECLARE $status_1 AS String;
DECLARE $message_1 AS String;
UPSERT INTO Operations (id, status, message) VALUES ($id_1, $status_1, $message_1)`
UPDATE Operations SET status = $status_1, message = $message_1 WHERE id = $id_1`
)
opId := types.GenerateObjectID()
backupId := types.GenerateObjectID()
4 changes: 2 additions & 2 deletions internal/connectors/db/yql/schema/fill_tables.yql
Original file line number Diff line number Diff line change
@@ -7,5 +7,5 @@ UPSERT INTO `OperationTypes` (code, description, is_cancellable) VALUES
UPSERT INTO `Backups` (id, container_id, database, status) VALUES
(Uuid('12345678-1234-5678-1234-567812345678'), '', '', 'PENDING');

UPSERT INTO `Operations` (id, container_id, database, type, status, operation_id, backup_id) VALUES
(Uuid('11111111-1111-1111-1111-111111111111'), '', '', 'TB', 'DONE', '', Uuid('11111111-1111-1111-1111-111111111112'));
UPSERT INTO `Operations` (id, container_id, database, type, status, operation_id, backup_id, created_at) VALUES
(Uuid('11111111-1111-1111-1111-111111111111'), '', '', 'TB', 'DONE', '', Uuid('11111111-1111-1111-1111-111111111112'), CurrentUtcTimestamp());